Skip to content

Commit

Permalink
make test/install
Browse files Browse the repository at this point in the history
  • Loading branch information
ebuchman committed Jan 6, 2018
1 parent e45ad06 commit 2c1d533
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 94 deletions.
20 changes: 6 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ GOTOOLS = github.com/mitchellh/gox \
github.com/rigelrozanski/shelldown/cmd/shelldown
TUTORIALS=$(shell find docs/guide -name "*md" -type f)

# EXAMPLES := counter eyes basecoin
EXAMPLES := eyes
EXAMPLES := dummy basecoin

INSTALL_EXAMPLES := $(addprefix install_,${EXAMPLES})
TEST_EXAMPLES := $(addprefix testex_,${EXAMPLES})
Expand All @@ -13,17 +12,13 @@ LINKER_FLAGS:="-X github.com/cosmos/cosmos-sdk/client/commands.CommitHash=`git r

all: get_vendor_deps install test

build:
@go build ./cmd/...

$(INSTALL_EXAMPLES): install_%:
cd ./examples/$* && make install
cd ./examples/$* && go install

$(TEST_EXAMPLES): testex_%:
cd ./examples/$* && make test_cli

install: $(INSTALL_EXAMPLES)
@go install -ldflags $(LINKER_FLAGS) ./cmd/...

dist:
@bash publish/dist.sh
Expand All @@ -33,10 +28,10 @@ benchmark:
@go test -bench=. ./modules/...

#test: test_unit test_cli test_tutorial
test: test_unit test_cli
test: test_unit # test_cli

test_unit:
@go test `glide novendor | grep -v _attic | grep -v examples`
@go test `glide novendor | grep -v _attic`

test_cli: $(TEST_EXAMPLES)
# sudo apt-get install jq
Expand All @@ -48,18 +43,15 @@ test_tutorial:
bash $$script ; \
done

test_store:
@go test store/*.go

get_vendor_deps: tools
get_vendor_deps: get_tools
@glide install

build-docker:
@docker run -it --rm -v "$(PWD):/go/src/github.com/tendermint/basecoin" -w \
"/go/src/github.com/tendermint/basecoin" -e "CGO_ENABLED=0" golang:alpine go build ./cmd/basecoin
@docker build -t "tendermint/basecoin" .

tools:
get_tools:
@go get $(GOTOOLS)

clean:
Expand Down
33 changes: 20 additions & 13 deletions app/app_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,31 @@ import (
dbm "github.com/tendermint/tmlibs/db"
)

func TestBasic(t *testing.T) {
// A mock transaction to update a validator's voting power.
type testTx struct {
Addr []byte
NewPower int64
}

// A mock transaction to update a validator's voting power.
type testTx struct {
Addr []byte
NewPower int64
}
func (tx testTx) Get(key interface{}) (value interface{}) { return nil }
func (tx testTx) SignBytes() []byte { return nil }
func (tx testTx) ValidateBasic() error { return nil }
func (tx testTx) Signers() []types.Address { return nil }
func (tx testTx) TxBytes() []byte { return nil }
func (tx testTx) Signatures() []types.StdSignature { return nil }

func TestBasic(t *testing.T) {

// Create app.
app := NewApp(t.Name())
app.SetCommitMultiStore(newCommitMultiStore())
app.SetHandler(func(ctx types.Context, store types.MultiStore, tx types.Tx) types.Result {

// This could be a decorator.
app.SetTxParser(func(txBytes []byte) (types.Tx, error) {
var ttx testTx
fromJSON(ctx.TxBytes(), &ttx)

// XXX
fromJSON(txBytes, &ttx)
return ttx, nil
})
app.SetHandler(func(ctx types.Context, store types.MultiStore, tx types.Tx) types.Result {
// TODO
return types.Result{}
})

Expand Down Expand Up @@ -152,7 +159,7 @@ func fromJSON(bz []byte, ptr interface{}) {
func newCommitMultiStore() types.CommitMultiStore {
dbMain := dbm.NewMemDB()
dbXtra := dbm.NewMemDB()
ms := store.NewMultiStore(dbMain) // Also store rootMultiStore metadata here (it shouldn't clash)
ms := store.NewCommitMultiStore(dbMain) // Also store rootMultiStore metadata here (it shouldn't clash)
ms.SetSubstoreLoader("main", store.NewIAVLStoreLoader(dbMain, 0, 0))
ms.SetSubstoreLoader("xtra", store.NewIAVLStoreLoader(dbXtra, 0, 0))
return ms
Expand Down
2 changes: 1 addition & 1 deletion store/rootmultistore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ func TestMultistoreCommitLoad(t *testing.T) {
// utils

func newMultiStoreWithLoaders(db dbm.DB) *rootMultiStore {
store := NewMultiStore(db)
store := NewCommitMultiStore(db)
storeLoaders := map[string]CommitStoreLoader{
"store1": newMockCommitStore,
"store2": newMockCommitStore,
Expand Down
64 changes: 64 additions & 0 deletions types/coin.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ package types

import (
"fmt"
"regexp"
"sort"
"strconv"
"strings"

"github.com/pkg/errors"
)

// Coin hold some amount of one currency
Expand Down Expand Up @@ -205,3 +209,63 @@ type Coinser interface {
GetCoins() Coins
SetCoins(Coins)
}

//----------------------------------------
// Parsing

var (
// Denominations can be 3 ~ 16 characters long.
reDnm = `[[:alpha:]][[:alnum:]]{2,15}`
reAmt = `[[:digit:]]+`
reSpc = `[[:space:]]*`
reCoin = regexp.MustCompile(fmt.Sprintf(`^(%s)%s(%s)$`, reAmt, reSpc, reDnm))
)

// ParseCoin parses a cli input for one coin type, returning errors if invalid.
// This returns an error on an empty string as well.
func ParseCoin(coinStr string) (coin Coin, err error) {
coinStr = strings.TrimSpace(coinStr)

matches := reCoin.FindStringSubmatch(coinStr)
if matches == nil {
err = errors.Errorf("Invalid coin expression: %s", coinStr)
return
}
denomStr, amountStr := matches[2], matches[1]

amount, err := strconv.Atoi(amountStr)
if err != nil {
return
}

return Coin{denomStr, int64(amount)}, nil
}

// ParseCoins will parse out a list of coins separated by commas.
// If nothing is provided, it returns nil Coins.
// Returned coins are sorted.
func ParseCoins(coinsStr string) (coins Coins, err error) {
coinsStr = strings.TrimSpace(coinsStr)
if len(coinsStr) == 0 {
return nil, nil
}

coinStrs := strings.Split(coinsStr, ",")
for _, coinStr := range coinStrs {
coin, err := ParseCoin(coinStr)
if err != nil {
return nil, err
}
coins = append(coins, coin)
}

// Sort coins for determinism.
coins.Sort()

// Validate coins before returning.
if !coins.IsValid() {
return nil, errors.Errorf("ParseCoins invalid: %#v", coins)
}

return coins, nil
}
66 changes: 0 additions & 66 deletions x/coinstore/_attic/utils.go

This file was deleted.

0 comments on commit 2c1d533

Please sign in to comment.