* remove client type struct Remove the client type struct, remove ClientType interface function from Header and Misbehaviour. ClientState and ConsensusState return the ClientType as a string. All uses of client type in testing are now pointing at the testing package so changing the location of the client type const will be painless. * update godoc and add back client type interface func Add godoc to client type constant for solo machine, tendermint, and localhost as per @fedekunze review suggestion. Add back the ClientType interface function for misbehaviour and header for solo machine and tendermint and add back the one liner unit tests as per @AdityaSripal suggestion. * remove client state from return remove client state from the return of CreateClient, UpdateClient, and CheckMisbehaviourAndUpdateState as well as update tests to reflect this change. * fix build error introduced by latest merge Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
77 lines
2.1 KiB
Go
77 lines
2.1 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/simulation"
|
|
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
|
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
|
host "github.com/cosmos/cosmos-sdk/x/ibc/24-host"
|
|
ibctesting "github.com/cosmos/cosmos-sdk/x/ibc/testing"
|
|
)
|
|
|
|
func TestDecodeStore(t *testing.T) {
|
|
app := simapp.Setup(false)
|
|
clientID := "clientidone"
|
|
|
|
height := types.NewHeight(0, 10)
|
|
|
|
clientState := &ibctmtypes.ClientState{
|
|
FrozenHeight: height,
|
|
}
|
|
|
|
consState := &ibctmtypes.ConsensusState{
|
|
Timestamp: time.Now().UTC(),
|
|
}
|
|
|
|
kvPairs := kv.Pairs{
|
|
Pairs: []kv.Pair{
|
|
{
|
|
Key: host.FullKeyClientPath(clientID, host.KeyClientState()),
|
|
Value: app.IBCKeeper.ClientKeeper.MustMarshalClientState(clientState),
|
|
},
|
|
{
|
|
Key: host.FullKeyClientPath(clientID, host.KeyClientType()),
|
|
Value: []byte(ibctesting.Tendermint),
|
|
},
|
|
{
|
|
Key: host.FullKeyClientPath(clientID, host.KeyConsensusState(height)),
|
|
Value: app.IBCKeeper.ClientKeeper.MustMarshalConsensusState(consState),
|
|
},
|
|
{
|
|
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", ibctesting.Tendermint, ibctesting.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.Pairs[i], kvPairs.Pairs[i])
|
|
if i == len(tests)-1 {
|
|
require.False(t, found, string(kvPairs.Pairs[i].Key))
|
|
require.Empty(t, res, string(kvPairs.Pairs[i].Key))
|
|
} else {
|
|
require.True(t, found, string(kvPairs.Pairs[i].Key))
|
|
require.Equal(t, tt.expectedLog, res, string(kvPairs.Pairs[i].Key))
|
|
}
|
|
})
|
|
}
|
|
}
|