cosmos-sdk/x/ibc/02-client/simulation/decoder_test.go
atheeshp ceba0cb45d
x/ibc migrate genesis proto (#6878)
* migrated channel genesis types to proto

* connection genesis types migrated to proto

* client proto migration

* failing tests due to tendermint part incomplete

* add genesis test

* x/ibc: ClientState Any

* add genesis test

* suite NotPanics

* comment tests

* update export logic

* refactor

* update test

* fix non-determinism

* castrepeated

* x/ibc: migrate simulations to protobuf

* add proto genesis

* add UnpackInterfaces func to genclientstate

* add unpackinterfaces for consensus states

* formatting

* fix genesis tests

* add modified genesis test

* update comments

* remove localhost register codec

* use app registry

* fix bug

* Update simapp/app.go

* Update x/ibc/02-client/types/genesis.go

* unmarshaler interface

Co-authored-by: Colin Axner <colinaxner@berkeley.edu>
Co-authored-by: Federico Kunze <federico.kunze94@gmail.com>
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-07 08:33:47 +00:00

73 lines
2.0 KiB
Go

package simulation_test
import (
"fmt"
"testing"
"time"
"github.com/stretchr/testify/require"
"github.com/cosmos/cosmos-sdk/simapp"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/simulation"
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
)
func TestDecodeStore(t *testing.T) {
app := simapp.Setup(false)
clientID := "clientidone"
clientState := &ibctmtypes.ClientState{
FrozenHeight: 10,
}
consState := &ibctmtypes.ConsensusState{
Height: 10,
Timestamp: time.Now().UTC(),
}
kvPairs := kv.Pairs{
kv.Pair{
Key: host.FullKeyClientPath(clientID, host.KeyClientState()),
Value: app.IBCKeeper.ClientKeeper.MustMarshalClientState(clientState),
},
kv.Pair{
Key: host.FullKeyClientPath(clientID, host.KeyClientType()),
Value: []byte(exported.Tendermint.String()),
},
kv.Pair{
Key: host.FullKeyClientPath(clientID, host.KeyConsensusState(10)),
Value: app.IBCKeeper.ClientKeeper.MustMarshalConsensusState(consState),
},
kv.Pair{
Key: []byte{0x99},
Value: []byte{0x99},
},
}
tests := []struct {
name string
expectedLog string
}{
{"ClientState", fmt.Sprintf("ClientState A: %v\nClientState B: %v", clientState, clientState)},
{"client type", fmt.Sprintf("Client type A: %s\nClient type B: %s", exported.Tendermint, exported.Tendermint)},
{"ConsensusState", fmt.Sprintf("ConsensusState A: %v\nConsensusState B: %v", consState, consState)},
{"other", ""},
}
for i, tt := range tests {
i, tt := i, tt
t.Run(tt.name, func(t *testing.T) {
res, found := simulation.NewDecodeStore(app.IBCKeeper.ClientKeeper, kvPairs[i], kvPairs[i])
if i == len(tests)-1 {
require.False(t, found, string(kvPairs[i].Key))
require.Empty(t, res, string(kvPairs[i].Key))
} else {
require.True(t, found, string(kvPairs[i].Key))
require.Equal(t, tt.expectedLog, res, string(kvPairs[i].Key))
}
})
}
}