github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/cosmos-sdk/x/supply/simulation/decoder_test.go (about) 1 package simulation 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/stretchr/testify/require" 8 9 tmkv "github.com/fibonacci-chain/fbc/libs/tendermint/libs/kv" 10 11 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/codec" 12 sdk "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types" 13 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/supply/internal/keeper" 14 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/x/supply/internal/types" 15 ) 16 17 func makeTestCodec() (cdc *codec.Codec) { 18 cdc = codec.New() 19 sdk.RegisterCodec(cdc) 20 codec.RegisterCrypto(cdc) 21 types.RegisterCodec(cdc) 22 return 23 } 24 func TestDecodeStore(t *testing.T) { 25 cdc := makeTestCodec() 26 27 totalSupply := types.NewSupply(sdk.NewCoins(sdk.NewInt64Coin(sdk.DefaultBondDenom, 1000))) 28 29 kvPairs := tmkv.Pairs{ 30 tmkv.Pair{Key: keeper.SupplyKey, Value: cdc.MustMarshalBinaryLengthPrefixed(totalSupply)}, 31 tmkv.Pair{Key: []byte{0x99}, Value: []byte{0x99}}, 32 } 33 34 tests := []struct { 35 name string 36 expectedLog string 37 }{ 38 {"Supply", fmt.Sprintf("%v\n%v", totalSupply, totalSupply)}, 39 {"other", ""}, 40 } 41 42 for i, tt := range tests { 43 i, tt := i, tt 44 t.Run(tt.name, func(t *testing.T) { 45 switch i { 46 case len(tests) - 1: 47 require.Panics(t, func() { DecodeStore(cdc, kvPairs[i], kvPairs[i]) }, tt.name) 48 default: 49 require.Equal(t, tt.expectedLog, DecodeStore(cdc, kvPairs[i], kvPairs[i]), tt.name) 50 } 51 }) 52 } 53 }