github.com/okex/exchain@v1.8.0/libs/ibc-go/testing/simapp/utils_test.go (about) 1 package simapp 2 3 import ( 4 "fmt" 5 "github.com/okex/exchain/libs/cosmos-sdk/codec" 6 ibc_tx "github.com/okex/exchain/libs/cosmos-sdk/x/auth/ibc-tx" 7 tmkv "github.com/okex/exchain/libs/tendermint/libs/kv" 8 "testing" 9 10 "github.com/stretchr/testify/require" 11 12 "github.com/okex/exchain/libs/cosmos-sdk/codec/types" 13 sdk "github.com/okex/exchain/libs/cosmos-sdk/types" 14 "github.com/okex/exchain/libs/cosmos-sdk/types/module" 15 authtypes "github.com/okex/exchain/libs/cosmos-sdk/x/auth/types" 16 ) 17 18 func makeCodec(bm module.BasicManager) types.InterfaceRegistry { 19 // cdc := codec.NewLegacyAmino() 20 21 // bm.RegisterLegacyAminoCodec(cdc) 22 // std.RegisterLegacyAminoCodec(cdc) 23 interfaceReg := types.NewInterfaceRegistry() 24 bm.RegisterInterfaces(interfaceReg) 25 26 ibc_tx.PubKeyRegisterInterfaces(interfaceReg) 27 28 return interfaceReg 29 } 30 31 func TestGetSimulationLog(t *testing.T) { 32 //cdc := makeCodec(ModuleBasics) 33 cdc := codec.NewCodecProxy(codec.NewProtoCodec(makeCodec(ModuleBasics)), codec.New()) 34 35 decoders := make(sdk.StoreDecoderRegistry) 36 decoders[authtypes.StoreKey] = func(cdc *codec.Codec, kvAs, kvBs tmkv.Pair) string { return "10" } 37 38 tests := []struct { 39 store string 40 kvPairs []tmkv.Pair 41 expectedLog string 42 }{ 43 { 44 "Empty", 45 []tmkv.Pair{{}}, 46 "", 47 }, 48 { 49 authtypes.StoreKey, 50 // todo old one is MustMarshal. does it want to test pb codec? 51 []tmkv.Pair{{Key: authtypes.GlobalAccountNumberKey, Value: cdc.GetCdc().MustMarshalBinaryBare(uint64(10))}}, 52 "10", 53 }, 54 { 55 "OtherStore", 56 []tmkv.Pair{{Key: []byte("key"), Value: []byte("value")}}, 57 fmt.Sprintf("store A %X => %X\nstore B %X => %X\n", []byte("key"), []byte("value"), []byte("key"), []byte("value")), 58 }, 59 } 60 61 for _, tt := range tests { 62 tt := tt 63 t.Run(tt.store, func(t *testing.T) { 64 require.Equal(t, tt.expectedLog, GetSimulationLog(tt.store, decoders, tt.kvPairs, tt.kvPairs), tt.store) 65 }) 66 } 67 }