github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/03-connection/simulation/decoder_test.go (about) 1 package simulation_test 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/kv" 8 tmkv "github.com/fibonacci-chain/fbc/libs/tendermint/libs/kv" 9 10 "github.com/stretchr/testify/require" 11 12 // "github.com/cosmos/cosmos-sdk/types/kv" 13 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/03-connection/simulation" 14 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/03-connection/types" 15 host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host" 16 "github.com/fibonacci-chain/fbc/libs/ibc-go/testing/simapp" 17 ) 18 19 func TestDecodeStore(t *testing.T) { 20 app := simapp.Setup(false) 21 cdc := app.AppCodec() 22 23 connectionID := "connectionidone" 24 25 connection := types.ConnectionEnd{ 26 ClientId: "clientidone", 27 Versions: types.ExportedVersionsToProto(types.GetCompatibleVersions()), 28 } 29 30 paths := types.ClientPaths{ 31 Paths: []string{connectionID}, 32 } 33 34 kvPairs := kv.Pairs{ 35 Pairs: []kv.Pair{ 36 { 37 Key: host.ClientConnectionsKey(connection.ClientId), 38 //Value: cdc.MustMarshal(&paths), 39 Value: cdc.GetProtocMarshal().MustMarshalBinaryBare(&paths), 40 }, 41 { 42 Key: host.ConnectionKey(connectionID), 43 //Value: cdc.MustMarshal(&connection), 44 Value: cdc.GetProtocMarshal().MustMarshalBinaryBare(&connection), 45 }, 46 { 47 Key: []byte{0x99}, 48 Value: []byte{0x99}, 49 }, 50 }, 51 } 52 tests := []struct { 53 name string 54 expectedLog string 55 }{ 56 {"ClientPaths", fmt.Sprintf("ClientPaths A: %v\nClientPaths B: %v", paths, paths)}, 57 {"ConnectionEnd", fmt.Sprintf("ConnectionEnd A: %v\nConnectionEnd B: %v", connection, connection)}, 58 {"other", ""}, 59 } 60 61 for i, tt := range tests { 62 i, tt := i, tt 63 t.Run(tt.name, func(t *testing.T) { 64 // res, found := simulation.NewDecodeStore(cdc, kvPairs.Pairs[i], kvPairs.Pairs[i]) 65 kvA := tmkv.Pair{ 66 Key: kvPairs.Pairs[i].GetKey(), 67 Value: kvPairs.Pairs[i].GetValue(), 68 } 69 res, found := simulation.NewDecodeStore(cdc, kvA, kvA) 70 if i == len(tests)-1 { 71 require.False(t, found, string(kvPairs.Pairs[i].Key)) 72 require.Empty(t, res, string(kvPairs.Pairs[i].Key)) 73 } else { 74 require.True(t, found, string(kvPairs.Pairs[i].Key)) 75 require.Equal(t, tt.expectedLog, res, string(kvPairs.Pairs[i].Key)) 76 } 77 }) 78 } 79 }