make test/install
This commit is contained in:
parent
e45ad068fb
commit
2c1d5332be
20
Makefile
20
Makefile
@ -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})
|
||||
@ -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
|
||||
@ -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
|
||||
@ -48,10 +43,7 @@ test_tutorial:
|
||||
bash $$script ; \
|
||||
done
|
||||
|
||||
test_store:
|
||||
@go test store/*.go
|
||||
|
||||
get_vendor_deps: tools
|
||||
get_vendor_deps: get_tools
|
||||
@glide install
|
||||
|
||||
build-docker:
|
||||
@ -59,7 +51,7 @@ build-docker:
|
||||
"/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:
|
||||
|
||||
@ -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{}
|
||||
})
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -2,8 +2,12 @@ package types
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
// Coin hold some amount of one currency
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -1,66 +0,0 @@
|
||||
package coin
|
||||
|
||||
import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var (
|
||||
// Denominations can be 3 ~ 16 characters long.
|
||||
rDnm = `[[:alpha:]][[:alnum:]]{2,15}`
|
||||
rAmt = `[[:digit:]]+`
|
||||
rSpc = `[[:space:]]*`
|
||||
reCoin_ = fmt.Sprintf(`^(%s)%s(%s)$`, reDenom_, re_, reAmt_)
|
||||
)
|
||||
|
||||
// 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
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user