package simulation import ( "fmt" "testing" "github.com/stretchr/testify/require" tmkv "github.com/tendermint/tendermint/libs/kv" "github.com/cosmos/cosmos-sdk/codec" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/cosmos/cosmos-sdk/x/supply/keeper" "github.com/cosmos/cosmos-sdk/x/supply/types" ) func makeTestCodec() (cdc *codec.Codec) { cdc = codec.New() sdk.RegisterCodec(cdc) codec.RegisterCrypto(cdc) types.RegisterCodec(cdc) return } func TestDecodeStore(t *testing.T) { cdc := makeTestCodec() totalSupply := types.NewSupply(sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000))) kvPairs := tmkv.Pairs{ tmkv.Pair{Key: keeper.SupplyKey, Value: cdc.MustMarshalBinaryBare(totalSupply)}, tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, } tests := []struct { name string expectedLog string }{ {"Supply", fmt.Sprintf("%v\n%v", totalSupply, totalSupply)}, {"other", ""}, } for i, tt := range tests { i, tt := i, tt t.Run(tt.name, func(t *testing.T) { switch i { case len(tests) - 1: require.Panics(t, func() { DecodeStore(cdc, kvPairs[i], kvPairs[i]) }, tt.name) default: require.Equal(t, tt.expectedLog, DecodeStore(cdc, kvPairs[i], kvPairs[i]), tt.name) } }) } }