From 9b206153e279feca2aebb8045af37a430c4656f7 Mon Sep 17 00:00:00 2001 From: Ethan Frey Date: Mon, 16 Oct 2017 19:58:12 +0200 Subject: [PATCH] Eyes takes init state, fix cli test about genesis --- examples/basecoin/cmd/basecoin/main.go | 3 +++ examples/basecoin/tests/cli/init-server.sh | 6 +++--- modules/eyes/handler.go | 15 +++++++++++++-- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/examples/basecoin/cmd/basecoin/main.go b/examples/basecoin/cmd/basecoin/main.go index 2a96f76bd1..af31e2fe80 100644 --- a/examples/basecoin/cmd/basecoin/main.go +++ b/examples/basecoin/cmd/basecoin/main.go @@ -11,6 +11,7 @@ import ( "github.com/cosmos/cosmos-sdk/modules/auth" "github.com/cosmos/cosmos-sdk/modules/base" "github.com/cosmos/cosmos-sdk/modules/coin" + "github.com/cosmos/cosmos-sdk/modules/eyes" "github.com/cosmos/cosmos-sdk/modules/fee" "github.com/cosmos/cosmos-sdk/modules/ibc" "github.com/cosmos/cosmos-sdk/modules/nonce" @@ -45,6 +46,8 @@ func BuildApp(feeDenom string) sdk.Handler { coin.NewHandler(), stack.WrapHandler(roles.NewHandler()), stack.WrapHandler(ibc.NewHandler()), + // and just for run, add eyes as well + stack.WrapHandler(eyes.NewHandler()), ) } diff --git a/examples/basecoin/tests/cli/init-server.sh b/examples/basecoin/tests/cli/init-server.sh index dfd503df7d..9923540819 100755 --- a/examples/basecoin/tests/cli/init-server.sh +++ b/examples/basecoin/tests/cli/init-server.sh @@ -12,7 +12,7 @@ test01initOption() { GENESIS_FILE=${SERVE_DIR}/genesis.json HEX="deadbeef1234deadbeef1234deadbeef1234aaaa" - ${SERVER_EXE} init ${HEX} --home="$SERVE_DIR" -p=app1/key1/val1 -p='"app2/key2/{""name"": ""joe"", ""age"": ""100""}"' >/dev/null + ${SERVER_EXE} init ${HEX} --home="$SERVE_DIR" -p=eyes/key1/val1 -p='"eyes/key2/{""name"": ""joe"", ""age"": ""100""}"' >/dev/null if ! assertTrue "line=${LINENO}" $?; then return 1; fi OPTION1KEY=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[2]') @@ -21,9 +21,9 @@ test01initOption() { OPTION2VAL=$(cat ${GENESIS_FILE} | jq '.app_options.plugin_options[5]') OPTION2VALEXPECTED=$(echo '{"name": "joe", "age": "100"}' | jq '.') - assertEquals "line=${LINENO}" '"app1/key1"' $OPTION1KEY + assertEquals "line=${LINENO}" '"eyes/key1"' $OPTION1KEY assertEquals "line=${LINENO}" '"val1"' $OPTION1VAL - assertEquals "line=${LINENO}" '"app2/key2"' $OPTION2KEY + assertEquals "line=${LINENO}" '"eyes/key2"' $OPTION2KEY assertEquals "line=${LINENO}" "$OPTION2VALEXPECTED" "$OPTION2VAL" } diff --git a/modules/eyes/handler.go b/modules/eyes/handler.go index 478019b33d..34a54877e4 100644 --- a/modules/eyes/handler.go +++ b/modules/eyes/handler.go @@ -1,10 +1,12 @@ package eyes import ( + wire "github.com/tendermint/go-wire" + "github.com/tendermint/tmlibs/log" + sdk "github.com/cosmos/cosmos-sdk" "github.com/cosmos/cosmos-sdk/errors" "github.com/cosmos/cosmos-sdk/state" - wire "github.com/tendermint/go-wire" ) const ( @@ -19,7 +21,6 @@ const ( // Handler allows us to set and remove data type Handler struct { - sdk.NopInitState sdk.NopInitValidate } @@ -35,6 +36,16 @@ func (Handler) Name() string { return Name } +// InitState - sets the genesis state +func (h Handler) InitState(l log.Logger, store state.SimpleDB, + module, key, value string) (log string, err error) { + if module != Name { + return "", errors.ErrUnknownModule(module) + } + store.Set([]byte(key), []byte(value)) + return key, nil +} + // CheckTx verifies if the transaction is properly formated func (h Handler) CheckTx(ctx sdk.Context, store state.SimpleDB, tx sdk.Tx) (res sdk.CheckResult, err error) { err = tx.ValidateBasic()