diff --git a/app/app_test.go b/app/app_test.go index 7889a31b0..38aa990cd 100644 --- a/app/app_test.go +++ b/app/app_test.go @@ -5,6 +5,7 @@ import ( "os" "testing" + "github.com/pkg/errors" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -13,6 +14,7 @@ import ( "github.com/tendermint/basecoin/modules/auth" "github.com/tendermint/basecoin/modules/base" "github.com/tendermint/basecoin/modules/coin" + "github.com/tendermint/basecoin/stack" "github.com/tendermint/basecoin/state" wire "github.com/tendermint/go-wire" eyes "github.com/tendermint/merkleeyes/client" @@ -82,8 +84,16 @@ func (at *appTest) reset() { } func getBalance(key basecoin.Actor, state state.KVStore) (coin.Coins, error) { - acct, err := coin.NewAccountant("").GetAccount(state, key) - return acct.Coins, err + var acct coin.Account + k := stack.PrefixedKey(coin.NameCoin, key.Bytes()) + v := state.Get(k) + // empty if no data + if len(v) == 0 { + return nil, nil + } + // otherwise read it + err := wire.ReadBinaryBytes(v, &acct) + return acct.Coins, errors.WithStack(err) } func getAddr(addr []byte, state state.KVStore) (coin.Coins, error) { diff --git a/stack/prefixstore.go b/stack/prefixstore.go index e9616ad52..cc0c5807f 100644 --- a/stack/prefixstore.go +++ b/stack/prefixstore.go @@ -26,6 +26,20 @@ func stateSpace(store state.KVStore, app string) state.KVStore { store = pstore.store } // wrap it with the prefix - prefix := append([]byte(app), byte(0)) + prefix := makePrefix(app) return prefixStore{prefix, store} } + +func makePrefix(app string) []byte { + return append([]byte(app), byte(0)) +} + +// PrefixedKey gives us the absolute path to a key that is embedded in an +// application-specific state-space. +// +// This is useful for tests or utilities that have access to the global +// state to check individual app spaces. Individual apps should not be able +// to use this to read each other's space +func PrefixedKey(app string, key []byte) []byte { + return append(makePrefix(app), key...) +}