github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/simulation/decoder_test.go (about) 1 package simulation_test 2 3 import ( 4 "fmt" 5 "testing" 6 7 tmkv "github.com/fibonacci-chain/fbc/libs/tendermint/libs/kv" 8 9 "github.com/stretchr/testify/require" 10 11 //"github.com/cosmos/cosmos-sdk/types/kv" 12 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/kv" 13 clienttypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/02-client/types" 14 connectiontypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/03-connection/types" 15 channeltypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/04-channel/types" 16 host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host" 17 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/simulation" 18 ibctmtypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/light-clients/07-tendermint/types" 19 "github.com/fibonacci-chain/fbc/libs/ibc-go/testing/simapp" 20 ) 21 22 func TestDecodeStore(t *testing.T) { 23 app := simapp.Setup(false) 24 dec := simulation.NewDecodeStore(*app.IBCKeeper.V2Keeper) 25 26 clientID := "clientidone" 27 connectionID := "connectionidone" 28 channelID := "channelidone" 29 portID := "portidone" 30 31 clientState := &ibctmtypes.ClientState{ 32 FrozenHeight: clienttypes.NewHeight(0, 10), 33 } 34 connection := connectiontypes.ConnectionEnd{ 35 ClientId: "clientidone", 36 Versions: []*connectiontypes.Version{connectiontypes.NewVersion("1", nil)}, 37 } 38 channel := channeltypes.Channel{ 39 State: channeltypes.OPEN, 40 Version: "1.0", 41 } 42 43 kvPairs := kv.Pairs{ 44 Pairs: []kv.Pair{ 45 { 46 Key: host.FullClientStateKey(clientID), 47 Value: app.IBCKeeper.V2Keeper.ClientKeeper.MustMarshalClientState(clientState), 48 }, 49 { 50 Key: host.ConnectionKey(connectionID), 51 Value: app.IBCKeeper.V2Keeper.Codec().GetProtocMarshal().MustMarshalBinaryBare(&connection), 52 }, 53 { 54 Key: host.ChannelKey(portID, channelID), 55 Value: app.IBCKeeper.V2Keeper.Codec().GetProtocMarshal().MustMarshalBinaryBare(&channel), 56 }, 57 { 58 Key: []byte{0x99}, 59 Value: []byte{0x99}, 60 }, 61 }, 62 } 63 tests := []struct { 64 name string 65 expectedLog string 66 }{ 67 {"ClientState", fmt.Sprintf("ClientState A: %v\nClientState B: %v", clientState, clientState)}, 68 {"ConnectionEnd", fmt.Sprintf("ConnectionEnd A: %v\nConnectionEnd B: %v", connection, connection)}, 69 {"Channel", fmt.Sprintf("Channel A: %v\nChannel B: %v", channel, channel)}, 70 {"other", ""}, 71 } 72 73 for i, tt := range tests { 74 i, tt := i, tt 75 t.Run(tt.name, func(t *testing.T) { 76 if i == len(tests)-1 { 77 // require.Panics(t, func() { dec(nil, kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name) 78 kvA := tmkv.Pair{ 79 Key: kvPairs.Pairs[i].GetKey(), 80 Value: kvPairs.Pairs[i].GetValue(), 81 } 82 require.Panics(t, func() { dec(nil, kvA, kvA) }, tt.name) 83 } else { 84 // require.Equal(t, tt.expectedLog, dec(nil, kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name) 85 kvA := tmkv.Pair{ 86 Key: kvPairs.Pairs[i].GetKey(), 87 Value: kvPairs.Pairs[i].GetValue(), 88 } 89 require.Equal(t, tt.expectedLog, dec(nil, kvA, kvA), tt.name) 90 } 91 }) 92 } 93 }