github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/02-client/simulation/decoder_test.go (about) 1 package simulation_test 2 3 import ( 4 "fmt" 5 "testing" 6 "time" 7 8 "github.com/fibonacci-chain/fbc/libs/cosmos-sdk/types/kv" 9 tmkv "github.com/fibonacci-chain/fbc/libs/tendermint/libs/kv" 10 11 "github.com/stretchr/testify/require" 12 13 // "github.com/cosmos/cosmos-sdk/types/kv" 14 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/02-client/simulation" 15 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/02-client/types" 16 host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host" 17 ibctmtypes "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/light-clients/07-tendermint/types" 18 "github.com/fibonacci-chain/fbc/libs/ibc-go/testing/simapp" 19 ) 20 21 func TestDecodeStore(t *testing.T) { 22 app := simapp.Setup(false) 23 clientID := "clientidone" 24 25 height := types.NewHeight(0, 10) 26 27 clientState := &ibctmtypes.ClientState{ 28 FrozenHeight: height, 29 } 30 31 consState := &ibctmtypes.ConsensusState{ 32 Timestamp: time.Now().UTC(), 33 } 34 35 kvPairs := kv.Pairs{ 36 Pairs: []kv.Pair{ 37 { 38 Key: host.FullClientStateKey(clientID), 39 Value: app.IBCKeeper.V2Keeper.ClientKeeper.MustMarshalClientState(clientState), 40 }, 41 { 42 Key: host.FullConsensusStateKey(clientID, height), 43 Value: app.IBCKeeper.V2Keeper.ClientKeeper.MustMarshalConsensusState(consState), 44 }, 45 { 46 Key: []byte{0x99}, 47 Value: []byte{0x99}, 48 }, 49 }, 50 } 51 tests := []struct { 52 name string 53 expectedLog string 54 }{ 55 {"ClientState", fmt.Sprintf("ClientState A: %v\nClientState B: %v", clientState, clientState)}, 56 {"ConsensusState", fmt.Sprintf("ConsensusState A: %v\nConsensusState B: %v", consState, consState)}, 57 {"other", ""}, 58 } 59 60 for i, tt := range tests { 61 i, tt := i, tt 62 t.Run(tt.name, func(t *testing.T) { 63 // res, found := simulation.NewDecodeStore(app.IBCKeeper.ClientKeeper, kvPairs.Pairs[i], kvPairs.Pairs[i]) 64 kvA := tmkv.Pair{ 65 Key: kvPairs.Pairs[i].GetKey(), 66 Value: kvPairs.Pairs[i].GetValue(), 67 } 68 res, found := simulation.NewDecodeStore(app.IBCKeeper.V2Keeper.ClientKeeper, kvA, kvA) 69 if i == len(tests)-1 { 70 require.False(t, found, string(kvPairs.Pairs[i].Key)) 71 require.Empty(t, res, string(kvPairs.Pairs[i].Key)) 72 } else { 73 require.True(t, found, string(kvPairs.Pairs[i].Key)) 74 require.Equal(t, tt.expectedLog, res, string(kvPairs.Pairs[i].Key)) 75 } 76 }) 77 } 78 }