parent
da92383bff
commit
b93300288e
|
@ -25,6 +25,7 @@ type ClientState interface {
|
|||
// State verification functions
|
||||
|
||||
VerifyClientConsensusState(
|
||||
store sdk.KVStore,
|
||||
cdc *codec.Codec,
|
||||
root commitmentexported.Root,
|
||||
height uint64,
|
||||
|
@ -35,6 +36,7 @@ type ClientState interface {
|
|||
consensusState ConsensusState,
|
||||
) error
|
||||
VerifyConnectionState(
|
||||
store sdk.KVStore,
|
||||
cdc codec.Marshaler,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
|
@ -44,6 +46,7 @@ type ClientState interface {
|
|||
consensusState ConsensusState,
|
||||
) error
|
||||
VerifyChannelState(
|
||||
store sdk.KVStore,
|
||||
cdc codec.Marshaler,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
|
@ -54,6 +57,7 @@ type ClientState interface {
|
|||
consensusState ConsensusState,
|
||||
) error
|
||||
VerifyPacketCommitment(
|
||||
store sdk.KVStore,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
proof commitmentexported.Proof,
|
||||
|
@ -64,6 +68,7 @@ type ClientState interface {
|
|||
consensusState ConsensusState,
|
||||
) error
|
||||
VerifyPacketAcknowledgement(
|
||||
store sdk.KVStore,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
proof commitmentexported.Proof,
|
||||
|
@ -74,6 +79,7 @@ type ClientState interface {
|
|||
consensusState ConsensusState,
|
||||
) error
|
||||
VerifyPacketAcknowledgementAbsence(
|
||||
store sdk.KVStore,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
proof commitmentexported.Proof,
|
||||
|
@ -83,6 +89,7 @@ type ClientState interface {
|
|||
consensusState ConsensusState,
|
||||
) error
|
||||
VerifyNextSequenceRecv(
|
||||
store sdk.KVStore,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
proof commitmentexported.Proof,
|
||||
|
|
|
@ -30,11 +30,7 @@ func InitGenesis(ctx sdk.Context, k Keeper, gs GenesisState) {
|
|||
}
|
||||
|
||||
// client id is always "localhost"
|
||||
clientState := localhosttypes.NewClientState(
|
||||
k.ClientStore(ctx, exported.ClientTypeLocalHost),
|
||||
ctx.ChainID(),
|
||||
ctx.BlockHeight(),
|
||||
)
|
||||
clientState := localhosttypes.NewClientState(ctx.ChainID(), ctx.BlockHeight())
|
||||
|
||||
_, err := k.CreateClient(ctx, clientState, nil)
|
||||
if err != nil {
|
||||
|
|
|
@ -31,11 +31,7 @@ func HandleMsgCreateClient(ctx sdk.Context, k Keeper, msg exported.MsgCreateClie
|
|||
}
|
||||
case exported.Localhost:
|
||||
// msg client id is always "localhost"
|
||||
clientState = localhosttypes.NewClientState(
|
||||
k.ClientStore(ctx, msg.GetClientID()),
|
||||
ctx.ChainID(),
|
||||
ctx.BlockHeight(),
|
||||
)
|
||||
clientState = localhosttypes.NewClientState(ctx.ChainID(), ctx.BlockHeight())
|
||||
default:
|
||||
return nil, sdkerrors.Wrap(ErrInvalidClientType, msg.GetClientType())
|
||||
}
|
||||
|
|
|
@ -88,7 +88,6 @@ func (k Keeper) UpdateClient(ctx sdk.Context, clientID string, header exported.H
|
|||
case exported.Localhost:
|
||||
// override client state and update the block height
|
||||
clientState = localhosttypes.NewClientState(
|
||||
k.ClientStore(ctx, clientState.GetID()),
|
||||
ctx.ChainID(), // use the chain ID from context since the client is from the running chain (i.e self).
|
||||
ctx.BlockHeight(),
|
||||
)
|
||||
|
|
|
@ -178,11 +178,7 @@ func (suite *KeeperTestSuite) TestUpdateClientTendermint() {
|
|||
}
|
||||
|
||||
func (suite *KeeperTestSuite) TestUpdateClientLocalhost() {
|
||||
var localhostClient exported.ClientState = localhosttypes.NewClientState(
|
||||
suite.keeper.ClientStore(suite.ctx, exported.ClientTypeLocalHost),
|
||||
suite.header.ChainID,
|
||||
suite.ctx.BlockHeight(),
|
||||
)
|
||||
var localhostClient exported.ClientState = localhosttypes.NewClientState(suite.header.ChainID, suite.ctx.BlockHeight())
|
||||
|
||||
suite.ctx = suite.ctx.WithBlockHeight(suite.ctx.BlockHeight() + 1)
|
||||
|
||||
|
|
|
@ -7,10 +7,7 @@ import (
|
|||
"github.com/stretchr/testify/require"
|
||||
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/store/cachekv"
|
||||
"github.com/cosmos/cosmos-sdk/store/dbadapter"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/types"
|
||||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
|
@ -36,8 +33,6 @@ func TestValidateGenesis(t *testing.T) {
|
|||
val := tmtypes.NewValidator(pubKey, 10)
|
||||
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{val})
|
||||
|
||||
mem := dbadapter.Store{DB: dbm.NewMemDB()}
|
||||
store := cachekv.NewStore(mem)
|
||||
header := ibctmtypes.CreateTestHeader("chainID", 10, now, valSet, []tmtypes.PrivValidator{privVal})
|
||||
|
||||
testCases := []struct {
|
||||
|
@ -55,7 +50,7 @@ func TestValidateGenesis(t *testing.T) {
|
|||
genState: types.NewGenesisState(
|
||||
[]exported.ClientState{
|
||||
ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, header),
|
||||
localhosttypes.NewClientState(store, "chaindID", 10),
|
||||
localhosttypes.NewClientState("chaindID", 10),
|
||||
},
|
||||
[]types.ClientConsensusStates{
|
||||
{
|
||||
|
@ -76,7 +71,7 @@ func TestValidateGenesis(t *testing.T) {
|
|||
genState: types.NewGenesisState(
|
||||
[]exported.ClientState{
|
||||
ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, header),
|
||||
localhosttypes.NewClientState(store, "chaindID", 0),
|
||||
localhosttypes.NewClientState("chaindID", 0),
|
||||
},
|
||||
nil,
|
||||
true,
|
||||
|
@ -88,7 +83,7 @@ func TestValidateGenesis(t *testing.T) {
|
|||
genState: types.NewGenesisState(
|
||||
[]exported.ClientState{
|
||||
ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, header),
|
||||
localhosttypes.NewClientState(store, "chaindID", 10),
|
||||
localhosttypes.NewClientState("chaindID", 10),
|
||||
},
|
||||
[]types.ClientConsensusStates{
|
||||
{
|
||||
|
@ -109,7 +104,7 @@ func TestValidateGenesis(t *testing.T) {
|
|||
genState: types.NewGenesisState(
|
||||
[]exported.ClientState{
|
||||
ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, header),
|
||||
localhosttypes.NewClientState(store, "chaindID", 10),
|
||||
localhosttypes.NewClientState("chaindID", 10),
|
||||
},
|
||||
[]types.ClientConsensusStates{
|
||||
types.NewClientConsensusStates(
|
||||
|
|
|
@ -32,7 +32,8 @@ func (k Keeper) VerifyClientConsensusState(
|
|||
}
|
||||
|
||||
return clientState.VerifyClientConsensusState(
|
||||
k.aminoCdc, targetConsState.GetRoot(), height, connection.GetCounterparty().GetClientID(), consensusHeight, connection.GetCounterparty().GetPrefix(), proof, consensusState,
|
||||
k.clientKeeper.ClientStore(ctx, clientID), k.aminoCdc, targetConsState.GetRoot(), height,
|
||||
connection.GetCounterparty().GetClientID(), consensusHeight, connection.GetCounterparty().GetPrefix(), proof, consensusState,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -63,7 +64,8 @@ func (k Keeper) VerifyConnectionState(
|
|||
}
|
||||
|
||||
return clientState.VerifyConnectionState(
|
||||
k.cdc, height, connection.GetCounterparty().GetPrefix(), proof, connectionID, connectionEnd, consensusState,
|
||||
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
|
||||
connection.GetCounterparty().GetPrefix(), proof, connectionID, connectionEnd, consensusState,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -95,7 +97,8 @@ func (k Keeper) VerifyChannelState(
|
|||
}
|
||||
|
||||
return clientState.VerifyChannelState(
|
||||
k.cdc, height, connection.GetCounterparty().GetPrefix(), proof,
|
||||
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), k.cdc, height,
|
||||
connection.GetCounterparty().GetPrefix(), proof,
|
||||
portID, channelID, channel, consensusState,
|
||||
)
|
||||
}
|
||||
|
@ -129,7 +132,8 @@ func (k Keeper) VerifyPacketCommitment(
|
|||
}
|
||||
|
||||
return clientState.VerifyPacketCommitment(
|
||||
height, connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
|
||||
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), height,
|
||||
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
|
||||
sequence, commitmentBytes, consensusState,
|
||||
)
|
||||
}
|
||||
|
@ -163,7 +167,8 @@ func (k Keeper) VerifyPacketAcknowledgement(
|
|||
}
|
||||
|
||||
return clientState.VerifyPacketAcknowledgement(
|
||||
height, connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
|
||||
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), height,
|
||||
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
|
||||
sequence, acknowledgement, consensusState,
|
||||
)
|
||||
}
|
||||
|
@ -197,7 +202,8 @@ func (k Keeper) VerifyPacketAcknowledgementAbsence(
|
|||
}
|
||||
|
||||
return clientState.VerifyPacketAcknowledgementAbsence(
|
||||
height, connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
|
||||
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), height,
|
||||
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
|
||||
sequence, consensusState,
|
||||
)
|
||||
}
|
||||
|
@ -230,7 +236,8 @@ func (k Keeper) VerifyNextSequenceRecv(
|
|||
}
|
||||
|
||||
return clientState.VerifyNextSequenceRecv(
|
||||
height, connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
|
||||
k.clientKeeper.ClientStore(ctx, connection.GetClientID()), height,
|
||||
connection.GetCounterparty().GetPrefix(), proof, portID, channelID,
|
||||
nextSequenceRecv, consensusState,
|
||||
)
|
||||
}
|
||||
|
|
|
@ -11,4 +11,5 @@ type ClientKeeper interface {
|
|||
GetClientConsensusState(ctx sdk.Context, clientID string, height uint64) (clientexported.ConsensusState, bool)
|
||||
GetSelfConsensusState(ctx sdk.Context, height uint64) (clientexported.ConsensusState, bool)
|
||||
IterateClients(ctx sdk.Context, cb func(clientexported.ClientState) bool)
|
||||
ClientStore(ctx sdk.Context, clientID string) sdk.KVStore
|
||||
}
|
||||
|
|
|
@ -135,6 +135,7 @@ func (cs ClientState) Validate() error {
|
|||
// VerifyClientConsensusState verifies a proof of the consensus state of the
|
||||
// Tendermint client stored on the target machine.
|
||||
func (cs ClientState) VerifyClientConsensusState(
|
||||
_ sdk.KVStore,
|
||||
cdc *codec.Codec,
|
||||
provingRoot commitmentexported.Root,
|
||||
height uint64,
|
||||
|
@ -169,6 +170,7 @@ func (cs ClientState) VerifyClientConsensusState(
|
|||
// VerifyConnectionState verifies a proof of the connection state of the
|
||||
// specified connection end stored on the target machine.
|
||||
func (cs ClientState) VerifyConnectionState(
|
||||
_ sdk.KVStore,
|
||||
cdc codec.Marshaler,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
|
@ -206,6 +208,7 @@ func (cs ClientState) VerifyConnectionState(
|
|||
// VerifyChannelState verifies a proof of the channel state of the specified
|
||||
// channel end, under the specified port, stored on the target machine.
|
||||
func (cs ClientState) VerifyChannelState(
|
||||
_ sdk.KVStore,
|
||||
cdc codec.Marshaler,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
|
@ -244,6 +247,7 @@ func (cs ClientState) VerifyChannelState(
|
|||
// VerifyPacketCommitment verifies a proof of an outgoing packet commitment at
|
||||
// the specified port, specified channel, and specified sequence.
|
||||
func (cs ClientState) VerifyPacketCommitment(
|
||||
_ sdk.KVStore,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
proof commitmentexported.Proof,
|
||||
|
@ -272,6 +276,7 @@ func (cs ClientState) VerifyPacketCommitment(
|
|||
// VerifyPacketAcknowledgement verifies a proof of an incoming packet
|
||||
// acknowledgement at the specified port, specified channel, and specified sequence.
|
||||
func (cs ClientState) VerifyPacketAcknowledgement(
|
||||
_ sdk.KVStore,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
proof commitmentexported.Proof,
|
||||
|
@ -301,6 +306,7 @@ func (cs ClientState) VerifyPacketAcknowledgement(
|
|||
// incoming packet acknowledgement at the specified port, specified channel, and
|
||||
// specified sequence.
|
||||
func (cs ClientState) VerifyPacketAcknowledgementAbsence(
|
||||
_ sdk.KVStore,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
proof commitmentexported.Proof,
|
||||
|
@ -328,6 +334,7 @@ func (cs ClientState) VerifyPacketAcknowledgementAbsence(
|
|||
// VerifyNextSequenceRecv verifies a proof of the next sequence number to be
|
||||
// received of the specified channel at the specified port.
|
||||
func (cs ClientState) VerifyNextSequenceRecv(
|
||||
_ sdk.KVStore,
|
||||
height uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
proof commitmentexported.Proof,
|
||||
|
|
|
@ -128,7 +128,7 @@ func (suite *TendermintTestSuite) TestVerifyClientConsensusState() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyClientConsensusState(
|
||||
suite.aminoCdc, tc.consensusState.Root, height, "chainA", tc.consensusState.GetHeight(), tc.prefix, tc.proof, tc.consensusState,
|
||||
nil, suite.aminoCdc, tc.consensusState.Root, height, "chainA", tc.consensusState.GetHeight(), tc.prefix, tc.proof, tc.consensusState,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -211,7 +211,7 @@ func (suite *TendermintTestSuite) TestVerifyConnectionState() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyConnectionState(
|
||||
suite.cdc, height, tc.prefix, tc.proof, testConnectionID, tc.connection, tc.consensusState,
|
||||
nil, suite.cdc, height, tc.prefix, tc.proof, testConnectionID, tc.connection, tc.consensusState,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -294,7 +294,7 @@ func (suite *TendermintTestSuite) TestVerifyChannelState() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyChannelState(
|
||||
suite.cdc, height, tc.prefix, tc.proof, testPortID, testChannelID, &tc.channel, tc.consensusState,
|
||||
nil, suite.cdc, height, tc.prefix, tc.proof, testPortID, testChannelID, &tc.channel, tc.consensusState,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -374,7 +374,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketCommitment() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyPacketCommitment(
|
||||
height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.commitment, tc.consensusState,
|
||||
nil, height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.commitment, tc.consensusState,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -454,7 +454,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgement() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyPacketAcknowledgement(
|
||||
height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.ack, tc.consensusState,
|
||||
nil, height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.ack, tc.consensusState,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -529,7 +529,7 @@ func (suite *TendermintTestSuite) TestVerifyPacketAcknowledgementAbsence() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyPacketAcknowledgementAbsence(
|
||||
height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.consensusState,
|
||||
nil, height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.consensusState,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -604,7 +604,7 @@ func (suite *TendermintTestSuite) TestVerifyNextSeqRecv() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyNextSequenceRecv(
|
||||
height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.consensusState,
|
||||
nil, height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.consensusState,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
|
|
@ -6,10 +6,12 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
)
|
||||
|
||||
|
@ -24,6 +26,7 @@ const (
|
|||
type TendermintTestSuite struct {
|
||||
suite.Suite
|
||||
|
||||
ctx sdk.Context
|
||||
aminoCdc *codec.Codec
|
||||
cdc codec.Marshaler
|
||||
privVal tmtypes.PrivValidator
|
||||
|
@ -48,6 +51,7 @@ func (suite *TendermintTestSuite) SetupTest() {
|
|||
val := tmtypes.NewValidator(pubKey, 10)
|
||||
suite.valSet = tmtypes.NewValidatorSet([]*tmtypes.Validator{val})
|
||||
suite.header = ibctmtypes.CreateTestHeader(chainID, height, suite.now, suite.valSet, []tmtypes.PrivValidator{suite.privVal})
|
||||
suite.ctx = app.BaseApp.NewContext(checkTx, abci.Header{Height: 1, Time: suite.now})
|
||||
}
|
||||
|
||||
func TestTendermintTestSuite(t *testing.T) {
|
||||
|
|
|
@ -27,16 +27,14 @@ var _ clientexported.ClientState = ClientState{}
|
|||
|
||||
// ClientState requires (read-only) access to keys outside the client prefix.
|
||||
type ClientState struct {
|
||||
store sdk.KVStore
|
||||
ID string `json:"id" yaml:"id"`
|
||||
ChainID string `json:"chain_id" yaml:"chain_id"`
|
||||
Height int64 `json:"height" yaml:"height"`
|
||||
}
|
||||
|
||||
// NewClientState creates a new ClientState instance
|
||||
func NewClientState(store sdk.KVStore, chainID string, height int64) ClientState {
|
||||
func NewClientState(chainID string, height int64) ClientState {
|
||||
return ClientState{
|
||||
store: store,
|
||||
ID: clientexported.Localhost.String(),
|
||||
ChainID: chainID,
|
||||
Height: height,
|
||||
|
@ -70,19 +68,13 @@ func (cs ClientState) IsFrozen() bool {
|
|||
|
||||
// Validate performs a basic validation of the client state fields.
|
||||
func (cs ClientState) Validate() error {
|
||||
if err := host.DefaultClientIdentifierValidator(cs.ID); err != nil {
|
||||
return err
|
||||
}
|
||||
if strings.TrimSpace(cs.ChainID) == "" {
|
||||
return errors.New("chain id cannot be blank")
|
||||
}
|
||||
if cs.Height <= 0 {
|
||||
return fmt.Errorf("height must be positive: %d", cs.Height)
|
||||
}
|
||||
if cs.store == nil {
|
||||
return errors.New("KVStore cannot be nil")
|
||||
}
|
||||
return nil
|
||||
return host.DefaultClientIdentifierValidator(cs.ID)
|
||||
}
|
||||
|
||||
// VerifyClientConsensusState verifies a proof of the consensus
|
||||
|
@ -90,6 +82,7 @@ func (cs ClientState) Validate() error {
|
|||
// VerifyClientConsensusState verifies a proof of the consensus state of the
|
||||
// Tendermint client stored on the target machine.
|
||||
func (cs ClientState) VerifyClientConsensusState(
|
||||
store sdk.KVStore,
|
||||
cdc *codec.Codec,
|
||||
_ commitmentexported.Root,
|
||||
height uint64,
|
||||
|
@ -104,7 +97,7 @@ func (cs ClientState) VerifyClientConsensusState(
|
|||
return err
|
||||
}
|
||||
|
||||
data := cs.store.Get([]byte(path.String()))
|
||||
data := store.Get([]byte(path.String()))
|
||||
if len(data) == 0 {
|
||||
return sdkerrors.Wrapf(clienttypes.ErrFailedClientConsensusStateVerification, "not found for path %s", path)
|
||||
}
|
||||
|
@ -127,6 +120,7 @@ func (cs ClientState) VerifyClientConsensusState(
|
|||
// VerifyConnectionState verifies a proof of the connection state of the
|
||||
// specified connection end stored locally.
|
||||
func (cs ClientState) VerifyConnectionState(
|
||||
store sdk.KVStore,
|
||||
cdc codec.Marshaler,
|
||||
_ uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
|
@ -140,7 +134,7 @@ func (cs ClientState) VerifyConnectionState(
|
|||
return err
|
||||
}
|
||||
|
||||
bz := cs.store.Get([]byte(path.String()))
|
||||
bz := store.Get([]byte(path.String()))
|
||||
if bz == nil {
|
||||
return sdkerrors.Wrapf(clienttypes.ErrFailedConnectionStateVerification, "not found for path %s", path)
|
||||
}
|
||||
|
@ -164,6 +158,7 @@ func (cs ClientState) VerifyConnectionState(
|
|||
// VerifyChannelState verifies a proof of the channel state of the specified
|
||||
// channel end, under the specified port, stored on the local machine.
|
||||
func (cs ClientState) VerifyChannelState(
|
||||
store sdk.KVStore,
|
||||
cdc codec.Marshaler,
|
||||
_ uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
|
@ -178,7 +173,7 @@ func (cs ClientState) VerifyChannelState(
|
|||
return err
|
||||
}
|
||||
|
||||
bz := cs.store.Get([]byte(path.String()))
|
||||
bz := store.Get([]byte(path.String()))
|
||||
if bz == nil {
|
||||
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "not found for path %s", path)
|
||||
}
|
||||
|
@ -202,6 +197,7 @@ func (cs ClientState) VerifyChannelState(
|
|||
// VerifyPacketCommitment verifies a proof of an outgoing packet commitment at
|
||||
// the specified port, specified channel, and specified sequence.
|
||||
func (cs ClientState) VerifyPacketCommitment(
|
||||
store sdk.KVStore,
|
||||
_ uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
_ commitmentexported.Proof,
|
||||
|
@ -216,7 +212,7 @@ func (cs ClientState) VerifyPacketCommitment(
|
|||
return err
|
||||
}
|
||||
|
||||
data := cs.store.Get([]byte(path.String()))
|
||||
data := store.Get([]byte(path.String()))
|
||||
if len(data) == 0 {
|
||||
return sdkerrors.Wrapf(clienttypes.ErrFailedPacketCommitmentVerification, "not found for path %s", path)
|
||||
}
|
||||
|
@ -234,6 +230,7 @@ func (cs ClientState) VerifyPacketCommitment(
|
|||
// VerifyPacketAcknowledgement verifies a proof of an incoming packet
|
||||
// acknowledgement at the specified port, specified channel, and specified sequence.
|
||||
func (cs ClientState) VerifyPacketAcknowledgement(
|
||||
store sdk.KVStore,
|
||||
_ uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
_ commitmentexported.Proof,
|
||||
|
@ -248,7 +245,7 @@ func (cs ClientState) VerifyPacketAcknowledgement(
|
|||
return err
|
||||
}
|
||||
|
||||
data := cs.store.Get([]byte(path.String()))
|
||||
data := store.Get([]byte(path.String()))
|
||||
if len(data) == 0 {
|
||||
return sdkerrors.Wrapf(clienttypes.ErrFailedPacketAckVerification, "not found for path %s", path)
|
||||
}
|
||||
|
@ -267,6 +264,7 @@ func (cs ClientState) VerifyPacketAcknowledgement(
|
|||
// incoming packet acknowledgement at the specified port, specified channel, and
|
||||
// specified sequence.
|
||||
func (cs ClientState) VerifyPacketAcknowledgementAbsence(
|
||||
store sdk.KVStore,
|
||||
_ uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
_ commitmentexported.Proof,
|
||||
|
@ -280,7 +278,7 @@ func (cs ClientState) VerifyPacketAcknowledgementAbsence(
|
|||
return err
|
||||
}
|
||||
|
||||
data := cs.store.Get([]byte(path.String()))
|
||||
data := store.Get([]byte(path.String()))
|
||||
if data != nil {
|
||||
return sdkerrors.Wrap(clienttypes.ErrFailedPacketAckAbsenceVerification, "expected no ack absence")
|
||||
}
|
||||
|
@ -291,6 +289,7 @@ func (cs ClientState) VerifyPacketAcknowledgementAbsence(
|
|||
// VerifyNextSequenceRecv verifies a proof of the next sequence number to be
|
||||
// received of the specified channel at the specified port.
|
||||
func (cs ClientState) VerifyNextSequenceRecv(
|
||||
store sdk.KVStore,
|
||||
_ uint64,
|
||||
prefix commitmentexported.Prefix,
|
||||
_ commitmentexported.Proof,
|
||||
|
@ -304,7 +303,7 @@ func (cs ClientState) VerifyNextSequenceRecv(
|
|||
return err
|
||||
}
|
||||
|
||||
data := cs.store.Get([]byte(path.String()))
|
||||
data := store.Get([]byte(path.String()))
|
||||
if len(data) == 0 {
|
||||
return sdkerrors.Wrapf(clienttypes.ErrFailedNextSeqRecvVerification, "not found for path %s", path)
|
||||
}
|
||||
|
|
|
@ -23,22 +23,17 @@ func (suite *LocalhostTestSuite) TestValidate() {
|
|||
}{
|
||||
{
|
||||
name: "valid client",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
expPass: true,
|
||||
},
|
||||
{
|
||||
name: "invalid chain id",
|
||||
clientState: types.NewClientState(suite.store, " ", 10),
|
||||
clientState: types.NewClientState(" ", 10),
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "invalid height",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 0),
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "invalid store",
|
||||
clientState: types.NewClientState(nil, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 0),
|
||||
expPass: false,
|
||||
},
|
||||
}
|
||||
|
@ -63,13 +58,13 @@ func (suite *LocalhostTestSuite) TestVerifyClientConsensusState() {
|
|||
}{
|
||||
{
|
||||
name: "ApplyPrefix failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
prefix: commitmenttypes.MerklePrefix{},
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "proof verification failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
proof: commitmenttypes.MerkleProof{},
|
||||
expPass: false,
|
||||
|
@ -80,9 +75,7 @@ func (suite *LocalhostTestSuite) TestVerifyClientConsensusState() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyClientConsensusState(
|
||||
suite.aminoCdc, nil, height, "chainA", 0, tc.prefix, tc.proof, nil,
|
||||
|
||||
// suite.cdc, height, tc.prefix, tc.proof, nil,
|
||||
suite.store, suite.aminoCdc, nil, height, "chainA", 0, tc.prefix, tc.proof, nil,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -107,14 +100,14 @@ func (suite *LocalhostTestSuite) TestVerifyConnectionState() {
|
|||
}{
|
||||
{
|
||||
name: "ApplyPrefix failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
connection: conn,
|
||||
prefix: commitmenttypes.MerklePrefix{},
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "proof verification failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
connection: conn,
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
proof: commitmenttypes.MerkleProof{},
|
||||
|
@ -126,7 +119,7 @@ func (suite *LocalhostTestSuite) TestVerifyConnectionState() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyConnectionState(
|
||||
suite.cdc, height, tc.prefix, tc.proof, testConnectionID, &tc.connection, nil,
|
||||
suite.store, suite.cdc, height, tc.prefix, tc.proof, testConnectionID, &tc.connection, nil,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -151,21 +144,21 @@ func (suite *LocalhostTestSuite) TestVerifyChannelState() {
|
|||
}{
|
||||
{
|
||||
name: "ApplyPrefix failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
channel: ch,
|
||||
prefix: commitmenttypes.MerklePrefix{},
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "latest client height < height",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
channel: ch,
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "proof verification failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
channel: ch,
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
proof: commitmenttypes.MerkleProof{},
|
||||
|
@ -177,7 +170,7 @@ func (suite *LocalhostTestSuite) TestVerifyChannelState() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyChannelState(
|
||||
suite.cdc, height, tc.prefix, tc.proof, testPortID, testChannelID, &tc.channel, nil,
|
||||
suite.store, suite.cdc, height, tc.prefix, tc.proof, testPortID, testChannelID, &tc.channel, nil,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -199,28 +192,28 @@ func (suite *LocalhostTestSuite) TestVerifyPacketCommitment() {
|
|||
}{
|
||||
{
|
||||
name: "ApplyPrefix failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
commitment: []byte{},
|
||||
prefix: commitmenttypes.MerklePrefix{},
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "latest client height < height",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
commitment: []byte{},
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "client is frozen",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
commitment: []byte{},
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "proof verification failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
commitment: []byte{},
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
proof: commitmenttypes.MerkleProof{},
|
||||
|
@ -232,7 +225,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketCommitment() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyPacketCommitment(
|
||||
height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.commitment, nil,
|
||||
suite.store, height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.commitment, nil,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -254,28 +247,28 @@ func (suite *LocalhostTestSuite) TestVerifyPacketAcknowledgement() {
|
|||
}{
|
||||
{
|
||||
name: "ApplyPrefix failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
ack: []byte{},
|
||||
prefix: commitmenttypes.MerklePrefix{},
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "latest client height < height",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
ack: []byte{},
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "client is frozen",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
ack: []byte{},
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "proof verification failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
ack: []byte{},
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
proof: commitmenttypes.MerkleProof{},
|
||||
|
@ -287,7 +280,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketAcknowledgement() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyPacketAcknowledgement(
|
||||
height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.ack, nil,
|
||||
suite.store, height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, tc.ack, nil,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -308,7 +301,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketAcknowledgementAbsence() {
|
|||
}{
|
||||
{
|
||||
name: "ApplyPrefix failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
prefix: commitmenttypes.MerklePrefix{},
|
||||
expPass: false,
|
||||
},
|
||||
|
@ -318,7 +311,7 @@ func (suite *LocalhostTestSuite) TestVerifyPacketAcknowledgementAbsence() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyPacketAcknowledgementAbsence(
|
||||
height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, nil,
|
||||
suite.store, height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, nil,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
@ -339,25 +332,25 @@ func (suite *LocalhostTestSuite) TestVerifyNextSeqRecv() {
|
|||
}{
|
||||
{
|
||||
name: "ApplyPrefix failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
prefix: commitmenttypes.MerklePrefix{},
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "latest client height < height",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "client is frozen",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
expPass: false,
|
||||
},
|
||||
{
|
||||
name: "proof verification failed",
|
||||
clientState: types.NewClientState(suite.store, "chainID", 10),
|
||||
clientState: types.NewClientState("chainID", 10),
|
||||
prefix: commitmenttypes.NewMerklePrefix([]byte("ibc")),
|
||||
proof: commitmenttypes.MerkleProof{},
|
||||
expPass: false,
|
||||
|
@ -368,7 +361,7 @@ func (suite *LocalhostTestSuite) TestVerifyNextSeqRecv() {
|
|||
tc := tc
|
||||
|
||||
err := tc.clientState.VerifyNextSequenceRecv(
|
||||
height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, nil,
|
||||
suite.store, height, tc.prefix, tc.proof, testPortID, testChannelID, testSequence, nil,
|
||||
)
|
||||
|
||||
if tc.expPass {
|
||||
|
|
|
@ -5,12 +5,12 @@ import (
|
|||
|
||||
"github.com/stretchr/testify/suite"
|
||||
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/store/cachekv"
|
||||
"github.com/cosmos/cosmos-sdk/store/dbadapter"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
clientexported "github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -22,18 +22,17 @@ type LocalhostTestSuite struct {
|
|||
|
||||
aminoCdc *codec.Codec
|
||||
cdc codec.Marshaler
|
||||
store *cachekv.Store
|
||||
store sdk.KVStore
|
||||
}
|
||||
|
||||
func (suite *LocalhostTestSuite) SetupTest() {
|
||||
checkTx := false
|
||||
app := simapp.Setup(checkTx)
|
||||
isCheckTx := false
|
||||
app := simapp.Setup(isCheckTx)
|
||||
|
||||
suite.aminoCdc = app.Codec()
|
||||
suite.cdc = app.AppCodec()
|
||||
|
||||
mem := dbadapter.Store{DB: dbm.NewMemDB()}
|
||||
suite.store = cachekv.NewStore(mem)
|
||||
ctx := app.BaseApp.NewContext(isCheckTx, abci.Header{Height: 1})
|
||||
suite.store = app.IBCKeeper.ClientKeeper.ClientStore(ctx, clientexported.ClientTypeLocalHost)
|
||||
}
|
||||
|
||||
func TestLocalhostTestSuite(t *testing.T) {
|
||||
|
|
|
@ -29,7 +29,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
|
|||
ClientGenesis: client.NewGenesisState(
|
||||
[]exported.ClientState{
|
||||
ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header),
|
||||
localhosttypes.NewClientState(suite.store, "chaindID", 10),
|
||||
localhosttypes.NewClientState("chaindID", 10),
|
||||
},
|
||||
[]client.ConsensusStates{
|
||||
client.NewClientConsensusStates(
|
||||
|
@ -82,7 +82,7 @@ func (suite *IBCTestSuite) TestValidateGenesis() {
|
|||
ClientGenesis: client.NewGenesisState(
|
||||
[]exported.ClientState{
|
||||
ibctmtypes.NewClientState(clientID, trustingPeriod, ubdPeriod, maxClockDrift, suite.header),
|
||||
localhosttypes.NewClientState(suite.store, "chaindID", 0),
|
||||
localhosttypes.NewClientState("chaindID", 0),
|
||||
},
|
||||
nil,
|
||||
false,
|
||||
|
|
|
@ -8,12 +8,9 @@ import (
|
|||
|
||||
abci "github.com/tendermint/tendermint/abci/types"
|
||||
tmtypes "github.com/tendermint/tendermint/types"
|
||||
dbm "github.com/tendermint/tm-db"
|
||||
|
||||
"github.com/cosmos/cosmos-sdk/codec"
|
||||
"github.com/cosmos/cosmos-sdk/simapp"
|
||||
"github.com/cosmos/cosmos-sdk/store/cachekv"
|
||||
"github.com/cosmos/cosmos-sdk/store/dbadapter"
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
ibctmtypes "github.com/cosmos/cosmos-sdk/x/ibc/07-tendermint/types"
|
||||
ibctypes "github.com/cosmos/cosmos-sdk/x/ibc/types"
|
||||
|
@ -45,7 +42,6 @@ type IBCTestSuite struct {
|
|||
cdc *codec.Codec
|
||||
ctx sdk.Context
|
||||
app *simapp.SimApp
|
||||
store sdk.KVStore
|
||||
header ibctmtypes.Header
|
||||
}
|
||||
|
||||
|
@ -62,8 +58,6 @@ func (suite *IBCTestSuite) SetupTest() {
|
|||
val := tmtypes.NewValidator(pubKey, 10)
|
||||
valSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{val})
|
||||
|
||||
mem := dbadapter.Store{DB: dbm.NewMemDB()}
|
||||
suite.store = cachekv.NewStore(mem)
|
||||
suite.header = ibctmtypes.CreateTestHeader("chainID", 10, now, valSet, []tmtypes.PrivValidator{privVal})
|
||||
|
||||
suite.cdc = suite.app.Codec()
|
||||
|
|
Loading…
Reference in New Issue