Eyes takes init state, fix cli test about genesis

This commit is contained in:
Ethan Frey 2017-10-16 19:58:12 +02:00
parent 3316bfcfb8
commit 9b206153e2
3 changed files with 19 additions and 5 deletions

View File

@ -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()),
)
}

View File

@ -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"
}

View File

@ -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()