cosmos-sdk/x/ibc/simulation/decoder_test.go
Aditya d208d2bed8
Make clients use proto Height (#7184)
* start using Height in TM client

* fix client tests

* fix client tests

* fix connection tests

* fix rest of tests

* Apply suggestions from code review

Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>

* fix simple issues

* add and use LTE and GTE methods

* remove TM-specific height semantics from 02-client

* fix lint and build

Co-authored-by: Federico Kunze <31522760+fedekunze@users.noreply.github.com>
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
2020-08-31 17:57:08 +00:00

81 lines
2.2 KiB
Go

package simulation_test
import (
"fmt"
"testing"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/types/kv"
clienttypes "github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
connectiontypes "github.com/cosmos/cosmos-sdk/x/ibc/03-connection/types"
channeltypes "github.com/cosmos/cosmos-sdk/x/ibc/04-channel/types"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
"github.com/cosmos/cosmos-sdk/x/ibc/simulation"
)
func TestDecodeStore(t *testing.T) {
app := simapp.Setup(false)
dec := simulation.NewDecodeStore(*app.IBCKeeper)
clientID := "clientidone"
connectionID := "connectionidone"
channelID := "channelidone"
portID := "portidone"
clientState := &ibctmtypes.ClientState{
FrozenHeight: clienttypes.NewHeight(0, 10),
}
connection := connectiontypes.ConnectionEnd{
ClientId: "clientidone",
Versions: []string{"1.0"},
}
channel := channeltypes.Channel{
State: channeltypes.OPEN,
Version: "1.0",
}
kvPairs := kv.Pairs{
Pairs: []kv.Pair{
{
Key: host.FullKeyClientPath(clientID, host.KeyClientState()),
Value: app.IBCKeeper.ClientKeeper.MustMarshalClientState(clientState),
},
{
Key: host.KeyConnection(connectionID),
Value: app.IBCKeeper.Codec().MustMarshalBinaryBare(&connection),
},
{
Key: host.KeyChannel(portID, channelID),
Value: app.IBCKeeper.Codec().MustMarshalBinaryBare(&channel),
},
{
Key: []byte{0x99},
Value: []byte{0x99},
},
},
}
tests := []struct {
name string
expectedLog string
}{
{"ClientState", fmt.Sprintf("ClientState A: %v\nClientState B: %v", clientState, clientState)},
{"ConnectionEnd", fmt.Sprintf("ConnectionEnd A: %v\nConnectionEnd B: %v", connection, connection)},
{"Channel", fmt.Sprintf("Channel A: %v\nChannel B: %v", channel, channel)},
{"other", ""},
}
for i, tt := range tests {
i, tt := i, tt
t.Run(tt.name, func(t *testing.T) {
if i == len(tests)-1 {
require.Panics(t, func() { dec(kvPairs.Pairs[i], kvPairs.Pairs[i]) }, tt.name)
} else {
require.Equal(t, tt.expectedLog, dec(kvPairs.Pairs[i], kvPairs.Pairs[i]), tt.name)
}
})
}
}