github.com/cosmos/cosmos-sdk@v0.50.10/x/authz/simulation/decoder_test.go (about) 1 package simulation_test 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 8 "github.com/stretchr/testify/require" 9 10 sdk "github.com/cosmos/cosmos-sdk/types" 11 "github.com/cosmos/cosmos-sdk/types/kv" 12 moduletestutil "github.com/cosmos/cosmos-sdk/types/module/testutil" 13 "github.com/cosmos/cosmos-sdk/x/authz" 14 "github.com/cosmos/cosmos-sdk/x/authz/keeper" 15 authzmodule "github.com/cosmos/cosmos-sdk/x/authz/module" 16 "github.com/cosmos/cosmos-sdk/x/authz/simulation" 17 banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" 18 ) 19 20 func TestDecodeStore(t *testing.T) { 21 encCfg := moduletestutil.MakeTestEncodingConfig(authzmodule.AppModuleBasic{}) 22 banktypes.RegisterInterfaces(encCfg.InterfaceRegistry) 23 24 dec := simulation.NewDecodeStore(encCfg.Codec) 25 26 now := time.Now().UTC() 27 e := now.Add(1) 28 sendAuthz := banktypes.NewSendAuthorization(sdk.NewCoins(sdk.NewInt64Coin("foo", 123)), nil) 29 grant, _ := authz.NewGrant(now, sendAuthz, &e) 30 grantBz, err := encCfg.Codec.Marshal(&grant) 31 require.NoError(t, err) 32 kvPairs := kv.Pairs{ 33 Pairs: []kv.Pair{ 34 {Key: keeper.GrantKey, Value: grantBz}, 35 {Key: []byte{0x99}, Value: []byte{0x99}}, 36 }, 37 } 38 39 tests := []struct { 40 name string 41 expectErr bool 42 expectedLog string 43 }{ 44 {"Grant", false, fmt.Sprintf("%v\n%v", grant, grant)}, 45 {"other", true, ""}, 46 } 47 48 for i, tt := range tests { 49 i, tt := i, tt 50 t.Run(tt.name, func(t *testing.T) { 51 if tt.expectErr { 52 require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name) 53 } else { 54 require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name) 55 } 56 }) 57 } 58 }