From e42d403a07a842a3247cf693205b79cb28743618 Mon Sep 17 00:00:00 2001 From: Charly Date: Mon, 2 Oct 2023 15:08:41 +0200 Subject: [PATCH 01/11] revert 02-client changes --- modules/core/02-client/keeper/keeper.go | 23 ++----------------- modules/core/02-client/keeper/keeper_test.go | 2 +- .../core/03-connection/keeper/verify_test.go | 3 +-- .../03-connection/types/expected_keepers.go | 2 +- 4 files changed, 5 insertions(+), 25 deletions(-) diff --git a/modules/core/02-client/keeper/keeper.go b/modules/core/02-client/keeper/keeper.go index 5b78b0e5cfd..4fe7de0af5c 100644 --- a/modules/core/02-client/keeper/keeper.go +++ b/modules/core/02-client/keeper/keeper.go @@ -17,7 +17,6 @@ import ( "github.com/cometbft/cometbft/libs/log" "github.com/cometbft/cometbft/light" - wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" @@ -258,7 +257,7 @@ func (k Keeper) GetLatestClientConsensusState(ctx sdk.Context, clientID string) // GetSelfConsensusState introspects the (self) past historical info at a given height // and returns the expected consensus state at that height. // For now, can only retrieve self consensus states for the current revision -func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height, clientType string) (exported.ConsensusState, error) { +func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) { selfHeight, ok := height.(types.Height) if !ok { return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "expected %T, got %T", types.Height{}, height) @@ -273,22 +272,11 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height, c return nil, errorsmod.Wrapf(ibcerrors.ErrNotFound, "no historical info found at height %d", selfHeight.RevisionHeight) } - tmConsensusState := &ibctm.ConsensusState{ + consensusState := &ibctm.ConsensusState{ Timestamp: histInfo.Header.Time, Root: commitmenttypes.NewMerkleRoot(histInfo.Header.GetAppHash()), NextValidatorsHash: histInfo.Header.NextValidatorsHash, } - var consensusState exported.ConsensusState - consensusState = tmConsensusState - if clientType == exported.Wasm { - wasmData, err := k.cdc.MarshalInterface(tmConsensusState) - if err != nil { - return nil, errorsmod.Wrapf(ibcerrors.ErrInvalidType, "cannot marshal tendermint consensus state") - } - consensusState = &wasmtypes.ConsensusState{ - Data: wasmData, - } - } return consensusState, nil } @@ -297,13 +285,6 @@ func (k Keeper) GetSelfConsensusState(ctx sdk.Context, height exported.Height, c // This function is only used to validate the client state the counterparty stores for this chain // Client must be in same revision as the executing chain func (k Keeper) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error { - if clientState.ClientType() == exported.Wasm { - wasmClientState := clientState.(*wasmtypes.ClientState) - err := k.cdc.UnmarshalInterface(wasmClientState.Data, &clientState) - if err != nil { - return errorsmod.Wrapf(types.ErrInvalidClient, "cannot unmarshal wasm client state data") - } - } tmClient, ok := clientState.(*ibctm.ClientState) if !ok { return errorsmod.Wrapf(types.ErrInvalidClient, "client must be a Tendermint client, expected: %T, got: %T", diff --git a/modules/core/02-client/keeper/keeper_test.go b/modules/core/02-client/keeper/keeper_test.go index b2e8ba7209b..9bb1a6704c7 100644 --- a/modules/core/02-client/keeper/keeper_test.go +++ b/modules/core/02-client/keeper/keeper_test.go @@ -293,7 +293,7 @@ func (suite KeeperTestSuite) TestGetConsensusState() { //nolint:govet // this is for i, tc := range cases { tc := tc - cs, err := suite.keeper.GetSelfConsensusState(suite.ctx, tc.height, exported.Tendermint) + cs, err := suite.keeper.GetSelfConsensusState(suite.ctx, tc.height) if tc.expPass { suite.Require().NoError(err, "Case %d should have passed: %s", i, tc.name) suite.Require().NotNil(cs, "Case %d should have passed: %s", i, tc.name) diff --git a/modules/core/03-connection/keeper/verify_test.go b/modules/core/03-connection/keeper/verify_test.go index b640c9075c9..02ae1b617f6 100644 --- a/modules/core/03-connection/keeper/verify_test.go +++ b/modules/core/03-connection/keeper/verify_test.go @@ -136,10 +136,9 @@ func (suite *KeeperTestSuite) TestVerifyClientConsensusState() { tc.malleate() connection := path.EndpointA.GetConnection() - clientState := suite.chainB.GetClientState(path.EndpointB.ClientID) proof, consensusHeight := suite.chainB.QueryConsensusStateProof(path.EndpointB.ClientID) proofHeight := clienttypes.NewHeight(1, uint64(suite.chainB.GetContext().BlockHeight()-1)) - consensusState, err := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetSelfConsensusState(suite.chainA.GetContext(), consensusHeight, clientState.ClientType()) + consensusState, err := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetSelfConsensusState(suite.chainA.GetContext(), consensusHeight) suite.Require().NoError(err) err = suite.chainA.App.GetIBCKeeper().ConnectionKeeper.VerifyClientConsensusState( diff --git a/modules/core/03-connection/types/expected_keepers.go b/modules/core/03-connection/types/expected_keepers.go index de084388580..7082595a0bf 100644 --- a/modules/core/03-connection/types/expected_keepers.go +++ b/modules/core/03-connection/types/expected_keepers.go @@ -12,7 +12,7 @@ type ClientKeeper interface { GetClientStatus(ctx sdk.Context, clientState exported.ClientState, clientID string) exported.Status GetClientState(ctx sdk.Context, clientID string) (exported.ClientState, bool) GetClientConsensusState(ctx sdk.Context, clientID string, height exported.Height) (exported.ConsensusState, bool) - GetSelfConsensusState(ctx sdk.Context, height exported.Height, clientType string) (exported.ConsensusState, error) + GetSelfConsensusState(ctx sdk.Context, height exported.Height) (exported.ConsensusState, error) ValidateSelfClient(ctx sdk.Context, clientState exported.ClientState) error IterateClientStates(ctx sdk.Context, prefix []byte, cb func(string, exported.ClientState) bool) ClientStore(ctx sdk.Context, clientID string) storetypes.KVStore From 969633e4bd89de7b1c0bbf3d0c0057010a75a4f0 Mon Sep 17 00:00:00 2001 From: Charly Date: Mon, 2 Oct 2023 15:17:14 +0200 Subject: [PATCH 02/11] rm extra argument --- modules/core/03-connection/keeper/handshake.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/core/03-connection/keeper/handshake.go b/modules/core/03-connection/keeper/handshake.go index 9a2885304bc..60267beff36 100644 --- a/modules/core/03-connection/keeper/handshake.go +++ b/modules/core/03-connection/keeper/handshake.go @@ -98,7 +98,7 @@ func (k Keeper) ConnOpenTry( return "", err } - expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight, clientState.ClientType()) + expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight) if err != nil { return "", errorsmod.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) } @@ -210,7 +210,7 @@ func (k Keeper) ConnOpenAck( } // Retrieve chainA's consensus state at consensusheight - expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight, clientState.ClientType()) + expectedConsensusState, err := k.clientKeeper.GetSelfConsensusState(ctx, consensusHeight) if err != nil { return errorsmod.Wrapf(err, "self consensus state not found for height %s", consensusHeight.String()) } From da2d494bdf77205377d901f8b76594158c084822 Mon Sep 17 00:00:00 2001 From: Charly Date: Mon, 2 Oct 2023 15:44:12 +0200 Subject: [PATCH 03/11] rm 08-wasm dependency from ibc-go go.mod --- README.md | 2 +- go.mod | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 798bc38f4d7..1d1672db4f1 100644 --- a/README.md +++ b/README.md @@ -92,7 +92,7 @@ To report a security vulnerability, see our [Coordinated Vulnerability Disclosur The following audits have been performed on the `ibc-go` source code: -- [ICS27 Interchain Accounts](https://github.com/cosmos/ibc-go/tree/main/docs/apps/interchain-accounts/audits) by Trail of Bits +- [ICS27 Interchain Accounts](https://github.com/cosmos/ibc-go/blob/main/docs/audits/Trail%20of%20Bits%20audit%20-%20Final%20Report.pdf) by Trail of Bits ## Quick Navigation diff --git a/go.mod b/go.mod index f75bc3d57eb..5cc00738dbe 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/cosmos/cosmos-sdk v0.47.5 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-go/modules/capability v1.0.0-rc1 - github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0 + github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-00010101000000-000000000000 github.com/cosmos/ics23/go v0.10.0 github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/grpc-gateway v1.16.0 From ccb077713d8413730eb37f90f6e29702438f3a15 Mon Sep 17 00:00:00 2001 From: Charly Date: Mon, 2 Oct 2023 15:50:37 +0200 Subject: [PATCH 04/11] comment out wasm tendermint tests --- .../08-wasm/types/client_state_test.go | 1205 +++++++------- .../08-wasm/types/genesis_test.go | 156 +- .../08-wasm/types/misbehaviour_handle_test.go | 1380 ++++++++--------- .../08-wasm/types/proposal_handle_test.go | 392 ++--- .../light-clients/08-wasm/types/types_test.go | 66 +- .../08-wasm/types/update_test.go | 1295 ++++++++-------- .../08-wasm/types/upgrade_test.go | 1074 +++++++------ 7 files changed, 2764 insertions(+), 2804 deletions(-) diff --git a/modules/light-clients/08-wasm/types/client_state_test.go b/modules/light-clients/08-wasm/types/client_state_test.go index 76d4429a12b..8c4cd2ed588 100644 --- a/modules/light-clients/08-wasm/types/client_state_test.go +++ b/modules/light-clients/08-wasm/types/client_state_test.go @@ -5,10 +5,7 @@ import ( "encoding/base64" "time" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" - transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -89,81 +86,81 @@ func (suite *TypesTestSuite) TestStatusGrandpa() { } } -func (suite *TypesTestSuite) TestStatusTendermint() { - var ( - path *ibctesting.Path - clientState *types.ClientState - tmClientState *tmtypes.ClientState - ) - - testCases := []struct { - name string - malleate func() - expStatus exported.Status - }{ - { - "client is active", - func() {}, - exported.Active, - }, - { - "client is frozen", - func() { - tmClientState.FrozenHeight = clienttypes.NewHeight(0, 1) - - wasmData, err := suite.chainA.Codec.MarshalInterface(tmClientState) - suite.Require().NoError(err) - - clientState.Data = wasmData - path.EndpointA.SetClientState(clientState) - }, - exported.Frozen, - }, - { - "client status without consensus state", - func() { - latestHeight := clientState.LatestHeight.Increment().(clienttypes.Height) - tmClientState.LatestHeight = latestHeight - - wasmData, err := suite.chainA.Codec.MarshalInterface(tmClientState) - suite.Require().NoError(err) - - clientState.Data = wasmData - clientState.LatestHeight = latestHeight - path.EndpointA.SetClientState(clientState) - }, - exported.Expired, - }, - { - "client status is expired", - func() { - suite.coordinator.IncrementTimeBy(tmClientState.TrustingPeriod) - }, - exported.Expired, - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - suite.SetupWasmTendermint() - path = ibctesting.NewPath(suite.chainA, suite.chainB) - suite.coordinator.SetupClients(path) - - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - clientState = path.EndpointA.GetClientState().(*types.ClientState) - - var cs exported.ClientState - err := suite.chainA.Codec.UnmarshalInterface(clientState.Data, &cs) - suite.Require().NoError(err) - tmClientState = cs.(*tmtypes.ClientState) - - tc.malleate() - - status := clientState.Status(suite.chainA.GetContext(), clientStore, suite.chainA.App.AppCodec()) - suite.Require().Equal(tc.expStatus, status) - }) - } -} +// func (suite *TypesTestSuite) TestStatusTendermint() { +// var ( +// path *ibctesting.Path +// clientState *types.ClientState +// tmClientState *tmtypes.ClientState +// ) + +// testCases := []struct { +// name string +// malleate func() +// expStatus exported.Status +// }{ +// { +// "client is active", +// func() {}, +// exported.Active, +// }, +// { +// "client is frozen", +// func() { +// tmClientState.FrozenHeight = clienttypes.NewHeight(0, 1) + +// wasmData, err := suite.chainA.Codec.MarshalInterface(tmClientState) +// suite.Require().NoError(err) + +// clientState.Data = wasmData +// path.EndpointA.SetClientState(clientState) +// }, +// exported.Frozen, +// }, +// { +// "client status without consensus state", +// func() { +// latestHeight := clientState.LatestHeight.Increment().(clienttypes.Height) +// tmClientState.LatestHeight = latestHeight + +// wasmData, err := suite.chainA.Codec.MarshalInterface(tmClientState) +// suite.Require().NoError(err) + +// clientState.Data = wasmData +// clientState.LatestHeight = latestHeight +// path.EndpointA.SetClientState(clientState) +// }, +// exported.Expired, +// }, +// { +// "client status is expired", +// func() { +// suite.coordinator.IncrementTimeBy(tmClientState.TrustingPeriod) +// }, +// exported.Expired, +// }, +// } + +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// suite.SetupWasmTendermint() +// path = ibctesting.NewPath(suite.chainA, suite.chainB) +// suite.coordinator.SetupClients(path) + +// clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) +// clientState = path.EndpointA.GetClientState().(*types.ClientState) + +// var cs exported.ClientState +// err := suite.chainA.Codec.UnmarshalInterface(clientState.Data, &cs) +// suite.Require().NoError(err) +// tmClientState = cs.(*tmtypes.ClientState) + +// tc.malleate() + +// status := clientState.Status(suite.chainA.GetContext(), clientStore, suite.chainA.App.AppCodec()) +// suite.Require().Equal(tc.expStatus, status) +// }) +// } +// } func (suite *TypesTestSuite) TestValidate() { testCases := []struct { @@ -274,66 +271,66 @@ func (suite *TypesTestSuite) TestInitializeGrandpa() { } } -func (suite *TypesTestSuite) TestInitializeTendermint() { - var consensusState exported.ConsensusState - testCases := []struct { - name string - malleate func() - expPass bool - }{ - { - name: "valid consensus", - malleate: func() { - tmConsensusState := tmtypes.NewConsensusState(time.Now(), commitmenttypes.NewMerkleRoot([]byte{0}), []byte(codeHash)) - tmConsensusStateData, err := suite.chainA.Codec.MarshalInterface(tmConsensusState) - suite.Require().NoError(err) - - consensusState = types.NewConsensusState(tmConsensusStateData, 1) - }, - expPass: true, - }, - { - name: "invalid consensus: consensus state is solomachine consensus", - malleate: func() { - consensusState = ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachine", "", 2).ConsensusState() - }, - expPass: false, - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - suite.SetupWasmTendermint() - path := ibctesting.NewPath(suite.chainA, suite.chainB) - - tmConfig, ok := path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig) - suite.Require().True(ok) - - tmClientState := tmtypes.NewClientState( - path.EndpointB.Chain.ChainID, - tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift, - suite.chainB.LastHeader.GetHeight().(clienttypes.Height), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, - ) - tmClientStateData, err := suite.chainA.Codec.MarshalInterface(tmClientState) - suite.Require().NoError(err) - wasmClientState := types.NewClientState(tmClientStateData, suite.codeHash, tmClientState.LatestHeight) - - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, path.EndpointA.ClientID) - tc.malleate() - err = wasmClientState.Initialize(suite.ctx, suite.chainA.Codec, clientStore, consensusState) - - if tc.expPass { - suite.Require().NoError(err) - suite.Require().True(clientStore.Has(host.ClientStateKey())) - suite.Require().True(clientStore.Has(host.ConsensusStateKey(suite.chainB.LastHeader.GetHeight()))) - } else { - suite.Require().Error(err) - suite.Require().False(clientStore.Has(host.ClientStateKey())) - suite.Require().False(clientStore.Has(host.ConsensusStateKey(suite.chainB.LastHeader.GetHeight()))) - } - }) - } -} +// func (suite *TypesTestSuite) TestInitializeTendermint() { +// var consensusState exported.ConsensusState +// testCases := []struct { +// name string +// malleate func() +// expPass bool +// }{ +// { +// name: "valid consensus", +// malleate: func() { +// tmConsensusState := tmtypes.NewConsensusState(time.Now(), commitmenttypes.NewMerkleRoot([]byte{0}), []byte(codeHash)) +// tmConsensusStateData, err := suite.chainA.Codec.MarshalInterface(tmConsensusState) +// suite.Require().NoError(err) + +// consensusState = types.NewConsensusState(tmConsensusStateData, 1) +// }, +// expPass: true, +// }, +// { +// name: "invalid consensus: consensus state is solomachine consensus", +// malleate: func() { +// consensusState = ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solomachine", "", 2).ConsensusState() +// }, +// expPass: false, +// }, +// } + +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// suite.SetupWasmTendermint() +// path := ibctesting.NewPath(suite.chainA, suite.chainB) + +// tmConfig, ok := path.EndpointB.ClientConfig.(*ibctesting.TendermintConfig) +// suite.Require().True(ok) + +// tmClientState := tmtypes.NewClientState( +// path.EndpointB.Chain.ChainID, +// tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift, +// suite.chainB.LastHeader.GetHeight().(clienttypes.Height), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath, +// ) +// tmClientStateData, err := suite.chainA.Codec.MarshalInterface(tmClientState) +// suite.Require().NoError(err) +// wasmClientState := types.NewClientState(tmClientStateData, suite.codeHash, tmClientState.LatestHeight) + +// clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, path.EndpointA.ClientID) +// tc.malleate() +// err = wasmClientState.Initialize(suite.ctx, suite.chainA.Codec, clientStore, consensusState) + +// if tc.expPass { +// suite.Require().NoError(err) +// suite.Require().True(clientStore.Has(host.ClientStateKey())) +// suite.Require().True(clientStore.Has(host.ConsensusStateKey(suite.chainB.LastHeader.GetHeight()))) +// } else { +// suite.Require().Error(err) +// suite.Require().False(clientStore.Has(host.ClientStateKey())) +// suite.Require().False(clientStore.Has(host.ConsensusStateKey(suite.chainB.LastHeader.GetHeight()))) +// } +// }) +// } +// } func (suite *TypesTestSuite) TestVerifyMembershipGrandpa() { const ( @@ -581,258 +578,258 @@ func (suite *TypesTestSuite) TestVerifyMembershipGrandpa() { } } -func (suite *TypesTestSuite) TestVerifyMembershipTendermint() { - var ( - testingpath *ibctesting.Path - err error - proofHeight exported.Height - proof []byte - path exported.Path - value []byte - delayTimePeriod uint64 - delayBlockPeriod uint64 - ) - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - { - "successful ClientState verification", - func() { - // default proof construction uses ClientState - }, - true, - }, - { - "successful ConsensusState verification", func() { - key := host.FullConsensusStateKey(testingpath.EndpointB.ClientID, testingpath.EndpointB.GetClientState().GetLatestHeight()) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = suite.chainB.QueryProof(key) - - consensusState := testingpath.EndpointB.GetConsensusState(testingpath.EndpointB.GetClientState().GetLatestHeight()).(*types.ConsensusState) - value, err = suite.chainB.Codec.MarshalInterface(consensusState) - suite.Require().NoError(err) - }, - true, - }, - { - "successful Connection verification", func() { - key := host.ConnectionKey(testingpath.EndpointB.ConnectionID) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = suite.chainB.QueryProof(key) - - connection := testingpath.EndpointB.GetConnection() - value, err = suite.chainB.Codec.Marshal(&connection) - suite.Require().NoError(err) - }, - true, - }, - { - "successful Channel verification", func() { - key := host.ChannelKey(testingpath.EndpointB.ChannelConfig.PortID, testingpath.EndpointB.ChannelID) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = suite.chainB.QueryProof(key) - - channel := testingpath.EndpointB.GetChannel() - value, err = suite.chainB.Codec.Marshal(&channel) - suite.Require().NoError(err) - }, - true, - }, - { - "successful PacketCommitment verification", func() { - // send from chainB to chainA since we are proving chainB sent a packet - sequence, err := testingpath.EndpointB.SendPacket(clienttypes.NewHeight(1, 100), 0, ibctesting.MockPacketData) - suite.Require().NoError(err) - - // make packet commitment proof - packet := channeltypes.NewPacket(ibctesting.MockPacketData, sequence, testingpath.EndpointB.ChannelConfig.PortID, testingpath.EndpointB.ChannelID, testingpath.EndpointA.ChannelConfig.PortID, testingpath.EndpointA.ChannelID, clienttypes.NewHeight(1, 100), 0) - key := host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = testingpath.EndpointB.QueryProof(key) - - value = channeltypes.CommitPacket(suite.chainA.App.GetIBCKeeper().Codec(), packet) - }, true, - }, - { - "successful Acknowledgement verification", func() { - // send from chainA to chainB since we are proving chainB wrote an acknowledgement - sequence, err := testingpath.EndpointA.SendPacket(clienttypes.NewHeight(1, 100), 0, ibctesting.MockPacketData) - suite.Require().NoError(err) - - // write receipt and ack - packet := channeltypes.NewPacket(ibctesting.MockPacketData, sequence, testingpath.EndpointA.ChannelConfig.PortID, testingpath.EndpointA.ChannelID, testingpath.EndpointB.ChannelConfig.PortID, testingpath.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) - err = testingpath.EndpointB.RecvPacket(packet) - suite.Require().NoError(err) - - key := host.PacketAcknowledgementKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = testingpath.EndpointB.QueryProof(key) - - value = channeltypes.CommitAcknowledgement(ibcmock.MockAcknowledgement.Acknowledgement()) - }, - true, - }, - { - "successful NextSequenceRecv verification", func() { - // send from chainA to chainB since we are proving chainB incremented the sequence recv - - // send packet - sequence, err := testingpath.EndpointA.SendPacket(clienttypes.NewHeight(1, 100), 0, ibctesting.MockPacketData) - suite.Require().NoError(err) - - // next seq recv incremented - packet := channeltypes.NewPacket(ibctesting.MockPacketData, sequence, testingpath.EndpointA.ChannelConfig.PortID, testingpath.EndpointA.ChannelID, testingpath.EndpointB.ChannelConfig.PortID, testingpath.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) - err = testingpath.EndpointB.RecvPacket(packet) - suite.Require().NoError(err) - - key := host.NextSequenceRecvKey(packet.GetSourcePort(), packet.GetSourceChannel()) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = testingpath.EndpointB.QueryProof(key) - - value = sdk.Uint64ToBigEndian(packet.GetSequence() + 1) - }, - true, - }, - { - "successful verification outside IBC store", func() { - key := transfertypes.PortKey - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(transfertypes.StoreKey)), merklePath) - suite.Require().NoError(err) - - clientState := testingpath.EndpointA.GetClientState() - proof, proofHeight = suite.chainB.QueryProofForStore(transfertypes.StoreKey, key, int64(clientState.GetLatestHeight().GetRevisionHeight())) - - value = []byte(GetSimApp(suite.chainB).TransferKeeper.GetPort(suite.chainB.GetContext())) - suite.Require().NoError(err) - }, - true, - }, - { - "delay time period has passed", func() { - delayTimePeriod = uint64(time.Second.Nanoseconds()) - }, - true, - }, - { - "delay time period has not passed", func() { - delayTimePeriod = uint64(time.Hour.Nanoseconds()) - }, - false, - }, - { - "delay block period has passed", func() { - delayBlockPeriod = 1 - }, - true, - }, - { - "delay block period has not passed", func() { - delayBlockPeriod = 1000 - }, - false, - }, - { - "latest client height < height", func() { - proofHeight = testingpath.EndpointA.GetClientState().GetLatestHeight().Increment() - }, false, - }, - { - "invalid path type", - func() { - path = ibcmock.KeyPath{} - }, - false, - }, - { - "failed to unmarshal merkle proof", func() { - proof = []byte("invalid proof") - }, false, - }, - { - "consensus state not found", func() { - proofHeight = clienttypes.ZeroHeight() - }, false, - }, - { - "proof verification failed", func() { - // change the value being proved - value = []byte("invalid value") - }, false, - }, - { - "proof is empty", func() { - // change the inserted proof - proof = []byte{} - }, false, - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - suite.SetupWasmTendermint() // reset - testingpath = ibctesting.NewPath(suite.chainA, suite.chainB) - testingpath.SetChannelOrdered() - suite.coordinator.Setup(testingpath) - - // reset time and block delays to 0, malleate may change to a specific non-zero value. - delayTimePeriod = 0 - delayBlockPeriod = 0 - - // create default proof, merklePath, and value which passes - // may be overwritten by malleate() - key := host.FullClientStateKey(testingpath.EndpointB.ClientID) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = suite.chainB.QueryProof(key) - - clientState := testingpath.EndpointB.GetClientState().(*types.ClientState) - value, err = suite.chainB.Codec.MarshalInterface(clientState) - suite.Require().NoError(err) - - tc.malleate() // make changes as necessary - - clientState = testingpath.EndpointA.GetClientState().(*types.ClientState) - - ctx := suite.chainA.GetContext() - store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, testingpath.EndpointA.ClientID) - - err = clientState.VerifyMembership( - ctx, store, suite.chainA.Codec, proofHeight, delayTimePeriod, delayBlockPeriod, - proof, path, value, - ) - - if tc.expPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - }) - } -} +// func (suite *TypesTestSuite) TestVerifyMembershipTendermint() { +// var ( +// testingpath *ibctesting.Path +// err error +// proofHeight exported.Height +// proof []byte +// path exported.Path +// value []byte +// delayTimePeriod uint64 +// delayBlockPeriod uint64 +// ) + +// testCases := []struct { +// name string +// malleate func() +// expPass bool +// }{ +// { +// "successful ClientState verification", +// func() { +// // default proof construction uses ClientState +// }, +// true, +// }, +// { +// "successful ConsensusState verification", func() { +// key := host.FullConsensusStateKey(testingpath.EndpointB.ClientID, testingpath.EndpointB.GetClientState().GetLatestHeight()) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = suite.chainB.QueryProof(key) + +// consensusState := testingpath.EndpointB.GetConsensusState(testingpath.EndpointB.GetClientState().GetLatestHeight()).(*types.ConsensusState) +// value, err = suite.chainB.Codec.MarshalInterface(consensusState) +// suite.Require().NoError(err) +// }, +// true, +// }, +// { +// "successful Connection verification", func() { +// key := host.ConnectionKey(testingpath.EndpointB.ConnectionID) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = suite.chainB.QueryProof(key) + +// connection := testingpath.EndpointB.GetConnection() +// value, err = suite.chainB.Codec.Marshal(&connection) +// suite.Require().NoError(err) +// }, +// true, +// }, +// { +// "successful Channel verification", func() { +// key := host.ChannelKey(testingpath.EndpointB.ChannelConfig.PortID, testingpath.EndpointB.ChannelID) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = suite.chainB.QueryProof(key) + +// channel := testingpath.EndpointB.GetChannel() +// value, err = suite.chainB.Codec.Marshal(&channel) +// suite.Require().NoError(err) +// }, +// true, +// }, +// { +// "successful PacketCommitment verification", func() { +// // send from chainB to chainA since we are proving chainB sent a packet +// sequence, err := testingpath.EndpointB.SendPacket(clienttypes.NewHeight(1, 100), 0, ibctesting.MockPacketData) +// suite.Require().NoError(err) + +// // make packet commitment proof +// packet := channeltypes.NewPacket(ibctesting.MockPacketData, sequence, testingpath.EndpointB.ChannelConfig.PortID, testingpath.EndpointB.ChannelID, testingpath.EndpointA.ChannelConfig.PortID, testingpath.EndpointA.ChannelID, clienttypes.NewHeight(1, 100), 0) +// key := host.PacketCommitmentKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = testingpath.EndpointB.QueryProof(key) + +// value = channeltypes.CommitPacket(suite.chainA.App.GetIBCKeeper().Codec(), packet) +// }, true, +// }, +// { +// "successful Acknowledgement verification", func() { +// // send from chainA to chainB since we are proving chainB wrote an acknowledgement +// sequence, err := testingpath.EndpointA.SendPacket(clienttypes.NewHeight(1, 100), 0, ibctesting.MockPacketData) +// suite.Require().NoError(err) + +// // write receipt and ack +// packet := channeltypes.NewPacket(ibctesting.MockPacketData, sequence, testingpath.EndpointA.ChannelConfig.PortID, testingpath.EndpointA.ChannelID, testingpath.EndpointB.ChannelConfig.PortID, testingpath.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) +// err = testingpath.EndpointB.RecvPacket(packet) +// suite.Require().NoError(err) + +// key := host.PacketAcknowledgementKey(packet.GetSourcePort(), packet.GetSourceChannel(), packet.GetSequence()) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = testingpath.EndpointB.QueryProof(key) + +// value = channeltypes.CommitAcknowledgement(ibcmock.MockAcknowledgement.Acknowledgement()) +// }, +// true, +// }, +// { +// "successful NextSequenceRecv verification", func() { +// // send from chainA to chainB since we are proving chainB incremented the sequence recv + +// // send packet +// sequence, err := testingpath.EndpointA.SendPacket(clienttypes.NewHeight(1, 100), 0, ibctesting.MockPacketData) +// suite.Require().NoError(err) + +// // next seq recv incremented +// packet := channeltypes.NewPacket(ibctesting.MockPacketData, sequence, testingpath.EndpointA.ChannelConfig.PortID, testingpath.EndpointA.ChannelID, testingpath.EndpointB.ChannelConfig.PortID, testingpath.EndpointB.ChannelID, clienttypes.NewHeight(1, 100), 0) +// err = testingpath.EndpointB.RecvPacket(packet) +// suite.Require().NoError(err) + +// key := host.NextSequenceRecvKey(packet.GetSourcePort(), packet.GetSourceChannel()) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = testingpath.EndpointB.QueryProof(key) + +// value = sdk.Uint64ToBigEndian(packet.GetSequence() + 1) +// }, +// true, +// }, +// { +// "successful verification outside IBC store", func() { +// key := transfertypes.PortKey +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(transfertypes.StoreKey)), merklePath) +// suite.Require().NoError(err) + +// clientState := testingpath.EndpointA.GetClientState() +// proof, proofHeight = suite.chainB.QueryProofForStore(transfertypes.StoreKey, key, int64(clientState.GetLatestHeight().GetRevisionHeight())) + +// value = []byte(GetSimApp(suite.chainB).TransferKeeper.GetPort(suite.chainB.GetContext())) +// suite.Require().NoError(err) +// }, +// true, +// }, +// { +// "delay time period has passed", func() { +// delayTimePeriod = uint64(time.Second.Nanoseconds()) +// }, +// true, +// }, +// { +// "delay time period has not passed", func() { +// delayTimePeriod = uint64(time.Hour.Nanoseconds()) +// }, +// false, +// }, +// { +// "delay block period has passed", func() { +// delayBlockPeriod = 1 +// }, +// true, +// }, +// { +// "delay block period has not passed", func() { +// delayBlockPeriod = 1000 +// }, +// false, +// }, +// { +// "latest client height < height", func() { +// proofHeight = testingpath.EndpointA.GetClientState().GetLatestHeight().Increment() +// }, false, +// }, +// { +// "invalid path type", +// func() { +// path = ibcmock.KeyPath{} +// }, +// false, +// }, +// { +// "failed to unmarshal merkle proof", func() { +// proof = []byte("invalid proof") +// }, false, +// }, +// { +// "consensus state not found", func() { +// proofHeight = clienttypes.ZeroHeight() +// }, false, +// }, +// { +// "proof verification failed", func() { +// // change the value being proved +// value = []byte("invalid value") +// }, false, +// }, +// { +// "proof is empty", func() { +// // change the inserted proof +// proof = []byte{} +// }, false, +// }, +// } + +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// suite.SetupWasmTendermint() // reset +// testingpath = ibctesting.NewPath(suite.chainA, suite.chainB) +// testingpath.SetChannelOrdered() +// suite.coordinator.Setup(testingpath) + +// // reset time and block delays to 0, malleate may change to a specific non-zero value. +// delayTimePeriod = 0 +// delayBlockPeriod = 0 + +// // create default proof, merklePath, and value which passes +// // may be overwritten by malleate() +// key := host.FullClientStateKey(testingpath.EndpointB.ClientID) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = suite.chainB.QueryProof(key) + +// clientState := testingpath.EndpointB.GetClientState().(*types.ClientState) +// value, err = suite.chainB.Codec.MarshalInterface(clientState) +// suite.Require().NoError(err) + +// tc.malleate() // make changes as necessary + +// clientState = testingpath.EndpointA.GetClientState().(*types.ClientState) + +// ctx := suite.chainA.GetContext() +// store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, testingpath.EndpointA.ClientID) + +// err = clientState.VerifyMembership( +// ctx, store, suite.chainA.Codec, proofHeight, delayTimePeriod, delayBlockPeriod, +// proof, path, value, +// ) + +// if tc.expPass { +// suite.Require().NoError(err) +// } else { +// suite.Require().Error(err) +// } +// }) +// } +// } func (suite *TypesTestSuite) TestVerifyNonMembershipGrandpa() { const ( @@ -1031,217 +1028,217 @@ func (suite *TypesTestSuite) TestVerifyNonMembershipGrandpa() { } } -func (suite *TypesTestSuite) TestVerifyNonMembershipTendermint() { - const ( - invalidClientID = "09-tendermint-0" - invalidConnectionID = "connection-100" - invalidChannelID = "channel-800" - invalidPortID = "invalid-port" - ) - - var ( - testingpath *ibctesting.Path - delayTimePeriod uint64 - delayBlockPeriod uint64 - err error - proofHeight exported.Height - path exported.Path - proof []byte - ) - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - { - "successful ClientState verification of non membership", - func() { - // default proof construction uses ClientState - }, - true, - }, - { - "successful ConsensusState verification of non membership", func() { - key := host.FullConsensusStateKey(invalidClientID, testingpath.EndpointB.GetClientState().GetLatestHeight()) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = suite.chainB.QueryProof(key) - }, - true, - }, - { - "successful Connection verification of non membership", func() { - key := host.ConnectionKey(invalidConnectionID) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = suite.chainB.QueryProof(key) - }, - true, - }, - { - "successful Channel verification of non membership", func() { - key := host.ChannelKey(testingpath.EndpointB.ChannelConfig.PortID, invalidChannelID) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = suite.chainB.QueryProof(key) - }, - true, - }, - { - "successful PacketCommitment verification of non membership", func() { - // make packet commitment proof - key := host.PacketCommitmentKey(invalidPortID, invalidChannelID, 1) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = testingpath.EndpointB.QueryProof(key) - }, true, - }, - { - "successful Acknowledgement verification of non membership", func() { - key := host.PacketAcknowledgementKey(invalidPortID, invalidChannelID, 1) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = testingpath.EndpointB.QueryProof(key) - }, - true, - }, - { - "successful NextSequenceRecv verification of non membership", func() { - key := host.NextSequenceRecvKey(invalidPortID, invalidChannelID) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = testingpath.EndpointB.QueryProof(key) - }, - true, - }, - { - "successful verification of non membership outside IBC store", func() { - key := []byte{0x08} - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(transfertypes.StoreKey)), merklePath) - suite.Require().NoError(err) - - clientState := testingpath.EndpointA.GetClientState() - proof, proofHeight = suite.chainB.QueryProofForStore(transfertypes.StoreKey, key, int64(clientState.GetLatestHeight().GetRevisionHeight())) - }, - true, - }, - { - "delay time period has passed", func() { - delayTimePeriod = uint64(time.Second.Nanoseconds()) - }, - true, - }, - { - "delay time period has not passed", func() { - delayTimePeriod = uint64(time.Hour.Nanoseconds()) - }, - false, - }, - { - "delay block period has passed", func() { - delayBlockPeriod = 1 - }, - true, - }, - { - "delay block period has not passed", func() { - delayBlockPeriod = 1000 - }, - false, - }, - { - "latest client height < height", func() { - proofHeight = testingpath.EndpointA.GetClientState().GetLatestHeight().Increment() - }, false, - }, - { - "invalid path type", - func() { - path = ibcmock.KeyPath{} - }, - false, - }, - { - "failed to unmarshal merkle proof", func() { - proof = []byte("invalid proof") - }, false, - }, - { - "consensus state not found", func() { - proofHeight = clienttypes.ZeroHeight() - }, false, - }, - { - "verify non membership fails as path exists", func() { - // change the value being proved - key := host.FullClientStateKey(testingpath.EndpointB.ClientID) - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = suite.chainB.QueryProof(key) - }, false, - }, - { - "proof is empty", func() { - // change the inserted proof - proof = []byte{} - }, false, - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - suite.SetupWasmTendermint() // reset - testingpath = ibctesting.NewPath(suite.chainA, suite.chainB) - testingpath.SetChannelOrdered() - suite.coordinator.Setup(testingpath) - - // reset time and block delays to 0, malleate may change to a specific non-zero value. - delayTimePeriod = 0 - delayBlockPeriod = 0 - - // create default proof, merklePath, and value which passes - // may be overwritten by malleate() - key := host.FullClientStateKey(invalidClientID) - - merklePath := commitmenttypes.NewMerklePath(string(key)) - path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) - suite.Require().NoError(err) - - proof, proofHeight = suite.chainB.QueryProof(key) - - tc.malleate() // make changes as necessary - - clientState := testingpath.EndpointA.GetClientState().(*types.ClientState) - - ctx := suite.chainA.GetContext() - store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, testingpath.EndpointA.ClientID) - - err = clientState.VerifyNonMembership( - ctx, store, suite.chainA.Codec, proofHeight, delayTimePeriod, delayBlockPeriod, - proof, path, - ) - - if tc.expPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - }) - } -} +// func (suite *TypesTestSuite) TestVerifyNonMembershipTendermint() { +// const ( +// invalidClientID = "09-tendermint-0" +// invalidConnectionID = "connection-100" +// invalidChannelID = "channel-800" +// invalidPortID = "invalid-port" +// ) + +// var ( +// testingpath *ibctesting.Path +// delayTimePeriod uint64 +// delayBlockPeriod uint64 +// err error +// proofHeight exported.Height +// path exported.Path +// proof []byte +// ) + +// testCases := []struct { +// name string +// malleate func() +// expPass bool +// }{ +// { +// "successful ClientState verification of non membership", +// func() { +// // default proof construction uses ClientState +// }, +// true, +// }, +// { +// "successful ConsensusState verification of non membership", func() { +// key := host.FullConsensusStateKey(invalidClientID, testingpath.EndpointB.GetClientState().GetLatestHeight()) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = suite.chainB.QueryProof(key) +// }, +// true, +// }, +// { +// "successful Connection verification of non membership", func() { +// key := host.ConnectionKey(invalidConnectionID) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = suite.chainB.QueryProof(key) +// }, +// true, +// }, +// { +// "successful Channel verification of non membership", func() { +// key := host.ChannelKey(testingpath.EndpointB.ChannelConfig.PortID, invalidChannelID) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = suite.chainB.QueryProof(key) +// }, +// true, +// }, +// { +// "successful PacketCommitment verification of non membership", func() { +// // make packet commitment proof +// key := host.PacketCommitmentKey(invalidPortID, invalidChannelID, 1) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = testingpath.EndpointB.QueryProof(key) +// }, true, +// }, +// { +// "successful Acknowledgement verification of non membership", func() { +// key := host.PacketAcknowledgementKey(invalidPortID, invalidChannelID, 1) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = testingpath.EndpointB.QueryProof(key) +// }, +// true, +// }, +// { +// "successful NextSequenceRecv verification of non membership", func() { +// key := host.NextSequenceRecvKey(invalidPortID, invalidChannelID) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = testingpath.EndpointB.QueryProof(key) +// }, +// true, +// }, +// { +// "successful verification of non membership outside IBC store", func() { +// key := []byte{0x08} +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(transfertypes.StoreKey)), merklePath) +// suite.Require().NoError(err) + +// clientState := testingpath.EndpointA.GetClientState() +// proof, proofHeight = suite.chainB.QueryProofForStore(transfertypes.StoreKey, key, int64(clientState.GetLatestHeight().GetRevisionHeight())) +// }, +// true, +// }, +// { +// "delay time period has passed", func() { +// delayTimePeriod = uint64(time.Second.Nanoseconds()) +// }, +// true, +// }, +// { +// "delay time period has not passed", func() { +// delayTimePeriod = uint64(time.Hour.Nanoseconds()) +// }, +// false, +// }, +// { +// "delay block period has passed", func() { +// delayBlockPeriod = 1 +// }, +// true, +// }, +// { +// "delay block period has not passed", func() { +// delayBlockPeriod = 1000 +// }, +// false, +// }, +// { +// "latest client height < height", func() { +// proofHeight = testingpath.EndpointA.GetClientState().GetLatestHeight().Increment() +// }, false, +// }, +// { +// "invalid path type", +// func() { +// path = ibcmock.KeyPath{} +// }, +// false, +// }, +// { +// "failed to unmarshal merkle proof", func() { +// proof = []byte("invalid proof") +// }, false, +// }, +// { +// "consensus state not found", func() { +// proofHeight = clienttypes.ZeroHeight() +// }, false, +// }, +// { +// "verify non membership fails as path exists", func() { +// // change the value being proved +// key := host.FullClientStateKey(testingpath.EndpointB.ClientID) +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = suite.chainB.QueryProof(key) +// }, false, +// }, +// { +// "proof is empty", func() { +// // change the inserted proof +// proof = []byte{} +// }, false, +// }, +// } + +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// suite.SetupWasmTendermint() // reset +// testingpath = ibctesting.NewPath(suite.chainA, suite.chainB) +// testingpath.SetChannelOrdered() +// suite.coordinator.Setup(testingpath) + +// // reset time and block delays to 0, malleate may change to a specific non-zero value. +// delayTimePeriod = 0 +// delayBlockPeriod = 0 + +// // create default proof, merklePath, and value which passes +// // may be overwritten by malleate() +// key := host.FullClientStateKey(invalidClientID) + +// merklePath := commitmenttypes.NewMerklePath(string(key)) +// path, err = commitmenttypes.ApplyPrefix(suite.chainB.GetPrefix(), merklePath) +// suite.Require().NoError(err) + +// proof, proofHeight = suite.chainB.QueryProof(key) + +// tc.malleate() // make changes as necessary + +// clientState := testingpath.EndpointA.GetClientState().(*types.ClientState) + +// ctx := suite.chainA.GetContext() +// store := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, testingpath.EndpointA.ClientID) + +// err = clientState.VerifyNonMembership( +// ctx, store, suite.chainA.Codec, proofHeight, delayTimePeriod, delayBlockPeriod, +// proof, path, +// ) + +// if tc.expPass { +// suite.Require().NoError(err) +// } else { +// suite.Require().Error(err) +// } +// }) +// } +// } diff --git a/modules/light-clients/08-wasm/types/genesis_test.go b/modules/light-clients/08-wasm/types/genesis_test.go index 57edb0d0b5f..a963699d46c 100644 --- a/modules/light-clients/08-wasm/types/genesis_test.go +++ b/modules/light-clients/08-wasm/types/genesis_test.go @@ -3,12 +3,8 @@ package types_test import ( "encoding/base64" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - ibctesting "github.com/cosmos/ibc-go/v7/testing" ) func (suite *TypesTestSuite) TestExportGenesisGrandpa() { @@ -26,79 +22,79 @@ func (suite *TypesTestSuite) TestExportGenesisGrandpa() { // expected export ordering: // processed height and processed time per height // then all iteration keys -func (suite *TypesTestSuite) TestExportMetadataTendermint() { - suite.SetupWasmTendermint() - - // test intializing client and exporting metadata - path := ibctesting.NewPath(suite.chainA, suite.chainB) - suite.coordinator.SetupClients(path) - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - clientState := path.EndpointA.GetClientState() - height := clientState.GetLatestHeight() - - initIteration := ibctm.GetIterationKey(clientStore, height) - suite.Require().NotEqual(0, len(initIteration)) - initProcessedTime, found := ibctm.GetProcessedTime(clientStore, height) - suite.Require().True(found) - initProcessedHeight, found := GetProcessedHeight(clientStore, height) - suite.Require().True(found) - - gm := clientState.ExportMetadata(suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID)) - suite.Require().NotNil(gm, "client with metadata returned nil exported metadata") - suite.Require().Len(gm, 3, "exported metadata has unexpected length") - - suite.Require().Equal(ibctm.ProcessedHeightKey(height), gm[0].GetKey(), "metadata has unexpected key") - actualProcessedHeight := sdk.BigEndianToUint64(gm[0].GetValue()) - suite.Require().Equal(initProcessedHeight, actualProcessedHeight, "metadata has unexpected value") - - suite.Require().Equal(ibctm.ProcessedTimeKey(height), gm[1].GetKey(), "metadata has unexpected key") - suite.Require().Equal(initProcessedTime, sdk.BigEndianToUint64(gm[1].GetValue()), "metadata has unexpected value") - - suite.Require().Equal(ibctm.IterationKey(height), gm[2].GetKey(), "metadata has unexpected key") - suite.Require().Equal(initIteration, gm[2].GetValue(), "metadata has unexpected value") - - // test updating client and exporting metadata - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - clientState = path.EndpointA.GetClientState() - updateHeight := clientState.GetLatestHeight() - - iteration := ibctm.GetIterationKey(clientStore, updateHeight) - suite.Require().NotEqual(0, len(initIteration)) - processedTime, found := ibctm.GetProcessedTime(clientStore, updateHeight) - suite.Require().True(found) - processedHeight, found := GetProcessedHeight(clientStore, updateHeight) - suite.Require().True(found) - - gm = clientState.ExportMetadata(suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID)) - suite.Require().NotNil(gm, "client with metadata returned nil exported metadata") - suite.Require().Len(gm, 6, "exported metadata has unexpected length") - - // expected ordering: - // initProcessedHeight, initProcessedTime, processedHeight, processedTime, initIteration, iteration - - // check init processed height and time - suite.Require().Equal(ibctm.ProcessedHeightKey(height), gm[0].GetKey(), "metadata has unexpected key") - actualProcessedHeight = sdk.BigEndianToUint64(gm[0].GetValue()) - suite.Require().Equal(initProcessedHeight, actualProcessedHeight, "metadata has unexpected value") - - suite.Require().Equal(ibctm.ProcessedTimeKey(height), gm[1].GetKey(), "metadata has unexpected key") - suite.Require().Equal(initProcessedTime, sdk.BigEndianToUint64(gm[1].GetValue()), "metadata has unexpected value") - - // check processed height and time after update - suite.Require().Equal(ibctm.ProcessedHeightKey(updateHeight), gm[2].GetKey(), "metadata has unexpected key") - actualProcessedHeight = sdk.BigEndianToUint64(gm[2].GetValue()) - suite.Require().NoError(err) - suite.Require().Equal(processedHeight, actualProcessedHeight, "metadata has unexpected value") - - suite.Require().Equal(ibctm.ProcessedTimeKey(updateHeight), gm[3].GetKey(), "metadata has unexpected key") - suite.Require().Equal(processedTime, sdk.BigEndianToUint64(gm[3].GetValue()), "metadata has unexpected value") - - // check iteration keys - suite.Require().Equal(ibctm.IterationKey(height), gm[4].GetKey(), "metadata has unexpected key") - suite.Require().Equal(initIteration, gm[4].GetValue(), "metadata has unexpected value") - - suite.Require().Equal(ibctm.IterationKey(updateHeight), gm[5].GetKey(), "metadata has unexpected key") - suite.Require().Equal(iteration, gm[5].GetValue(), "metadata has unexpected value") -} +// func (suite *TypesTestSuite) TestExportMetadataTendermint() { +// suite.SetupWasmTendermint() + +// // test intializing client and exporting metadata +// path := ibctesting.NewPath(suite.chainA, suite.chainB) +// suite.coordinator.SetupClients(path) +// clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) +// clientState := path.EndpointA.GetClientState() +// height := clientState.GetLatestHeight() + +// initIteration := ibctm.GetIterationKey(clientStore, height) +// suite.Require().NotEqual(0, len(initIteration)) +// initProcessedTime, found := ibctm.GetProcessedTime(clientStore, height) +// suite.Require().True(found) +// initProcessedHeight, found := GetProcessedHeight(clientStore, height) +// suite.Require().True(found) + +// gm := clientState.ExportMetadata(suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID)) +// suite.Require().NotNil(gm, "client with metadata returned nil exported metadata") +// suite.Require().Len(gm, 3, "exported metadata has unexpected length") + +// suite.Require().Equal(ibctm.ProcessedHeightKey(height), gm[0].GetKey(), "metadata has unexpected key") +// actualProcessedHeight := sdk.BigEndianToUint64(gm[0].GetValue()) +// suite.Require().Equal(initProcessedHeight, actualProcessedHeight, "metadata has unexpected value") + +// suite.Require().Equal(ibctm.ProcessedTimeKey(height), gm[1].GetKey(), "metadata has unexpected key") +// suite.Require().Equal(initProcessedTime, sdk.BigEndianToUint64(gm[1].GetValue()), "metadata has unexpected value") + +// suite.Require().Equal(ibctm.IterationKey(height), gm[2].GetKey(), "metadata has unexpected key") +// suite.Require().Equal(initIteration, gm[2].GetValue(), "metadata has unexpected value") + +// // test updating client and exporting metadata +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// clientState = path.EndpointA.GetClientState() +// updateHeight := clientState.GetLatestHeight() + +// iteration := ibctm.GetIterationKey(clientStore, updateHeight) +// suite.Require().NotEqual(0, len(initIteration)) +// processedTime, found := ibctm.GetProcessedTime(clientStore, updateHeight) +// suite.Require().True(found) +// processedHeight, found := GetProcessedHeight(clientStore, updateHeight) +// suite.Require().True(found) + +// gm = clientState.ExportMetadata(suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID)) +// suite.Require().NotNil(gm, "client with metadata returned nil exported metadata") +// suite.Require().Len(gm, 6, "exported metadata has unexpected length") + +// // expected ordering: +// // initProcessedHeight, initProcessedTime, processedHeight, processedTime, initIteration, iteration + +// // check init processed height and time +// suite.Require().Equal(ibctm.ProcessedHeightKey(height), gm[0].GetKey(), "metadata has unexpected key") +// actualProcessedHeight = sdk.BigEndianToUint64(gm[0].GetValue()) +// suite.Require().Equal(initProcessedHeight, actualProcessedHeight, "metadata has unexpected value") + +// suite.Require().Equal(ibctm.ProcessedTimeKey(height), gm[1].GetKey(), "metadata has unexpected key") +// suite.Require().Equal(initProcessedTime, sdk.BigEndianToUint64(gm[1].GetValue()), "metadata has unexpected value") + +// // check processed height and time after update +// suite.Require().Equal(ibctm.ProcessedHeightKey(updateHeight), gm[2].GetKey(), "metadata has unexpected key") +// actualProcessedHeight = sdk.BigEndianToUint64(gm[2].GetValue()) +// suite.Require().NoError(err) +// suite.Require().Equal(processedHeight, actualProcessedHeight, "metadata has unexpected value") + +// suite.Require().Equal(ibctm.ProcessedTimeKey(updateHeight), gm[3].GetKey(), "metadata has unexpected key") +// suite.Require().Equal(processedTime, sdk.BigEndianToUint64(gm[3].GetValue()), "metadata has unexpected value") + +// // check iteration keys +// suite.Require().Equal(ibctm.IterationKey(height), gm[4].GetKey(), "metadata has unexpected key") +// suite.Require().Equal(initIteration, gm[4].GetValue(), "metadata has unexpected value") + +// suite.Require().Equal(ibctm.IterationKey(updateHeight), gm[5].GetKey(), "metadata has unexpected key") +// suite.Require().Equal(iteration, gm[5].GetValue(), "metadata has unexpected value") +// } diff --git a/modules/light-clients/08-wasm/types/misbehaviour_handle_test.go b/modules/light-clients/08-wasm/types/misbehaviour_handle_test.go index 859ea0a46ec..9ea18d436f1 100644 --- a/modules/light-clients/08-wasm/types/misbehaviour_handle_test.go +++ b/modules/light-clients/08-wasm/types/misbehaviour_handle_test.go @@ -1,22 +1,6 @@ package types_test -import ( - // "encoding/base64" - "fmt" - "strings" - "time" - - tmtypes "github.com/cometbft/cometbft/types" - - "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" - clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" - "github.com/cosmos/ibc-go/v7/modules/core/exported" - solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine" - ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - ibctesting "github.com/cosmos/ibc-go/v7/testing" - ibctestingmock "github.com/cosmos/ibc-go/v7/testing/mock" -) +// "encoding/base64" /* func (suite *TypesTestSuite) TestVerifyMisbehaviourGrandpa() { var ( @@ -93,425 +77,425 @@ import ( } }*/ -func (suite *TypesTestSuite) TestVerifyMisbehaviourTendermint() { - // Setup different validators and signers for testing different types of updates - altPrivVal := ibctestingmock.NewPV() - altPubKey, err := altPrivVal.GetPubKey() - suite.Require().NoError(err) - - // create modified heights to use for test-cases - altVal := tmtypes.NewValidator(altPubKey, 100) - - // Create alternative validator set with only altVal, invalid update (too much change in valSet) - altValSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{altVal}) - altSigners := getAltSigners(altVal, altPrivVal) - - var ( - path *ibctesting.Path - misbehaviour exported.ClientMessage - ) - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - { - "valid fork misbehaviour", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, - true, - }, - { - "valid time misbehaviour", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+3, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, - true, - }, - { - "valid time misbehaviour, header 1 time stricly less than header 2 time", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+3, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, - true, - }, - { - "valid misbehavior at height greater than last consensusState", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, true, - }, - { - "valid misbehaviour with different trusted heights", func() { - trustedHeight1 := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals1, found := suite.chainB.GetValsAtHeight(int64(trustedHeight1.RevisionHeight) + 1) - suite.Require().True(found) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - trustedHeight2 := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals2, found := suite.chainB.GetValsAtHeight(int64(trustedHeight2.RevisionHeight) + 1) - suite.Require().True(found) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight1, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals1, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight2, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals2, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, - true, - }, - { - "valid misbehaviour at a previous revision", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - - // increment revision number - err = path.EndpointB.UpgradeChain() - suite.Require().NoError(err) - }, - true, - }, - { - "valid misbehaviour at a future revision", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - futureRevision := fmt.Sprintf("%s-%d", strings.TrimSuffix(suite.chainB.ChainID, fmt.Sprintf("-%d", clienttypes.ParseChainID(suite.chainB.ChainID))), height.GetRevisionNumber()+1) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(futureRevision, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(futureRevision, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, - true, - }, - { - "valid misbehaviour with trusted heights at a previous revision", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - // increment revision of chainID - err := path.EndpointB.UpgradeChain() - suite.Require().NoError(err) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, - true, - }, - { - "consensus state's valset hash different from misbehaviour should still pass", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - // Create bothValSet with both suite validator and altVal - bothValSet := tmtypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altValSet.Proposer)) - bothSigners := suite.chainB.Signers - bothSigners[altValSet.Proposer.Address.String()] = altPrivVal - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), bothValSet, suite.chainB.NextVals, trustedVals, bothSigners), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, bothValSet, suite.chainB.NextVals, trustedVals, bothSigners), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, true, - }, - { - "invalid misbehaviour: misbehaviour from different chain", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader("evmos", int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader("evmos", int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, false, - }, - { - "misbehaviour trusted validators does not match validator hash in trusted consensus state", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, altValSet, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, altValSet, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, false, - }, - { - "trusted consensus state does not exist", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight.Increment().(clienttypes.Height), suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, false, - }, - { - "invalid tendermint misbehaviour", func() { - misbehaviour = &solomachine.Misbehaviour{} - }, false, - }, - { - "trusting period expired", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - suite.chainA.ExpireClient(path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, false, - }, - { - "header 1 valset has too much change", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight+1), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), altValSet, suite.chainB.NextVals, trustedVals, altSigners), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, false, - }, - { - "header 2 valset has too much change", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight+1), trustedHeight, suite.chainB.CurrentHeader.Time, altValSet, suite.chainB.NextVals, trustedVals, altSigners), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, false, - }, - { - "both header 1 and header 2 valsets have too much change", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight+1), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), altValSet, suite.chainB.NextVals, trustedVals, altSigners), - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight+1), trustedHeight, suite.chainB.CurrentHeader.Time, altValSet, suite.chainB.NextVals, trustedVals, altSigners), - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - misbehaviour = &types.ClientMessage{ - Data: wasmData, - } - }, false, - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - suite.SetupWasmTendermint() - path = ibctesting.NewPath(suite.chainA, suite.chainB) - - err := path.EndpointA.CreateClient() - suite.Require().NoError(err) - - tc.malleate() - - clientState := path.EndpointA.GetClientState() - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - - err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, misbehaviour) - - if tc.expPass { - suite.Require().NoError(err) - } else { - suite.Require().Error(err) - } - }) - } -} +// func (suite *TypesTestSuite) TestVerifyMisbehaviourTendermint() { +// // Setup different validators and signers for testing different types of updates +// altPrivVal := ibctestingmock.NewPV() +// altPubKey, err := altPrivVal.GetPubKey() +// suite.Require().NoError(err) + +// // create modified heights to use for test-cases +// altVal := tmtypes.NewValidator(altPubKey, 100) + +// // Create alternative validator set with only altVal, invalid update (too much change in valSet) +// altValSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{altVal}) +// altSigners := getAltSigners(altVal, altPrivVal) + +// var ( +// path *ibctesting.Path +// misbehaviour exported.ClientMessage +// ) + +// testCases := []struct { +// name string +// malleate func() +// expPass bool +// }{ +// { +// "valid fork misbehaviour", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, +// true, +// }, +// { +// "valid time misbehaviour", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+3, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, +// true, +// }, +// { +// "valid time misbehaviour, header 1 time stricly less than header 2 time", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+3, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, +// true, +// }, +// { +// "valid misbehavior at height greater than last consensusState", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, true, +// }, +// { +// "valid misbehaviour with different trusted heights", func() { +// trustedHeight1 := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals1, found := suite.chainB.GetValsAtHeight(int64(trustedHeight1.RevisionHeight) + 1) +// suite.Require().True(found) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// trustedHeight2 := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals2, found := suite.chainB.GetValsAtHeight(int64(trustedHeight2.RevisionHeight) + 1) +// suite.Require().True(found) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight1, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals1, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight2, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals2, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, +// true, +// }, +// { +// "valid misbehaviour at a previous revision", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } + +// // increment revision number +// err = path.EndpointB.UpgradeChain() +// suite.Require().NoError(err) +// }, +// true, +// }, +// { +// "valid misbehaviour at a future revision", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// futureRevision := fmt.Sprintf("%s-%d", strings.TrimSuffix(suite.chainB.ChainID, fmt.Sprintf("-%d", clienttypes.ParseChainID(suite.chainB.ChainID))), height.GetRevisionNumber()+1) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(futureRevision, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Second), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(futureRevision, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, +// true, +// }, +// { +// "valid misbehaviour with trusted heights at a previous revision", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// // increment revision of chainID +// err := path.EndpointB.UpgradeChain() +// suite.Require().NoError(err) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, +// true, +// }, +// { +// "consensus state's valset hash different from misbehaviour should still pass", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// // Create bothValSet with both suite validator and altVal +// bothValSet := tmtypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altValSet.Proposer)) +// bothSigners := suite.chainB.Signers +// bothSigners[altValSet.Proposer.Address.String()] = altPrivVal + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), bothValSet, suite.chainB.NextVals, trustedVals, bothSigners), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, bothValSet, suite.chainB.NextVals, trustedVals, bothSigners), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, true, +// }, +// { +// "invalid misbehaviour: misbehaviour from different chain", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader("evmos", int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader("evmos", int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, false, +// }, +// { +// "misbehaviour trusted validators does not match validator hash in trusted consensus state", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, altValSet, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, altValSet, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, false, +// }, +// { +// "trusted consensus state does not exist", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight.Increment().(clienttypes.Height), suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, false, +// }, +// { +// "invalid tendermint misbehaviour", func() { +// misbehaviour = &solomachine.Misbehaviour{} +// }, false, +// }, +// { +// "trusting period expired", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// suite.chainA.ExpireClient(path.EndpointA.ClientConfig.(*ibctesting.TendermintConfig).TrustingPeriod) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, false, +// }, +// { +// "header 1 valset has too much change", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight+1), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), altValSet, suite.chainB.NextVals, trustedVals, altSigners), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, false, +// }, +// { +// "header 2 valset has too much change", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight+1), trustedHeight, suite.chainB.CurrentHeader.Time, altValSet, suite.chainB.NextVals, trustedVals, altSigners), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, false, +// }, +// { +// "both header 1 and header 2 valsets have too much change", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight+1), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), altValSet, suite.chainB.NextVals, trustedVals, altSigners), +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight+1), trustedHeight, suite.chainB.CurrentHeader.Time, altValSet, suite.chainB.NextVals, trustedVals, altSigners), +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// misbehaviour = &types.ClientMessage{ +// Data: wasmData, +// } +// }, false, +// }, +// } + +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// suite.SetupWasmTendermint() +// path = ibctesting.NewPath(suite.chainA, suite.chainB) + +// err := path.EndpointA.CreateClient() +// suite.Require().NoError(err) + +// tc.malleate() + +// clientState := path.EndpointA.GetClientState() +// clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + +// err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, misbehaviour) + +// if tc.expPass { +// suite.Require().NoError(err) +// } else { +// suite.Require().Error(err) +// } +// }) +// } +// } /* func (suite *TypesTestSuite) TestCheckForMisbehaviourGrandpa() { var ( @@ -594,265 +578,265 @@ func (suite *TypesTestSuite) TestVerifyMisbehaviourTendermint() { } }*/ -func (suite *TypesTestSuite) TestCheckForMisbehaviourTendermint() { - var ( - path *ibctesting.Path - clientMessage exported.ClientMessage - ) - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - { - "valid update no misbehaviour", - func() {}, - false, - }, - { - "consensus state already exists, already updated", - func() { - wasmHeader, ok := clientMessage.(*types.ClientMessage) - suite.Require().True(ok) - - var wasmData exported.ClientMessage - err := suite.chainA.Codec.UnmarshalInterface(wasmHeader.Data, &wasmData) - suite.Require().NoError(err) - - tmHeader, ok := wasmData.(*ibctm.Header) - suite.Require().True(ok) - - tmConsensusState := &ibctm.ConsensusState{ - Timestamp: tmHeader.GetTime(), - Root: commitmenttypes.NewMerkleRoot(tmHeader.Header.GetAppHash()), - NextValidatorsHash: tmHeader.Header.NextValidatorsHash, - } - - tmConsensusStateData, err := suite.chainA.Codec.MarshalInterface(tmConsensusState) - suite.Require().NoError(err) - wasmConsensusState := &types.ConsensusState{ - Data: tmConsensusStateData, - } - - suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientConsensusState( - suite.chainA.GetContext(), - path.EndpointA.ClientID, - tmHeader.GetHeight(), - wasmConsensusState, - ) - }, - false, - }, - { - "invalid fork misbehaviour: identical headers", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - misbehaviourHeader := suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: misbehaviourHeader, - Header2: misbehaviourHeader, - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - clientMessage = &types.ClientMessage{ - Data: wasmData, - } - }, false, - }, - { - "invalid time misbehaviour: monotonically increasing time", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - header1 := suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+3, trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - header2 := suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: header1, - Header2: header2, - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - clientMessage = &types.ClientMessage{ - Data: wasmData, - } - }, false, - }, - { - "consensus state already exists, app hash mismatch", - func() { - wasmHeader, ok := clientMessage.(*types.ClientMessage) - suite.Require().True(ok) - - var wasmData exported.ClientMessage - err := suite.chainA.Codec.UnmarshalInterface(wasmHeader.Data, &wasmData) - suite.Require().NoError(err) - - tmHeader, ok := wasmData.(*ibctm.Header) - suite.Require().True(ok) - - tmConsensusState := &ibctm.ConsensusState{ - Timestamp: tmHeader.GetTime(), - Root: commitmenttypes.NewMerkleRoot([]byte{}), // empty bytes - NextValidatorsHash: tmHeader.Header.NextValidatorsHash, - } - - tmConsensusStateData, err := suite.chainA.Codec.MarshalInterface(tmConsensusState) - suite.Require().NoError(err) - wasmConsensusState := &types.ConsensusState{ - Data: tmConsensusStateData, - } - - suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientConsensusState( - suite.chainA.GetContext(), - path.EndpointA.ClientID, - tmHeader.GetHeight(), - wasmConsensusState, - ) - }, - true, - }, - { - "previous consensus state exists and header time is before previous consensus state time", - func() { - wasmHeader, ok := clientMessage.(*types.ClientMessage) - suite.Require().True(ok) - - var wasmData exported.ClientMessage - err := suite.chainA.Codec.UnmarshalInterface(wasmHeader.Data, &wasmData) - suite.Require().NoError(err) - - tmHeader, ok := wasmData.(*ibctm.Header) - suite.Require().True(ok) - - // offset header timestamp before previous consensus state timestamp - tmHeader.Header.Time = tmHeader.GetTime().Add(-time.Hour) - - wasmHeader.Data, err = suite.chainA.Codec.MarshalInterface(tmHeader) - suite.Require().NoError(err) - }, - true, - }, - { - "next consensus state exists and header time is after next consensus state time", - func() { - wasmHeader, ok := clientMessage.(*types.ClientMessage) - suite.Require().True(ok) - - var wasmData exported.ClientMessage - err := suite.chainA.Codec.UnmarshalInterface(wasmHeader.Data, &wasmData) - suite.Require().NoError(err) - - tmHeader, ok := wasmData.(*ibctm.Header) - suite.Require().True(ok) - - // offset header timestamp before previous consensus state timestamp - tmHeader.Header.Time = tmHeader.GetTime().Add(time.Hour) - - wasmHeader.Data, err = suite.chainA.Codec.MarshalInterface(tmHeader) - suite.Require().NoError(err) - // commit block and update client, adding a new consensus state - suite.coordinator.CommitBlock(suite.chainB) - - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - }, - true, - }, - { - "valid fork misbehaviour returns true", - func() { - header1, err := path.EndpointA.Chain.ConstructUpdateTMClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) - suite.Require().NoError(err) - - // commit block and update client - suite.coordinator.CommitBlock(suite.chainB) - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - header2, err := path.EndpointA.Chain.ConstructUpdateTMClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) - suite.Require().NoError(err) - - // assign the same height, each header will have a different commit hash - header1.Header.Height = header2.Header.Height - header1.Commit.Height = header2.Commit.Height - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: header1, - Header2: header2, - } - - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - clientMessage = &types.ClientMessage{ - Data: wasmData, - } - }, - true, - }, - { - "valid time misbehaviour: not monotonically increasing time", func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - tmMisbehaviour := &ibctm.Misbehaviour{ - Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+3, trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), - } - - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - clientMessage = &types.ClientMessage{ - Data: wasmData, - } - }, true, - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - // reset suite to create fresh application state - suite.SetupWasmTendermint() - path = ibctesting.NewPath(suite.chainA, suite.chainB) - - err := path.EndpointA.CreateClient() - suite.Require().NoError(err) - - // ensure counterparty state is committed - suite.coordinator.CommitBlock(suite.chainB) - clientMessage, _, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) - suite.Require().NoError(err) - - tc.malleate() - - clientState := path.EndpointA.GetClientState() - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - - foundMisbehaviour := clientState.CheckForMisbehaviour( - suite.chainA.GetContext(), - suite.chainA.App.AppCodec(), - clientStore, // pass in clientID prefixed clientStore - clientMessage, - ) - - if tc.expPass { - suite.Require().True(foundMisbehaviour) - } else { - suite.Require().False(foundMisbehaviour) - } - }) - } -} +// func (suite *TypesTestSuite) TestCheckForMisbehaviourTendermint() { +// var ( +// path *ibctesting.Path +// clientMessage exported.ClientMessage +// ) + +// testCases := []struct { +// name string +// malleate func() +// expPass bool +// }{ +// { +// "valid update no misbehaviour", +// func() {}, +// false, +// }, +// { +// "consensus state already exists, already updated", +// func() { +// wasmHeader, ok := clientMessage.(*types.ClientMessage) +// suite.Require().True(ok) + +// var wasmData exported.ClientMessage +// err := suite.chainA.Codec.UnmarshalInterface(wasmHeader.Data, &wasmData) +// suite.Require().NoError(err) + +// tmHeader, ok := wasmData.(*ibctm.Header) +// suite.Require().True(ok) + +// tmConsensusState := &ibctm.ConsensusState{ +// Timestamp: tmHeader.GetTime(), +// Root: commitmenttypes.NewMerkleRoot(tmHeader.Header.GetAppHash()), +// NextValidatorsHash: tmHeader.Header.NextValidatorsHash, +// } + +// tmConsensusStateData, err := suite.chainA.Codec.MarshalInterface(tmConsensusState) +// suite.Require().NoError(err) +// wasmConsensusState := &types.ConsensusState{ +// Data: tmConsensusStateData, +// } + +// suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientConsensusState( +// suite.chainA.GetContext(), +// path.EndpointA.ClientID, +// tmHeader.GetHeight(), +// wasmConsensusState, +// ) +// }, +// false, +// }, +// { +// "invalid fork misbehaviour: identical headers", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// height := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// misbehaviourHeader := suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, int64(height.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: misbehaviourHeader, +// Header2: misbehaviourHeader, +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// clientMessage = &types.ClientMessage{ +// Data: wasmData, +// } +// }, false, +// }, +// { +// "invalid time misbehaviour: monotonically increasing time", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// header1 := suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+3, trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) +// header2 := suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: header1, +// Header2: header2, +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// clientMessage = &types.ClientMessage{ +// Data: wasmData, +// } +// }, false, +// }, +// { +// "consensus state already exists, app hash mismatch", +// func() { +// wasmHeader, ok := clientMessage.(*types.ClientMessage) +// suite.Require().True(ok) + +// var wasmData exported.ClientMessage +// err := suite.chainA.Codec.UnmarshalInterface(wasmHeader.Data, &wasmData) +// suite.Require().NoError(err) + +// tmHeader, ok := wasmData.(*ibctm.Header) +// suite.Require().True(ok) + +// tmConsensusState := &ibctm.ConsensusState{ +// Timestamp: tmHeader.GetTime(), +// Root: commitmenttypes.NewMerkleRoot([]byte{}), // empty bytes +// NextValidatorsHash: tmHeader.Header.NextValidatorsHash, +// } + +// tmConsensusStateData, err := suite.chainA.Codec.MarshalInterface(tmConsensusState) +// suite.Require().NoError(err) +// wasmConsensusState := &types.ConsensusState{ +// Data: tmConsensusStateData, +// } + +// suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientConsensusState( +// suite.chainA.GetContext(), +// path.EndpointA.ClientID, +// tmHeader.GetHeight(), +// wasmConsensusState, +// ) +// }, +// true, +// }, +// { +// "previous consensus state exists and header time is before previous consensus state time", +// func() { +// wasmHeader, ok := clientMessage.(*types.ClientMessage) +// suite.Require().True(ok) + +// var wasmData exported.ClientMessage +// err := suite.chainA.Codec.UnmarshalInterface(wasmHeader.Data, &wasmData) +// suite.Require().NoError(err) + +// tmHeader, ok := wasmData.(*ibctm.Header) +// suite.Require().True(ok) + +// // offset header timestamp before previous consensus state timestamp +// tmHeader.Header.Time = tmHeader.GetTime().Add(-time.Hour) + +// wasmHeader.Data, err = suite.chainA.Codec.MarshalInterface(tmHeader) +// suite.Require().NoError(err) +// }, +// true, +// }, +// { +// "next consensus state exists and header time is after next consensus state time", +// func() { +// wasmHeader, ok := clientMessage.(*types.ClientMessage) +// suite.Require().True(ok) + +// var wasmData exported.ClientMessage +// err := suite.chainA.Codec.UnmarshalInterface(wasmHeader.Data, &wasmData) +// suite.Require().NoError(err) + +// tmHeader, ok := wasmData.(*ibctm.Header) +// suite.Require().True(ok) + +// // offset header timestamp before previous consensus state timestamp +// tmHeader.Header.Time = tmHeader.GetTime().Add(time.Hour) + +// wasmHeader.Data, err = suite.chainA.Codec.MarshalInterface(tmHeader) +// suite.Require().NoError(err) +// // commit block and update client, adding a new consensus state +// suite.coordinator.CommitBlock(suite.chainB) + +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) +// }, +// true, +// }, +// { +// "valid fork misbehaviour returns true", +// func() { +// header1, err := path.EndpointA.Chain.ConstructUpdateTMClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) +// suite.Require().NoError(err) + +// // commit block and update client +// suite.coordinator.CommitBlock(suite.chainB) +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// header2, err := path.EndpointA.Chain.ConstructUpdateTMClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) +// suite.Require().NoError(err) + +// // assign the same height, each header will have a different commit hash +// header1.Header.Height = header2.Header.Height +// header1.Commit.Height = header2.Commit.Height + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: header1, +// Header2: header2, +// } + +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// clientMessage = &types.ClientMessage{ +// Data: wasmData, +// } +// }, +// true, +// }, +// { +// "valid time misbehaviour: not monotonically increasing time", func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header2: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+3, trustedHeight, suite.chainB.CurrentHeader.Time.Add(time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// Header1: suite.chainB.CreateTMClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers), +// } + +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// clientMessage = &types.ClientMessage{ +// Data: wasmData, +// } +// }, true, +// }, +// } + +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// // reset suite to create fresh application state +// suite.SetupWasmTendermint() +// path = ibctesting.NewPath(suite.chainA, suite.chainB) + +// err := path.EndpointA.CreateClient() +// suite.Require().NoError(err) + +// // ensure counterparty state is committed +// suite.coordinator.CommitBlock(suite.chainB) +// clientMessage, _, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) +// suite.Require().NoError(err) + +// tc.malleate() + +// clientState := path.EndpointA.GetClientState() +// clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + +// foundMisbehaviour := clientState.CheckForMisbehaviour( +// suite.chainA.GetContext(), +// suite.chainA.App.AppCodec(), +// clientStore, // pass in clientID prefixed clientStore +// clientMessage, +// ) + +// if tc.expPass { +// suite.Require().True(foundMisbehaviour) +// } else { +// suite.Require().False(foundMisbehaviour) +// } +// }) +// } +// } diff --git a/modules/light-clients/08-wasm/types/proposal_handle_test.go b/modules/light-clients/08-wasm/types/proposal_handle_test.go index a13a2f3793d..afea9372e24 100644 --- a/modules/light-clients/08-wasm/types/proposal_handle_test.go +++ b/modules/light-clients/08-wasm/types/proposal_handle_test.go @@ -78,202 +78,202 @@ func (suite *TypesTestSuite) TestCheckSubstituteAndUpdateStateGrandpa() { } } -func (suite *TypesTestSuite) TestCheckSubstituteAndUpdateStateBasicTendermint() { - var ( - substituteClientState exported.ClientState - substitutePath *ibctesting.Path - ) - testCases := []struct { - name string - malleate func() - }{ - { - "solo machine used for substitute", func() { - substituteClientState = ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solo machine", "", 1).ClientState() - }, - }, - { - "non-matching substitute", func() { - suite.coordinator.SetupClients(substitutePath) - substituteWasmClientState := suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*types.ClientState) - - var clientStateData exported.ClientState - err := suite.chainA.Codec.UnmarshalInterface(substituteWasmClientState.Data, &clientStateData) - suite.Require().NoError(err) - tmClientState := clientStateData.(*ibctm.ClientState) - - // change unbonding period so that test should fail - tmClientState.UnbondingPeriod = time.Hour * 24 * 7 - - tmClientStateBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmClientState) - suite.Require().NoError(err) - - substituteWasmClientState.Data = tmClientStateBz - - substituteClientState = substituteWasmClientState - substitutePath.EndpointA.SetClientState(substituteClientState) - }, - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - suite.SetupWasmTendermint() // reset - subjectPath := ibctesting.NewPath(suite.chainA, suite.chainB) - substitutePath = ibctesting.NewPath(suite.chainA, suite.chainB) - - suite.coordinator.SetupClients(subjectPath) - subjectClientState := suite.chainA.GetClientState(subjectPath.EndpointA.ClientID).(*types.ClientState) - - var clientStateData exported.ClientState - err := suite.chainA.Codec.UnmarshalInterface(subjectClientState.Data, &clientStateData) - suite.Require().NoError(err) - tmClientState := clientStateData.(*ibctm.ClientState) - - // expire subject client - suite.coordinator.IncrementTimeBy(tmClientState.TrustingPeriod) - suite.coordinator.CommitBlock(suite.chainA, suite.chainB) - - tc.malleate() - - subjectClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), subjectPath.EndpointA.ClientID) - substituteClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), substitutePath.EndpointA.ClientID) - - err = subjectClientState.CheckSubstituteAndUpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), subjectClientStore, substituteClientStore, substituteClientState) - suite.Require().Error(err) - }) - } -} - -func (suite *TypesTestSuite) TestCheckSubstituteAndUpdateStateTendermint() { - testCases := []struct { - name string - FreezeClient bool - expPass bool - }{ - { - name: "PASS: update checks are deprecated, client is not frozen", - FreezeClient: false, - expPass: true, - }, - { - name: "PASS: update checks are deprecated, client is frozen", - FreezeClient: true, - expPass: true, - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - suite.SetupWasmTendermint() // reset - - // construct subject using test case parameters - subjectPath := ibctesting.NewPath(suite.chainA, suite.chainB) - suite.coordinator.SetupClients(subjectPath) - subjectWasmClientState := suite.chainA.GetClientState(subjectPath.EndpointA.ClientID).(*types.ClientState) - - var subjectWasmClientStateData exported.ClientState - err := suite.chainA.Codec.UnmarshalInterface(subjectWasmClientState.Data, &subjectWasmClientStateData) - suite.Require().NoError(err) - subjectTmClientState := subjectWasmClientStateData.(*ibctm.ClientState) - - if tc.FreezeClient { - subjectTmClientState.FrozenHeight = frozenHeight - } - - subjectTmClientStateBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), subjectTmClientState) - suite.Require().NoError(err) - subjectWasmClientState.Data = subjectTmClientStateBz - subjectPath.EndpointA.SetClientState(subjectWasmClientState) - - // construct the substitute to match the subject client - - substitutePath := ibctesting.NewPath(suite.chainA, suite.chainB) - suite.coordinator.SetupClients(substitutePath) - substituteWasmClientState := suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*types.ClientState) - - var substituteWasmClientStateData exported.ClientState - err = suite.chainA.Codec.UnmarshalInterface(substituteWasmClientState.Data, &substituteWasmClientStateData) - suite.Require().NoError(err) - substituteTmClientState := substituteWasmClientStateData.(*ibctm.ClientState) - - // update trusting period of substitute client state - substituteTmClientState.TrustingPeriod = time.Hour * 24 * 7 - - substituteTmClientStateBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), substituteTmClientState) - suite.Require().NoError(err) - substituteWasmClientState.Data = substituteTmClientStateBz - substitutePath.EndpointA.SetClientState(substituteWasmClientState) - - // update substitute a few times - for i := 0; i < 3; i++ { - err := substitutePath.EndpointA.UpdateClient() - suite.Require().NoError(err) - // skip a block - suite.coordinator.CommitBlock(suite.chainA, suite.chainB) - } - - // get updated substitute - substituteWasmClientState = suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*types.ClientState) - err = suite.chainA.Codec.UnmarshalInterface(substituteWasmClientState.Data, &substituteWasmClientStateData) - suite.Require().NoError(err) - substituteTmClientState = substituteWasmClientStateData.(*ibctm.ClientState) - - // test that subject gets updated chain-id - newChainID := "new-chain-id" - substituteTmClientState.ChainId = newChainID - - substituteTmClientStateBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), substituteTmClientState) - suite.Require().NoError(err) - substituteWasmClientState.Data = substituteTmClientStateBz - substitutePath.EndpointA.SetClientState(substituteWasmClientState) - - subjectClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), subjectPath.EndpointA.ClientID) - substituteClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), substitutePath.EndpointA.ClientID) - - expectedConsState := substitutePath.EndpointA.GetConsensusState(substituteWasmClientState.GetLatestHeight()) - expectedProcessedTime, found := ibctm.GetProcessedTime(substituteClientStore, substituteWasmClientState.GetLatestHeight()) - suite.Require().True(found) - expectedProcessedHeight, found := GetProcessedHeight(substituteClientStore, substituteWasmClientState.GetLatestHeight()) - suite.Require().True(found) - expectedIterationKey := ibctm.GetIterationKey(substituteClientStore, substituteWasmClientState.GetLatestHeight()) - - err = subjectWasmClientState.CheckSubstituteAndUpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), subjectClientStore, substituteClientStore, substituteWasmClientState) - - if tc.expPass { - suite.Require().NoError(err) - - updatedWasmClient := subjectPath.EndpointA.GetClientState().(*types.ClientState) - var clientStateData exported.ClientState - err := suite.chainA.Codec.UnmarshalInterface(updatedWasmClient.Data, &clientStateData) - suite.Require().NoError(err) - updatedTmClientState := clientStateData.(*ibctm.ClientState) - suite.Require().Equal(clienttypes.ZeroHeight(), updatedTmClientState.FrozenHeight) - - subjectClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), subjectPath.EndpointA.ClientID) - - // check that the correct consensus state was copied over - suite.Require().Equal(substituteWasmClientState.GetLatestHeight(), updatedWasmClient.GetLatestHeight()) - subjectConsState := subjectPath.EndpointA.GetConsensusState(updatedWasmClient.GetLatestHeight()) - subjectProcessedTime, found := ibctm.GetProcessedTime(subjectClientStore, updatedWasmClient.GetLatestHeight()) - suite.Require().True(found) - subjectProcessedHeight, found := GetProcessedHeight(subjectClientStore, updatedWasmClient.GetLatestHeight()) - suite.Require().True(found) - subjectIterationKey := ibctm.GetIterationKey(subjectClientStore, updatedWasmClient.GetLatestHeight()) - - suite.Require().Equal(expectedConsState, subjectConsState) - suite.Require().Equal(expectedProcessedTime, subjectProcessedTime) - suite.Require().Equal(expectedProcessedHeight, subjectProcessedHeight) - suite.Require().Equal(expectedIterationKey, subjectIterationKey) - - suite.Require().Equal(newChainID, updatedTmClientState.ChainId) - suite.Require().Equal(time.Hour*24*7, updatedTmClientState.TrustingPeriod) - } else { - suite.Require().Error(err) - } - }) - } -} +// func (suite *TypesTestSuite) TestCheckSubstituteAndUpdateStateBasicTendermint() { +// var ( +// substituteClientState exported.ClientState +// substitutePath *ibctesting.Path +// ) +// testCases := []struct { +// name string +// malleate func() +// }{ +// { +// "solo machine used for substitute", func() { +// substituteClientState = ibctesting.NewSolomachine(suite.T(), suite.chainA.Codec, "solo machine", "", 1).ClientState() +// }, +// }, +// { +// "non-matching substitute", func() { +// suite.coordinator.SetupClients(substitutePath) +// substituteWasmClientState := suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*types.ClientState) + +// var clientStateData exported.ClientState +// err := suite.chainA.Codec.UnmarshalInterface(substituteWasmClientState.Data, &clientStateData) +// suite.Require().NoError(err) +// tmClientState := clientStateData.(*ibctm.ClientState) + +// // change unbonding period so that test should fail +// tmClientState.UnbondingPeriod = time.Hour * 24 * 7 + +// tmClientStateBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmClientState) +// suite.Require().NoError(err) + +// substituteWasmClientState.Data = tmClientStateBz + +// substituteClientState = substituteWasmClientState +// substitutePath.EndpointA.SetClientState(substituteClientState) +// }, +// }, +// } + +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// suite.SetupWasmTendermint() // reset +// subjectPath := ibctesting.NewPath(suite.chainA, suite.chainB) +// substitutePath = ibctesting.NewPath(suite.chainA, suite.chainB) + +// suite.coordinator.SetupClients(subjectPath) +// subjectClientState := suite.chainA.GetClientState(subjectPath.EndpointA.ClientID).(*types.ClientState) + +// var clientStateData exported.ClientState +// err := suite.chainA.Codec.UnmarshalInterface(subjectClientState.Data, &clientStateData) +// suite.Require().NoError(err) +// tmClientState := clientStateData.(*ibctm.ClientState) + +// // expire subject client +// suite.coordinator.IncrementTimeBy(tmClientState.TrustingPeriod) +// suite.coordinator.CommitBlock(suite.chainA, suite.chainB) + +// tc.malleate() + +// subjectClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), subjectPath.EndpointA.ClientID) +// substituteClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), substitutePath.EndpointA.ClientID) + +// err = subjectClientState.CheckSubstituteAndUpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), subjectClientStore, substituteClientStore, substituteClientState) +// suite.Require().Error(err) +// }) +// } +// } + +// func (suite *TypesTestSuite) TestCheckSubstituteAndUpdateStateTendermint() { +// testCases := []struct { +// name string +// FreezeClient bool +// expPass bool +// }{ +// { +// name: "PASS: update checks are deprecated, client is not frozen", +// FreezeClient: false, +// expPass: true, +// }, +// { +// name: "PASS: update checks are deprecated, client is frozen", +// FreezeClient: true, +// expPass: true, +// }, +// } + +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// suite.SetupWasmTendermint() // reset + +// // construct subject using test case parameters +// subjectPath := ibctesting.NewPath(suite.chainA, suite.chainB) +// suite.coordinator.SetupClients(subjectPath) +// subjectWasmClientState := suite.chainA.GetClientState(subjectPath.EndpointA.ClientID).(*types.ClientState) + +// var subjectWasmClientStateData exported.ClientState +// err := suite.chainA.Codec.UnmarshalInterface(subjectWasmClientState.Data, &subjectWasmClientStateData) +// suite.Require().NoError(err) +// subjectTmClientState := subjectWasmClientStateData.(*ibctm.ClientState) + +// if tc.FreezeClient { +// subjectTmClientState.FrozenHeight = frozenHeight +// } + +// subjectTmClientStateBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), subjectTmClientState) +// suite.Require().NoError(err) +// subjectWasmClientState.Data = subjectTmClientStateBz +// subjectPath.EndpointA.SetClientState(subjectWasmClientState) + +// // construct the substitute to match the subject client + +// substitutePath := ibctesting.NewPath(suite.chainA, suite.chainB) +// suite.coordinator.SetupClients(substitutePath) +// substituteWasmClientState := suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*types.ClientState) + +// var substituteWasmClientStateData exported.ClientState +// err = suite.chainA.Codec.UnmarshalInterface(substituteWasmClientState.Data, &substituteWasmClientStateData) +// suite.Require().NoError(err) +// substituteTmClientState := substituteWasmClientStateData.(*ibctm.ClientState) + +// // update trusting period of substitute client state +// substituteTmClientState.TrustingPeriod = time.Hour * 24 * 7 + +// substituteTmClientStateBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), substituteTmClientState) +// suite.Require().NoError(err) +// substituteWasmClientState.Data = substituteTmClientStateBz +// substitutePath.EndpointA.SetClientState(substituteWasmClientState) + +// // update substitute a few times +// for i := 0; i < 3; i++ { +// err := substitutePath.EndpointA.UpdateClient() +// suite.Require().NoError(err) +// // skip a block +// suite.coordinator.CommitBlock(suite.chainA, suite.chainB) +// } + +// // get updated substitute +// substituteWasmClientState = suite.chainA.GetClientState(substitutePath.EndpointA.ClientID).(*types.ClientState) +// err = suite.chainA.Codec.UnmarshalInterface(substituteWasmClientState.Data, &substituteWasmClientStateData) +// suite.Require().NoError(err) +// substituteTmClientState = substituteWasmClientStateData.(*ibctm.ClientState) + +// // test that subject gets updated chain-id +// newChainID := "new-chain-id" +// substituteTmClientState.ChainId = newChainID + +// substituteTmClientStateBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), substituteTmClientState) +// suite.Require().NoError(err) +// substituteWasmClientState.Data = substituteTmClientStateBz +// substitutePath.EndpointA.SetClientState(substituteWasmClientState) + +// subjectClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), subjectPath.EndpointA.ClientID) +// substituteClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), substitutePath.EndpointA.ClientID) + +// expectedConsState := substitutePath.EndpointA.GetConsensusState(substituteWasmClientState.GetLatestHeight()) +// expectedProcessedTime, found := ibctm.GetProcessedTime(substituteClientStore, substituteWasmClientState.GetLatestHeight()) +// suite.Require().True(found) +// expectedProcessedHeight, found := GetProcessedHeight(substituteClientStore, substituteWasmClientState.GetLatestHeight()) +// suite.Require().True(found) +// expectedIterationKey := ibctm.GetIterationKey(substituteClientStore, substituteWasmClientState.GetLatestHeight()) + +// err = subjectWasmClientState.CheckSubstituteAndUpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), subjectClientStore, substituteClientStore, substituteWasmClientState) + +// if tc.expPass { +// suite.Require().NoError(err) + +// updatedWasmClient := subjectPath.EndpointA.GetClientState().(*types.ClientState) +// var clientStateData exported.ClientState +// err := suite.chainA.Codec.UnmarshalInterface(updatedWasmClient.Data, &clientStateData) +// suite.Require().NoError(err) +// updatedTmClientState := clientStateData.(*ibctm.ClientState) +// suite.Require().Equal(clienttypes.ZeroHeight(), updatedTmClientState.FrozenHeight) + +// subjectClientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), subjectPath.EndpointA.ClientID) + +// // check that the correct consensus state was copied over +// suite.Require().Equal(substituteWasmClientState.GetLatestHeight(), updatedWasmClient.GetLatestHeight()) +// subjectConsState := subjectPath.EndpointA.GetConsensusState(updatedWasmClient.GetLatestHeight()) +// subjectProcessedTime, found := ibctm.GetProcessedTime(subjectClientStore, updatedWasmClient.GetLatestHeight()) +// suite.Require().True(found) +// subjectProcessedHeight, found := GetProcessedHeight(subjectClientStore, updatedWasmClient.GetLatestHeight()) +// suite.Require().True(found) +// subjectIterationKey := ibctm.GetIterationKey(subjectClientStore, updatedWasmClient.GetLatestHeight()) + +// suite.Require().Equal(expectedConsState, subjectConsState) +// suite.Require().Equal(expectedProcessedTime, subjectProcessedTime) +// suite.Require().Equal(expectedProcessedHeight, subjectProcessedHeight) +// suite.Require().Equal(expectedIterationKey, subjectIterationKey) + +// suite.Require().Equal(newChainID, updatedTmClientState.ChainId) +// suite.Require().Equal(time.Hour*24*7, updatedTmClientState.TrustingPeriod) +// } else { +// suite.Require().Error(err) +// } +// }) +// } +// } func GetProcessedHeight(clientStore sdk.KVStore, height exported.Height) (uint64, bool) { key := ibctm.ProcessedHeightKey(height) diff --git a/modules/light-clients/08-wasm/types/types_test.go b/modules/light-clients/08-wasm/types/types_test.go index 43192f32b40..39ff576821f 100644 --- a/modules/light-clients/08-wasm/types/types_test.go +++ b/modules/light-clients/08-wasm/types/types_test.go @@ -75,39 +75,39 @@ func setupTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) { return app, simapp.NewDefaultGenesisState(encCdc.Codec) } -// SetupWasmTendermint sets up 2 chains and stores the tendermint/cometbft light client wasm contract on both. -func (suite *TypesTestSuite) SetupWasmTendermint() { - suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) - suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) - suite.chainA.SetWasm(true) - suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) - suite.chainB.SetWasm(true) - - // commit some blocks so that QueryProof returns valid proof (cannot return valid query if height <= 1) - suite.coordinator.CommitNBlocks(suite.chainA, 2) - suite.coordinator.CommitNBlocks(suite.chainB, 2) - - suite.ctx = suite.chainA.GetContext().WithBlockGasMeter(sdk.NewInfiniteGasMeter()) - suite.store = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, grandpaClientID) - - wasmContract, err := os.ReadFile("../test_data/ics07_tendermint_cw.wasm.gz") - suite.Require().NoError(err) - - msg := types.NewMsgStoreCode(authtypes.NewModuleAddress(govtypes.ModuleName).String(), wasmContract) - response, err := GetSimApp(suite.chainA).WasmClientKeeper.StoreCode(suite.chainA.GetContext(), msg) - suite.Require().NoError(err) - suite.Require().NotNil(response.Checksum) - suite.codeHash = response.Checksum - - response, err = GetSimApp(suite.chainB).WasmClientKeeper.StoreCode(suite.chainB.GetContext(), msg) - suite.Require().NoError(err) - suite.Require().NotNil(response.Checksum) - suite.codeHash = response.Checksum - - suite.coordinator.SetCodeHash(suite.codeHash) - suite.coordinator.CommitNBlocks(suite.chainA, 2) - suite.coordinator.CommitNBlocks(suite.chainB, 2) -} +// // SetupWasmTendermint sets up 2 chains and stores the tendermint/cometbft light client wasm contract on both. +// func (suite *TypesTestSuite) SetupWasmTendermint() { +// suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) +// suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) +// suite.chainA.SetWasm(true) +// suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) +// suite.chainB.SetWasm(true) + +// // commit some blocks so that QueryProof returns valid proof (cannot return valid query if height <= 1) +// suite.coordinator.CommitNBlocks(suite.chainA, 2) +// suite.coordinator.CommitNBlocks(suite.chainB, 2) + +// suite.ctx = suite.chainA.GetContext().WithBlockGasMeter(sdk.NewInfiniteGasMeter()) +// suite.store = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, grandpaClientID) + +// wasmContract, err := os.ReadFile("../test_data/ics07_tendermint_cw.wasm.gz") +// suite.Require().NoError(err) + +// msg := types.NewMsgStoreCode(authtypes.NewModuleAddress(govtypes.ModuleName).String(), wasmContract) +// response, err := GetSimApp(suite.chainA).WasmClientKeeper.StoreCode(suite.chainA.GetContext(), msg) +// suite.Require().NoError(err) +// suite.Require().NotNil(response.Checksum) +// suite.codeHash = response.Checksum + +// response, err = GetSimApp(suite.chainB).WasmClientKeeper.StoreCode(suite.chainB.GetContext(), msg) +// suite.Require().NoError(err) +// suite.Require().NotNil(response.Checksum) +// suite.codeHash = response.Checksum + +// suite.coordinator.SetCodeHash(suite.codeHash) +// suite.coordinator.CommitNBlocks(suite.chainA, 2) +// suite.coordinator.CommitNBlocks(suite.chainB, 2) +// } // SetupWasmGrandpa sets up 1 chain and stores the grandpa light client wasm contract on chain. func (suite *TypesTestSuite) SetupWasmGrandpa() { diff --git a/modules/light-clients/08-wasm/types/update_test.go b/modules/light-clients/08-wasm/types/update_test.go index adf462ab48d..b431e4b8e92 100644 --- a/modules/light-clients/08-wasm/types/update_test.go +++ b/modules/light-clients/08-wasm/types/update_test.go @@ -2,20 +2,11 @@ package types_test import ( "encoding/base64" - "time" - - sdk "github.com/cosmos/cosmos-sdk/types" - - tmtypes "github.com/cometbft/cometbft/types" "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" - ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - ibctesting "github.com/cosmos/ibc-go/v7/testing" - ibctestingmock "github.com/cosmos/ibc-go/v7/testing/mock" ) func (suite *TypesTestSuite) TestVerifyHeaderGrandpa() { @@ -84,302 +75,302 @@ func (suite *TypesTestSuite) TestVerifyHeaderGrandpa() { } } -func (suite *TypesTestSuite) TestVerifyHeaderTendermint() { - var ( - path *ibctesting.Path - header *types.ClientMessage - ) - - // Setup different validators and signers for testing different types of updates - altPrivVal := ibctestingmock.NewPV() - altPubKey, err := altPrivVal.GetPubKey() - suite.Require().NoError(err) - - revisionHeight := int64(height.RevisionHeight) - - // create modified heights to use for test-cases - altVal := tmtypes.NewValidator(altPubKey, 100) - // Create alternative validator set with only altVal, invalid update (too much change in valSet) - altValSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{altVal}) - altSigners := getAltSigners(altVal, altPrivVal) - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - { - name: "success", - malleate: func() {}, - expPass: true, - }, - { - name: "successful verify header for header with a previous height", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - // passing the CurrentHeader.Height as the block height as it will become a previous height once we commit N blocks - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - - // commit some blocks so that the created Header now has a previous height as the BlockHeight - suite.coordinator.CommitNBlocks(suite.chainB, 5) - - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - }, - expPass: true, - }, - { - name: "successful verify header: header with future height and different validator set", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - // Create bothValSet with both suite validator and altVal - bothValSet := tmtypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altVal)) - bothSigners := suite.chainB.Signers - bothSigners[altVal.Address.String()] = altPrivVal - - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+5, trustedHeight, suite.chainB.CurrentHeader.Time, bothValSet, suite.chainB.NextVals, trustedVals, bothSigners) - }, - expPass: true, - }, - { - name: "successful verify header: header with next height and different validator set", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - // Create bothValSet with both suite validator and altVal - bothValSet := tmtypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altVal)) - bothSigners := suite.chainB.Signers - bothSigners[altVal.Address.String()] = altPrivVal - - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, bothValSet, suite.chainB.NextVals, trustedVals, bothSigners) - }, - expPass: true, - }, - { - name: "unsuccessful updates, passed in incorrect trusted validators for given consensus state", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - // Create bothValSet with both suite validator and altVal - bothValSet := tmtypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altVal)) - bothSigners := suite.chainB.Signers - bothSigners[altVal.Address.String()] = altPrivVal - - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, bothValSet, bothValSet, bothValSet, bothSigners) - }, - expPass: false, - }, - { - name: "unsuccessful verify header with next height: update header mismatches nextValSetHash", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - // this will err as altValSet.Hash() != consState.NextValidatorsHash - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, altValSet, altValSet, trustedVals, altSigners) - }, - expPass: false, - }, - { - name: "unsuccessful update with future height: too much change in validator set", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, altValSet, altValSet, trustedVals, altSigners) - }, - expPass: false, - }, - { - name: "unsuccessful verify header: header height revision and trusted height revision mismatch", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - header = suite.chainB.CreateWasmClientHeader("gaia-revision-1", 3, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - }, - expPass: false, - }, - { - name: "unsuccessful verify header: header height < consensus height", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - heightMinus1 := clienttypes.NewHeight(trustedHeight.RevisionNumber, trustedHeight.RevisionHeight-1) - - // Make new header at height less than latest client state - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, int64(heightMinus1.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - }, - expPass: false, - }, - { - name: "unsuccessful verify header: header basic validation failed", - malleate: func() { - var wasmData exported.ClientMessage - err := suite.chainA.Codec.UnmarshalInterface(header.Data, &wasmData) - suite.Require().NoError(err) - - tmHeader, ok := wasmData.(*ibctm.Header) - suite.Require().True(ok) - - // cause header to fail validatebasic by changing commit height to mismatch header height - tmHeader.SignedHeader.Commit.Height = revisionHeight - 1 - - header.Data, err = suite.chainA.Codec.MarshalInterface(tmHeader) - suite.Require().NoError(err) - }, - expPass: false, - }, - { - name: "unsuccessful verify header: header timestamp is not past last client timestamp", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) - - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time.Add(-time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - }, - expPass: false, - }, - { - name: "unsuccessful verify header: header with incorrect header chain-id", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) - - header = suite.chainB.CreateWasmClientHeader("gaia", suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - }, - expPass: false, - }, - { - name: "unsuccessful update: trusting period has passed since last client timestamp", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) - suite.Require().True(found) - - header = suite.chainA.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - - suite.chainB.ExpireClient(ibctesting.TrustingPeriod) - }, - expPass: false, - }, - { - name: "unsuccessful update for a previous revision", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - // passing the CurrentHeader.Height as the block height as it will become an update to previous revision once we upgrade the client - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - - // increment the revision of the chain - err := path.EndpointB.UpgradeChain() - suite.Require().NoError(err) - }, - expPass: false, - }, - { - name: "successful update with identical header to a previous update", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - // passing the CurrentHeader.Height as the block height as it will become a previous height once we commit N blocks - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - - // update client so the header constructed becomes a duplicate - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - }, - expPass: true, - }, - { - name: "unsuccessful update to a future revision", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID+"-1", suite.chainB.CurrentHeader.Height+5, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - }, - expPass: false, - }, - { - name: "unsuccessful update: header height revision and trusted height revision mismatch", - malleate: func() { - trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) - suite.Require().True(found) - - // increment the revision of the chain - err := path.EndpointB.UpgradeChain() - suite.Require().NoError(err) - - header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) - }, - expPass: false, - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - suite.SetupWasmTendermint() - path = ibctesting.NewPath(suite.chainA, suite.chainB) - - err := path.EndpointA.CreateClient() - suite.Require().NoError(err) - - // ensure counterparty state is committed - suite.coordinator.CommitBlock(suite.chainB) - header, height, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) - suite.Require().NoError(err) - - tc.malleate() - - clientState := path.EndpointA.GetClientState() - - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - - err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, header) - - if tc.expPass { - suite.Require().NoError(err, tc.name) - } else { - suite.Require().Error(err) - } - }) - } -} +// func (suite *TypesTestSuite) TestVerifyHeaderTendermint() { +// var ( +// path *ibctesting.Path +// header *types.ClientMessage +// ) + +// // Setup different validators and signers for testing different types of updates +// altPrivVal := ibctestingmock.NewPV() +// altPubKey, err := altPrivVal.GetPubKey() +// suite.Require().NoError(err) + +// revisionHeight := int64(height.RevisionHeight) + +// // create modified heights to use for test-cases +// altVal := tmtypes.NewValidator(altPubKey, 100) +// // Create alternative validator set with only altVal, invalid update (too much change in valSet) +// altValSet := tmtypes.NewValidatorSet([]*tmtypes.Validator{altVal}) +// altSigners := getAltSigners(altVal, altPrivVal) + +// testCases := []struct { +// name string +// malleate func() +// expPass bool +// }{ +// { +// name: "success", +// malleate: func() {}, +// expPass: true, +// }, +// { +// name: "successful verify header for header with a previous height", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// // passing the CurrentHeader.Height as the block height as it will become a previous height once we commit N blocks +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) + +// // commit some blocks so that the created Header now has a previous height as the BlockHeight +// suite.coordinator.CommitNBlocks(suite.chainB, 5) + +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) +// }, +// expPass: true, +// }, +// { +// name: "successful verify header: header with future height and different validator set", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// // Create bothValSet with both suite validator and altVal +// bothValSet := tmtypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altVal)) +// bothSigners := suite.chainB.Signers +// bothSigners[altVal.Address.String()] = altPrivVal + +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+5, trustedHeight, suite.chainB.CurrentHeader.Time, bothValSet, suite.chainB.NextVals, trustedVals, bothSigners) +// }, +// expPass: true, +// }, +// { +// name: "successful verify header: header with next height and different validator set", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// // Create bothValSet with both suite validator and altVal +// bothValSet := tmtypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altVal)) +// bothSigners := suite.chainB.Signers +// bothSigners[altVal.Address.String()] = altPrivVal + +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, bothValSet, suite.chainB.NextVals, trustedVals, bothSigners) +// }, +// expPass: true, +// }, +// { +// name: "unsuccessful updates, passed in incorrect trusted validators for given consensus state", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// // Create bothValSet with both suite validator and altVal +// bothValSet := tmtypes.NewValidatorSet(append(suite.chainB.Vals.Validators, altVal)) +// bothSigners := suite.chainB.Signers +// bothSigners[altVal.Address.String()] = altPrivVal + +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, bothValSet, bothValSet, bothValSet, bothSigners) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful verify header with next height: update header mismatches nextValSetHash", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// // this will err as altValSet.Hash() != consState.NextValidatorsHash +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, altValSet, altValSet, trustedVals, altSigners) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful update with future height: too much change in validator set", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, altValSet, altValSet, trustedVals, altSigners) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful verify header: header height revision and trusted height revision mismatch", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// header = suite.chainB.CreateWasmClientHeader("gaia-revision-1", 3, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful verify header: header height < consensus height", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// heightMinus1 := clienttypes.NewHeight(trustedHeight.RevisionNumber, trustedHeight.RevisionHeight-1) + +// // Make new header at height less than latest client state +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, int64(heightMinus1.RevisionHeight), trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful verify header: header basic validation failed", +// malleate: func() { +// var wasmData exported.ClientMessage +// err := suite.chainA.Codec.UnmarshalInterface(header.Data, &wasmData) +// suite.Require().NoError(err) + +// tmHeader, ok := wasmData.(*ibctm.Header) +// suite.Require().True(ok) + +// // cause header to fail validatebasic by changing commit height to mismatch header height +// tmHeader.SignedHeader.Commit.Height = revisionHeight - 1 + +// header.Data, err = suite.chainA.Codec.MarshalInterface(tmHeader) +// suite.Require().NoError(err) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful verify header: header timestamp is not past last client timestamp", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) +// suite.Require().True(found) + +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time.Add(-time.Minute), suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful verify header: header with incorrect header chain-id", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) +// suite.Require().True(found) + +// header = suite.chainB.CreateWasmClientHeader("gaia", suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful update: trusting period has passed since last client timestamp", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight)) +// suite.Require().True(found) + +// header = suite.chainA.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height+1, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) + +// suite.chainB.ExpireClient(ibctesting.TrustingPeriod) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful update for a previous revision", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// // passing the CurrentHeader.Height as the block height as it will become an update to previous revision once we upgrade the client +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) + +// // increment the revision of the chain +// err := path.EndpointB.UpgradeChain() +// suite.Require().NoError(err) +// }, +// expPass: false, +// }, +// { +// name: "successful update with identical header to a previous update", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// // passing the CurrentHeader.Height as the block height as it will become a previous height once we commit N blocks +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) + +// // update client so the header constructed becomes a duplicate +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) +// }, +// expPass: true, +// }, +// { +// name: "unsuccessful update to a future revision", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID+"-1", suite.chainB.CurrentHeader.Height+5, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful update: header height revision and trusted height revision mismatch", +// malleate: func() { +// trustedHeight := path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// trustedVals, found := suite.chainB.GetValsAtHeight(int64(trustedHeight.RevisionHeight) + 1) +// suite.Require().True(found) + +// // increment the revision of the chain +// err := path.EndpointB.UpgradeChain() +// suite.Require().NoError(err) + +// header = suite.chainB.CreateWasmClientHeader(suite.chainB.ChainID, suite.chainB.CurrentHeader.Height, trustedHeight, suite.chainB.CurrentHeader.Time, suite.chainB.Vals, suite.chainB.NextVals, trustedVals, suite.chainB.Signers) +// }, +// expPass: false, +// }, +// } + +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// suite.SetupWasmTendermint() +// path = ibctesting.NewPath(suite.chainA, suite.chainB) + +// err := path.EndpointA.CreateClient() +// suite.Require().NoError(err) + +// // ensure counterparty state is committed +// suite.coordinator.CommitBlock(suite.chainB) +// header, height, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) +// suite.Require().NoError(err) + +// tc.malleate() + +// clientState := path.EndpointA.GetClientState() + +// clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + +// err = clientState.VerifyClientMessage(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, header) + +// if tc.expPass { +// suite.Require().NoError(err, tc.name) +// } else { +// suite.Require().Error(err) +// } +// }) +// } +// } func (suite *TypesTestSuite) TestUpdateStateGrandpa() { var ( @@ -458,293 +449,293 @@ func (suite *TypesTestSuite) TestUpdateStateGrandpa() { } } -func (suite *TypesTestSuite) TestUpdateStateTendermint() { - var ( - path *ibctesting.Path - clientMessage exported.ClientMessage - clientStore sdk.KVStore - consensusHeights []exported.Height - pruneHeight clienttypes.Height - prevClientState exported.ClientState - prevConsensusState exported.ConsensusState - ) - - testCases := []struct { - name string - malleate func() - expResult func() - expPass bool - }{ - { - "success with height later than latest height", func() { - suite.Require().True(path.EndpointA.GetClientState().GetLatestHeight().LT(height)) - }, - func() { - clientState := path.EndpointA.GetClientState() - suite.Require().True(clientState.GetLatestHeight().EQ(height)) // new update, updated client state should have changed - suite.Require().True(clientState.GetLatestHeight().EQ(consensusHeights[0])) - }, true, - }, - { - "success with height earlier than latest height", func() { - // commit a block so the pre-created ClientMessage - // isn't used to update the client to a newer height - suite.coordinator.CommitBlock(suite.chainB) - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - suite.Require().True(path.EndpointA.GetClientState().GetLatestHeight().GT(height)) - - prevClientState = path.EndpointA.GetClientState() - }, - func() { - clientState := path.EndpointA.GetClientState() - suite.Require().Equal(clientState, prevClientState) // fill in height, no change to client state - suite.Require().True(clientState.GetLatestHeight().GT(consensusHeights[0])) - }, true, - }, - { - "success with duplicate header", func() { - // update client in advance - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - // use the same header which just updated the client - clientMessage, height, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) - suite.Require().NoError(err) - suite.Require().Equal(path.EndpointA.GetClientState().GetLatestHeight(), height) - - prevClientState = path.EndpointA.GetClientState() - prevConsensusState = path.EndpointA.GetConsensusState(height) - }, - func() { - clientState := path.EndpointA.GetClientState() - suite.Require().Equal(clientState, prevClientState) - suite.Require().True(clientState.GetLatestHeight().EQ(consensusHeights[0])) - suite.Require().Equal(path.EndpointA.GetConsensusState(height), prevConsensusState) - }, true, - }, - { - "success with pruned consensus state", func() { - // this height will be expired and pruned - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - pruneHeight = path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - // Increment the time by a week - suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) - - // create the consensus state that can be used as trusted height for next update - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - // Increment the time by another week, then update the client. - // This will cause the first two consensus states to become expired. - suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - // ensure counterparty state is committed - suite.coordinator.CommitBlock(suite.chainB) - clientMessage, height, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) - suite.Require().NoError(err) - }, - func() { - clientState := path.EndpointA.GetClientState() - suite.Require().True(clientState.GetLatestHeight().EQ(height)) // new update, updated client state should have changed - suite.Require().True(clientState.GetLatestHeight().EQ(consensusHeights[0])) - - // ensure consensus state was pruned - _, found := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) - suite.Require().False(found) - }, true, - }, - { - "success with pruned consensus state using duplicate header", func() { - // this height will be expired and pruned - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - pruneHeight = path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) - - // assert that a consensus state exists at the prune height - consensusState, found := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) - suite.Require().True(found) - suite.Require().NotNil(consensusState) - - // Increment the time by a week - suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) - - // create the consensus state that can be used as trusted height for next update - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - // Increment the time by another week, then update the client. - // This will cause the first two consensus states to become expired. - suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - // use the same header which just updated the client - clientMessage, height, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) - suite.Require().NoError(err) - }, - func() { - clientState := path.EndpointA.GetClientState() - suite.Require().True(clientState.GetLatestHeight().EQ(height)) // new update, updated client state should have changed - suite.Require().True(clientState.GetLatestHeight().EQ(consensusHeights[0])) - - // ensure consensus state was pruned - _, found := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) - suite.Require().False(found) - }, true, - }, - { - "invalid ClientMessage type", func() { - clientMessage = &ibctm.Misbehaviour{} - }, - func() {}, - false, - }, - } - for _, tc := range testCases { - suite.Run(tc.name, func() { - suite.SetupWasmTendermint() // reset - path = ibctesting.NewPath(suite.chainA, suite.chainB) - - err := path.EndpointA.CreateClient() - suite.Require().NoError(err) - - // ensure counterparty state is committed - suite.coordinator.CommitBlock(suite.chainB) - clientMessage, height, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) - suite.Require().NoError(err) - - tc.malleate() - - clientState := path.EndpointA.GetClientState() - clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - - if tc.expPass { - consensusHeights = clientState.UpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage) - - clientMessage, ok := clientMessage.(*types.ClientMessage) - suite.Require().True(ok) - var eHeader exported.ClientMessage - err := suite.chainA.Codec.UnmarshalInterface(clientMessage.Data, &eHeader) - tmHeader := eHeader.(*ibctm.Header) - suite.Require().NoError(err) - expTmConsensusState := &ibctm.ConsensusState{ - Timestamp: tmHeader.GetTime(), - Root: commitmenttypes.NewMerkleRoot(tmHeader.Header.GetAppHash()), - NextValidatorsHash: tmHeader.Header.NextValidatorsHash, - } - wasmData, err := suite.chainA.Codec.MarshalInterface(expTmConsensusState) - suite.Require().NoError(err) - expWasmConsensusState := &types.ConsensusState{ - Data: wasmData, - } - - bz := clientStore.Get(host.ConsensusStateKey(height)) - updatedConsensusState := clienttypes.MustUnmarshalConsensusState(suite.chainA.App.AppCodec(), bz) - - suite.Require().Equal(expWasmConsensusState, updatedConsensusState) - - } else { - suite.Require().Panics(func() { - clientState.UpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage) - }) - } - - // perform custom checks - tc.expResult() - }) - } -} - -func (suite *TypesTestSuite) TestPruneConsensusStateTendermint() { - suite.SetupWasmTendermint() - // create path and setup clients - path := ibctesting.NewPath(suite.chainA, suite.chainB) - suite.coordinator.SetupClients(path) - - // get the first height as it will be pruned first. - var pruneHeight exported.Height - getFirstHeightCb := func(height exported.Height) bool { - pruneHeight = height - return true - } - ctx := path.EndpointA.Chain.GetContext() - clientStore := path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) - ibctm.IterateConsensusStateAscending(clientStore, getFirstHeightCb) - - // this height will be expired but not pruned - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - expiredHeight := path.EndpointA.GetClientState().GetLatestHeight() - - // expected values that must still remain in store after pruning - expectedConsState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, expiredHeight) - suite.Require().True(ok) - ctx = path.EndpointA.Chain.GetContext() - clientStore = path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) - expectedProcessTime, ok := ibctm.GetProcessedTime(clientStore, expiredHeight) - suite.Require().True(ok) - expectedProcessHeight, ok := GetProcessedHeight(clientStore, expiredHeight) - suite.Require().True(ok) - expectedConsKey := ibctm.GetIterationKey(clientStore, expiredHeight) - suite.Require().NotNil(expectedConsKey) - - // Increment the time by a week - suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) - - // create the consensus state that can be used as trusted height for next update - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - // Increment the time by another week, then update the client. - // This will cause the first two consensus states to become expired. - suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - ctx = path.EndpointA.Chain.GetContext() - clientStore = path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) - - // check that the first expired consensus state got deleted along with all associated metadata - consState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) - suite.Require().Nil(consState, "expired consensus state not pruned") - suite.Require().False(ok) - // check processed time metadata is pruned - processTime, ok := ibctm.GetProcessedTime(clientStore, pruneHeight) - suite.Require().Equal(uint64(0), processTime, "processed time metadata not pruned") - suite.Require().False(ok) - processHeight, ok := GetProcessedHeight(clientStore, pruneHeight) - suite.Require().Zero(processHeight, "processed height metadata not pruned") - suite.Require().False(ok) - - // check iteration key metadata is pruned - consKey := ibctm.GetIterationKey(clientStore, pruneHeight) - suite.Require().Nil(consKey, "iteration key not pruned") - - // check that second expired consensus state doesn't get deleted - // this ensures that there is a cap on gas cost of UpdateClient - consState, ok = path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, expiredHeight) - suite.Require().Equal(expectedConsState, consState, "consensus state incorrectly pruned") - suite.Require().True(ok) - // check processed time metadata is not pruned - processTime, ok = ibctm.GetProcessedTime(clientStore, expiredHeight) - suite.Require().Equal(expectedProcessTime, processTime, "processed time metadata incorrectly pruned") - suite.Require().True(ok) - - // check processed height metadata is not pruned - processHeight, ok = GetProcessedHeight(clientStore, expiredHeight) - suite.Require().Equal(expectedProcessHeight, processHeight, "processed height metadata incorrectly pruned") - suite.Require().True(ok) - - // check iteration key metadata is not pruned - consKey = ibctm.GetIterationKey(clientStore, expiredHeight) - suite.Require().Equal(expectedConsKey, consKey, "iteration key incorrectly pruned") -} +// func (suite *TypesTestSuite) TestUpdateStateTendermint() { +// var ( +// path *ibctesting.Path +// clientMessage exported.ClientMessage +// clientStore sdk.KVStore +// consensusHeights []exported.Height +// pruneHeight clienttypes.Height +// prevClientState exported.ClientState +// prevConsensusState exported.ConsensusState +// ) + +// testCases := []struct { +// name string +// malleate func() +// expResult func() +// expPass bool +// }{ +// { +// "success with height later than latest height", func() { +// suite.Require().True(path.EndpointA.GetClientState().GetLatestHeight().LT(height)) +// }, +// func() { +// clientState := path.EndpointA.GetClientState() +// suite.Require().True(clientState.GetLatestHeight().EQ(height)) // new update, updated client state should have changed +// suite.Require().True(clientState.GetLatestHeight().EQ(consensusHeights[0])) +// }, true, +// }, +// { +// "success with height earlier than latest height", func() { +// // commit a block so the pre-created ClientMessage +// // isn't used to update the client to a newer height +// suite.coordinator.CommitBlock(suite.chainB) +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// suite.Require().True(path.EndpointA.GetClientState().GetLatestHeight().GT(height)) + +// prevClientState = path.EndpointA.GetClientState() +// }, +// func() { +// clientState := path.EndpointA.GetClientState() +// suite.Require().Equal(clientState, prevClientState) // fill in height, no change to client state +// suite.Require().True(clientState.GetLatestHeight().GT(consensusHeights[0])) +// }, true, +// }, +// { +// "success with duplicate header", func() { +// // update client in advance +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// // use the same header which just updated the client +// clientMessage, height, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) +// suite.Require().NoError(err) +// suite.Require().Equal(path.EndpointA.GetClientState().GetLatestHeight(), height) + +// prevClientState = path.EndpointA.GetClientState() +// prevConsensusState = path.EndpointA.GetConsensusState(height) +// }, +// func() { +// clientState := path.EndpointA.GetClientState() +// suite.Require().Equal(clientState, prevClientState) +// suite.Require().True(clientState.GetLatestHeight().EQ(consensusHeights[0])) +// suite.Require().Equal(path.EndpointA.GetConsensusState(height), prevConsensusState) +// }, true, +// }, +// { +// "success with pruned consensus state", func() { +// // this height will be expired and pruned +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) +// pruneHeight = path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// // Increment the time by a week +// suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) + +// // create the consensus state that can be used as trusted height for next update +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// // Increment the time by another week, then update the client. +// // This will cause the first two consensus states to become expired. +// suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// // ensure counterparty state is committed +// suite.coordinator.CommitBlock(suite.chainB) +// clientMessage, height, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) +// suite.Require().NoError(err) +// }, +// func() { +// clientState := path.EndpointA.GetClientState() +// suite.Require().True(clientState.GetLatestHeight().EQ(height)) // new update, updated client state should have changed +// suite.Require().True(clientState.GetLatestHeight().EQ(consensusHeights[0])) + +// // ensure consensus state was pruned +// _, found := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) +// suite.Require().False(found) +// }, true, +// }, +// { +// "success with pruned consensus state using duplicate header", func() { +// // this height will be expired and pruned +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) +// pruneHeight = path.EndpointA.GetClientState().GetLatestHeight().(clienttypes.Height) + +// // assert that a consensus state exists at the prune height +// consensusState, found := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) +// suite.Require().True(found) +// suite.Require().NotNil(consensusState) + +// // Increment the time by a week +// suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) + +// // create the consensus state that can be used as trusted height for next update +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// // Increment the time by another week, then update the client. +// // This will cause the first two consensus states to become expired. +// suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// // use the same header which just updated the client +// clientMessage, height, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) +// suite.Require().NoError(err) +// }, +// func() { +// clientState := path.EndpointA.GetClientState() +// suite.Require().True(clientState.GetLatestHeight().EQ(height)) // new update, updated client state should have changed +// suite.Require().True(clientState.GetLatestHeight().EQ(consensusHeights[0])) + +// // ensure consensus state was pruned +// _, found := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) +// suite.Require().False(found) +// }, true, +// }, +// { +// "invalid ClientMessage type", func() { +// clientMessage = &ibctm.Misbehaviour{} +// }, +// func() {}, +// false, +// }, +// } +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// suite.SetupWasmTendermint() // reset +// path = ibctesting.NewPath(suite.chainA, suite.chainB) + +// err := path.EndpointA.CreateClient() +// suite.Require().NoError(err) + +// // ensure counterparty state is committed +// suite.coordinator.CommitBlock(suite.chainB) +// clientMessage, height, err = path.EndpointA.Chain.ConstructUpdateWasmClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) +// suite.Require().NoError(err) + +// tc.malleate() + +// clientState := path.EndpointA.GetClientState() +// clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + +// if tc.expPass { +// consensusHeights = clientState.UpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage) + +// clientMessage, ok := clientMessage.(*types.ClientMessage) +// suite.Require().True(ok) +// var eHeader exported.ClientMessage +// err := suite.chainA.Codec.UnmarshalInterface(clientMessage.Data, &eHeader) +// tmHeader := eHeader.(*ibctm.Header) +// suite.Require().NoError(err) +// expTmConsensusState := &ibctm.ConsensusState{ +// Timestamp: tmHeader.GetTime(), +// Root: commitmenttypes.NewMerkleRoot(tmHeader.Header.GetAppHash()), +// NextValidatorsHash: tmHeader.Header.NextValidatorsHash, +// } +// wasmData, err := suite.chainA.Codec.MarshalInterface(expTmConsensusState) +// suite.Require().NoError(err) +// expWasmConsensusState := &types.ConsensusState{ +// Data: wasmData, +// } + +// bz := clientStore.Get(host.ConsensusStateKey(height)) +// updatedConsensusState := clienttypes.MustUnmarshalConsensusState(suite.chainA.App.AppCodec(), bz) + +// suite.Require().Equal(expWasmConsensusState, updatedConsensusState) + +// } else { +// suite.Require().Panics(func() { +// clientState.UpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage) +// }) +// } + +// // perform custom checks +// tc.expResult() +// }) +// } +// } + +// func (suite *TypesTestSuite) TestPruneConsensusStateTendermint() { +// suite.SetupWasmTendermint() +// // create path and setup clients +// path := ibctesting.NewPath(suite.chainA, suite.chainB) +// suite.coordinator.SetupClients(path) + +// // get the first height as it will be pruned first. +// var pruneHeight exported.Height +// getFirstHeightCb := func(height exported.Height) bool { +// pruneHeight = height +// return true +// } +// ctx := path.EndpointA.Chain.GetContext() +// clientStore := path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) +// ibctm.IterateConsensusStateAscending(clientStore, getFirstHeightCb) + +// // this height will be expired but not pruned +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) +// expiredHeight := path.EndpointA.GetClientState().GetLatestHeight() + +// // expected values that must still remain in store after pruning +// expectedConsState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, expiredHeight) +// suite.Require().True(ok) +// ctx = path.EndpointA.Chain.GetContext() +// clientStore = path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) +// expectedProcessTime, ok := ibctm.GetProcessedTime(clientStore, expiredHeight) +// suite.Require().True(ok) +// expectedProcessHeight, ok := GetProcessedHeight(clientStore, expiredHeight) +// suite.Require().True(ok) +// expectedConsKey := ibctm.GetIterationKey(clientStore, expiredHeight) +// suite.Require().NotNil(expectedConsKey) + +// // Increment the time by a week +// suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) + +// // create the consensus state that can be used as trusted height for next update +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// // Increment the time by another week, then update the client. +// // This will cause the first two consensus states to become expired. +// suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// ctx = path.EndpointA.Chain.GetContext() +// clientStore = path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) + +// // check that the first expired consensus state got deleted along with all associated metadata +// consState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) +// suite.Require().Nil(consState, "expired consensus state not pruned") +// suite.Require().False(ok) +// // check processed time metadata is pruned +// processTime, ok := ibctm.GetProcessedTime(clientStore, pruneHeight) +// suite.Require().Equal(uint64(0), processTime, "processed time metadata not pruned") +// suite.Require().False(ok) +// processHeight, ok := GetProcessedHeight(clientStore, pruneHeight) +// suite.Require().Zero(processHeight, "processed height metadata not pruned") +// suite.Require().False(ok) + +// // check iteration key metadata is pruned +// consKey := ibctm.GetIterationKey(clientStore, pruneHeight) +// suite.Require().Nil(consKey, "iteration key not pruned") + +// // check that second expired consensus state doesn't get deleted +// // this ensures that there is a cap on gas cost of UpdateClient +// consState, ok = path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, expiredHeight) +// suite.Require().Equal(expectedConsState, consState, "consensus state incorrectly pruned") +// suite.Require().True(ok) +// // check processed time metadata is not pruned +// processTime, ok = ibctm.GetProcessedTime(clientStore, expiredHeight) +// suite.Require().Equal(expectedProcessTime, processTime, "processed time metadata incorrectly pruned") +// suite.Require().True(ok) + +// // check processed height metadata is not pruned +// processHeight, ok = GetProcessedHeight(clientStore, expiredHeight) +// suite.Require().Equal(expectedProcessHeight, processHeight, "processed height metadata incorrectly pruned") +// suite.Require().True(ok) + +// // check iteration key metadata is not pruned +// consKey = ibctm.GetIterationKey(clientStore, expiredHeight) +// suite.Require().Equal(expectedConsKey, consKey, "iteration key incorrectly pruned") +// } /* func (suite *TypesTestSuite) TestUpdateStateOnMisbehaviourGrandpa() { var ( @@ -798,63 +789,63 @@ func (suite *TypesTestSuite) TestPruneConsensusStateTendermint() { } }*/ -func (suite *TypesTestSuite) TestUpdateStateOnMisbehaviourTendermint() { - var path *ibctesting.Path - - testCases := []struct { - name string - malleate func() - expPass bool - }{ - { - "success", - func() {}, - true, - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - // reset suite to create fresh application state - suite.SetupWasmTendermint() - path = ibctesting.NewPath(suite.chainA, suite.chainB) - - err := path.EndpointA.CreateClient() - suite.Require().NoError(err) - - tc.malleate() - - clientState := path.EndpointA.GetClientState() - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - - misbehaviourHeader, err := path.EndpointA.Chain.ConstructUpdateTMClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) - suite.Require().NoError(err) - tmMisbehaviour := &ibctm.Misbehaviour{ - Header1: misbehaviourHeader, - Header2: misbehaviourHeader, - } - wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) - suite.Require().NoError(err) - clientMessage := &types.ClientMessage{ - Data: wasmData, - } - clientState.UpdateStateOnMisbehaviour(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage) - - if tc.expPass { - clientStateBz := clientStore.Get(host.ClientStateKey()) - suite.Require().NotEmpty(clientStateBz) - - newClientState := clienttypes.MustUnmarshalClientState(suite.chainA.Codec, clientStateBz) - newWasmClientState := newClientState.(*types.ClientState) - - var innerClientState exported.ClientState - err = suite.chainA.Codec.UnmarshalInterface(newWasmClientState.Data, &innerClientState) - suite.Require().NoError(err) - suite.Require().Equal(misbehaviourHeader.GetHeight(), innerClientState.(*ibctm.ClientState).FrozenHeight) - - status := clientState.Status(suite.chainA.GetContext(), clientStore, suite.chainA.Codec) - suite.Require().Equal(exported.Frozen, status) - } - }) - } -} +// func (suite *TypesTestSuite) TestUpdateStateOnMisbehaviourTendermint() { +// var path *ibctesting.Path + +// testCases := []struct { +// name string +// malleate func() +// expPass bool +// }{ +// { +// "success", +// func() {}, +// true, +// }, +// } + +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// // reset suite to create fresh application state +// suite.SetupWasmTendermint() +// path = ibctesting.NewPath(suite.chainA, suite.chainB) + +// err := path.EndpointA.CreateClient() +// suite.Require().NoError(err) + +// tc.malleate() + +// clientState := path.EndpointA.GetClientState() +// clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + +// misbehaviourHeader, err := path.EndpointA.Chain.ConstructUpdateTMClientHeader(path.EndpointA.Counterparty.Chain, path.EndpointA.ClientID) +// suite.Require().NoError(err) +// tmMisbehaviour := &ibctm.Misbehaviour{ +// Header1: misbehaviourHeader, +// Header2: misbehaviourHeader, +// } +// wasmData, err := suite.chainB.Codec.MarshalInterface(tmMisbehaviour) +// suite.Require().NoError(err) +// clientMessage := &types.ClientMessage{ +// Data: wasmData, +// } +// clientState.UpdateStateOnMisbehaviour(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage) + +// if tc.expPass { +// clientStateBz := clientStore.Get(host.ClientStateKey()) +// suite.Require().NotEmpty(clientStateBz) + +// newClientState := clienttypes.MustUnmarshalClientState(suite.chainA.Codec, clientStateBz) +// newWasmClientState := newClientState.(*types.ClientState) + +// var innerClientState exported.ClientState +// err = suite.chainA.Codec.UnmarshalInterface(newWasmClientState.Data, &innerClientState) +// suite.Require().NoError(err) +// suite.Require().Equal(misbehaviourHeader.GetHeight(), innerClientState.(*ibctm.ClientState).FrozenHeight) + +// status := clientState.Status(suite.chainA.GetContext(), clientStore, suite.chainA.Codec) +// suite.Require().Equal(exported.Frozen, status) +// } +// }) +// } +// } diff --git a/modules/light-clients/08-wasm/types/upgrade_test.go b/modules/light-clients/08-wasm/types/upgrade_test.go index 0878c315913..d9330960f83 100644 --- a/modules/light-clients/08-wasm/types/upgrade_test.go +++ b/modules/light-clients/08-wasm/types/upgrade_test.go @@ -1,18 +1,10 @@ package types_test import ( - "time" - - upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types" - - "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" - commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" solomachine "github.com/cosmos/ibc-go/v7/modules/light-clients/06-solomachine" - ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - ibctesting "github.com/cosmos/ibc-go/v7/testing" ) // TestVerifyUpgrade currently only tests the interface into the contract. @@ -106,536 +98,536 @@ func (suite *TypesTestSuite) TestVerifyUpgradeGrandpa() { } } -func (suite *TypesTestSuite) TestVerifyUpgradeTendermint() { - var ( - newChainID string - upgradedClient exported.ClientState - upgradedConsState exported.ConsensusState - lastHeight clienttypes.Height - path *ibctesting.Path - proofUpgradedClient, proofUpgradedConsState []byte - upgradedClientBz, upgradedConsStateBz []byte - err error - ) - - testCases := []struct { - name string - setup func() - expPass bool - }{ - { - name: "successful upgrade", - setup: func() { - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) - - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test - - // commit upgrade store changes and update clients - - suite.coordinator.CommitBlock(suite.chainB) - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: true, - }, - { - name: "successful upgrade to same revision", - setup: func() { - var tmUpgradedClient exported.ClientState - tmUpgradedClient = ibctm.NewClientState(suite.chainB.ChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, clienttypes.NewHeight(clienttypes.ParseChainID(suite.chainB.ChainID), upgradedClient.GetLatestHeight().GetRevisionHeight()+10), commitmenttypes.GetSDKSpecs(), upgradePath) - tmUpgradedClient = tmUpgradedClient.ZeroCustomFields() - tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) - suite.Require().NoError(err) - - upgradedClient = types.NewClientState(tmUpgradedClientBz, suite.codeHash, clienttypes.NewHeight(tmUpgradedClient.GetLatestHeight().GetRevisionNumber(), tmUpgradedClient.GetLatestHeight().GetRevisionHeight())) - upgradedClientBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), upgradedClient) - suite.Require().NoError(err) - - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) - - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test - - // commit upgrade store changes and update clients - - suite.coordinator.CommitBlock(suite.chainB) - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: true, - }, - - { - name: "unsuccessful upgrade: upgrade height revision height is more than the current client revision height", - setup: func() { - // upgrade Height is 10 blocks from now - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+10)) - - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test - - // commit upgrade store changes and update clients - - suite.coordinator.CommitBlock(suite.chainB) - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: committed client does not have zeroed custom fields", - setup: func() { - // non-zeroed upgrade client - var tmUpgradedClient exported.ClientState //nolint:gosimple // ignore error for test - tmUpgradedClient = ibctm.NewClientState(newChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), upgradePath) - tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) - suite.Require().NoError(err) - - upgradedClient = types.NewClientState(tmUpgradedClientBz, suite.codeHash, clienttypes.NewHeight(tmUpgradedClient.GetLatestHeight().GetRevisionNumber(), tmUpgradedClient.GetLatestHeight().GetRevisionHeight())) - upgradedClientBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), upgradedClient) - suite.Require().NoError(err) - - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) - - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test - - // commit upgrade store changes and update clients - - suite.coordinator.CommitBlock(suite.chainB) - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: chain-specified parameters do not match committed client", - setup: func() { - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) - - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test - - // change upgradedClient client-specified parameters - var tmUpgradedClient exported.ClientState - tmUpgradedClient = ibctm.NewClientState("wrongchainID", ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), upgradePath) - tmUpgradedClient = tmUpgradedClient.ZeroCustomFields() - tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) - suite.Require().NoError(err) - - upgradedClient = types.NewClientState(tmUpgradedClientBz, suite.codeHash, clienttypes.NewHeight(tmUpgradedClient.GetLatestHeight().GetRevisionNumber(), tmUpgradedClient.GetLatestHeight().GetRevisionHeight())) - - suite.coordinator.CommitBlock(suite.chainB) - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: client-specified parameters do not match previous client", - setup: func() { - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test - - // change upgradedClient client-specified parameters - var tmUpgradedClient exported.ClientState - tmUpgradedClient = ibctm.NewClientState(newChainID, ibctm.DefaultTrustLevel, ubdPeriod, ubdPeriod+trustingPeriod, maxClockDrift+5, lastHeight, commitmenttypes.GetSDKSpecs(), upgradePath) - tmUpgradedClient = tmUpgradedClient.ZeroCustomFields() - tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) - suite.Require().NoError(err) - - upgradedClient = types.NewClientState(tmUpgradedClientBz, suite.codeHash, clienttypes.NewHeight(tmUpgradedClient.GetLatestHeight().GetRevisionNumber(), tmUpgradedClient.GetLatestHeight().GetRevisionHeight())) - - suite.coordinator.CommitBlock(suite.chainB) - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: relayer-submitted consensus state does not match counterparty-committed consensus state", - setup: func() { - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) - - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test - - var tmUpgradedConsState exported.ConsensusState //nolint:gosimple // ignore error for test - tmUpgradedConsState = &ibctm.ConsensusState{ - Timestamp: time.Now(), - Root: commitmenttypes.NewMerkleRoot([]byte("malicious root hash")), - NextValidatorsHash: []byte("01234567890123456789012345678901"), - } - tmUpgradedConsStateBz, err := clienttypes.MarshalConsensusState(suite.chainA.App.AppCodec(), tmUpgradedConsState) - suite.Require().NoError(err) - - upgradedConsState = &types.ConsensusState{ - Data: tmUpgradedConsStateBz, - } - - // commit upgrade store changes and update clients - suite.coordinator.CommitBlock(suite.chainB) - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: client proof unmarshal failed", - setup: func() { - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - - proofUpgradedClient = []byte("proof") - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: consensus state proof unmarshal failed", - setup: func() { - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - - proofUpgradedConsState = []byte("proof") - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: client proof verification failed", - setup: func() { - // do not store upgraded client - - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) - - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: consensus state proof verification failed", - setup: func() { - // do not store upgraded client - - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) - - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: upgrade path is empty", - setup: func() { - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) - - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - - // commit upgrade store changes and update clients - - suite.coordinator.CommitBlock(suite.chainB) - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - - // SetClientState with empty upgrade path - wasmClient, _ := cs.(*types.ClientState) - var wasmClientData exported.ClientState - err = suite.chainA.Codec.UnmarshalInterface(wasmClient.Data, &wasmClientData) - suite.Require().NoError(err) - tmClient := wasmClientData.(*ibctm.ClientState) - tmClient.UpgradePath = []string{""} - - tmClientBz, err := suite.chainA.Codec.MarshalInterface(tmClient) - suite.Require().NoError(err) - wasmClient.Data = tmClientBz - - suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID, wasmClient) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: upgraded height is not greater than current height", - setup: func() { - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) - - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - - // commit upgrade store changes and update clients - - suite.coordinator.CommitBlock(suite.chainB) - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: consensus state for upgrade height cannot be found", - setup: func() { - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+100)) - - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for - - // commit upgrade store changes and update clients - - suite.coordinator.CommitBlock(suite.chainB) - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: client is expired", - setup: func() { - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - - // commit upgrade store changes and update clients - - suite.coordinator.CommitBlock(suite.chainB) - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - // expire chainB's client - suite.chainA.ExpireClient(ubdPeriod) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: updated unbonding period is equal to trusting period", - setup: func() { - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) - - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test - - // commit upgrade store changes and update clients - - suite.coordinator.CommitBlock(suite.chainB) - err := path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - { - name: "unsuccessful upgrade: final client is not valid", - setup: func() { - // new client has smaller unbonding period such that old trusting period is no longer valid - var tmUpgradedClient exported.ClientState - tmUpgradedClient = ibctm.NewClientState(newChainID, ibctm.DefaultTrustLevel, trustingPeriod, trustingPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), upgradePath) - tmUpgradedClient = tmUpgradedClient.ZeroCustomFields() - tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) - suite.Require().NoError(err) - - upgradedClient = types.NewClientState(tmUpgradedClientBz, suite.codeHash, clienttypes.NewHeight(tmUpgradedClient.GetLatestHeight().GetRevisionNumber(), tmUpgradedClient.GetLatestHeight().GetRevisionHeight())) - upgradedClientBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), upgradedClient) - suite.Require().NoError(err) - - // upgrade Height is at next block - lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) - - // zero custom fields and store in upgrade store - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for testing - GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for testing - - // commit upgrade store changes and update clients - - suite.coordinator.CommitBlock(suite.chainB) - err = path.EndpointA.UpdateClient() - suite.Require().NoError(err) - - cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) - suite.Require().True(found) - - proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) - }, - expPass: false, - }, - } - - for _, tc := range testCases { - suite.Run(tc.name, func() { - // reset suite - suite.SetupWasmTendermint() - path = ibctesting.NewPath(suite.chainA, suite.chainB) - - suite.coordinator.SetupClients(path) - - clientState := path.EndpointA.GetClientState().(*types.ClientState) - var clientStateData exported.ClientState - err = suite.chainA.Codec.UnmarshalInterface(clientState.Data, &clientStateData) - suite.Require().NoError(err) - tmClientState := clientStateData.(*ibctm.ClientState) - - revisionNumber := clienttypes.ParseChainID(tmClientState.ChainId) - - newChainID, err = clienttypes.SetRevisionNumber(tmClientState.ChainId, revisionNumber+1) - suite.Require().NoError(err) - - var tmUpgradedClient exported.ClientState - tmUpgradedClient = ibctm.NewClientState(newChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, clienttypes.NewHeight(revisionNumber+1, clientState.GetLatestHeight().GetRevisionHeight()+1), commitmenttypes.GetSDKSpecs(), upgradePath) - tmUpgradedClient = tmUpgradedClient.ZeroCustomFields() - tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) - suite.Require().NoError(err) - - upgradedClient = types.NewClientState(tmUpgradedClientBz, clientState.CodeHash, clienttypes.NewHeight(revisionNumber+1, clientState.GetLatestHeight().GetRevisionHeight()+1)) - upgradedClientBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), upgradedClient) - suite.Require().NoError(err) - - var tmUpgradedConsState exported.ConsensusState //nolint:gosimple // ignore error for test - tmUpgradedConsState = &ibctm.ConsensusState{ - Timestamp: time.Now(), - Root: commitmenttypes.NewMerkleRoot([]byte("root hash")), - NextValidatorsHash: []byte("01234567890123456789012345678901"), - } - tmUpgradedConsStateBz, err := clienttypes.MarshalConsensusState(suite.chainA.App.AppCodec(), tmUpgradedConsState) - suite.Require().NoError(err) - - upgradedConsState = &types.ConsensusState{ - Data: tmUpgradedConsStateBz, - } - upgradedConsStateBz, err = clienttypes.MarshalConsensusState(suite.chainA.App.AppCodec(), upgradedConsState) - suite.Require().NoError(err) - - tc.setup() - - cs := suite.chainA.GetClientState(path.EndpointA.ClientID) - clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) - - err = cs.VerifyUpgradeAndUpdateState( - suite.chainA.GetContext(), - suite.chainA.Codec, - clientStore, - upgradedClient, - upgradedConsState, - proofUpgradedClient, - proofUpgradedConsState, - ) - - if tc.expPass { - suite.Require().NoError(err, "verify upgrade failed on valid case: %s", tc.name) - - clientState := suite.chainA.GetClientState(path.EndpointA.ClientID) - suite.Require().NotNil(clientState, "verify upgrade failed on valid case: %s", tc.name) - - consensusState, found := suite.chainA.GetConsensusState(path.EndpointA.ClientID, clientState.GetLatestHeight()) - suite.Require().NotNil(consensusState, "verify upgrade failed on valid case: %s", tc.name) - suite.Require().True(found) - } else { - suite.Require().Error(err, "verify upgrade passed on invalid case: %s", tc.name) - } - }) - } -} +// func (suite *TypesTestSuite) TestVerifyUpgradeTendermint() { +// var ( +// newChainID string +// upgradedClient exported.ClientState +// upgradedConsState exported.ConsensusState +// lastHeight clienttypes.Height +// path *ibctesting.Path +// proofUpgradedClient, proofUpgradedConsState []byte +// upgradedClientBz, upgradedConsStateBz []byte +// err error +// ) + +// testCases := []struct { +// name string +// setup func() +// expPass bool +// }{ +// { +// name: "successful upgrade", +// setup: func() { +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) + +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test + +// // commit upgrade store changes and update clients + +// suite.coordinator.CommitBlock(suite.chainB) +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: true, +// }, +// { +// name: "successful upgrade to same revision", +// setup: func() { +// var tmUpgradedClient exported.ClientState +// tmUpgradedClient = ibctm.NewClientState(suite.chainB.ChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, clienttypes.NewHeight(clienttypes.ParseChainID(suite.chainB.ChainID), upgradedClient.GetLatestHeight().GetRevisionHeight()+10), commitmenttypes.GetSDKSpecs(), upgradePath) +// tmUpgradedClient = tmUpgradedClient.ZeroCustomFields() +// tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) +// suite.Require().NoError(err) + +// upgradedClient = types.NewClientState(tmUpgradedClientBz, suite.codeHash, clienttypes.NewHeight(tmUpgradedClient.GetLatestHeight().GetRevisionNumber(), tmUpgradedClient.GetLatestHeight().GetRevisionHeight())) +// upgradedClientBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), upgradedClient) +// suite.Require().NoError(err) + +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) + +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test + +// // commit upgrade store changes and update clients + +// suite.coordinator.CommitBlock(suite.chainB) +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: true, +// }, + +// { +// name: "unsuccessful upgrade: upgrade height revision height is more than the current client revision height", +// setup: func() { +// // upgrade Height is 10 blocks from now +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+10)) + +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test + +// // commit upgrade store changes and update clients + +// suite.coordinator.CommitBlock(suite.chainB) +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: committed client does not have zeroed custom fields", +// setup: func() { +// // non-zeroed upgrade client +// var tmUpgradedClient exported.ClientState //nolint:gosimple // ignore error for test +// tmUpgradedClient = ibctm.NewClientState(newChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), upgradePath) +// tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) +// suite.Require().NoError(err) + +// upgradedClient = types.NewClientState(tmUpgradedClientBz, suite.codeHash, clienttypes.NewHeight(tmUpgradedClient.GetLatestHeight().GetRevisionNumber(), tmUpgradedClient.GetLatestHeight().GetRevisionHeight())) +// upgradedClientBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), upgradedClient) +// suite.Require().NoError(err) + +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) + +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test + +// // commit upgrade store changes and update clients + +// suite.coordinator.CommitBlock(suite.chainB) +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: chain-specified parameters do not match committed client", +// setup: func() { +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) + +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test + +// // change upgradedClient client-specified parameters +// var tmUpgradedClient exported.ClientState +// tmUpgradedClient = ibctm.NewClientState("wrongchainID", ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), upgradePath) +// tmUpgradedClient = tmUpgradedClient.ZeroCustomFields() +// tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) +// suite.Require().NoError(err) + +// upgradedClient = types.NewClientState(tmUpgradedClientBz, suite.codeHash, clienttypes.NewHeight(tmUpgradedClient.GetLatestHeight().GetRevisionNumber(), tmUpgradedClient.GetLatestHeight().GetRevisionHeight())) + +// suite.coordinator.CommitBlock(suite.chainB) +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: client-specified parameters do not match previous client", +// setup: func() { +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test + +// // change upgradedClient client-specified parameters +// var tmUpgradedClient exported.ClientState +// tmUpgradedClient = ibctm.NewClientState(newChainID, ibctm.DefaultTrustLevel, ubdPeriod, ubdPeriod+trustingPeriod, maxClockDrift+5, lastHeight, commitmenttypes.GetSDKSpecs(), upgradePath) +// tmUpgradedClient = tmUpgradedClient.ZeroCustomFields() +// tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) +// suite.Require().NoError(err) + +// upgradedClient = types.NewClientState(tmUpgradedClientBz, suite.codeHash, clienttypes.NewHeight(tmUpgradedClient.GetLatestHeight().GetRevisionNumber(), tmUpgradedClient.GetLatestHeight().GetRevisionHeight())) + +// suite.coordinator.CommitBlock(suite.chainB) +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: relayer-submitted consensus state does not match counterparty-committed consensus state", +// setup: func() { +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) + +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test + +// var tmUpgradedConsState exported.ConsensusState //nolint:gosimple // ignore error for test +// tmUpgradedConsState = &ibctm.ConsensusState{ +// Timestamp: time.Now(), +// Root: commitmenttypes.NewMerkleRoot([]byte("malicious root hash")), +// NextValidatorsHash: []byte("01234567890123456789012345678901"), +// } +// tmUpgradedConsStateBz, err := clienttypes.MarshalConsensusState(suite.chainA.App.AppCodec(), tmUpgradedConsState) +// suite.Require().NoError(err) + +// upgradedConsState = &types.ConsensusState{ +// Data: tmUpgradedConsStateBz, +// } + +// // commit upgrade store changes and update clients +// suite.coordinator.CommitBlock(suite.chainB) +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: client proof unmarshal failed", +// setup: func() { +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) + +// proofUpgradedClient = []byte("proof") +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: consensus state proof unmarshal failed", +// setup: func() { +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) + +// proofUpgradedConsState = []byte("proof") +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: client proof verification failed", +// setup: func() { +// // do not store upgraded client + +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) + +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for test + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: consensus state proof verification failed", +// setup: func() { +// // do not store upgraded client + +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) + +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: upgrade path is empty", +// setup: func() { +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) + +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test + +// // commit upgrade store changes and update clients + +// suite.coordinator.CommitBlock(suite.chainB) +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) + +// // SetClientState with empty upgrade path +// wasmClient, _ := cs.(*types.ClientState) +// var wasmClientData exported.ClientState +// err = suite.chainA.Codec.UnmarshalInterface(wasmClient.Data, &wasmClientData) +// suite.Require().NoError(err) +// tmClient := wasmClientData.(*ibctm.ClientState) +// tmClient.UpgradePath = []string{""} + +// tmClientBz, err := suite.chainA.Codec.MarshalInterface(tmClient) +// suite.Require().NoError(err) +// wasmClient.Data = tmClientBz + +// suite.chainA.App.GetIBCKeeper().ClientKeeper.SetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID, wasmClient) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: upgraded height is not greater than current height", +// setup: func() { +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) + +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test + +// // commit upgrade store changes and update clients + +// suite.coordinator.CommitBlock(suite.chainB) +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: consensus state for upgrade height cannot be found", +// setup: func() { +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+100)) + +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for + +// // commit upgrade store changes and update clients + +// suite.coordinator.CommitBlock(suite.chainB) +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: client is expired", +// setup: func() { +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test + +// // commit upgrade store changes and update clients + +// suite.coordinator.CommitBlock(suite.chainB) +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// // expire chainB's client +// suite.chainA.ExpireClient(ubdPeriod) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: updated unbonding period is equal to trusting period", +// setup: func() { +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) + +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for test + +// // commit upgrade store changes and update clients + +// suite.coordinator.CommitBlock(suite.chainB) +// err := path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// { +// name: "unsuccessful upgrade: final client is not valid", +// setup: func() { +// // new client has smaller unbonding period such that old trusting period is no longer valid +// var tmUpgradedClient exported.ClientState +// tmUpgradedClient = ibctm.NewClientState(newChainID, ibctm.DefaultTrustLevel, trustingPeriod, trustingPeriod, maxClockDrift, newClientHeight, commitmenttypes.GetSDKSpecs(), upgradePath) +// tmUpgradedClient = tmUpgradedClient.ZeroCustomFields() +// tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) +// suite.Require().NoError(err) + +// upgradedClient = types.NewClientState(tmUpgradedClientBz, suite.codeHash, clienttypes.NewHeight(tmUpgradedClient.GetLatestHeight().GetRevisionNumber(), tmUpgradedClient.GetLatestHeight().GetRevisionHeight())) +// upgradedClientBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), upgradedClient) +// suite.Require().NoError(err) + +// // upgrade Height is at next block +// lastHeight = clienttypes.NewHeight(0, uint64(suite.chainB.GetContext().BlockHeight()+1)) + +// // zero custom fields and store in upgrade store +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedClient(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedClientBz) //nolint:errcheck // ignore error for testing +// GetSimApp(suite.chainB).UpgradeKeeper.SetUpgradedConsensusState(suite.chainB.GetContext(), int64(lastHeight.GetRevisionHeight()), upgradedConsStateBz) //nolint:errcheck // ignore error for testing + +// // commit upgrade store changes and update clients + +// suite.coordinator.CommitBlock(suite.chainB) +// err = path.EndpointA.UpdateClient() +// suite.Require().NoError(err) + +// cs, found := suite.chainA.App.GetIBCKeeper().ClientKeeper.GetClientState(suite.chainA.GetContext(), path.EndpointA.ClientID) +// suite.Require().True(found) + +// proofUpgradedClient, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedClientKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// proofUpgradedConsState, _ = suite.chainB.QueryUpgradeProof(upgradetypes.UpgradedConsStateKey(int64(lastHeight.GetRevisionHeight())), cs.GetLatestHeight().GetRevisionHeight()) +// }, +// expPass: false, +// }, +// } + +// for _, tc := range testCases { +// suite.Run(tc.name, func() { +// // reset suite +// suite.SetupWasmTendermint() +// path = ibctesting.NewPath(suite.chainA, suite.chainB) + +// suite.coordinator.SetupClients(path) + +// clientState := path.EndpointA.GetClientState().(*types.ClientState) +// var clientStateData exported.ClientState +// err = suite.chainA.Codec.UnmarshalInterface(clientState.Data, &clientStateData) +// suite.Require().NoError(err) +// tmClientState := clientStateData.(*ibctm.ClientState) + +// revisionNumber := clienttypes.ParseChainID(tmClientState.ChainId) + +// newChainID, err = clienttypes.SetRevisionNumber(tmClientState.ChainId, revisionNumber+1) +// suite.Require().NoError(err) + +// var tmUpgradedClient exported.ClientState +// tmUpgradedClient = ibctm.NewClientState(newChainID, ibctm.DefaultTrustLevel, trustingPeriod, ubdPeriod+trustingPeriod, maxClockDrift, clienttypes.NewHeight(revisionNumber+1, clientState.GetLatestHeight().GetRevisionHeight()+1), commitmenttypes.GetSDKSpecs(), upgradePath) +// tmUpgradedClient = tmUpgradedClient.ZeroCustomFields() +// tmUpgradedClientBz, err := clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), tmUpgradedClient) +// suite.Require().NoError(err) + +// upgradedClient = types.NewClientState(tmUpgradedClientBz, clientState.CodeHash, clienttypes.NewHeight(revisionNumber+1, clientState.GetLatestHeight().GetRevisionHeight()+1)) +// upgradedClientBz, err = clienttypes.MarshalClientState(suite.chainA.App.AppCodec(), upgradedClient) +// suite.Require().NoError(err) + +// var tmUpgradedConsState exported.ConsensusState //nolint:gosimple // ignore error for test +// tmUpgradedConsState = &ibctm.ConsensusState{ +// Timestamp: time.Now(), +// Root: commitmenttypes.NewMerkleRoot([]byte("root hash")), +// NextValidatorsHash: []byte("01234567890123456789012345678901"), +// } +// tmUpgradedConsStateBz, err := clienttypes.MarshalConsensusState(suite.chainA.App.AppCodec(), tmUpgradedConsState) +// suite.Require().NoError(err) + +// upgradedConsState = &types.ConsensusState{ +// Data: tmUpgradedConsStateBz, +// } +// upgradedConsStateBz, err = clienttypes.MarshalConsensusState(suite.chainA.App.AppCodec(), upgradedConsState) +// suite.Require().NoError(err) + +// tc.setup() + +// cs := suite.chainA.GetClientState(path.EndpointA.ClientID) +// clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) + +// err = cs.VerifyUpgradeAndUpdateState( +// suite.chainA.GetContext(), +// suite.chainA.Codec, +// clientStore, +// upgradedClient, +// upgradedConsState, +// proofUpgradedClient, +// proofUpgradedConsState, +// ) + +// if tc.expPass { +// suite.Require().NoError(err, "verify upgrade failed on valid case: %s", tc.name) + +// clientState := suite.chainA.GetClientState(path.EndpointA.ClientID) +// suite.Require().NotNil(clientState, "verify upgrade failed on valid case: %s", tc.name) + +// consensusState, found := suite.chainA.GetConsensusState(path.EndpointA.ClientID, clientState.GetLatestHeight()) +// suite.Require().NotNil(consensusState, "verify upgrade failed on valid case: %s", tc.name) +// suite.Require().True(found) +// } else { +// suite.Require().Error(err, "verify upgrade passed on invalid case: %s", tc.name) +// } +// }) +// } +// } From 37b4f72613a8ff7877ca69a3c0f56734f0ed1cf0 Mon Sep 17 00:00:00 2001 From: Charly Date: Mon, 2 Oct 2023 15:51:20 +0200 Subject: [PATCH 05/11] unused import --- modules/light-clients/08-wasm/types/proposal_handle_test.go | 2 -- 1 file changed, 2 deletions(-) diff --git a/modules/light-clients/08-wasm/types/proposal_handle_test.go b/modules/light-clients/08-wasm/types/proposal_handle_test.go index afea9372e24..25f4e722a4e 100644 --- a/modules/light-clients/08-wasm/types/proposal_handle_test.go +++ b/modules/light-clients/08-wasm/types/proposal_handle_test.go @@ -2,7 +2,6 @@ package types_test import ( "encoding/base64" - "time" sdk "github.com/cosmos/cosmos-sdk/types" @@ -11,7 +10,6 @@ import ( host "github.com/cosmos/ibc-go/v7/modules/core/24-host" "github.com/cosmos/ibc-go/v7/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" - ibctesting "github.com/cosmos/ibc-go/v7/testing" ) var frozenHeight = clienttypes.NewHeight(0, 1) From 701f210daad10b48b2d9470fdc2b2f80f6e361f0 Mon Sep 17 00:00:00 2001 From: Charly Date: Mon, 2 Oct 2023 16:42:48 +0200 Subject: [PATCH 06/11] rm wasm code from testing utils --- go.mod | 2 - go.sum | 2 - .../08-wasm/types/client_state_test.go | 3 + .../08-wasm/types/proposal_handle_test.go | 2 +- .../light-clients/08-wasm/types/types_test.go | 19 ++- testing/endpoint.go | 48 +------ testing/wasm.go | 123 +++++++++--------- 7 files changed, 75 insertions(+), 124 deletions(-) diff --git a/go.mod b/go.mod index 5cc00738dbe..d30512f7c5f 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,6 @@ require ( github.com/cosmos/cosmos-sdk v0.47.5 github.com/cosmos/gogoproto v1.4.10 github.com/cosmos/ibc-go/modules/capability v1.0.0-rc1 - github.com/cosmos/ibc-go/modules/light-clients/08-wasm v0.0.0-00010101000000-000000000000 github.com/cosmos/ics23/go v0.10.0 github.com/golang/protobuf v1.5.3 github.com/grpc-ecosystem/grpc-gateway v1.16.0 @@ -41,7 +40,6 @@ require ( github.com/99designs/go-keychain v0.0.0-20191008050251-8e49817e8af4 // indirect github.com/99designs/keyring v1.2.1 // indirect github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d // indirect - github.com/CosmWasm/wasmvm v1.2.4 // indirect github.com/aws/aws-sdk-go v1.44.203 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect diff --git a/go.sum b/go.sum index 063d22cbebb..b5e2e1063d6 100644 --- a/go.sum +++ b/go.sum @@ -214,8 +214,6 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03 github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d h1:nalkkPQcITbvhmL4+C4cKA87NW0tfm3Kl9VXRoPywFg= github.com/ChainSafe/go-schnorrkel v0.0.0-20200405005733-88cbf1b4c40d/go.mod h1:URdX5+vg25ts3aCh8H5IFZybJYKWhJHYMTnf+ULtoC4= -github.com/CosmWasm/wasmvm v1.2.4 h1:6OfeZuEcEH/9iqwrg2pkeVtDCkMoj9U6PpKtcrCyVrQ= -github.com/CosmWasm/wasmvm v1.2.4/go.mod h1:vW/E3h8j9xBQs9bCoijDuawKo9kCtxOaS8N8J7KFtkc= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0= github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg= diff --git a/modules/light-clients/08-wasm/types/client_state_test.go b/modules/light-clients/08-wasm/types/client_state_test.go index 8c4cd2ed588..2aa29c8089e 100644 --- a/modules/light-clients/08-wasm/types/client_state_test.go +++ b/modules/light-clients/08-wasm/types/client_state_test.go @@ -5,7 +5,10 @@ import ( "encoding/base64" "time" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" + transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" diff --git a/modules/light-clients/08-wasm/types/proposal_handle_test.go b/modules/light-clients/08-wasm/types/proposal_handle_test.go index 25f4e722a4e..6e83a1f8ead 100644 --- a/modules/light-clients/08-wasm/types/proposal_handle_test.go +++ b/modules/light-clients/08-wasm/types/proposal_handle_test.go @@ -12,7 +12,7 @@ import ( ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint" ) -var frozenHeight = clienttypes.NewHeight(0, 1) +// var frozenHeight = clienttypes.NewHeight(0, 1) // TestCheckSubstituteAndUpdateState only tests the interface to the contract, not the full logic of the contract. func (suite *TypesTestSuite) TestCheckSubstituteAndUpdateStateGrandpa() { diff --git a/modules/light-clients/08-wasm/types/types_test.go b/modules/light-clients/08-wasm/types/types_test.go index 39ff576821f..ae1f2486790 100644 --- a/modules/light-clients/08-wasm/types/types_test.go +++ b/modules/light-clients/08-wasm/types/types_test.go @@ -21,7 +21,6 @@ import ( simapp "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/testing/simapp" "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" - clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" "github.com/cosmos/ibc-go/v7/modules/core/exported" ibctesting "github.com/cosmos/ibc-go/v7/testing" ) @@ -35,17 +34,17 @@ const ( maxClockDrift time.Duration = time.Second * 10 ) -var ( - height = clienttypes.NewHeight(0, 4) - newClientHeight = clienttypes.NewHeight(1, 1) - upgradePath = []string{"upgrade", "upgradedIBCState"} -) +// var ( +// height = clienttypes.NewHeight(0, 4) +// newClientHeight = clienttypes.NewHeight(1, 1) +// upgradePath = []string{"upgrade", "upgradedIBCState"} +// ) type TypesTestSuite struct { testifysuite.Suite coordinator *ibctesting.Coordinator chainA *ibctesting.TestChain - chainB *ibctesting.TestChain + // chainB *ibctesting.TestChain ctx sdk.Context store sdk.KVStore @@ -179,6 +178,6 @@ func TestWasmTestSuite(t *testing.T) { testifysuite.Run(t, new(TypesTestSuite)) } -func getAltSigners(altVal *tmtypes.Validator, altPrivVal tmtypes.PrivValidator) map[string]tmtypes.PrivValidator { - return map[string]tmtypes.PrivValidator{altVal.Address.String(): altPrivVal} -} +// func getAltSigners(altVal *tmtypes.Validator, altPrivVal tmtypes.PrivValidator) map[string]tmtypes.PrivValidator { +// return map[string]tmtypes.PrivValidator{altVal.Address.String(): altPrivVal} +// } diff --git a/testing/endpoint.go b/testing/endpoint.go index 04d293d4137..ee2baca8c14 100644 --- a/testing/endpoint.go +++ b/testing/endpoint.go @@ -9,7 +9,6 @@ import ( "github.com/cosmos/cosmos-sdk/baseapp" sdk "github.com/cosmos/cosmos-sdk/types" - wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" @@ -104,26 +103,6 @@ func (endpoint *Endpoint) CreateClient() (err error) { // solo := NewSolomachine(endpoint.Chain.TB, endpoint.Chain.Codec, clientID, "", 1) // clientState = solo.ClientState() // consensusState = solo.ConsensusState() - case exported.Wasm: - tmConfig, ok := endpoint.ClientConfig.(*TendermintConfig) - require.True(endpoint.Chain.TB, ok) - - height := endpoint.Counterparty.Chain.LastHeader.GetHeight().(clienttypes.Height) - tmClientState := ibctm.NewClientState( - endpoint.Counterparty.Chain.ChainID, tmConfig.TrustLevel, tmConfig.TrustingPeriod, tmConfig.UnbondingPeriod, tmConfig.MaxClockDrift, - height, commitmenttypes.GetSDKSpecs(), UpgradePath) - tmConsensusState := endpoint.Counterparty.Chain.LastHeader.ConsensusState() - wasmClientState, err := endpoint.Chain.Codec.MarshalInterface(tmClientState) - if err != nil { - return err - } - clientState = wasmtypes.NewClientState(wasmClientState, endpoint.Chain.Coordinator.CodeHash, height) - - wasmConsensusState, err := endpoint.Chain.Codec.MarshalInterface(tmConsensusState) - if err != nil { - return err - } - consensusState = wasmtypes.NewConsensusState(wasmConsensusState, tmConsensusState.GetTimestamp()) default: err = fmt.Errorf("client type %s is not supported", endpoint.ClientConfig.GetClientType()) } @@ -158,8 +137,6 @@ func (endpoint *Endpoint) UpdateClient() (err error) { switch endpoint.ClientConfig.GetClientType() { case exported.Tendermint: header, err = endpoint.Chain.ConstructUpdateTMClientHeader(endpoint.Counterparty.Chain, endpoint.ClientID) - case exported.Wasm: - header, _, err = endpoint.Chain.ConstructUpdateWasmClientHeader(endpoint.Counterparty.Chain, endpoint.ClientID) default: err = fmt.Errorf("client type %s is not supported", endpoint.ClientConfig.GetClientType()) } @@ -188,13 +165,6 @@ func (endpoint *Endpoint) UpgradeChain() error { } clientState := endpoint.Counterparty.GetClientState() - - var wasmClientState *wasmtypes.ClientState - if endpoint.ClientConfig.GetClientType() == exported.Wasm { - wasmClientState = clientState.(*wasmtypes.ClientState) - err := endpoint.Chain.Codec.UnmarshalInterface(wasmClientState.Data, &clientState) - require.NoError(endpoint.Chain.TB, err) - } tmClientState := clientState.(*ibctm.ClientState) // increment revision number in chainID @@ -219,13 +189,6 @@ func (endpoint *Endpoint) UpgradeChain() error { tmClientState.ChainId = newChainID tmClientState.LatestHeight = clienttypes.NewHeight(revisionNumber+1, tmClientState.LatestHeight.GetRevisionHeight()+1) - if endpoint.ClientConfig.GetClientType() == exported.Wasm { - wasmData, err := endpoint.Chain.Codec.MarshalInterface(tmClientState) - require.NoError(endpoint.Chain.TB, err) - wasmClientState.Data = wasmData - wasmClientState.LatestHeight = tmClientState.LatestHeight - clientState = wasmClientState - } endpoint.Counterparty.SetClientState(clientState) tmConsensusState := &ibctm.ConsensusState{ @@ -233,16 +196,7 @@ func (endpoint *Endpoint) UpgradeChain() error { Root: commitmenttypes.NewMerkleRoot(endpoint.Chain.LastHeader.Header.GetAppHash()), NextValidatorsHash: endpoint.Chain.LastHeader.Header.NextValidatorsHash, } - var consensusState exported.ConsensusState - consensusState = tmConsensusState - if endpoint.ClientConfig.GetClientType() == exported.Wasm { - wasmData, err := endpoint.Chain.Codec.MarshalInterface(tmConsensusState) - require.NoError(endpoint.Chain.TB, err) - consensusState = &wasmtypes.ConsensusState{ - Data: wasmData, - } - } - endpoint.Counterparty.SetConsensusState(consensusState, clientState.GetLatestHeight()) + endpoint.Counterparty.SetConsensusState(tmConsensusState, clientState.GetLatestHeight()) // ensure the next update isn't identical to the one set in state endpoint.Chain.Coordinator.IncrementTime() diff --git a/testing/wasm.go b/testing/wasm.go index c0ca7e41c58..49fd21e3a54 100644 --- a/testing/wasm.go +++ b/testing/wasm.go @@ -1,64 +1,63 @@ package ibctesting -import ( - "fmt" - "time" - - "github.com/stretchr/testify/require" - - tmtypes "github.com/cometbft/cometbft/types" - - wasmtypes "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" - clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" -) - -// ConstructUpdateWasmClientHeader will construct a valid 08-wasm Header with a zero height -// to update the light client on the source chain. -func (chain *TestChain) ConstructUpdateWasmClientHeader(counterparty *TestChain, clientID string) (*wasmtypes.ClientMessage, clienttypes.Height, error) { - return chain.ConstructUpdateWasmClientHeaderWithTrustedHeight(counterparty, clientID, clienttypes.ZeroHeight()) -} - -// ConstructUpdateWasmClientHeaderWithTrustedHeight will construct a valid 08-wasm Header -// to update the light client on the source chain. -func (chain *TestChain) ConstructUpdateWasmClientHeaderWithTrustedHeight( - counterparty *TestChain, - clientID string, - trustedHeight clienttypes.Height, -) (*wasmtypes.ClientMessage, clienttypes.Height, error) { - tmHeader, err := chain.ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty, clientID, trustedHeight) - if err != nil { - return nil, clienttypes.ZeroHeight(), err - } - - tmWasmHeaderData, err := chain.Codec.MarshalInterface(tmHeader) - if err != nil { - return nil, clienttypes.ZeroHeight(), err - } - - height, ok := tmHeader.GetHeight().(clienttypes.Height) - if !ok { - return nil, clienttypes.ZeroHeight(), fmt.Errorf("error casting exported height to clienttypes height") - } - - wasmHeader := wasmtypes.ClientMessage{ - Data: tmWasmHeaderData, - } - - return &wasmHeader, height, nil -} - -func (chain *TestChain) CreateWasmClientHeader( - chainID string, - blockHeight int64, - trustedHeight clienttypes.Height, - timestamp time.Time, - tmValSet, nextVals, tmTrustedVals *tmtypes.ValidatorSet, - signers map[string]tmtypes.PrivValidator, -) *wasmtypes.ClientMessage { - tmHeader := chain.CreateTMClientHeader(chainID, blockHeight, trustedHeight, timestamp, tmValSet, nextVals, tmTrustedVals, signers) - tmWasmHeaderData, err := chain.Codec.MarshalInterface(tmHeader) - require.NoError(chain.TB, err) - return &wasmtypes.ClientMessage{ - Data: tmWasmHeaderData, - } -} +// import ( +// "fmt" +// "time" + +// "github.com/stretchr/testify/require" + +// tmtypes "github.com/cometbft/cometbft/types" + +// clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" +// ) + +// // ConstructUpdateWasmClientHeader will construct a valid 08-wasm Header with a zero height +// // to update the light client on the source chain. +// func (chain *TestChain) ConstructUpdateWasmClientHeader(counterparty *TestChain, clientID string) (*wasmtypes.ClientMessage, clienttypes.Height, error) { +// return chain.ConstructUpdateWasmClientHeaderWithTrustedHeight(counterparty, clientID, clienttypes.ZeroHeight()) +// } + +// // ConstructUpdateWasmClientHeaderWithTrustedHeight will construct a valid 08-wasm Header +// // to update the light client on the source chain. +// func (chain *TestChain) ConstructUpdateWasmClientHeaderWithTrustedHeight( +// counterparty *TestChain, +// clientID string, +// trustedHeight clienttypes.Height, +// ) (*wasmtypes.ClientMessage, clienttypes.Height, error) { +// tmHeader, err := chain.ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty, clientID, trustedHeight) +// if err != nil { +// return nil, clienttypes.ZeroHeight(), err +// } + +// tmWasmHeaderData, err := chain.Codec.MarshalInterface(tmHeader) +// if err != nil { +// return nil, clienttypes.ZeroHeight(), err +// } + +// height, ok := tmHeader.GetHeight().(clienttypes.Height) +// if !ok { +// return nil, clienttypes.ZeroHeight(), fmt.Errorf("error casting exported height to clienttypes height") +// } + +// wasmHeader := wasmtypes.ClientMessage{ +// Data: tmWasmHeaderData, +// } + +// return &wasmHeader, height, nil +// } + +// func (chain *TestChain) CreateWasmClientHeader( +// chainID string, +// blockHeight int64, +// trustedHeight clienttypes.Height, +// timestamp time.Time, +// tmValSet, nextVals, tmTrustedVals *tmtypes.ValidatorSet, +// signers map[string]tmtypes.PrivValidator, +// ) *wasmtypes.ClientMessage { +// tmHeader := chain.CreateTMClientHeader(chainID, blockHeight, trustedHeight, timestamp, tmValSet, nextVals, tmTrustedVals, signers) +// tmWasmHeaderData, err := chain.Codec.MarshalInterface(tmHeader) +// require.NoError(chain.TB, err) +// return &wasmtypes.ClientMessage{ +// Data: tmWasmHeaderData, +// } +// } From a5f883fdec85f768a908a6be96017f23f89f165e Mon Sep 17 00:00:00 2001 From: Charly Date: Mon, 2 Oct 2023 16:45:32 +0200 Subject: [PATCH 07/11] linter --- modules/light-clients/08-wasm/types/client_state_test.go | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/light-clients/08-wasm/types/client_state_test.go b/modules/light-clients/08-wasm/types/client_state_test.go index 2aa29c8089e..6d73f98ba4f 100644 --- a/modules/light-clients/08-wasm/types/client_state_test.go +++ b/modules/light-clients/08-wasm/types/client_state_test.go @@ -5,11 +5,7 @@ import ( "encoding/base64" "time" - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" - transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" - clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" From 7eba9a41f6b9ce6d61420a7399874ab2ed35dfa9 Mon Sep 17 00:00:00 2001 From: Charly Date: Mon, 2 Oct 2023 17:24:11 +0200 Subject: [PATCH 08/11] clienttypes --- modules/light-clients/08-wasm/types/client_state_test.go | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/light-clients/08-wasm/types/client_state_test.go b/modules/light-clients/08-wasm/types/client_state_test.go index 6d73f98ba4f..8c4cd2ed588 100644 --- a/modules/light-clients/08-wasm/types/client_state_test.go +++ b/modules/light-clients/08-wasm/types/client_state_test.go @@ -6,6 +6,7 @@ import ( "time" "github.com/cosmos/ibc-go/modules/light-clients/08-wasm/types" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types" From 58af513eae454c583a1abef40597aeefefb4a442 Mon Sep 17 00:00:00 2001 From: Carlos Rodriguez Date: Tue, 3 Oct 2023 09:50:25 +0200 Subject: [PATCH 09/11] comment out some extra code that was used by tendermint tests --- .../light-clients/08-wasm/types/types_test.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/modules/light-clients/08-wasm/types/types_test.go b/modules/light-clients/08-wasm/types/types_test.go index ae1f2486790..7435da88c12 100644 --- a/modules/light-clients/08-wasm/types/types_test.go +++ b/modules/light-clients/08-wasm/types/types_test.go @@ -5,7 +5,6 @@ import ( "errors" "os" "testing" - "time" testifysuite "github.com/stretchr/testify/suite" @@ -26,12 +25,12 @@ import ( ) const ( - tmClientID = "07-tendermint-0" - grandpaClientID = "08-wasm-0" - codeHash = "01234567012345670123456701234567" - trustingPeriod time.Duration = time.Hour * 24 * 7 * 2 - ubdPeriod time.Duration = time.Hour * 24 * 7 * 3 - maxClockDrift time.Duration = time.Second * 10 + tmClientID = "07-tendermint-0" + grandpaClientID = "08-wasm-0" + codeHash = "01234567012345670123456701234567" + // trustingPeriod time.Duration = time.Hour * 24 * 7 * 2 + // ubdPeriod time.Duration = time.Hour * 24 * 7 * 3 + // maxClockDrift time.Duration = time.Second * 10 ) // var ( @@ -52,9 +51,9 @@ type TypesTestSuite struct { testData map[string]string } -func init() { - ibctesting.DefaultTestingAppInit = setupTestingApp -} +// func init() { +// ibctesting.DefaultTestingAppInit = setupTestingApp +// } // GetSimApp returns the duplicated SimApp from within the 08-wasm directory. // This must be used instead of chain.GetSimApp() for tests within this directory. From 870e7de780ff7183ebd3c5a1e0efdefc799968cb Mon Sep 17 00:00:00 2001 From: Charly Date: Wed, 4 Oct 2023 10:27:15 +0200 Subject: [PATCH 10/11] delete testing code --- go.mod | 4 +- .../light-clients/08-wasm/types/types_test.go | 34 -------- .../08-wasm/types/update_test.go | 85 ------------------- 3 files changed, 1 insertion(+), 122 deletions(-) diff --git a/go.mod b/go.mod index d30512f7c5f..656fd706525 100644 --- a/go.mod +++ b/go.mod @@ -174,6 +174,4 @@ require ( sigs.k8s.io/yaml v1.3.0 // indirect ) -replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 - -replace github.com/cosmos/ibc-go/modules/light-clients/08-wasm => ./modules/light-clients/08-wasm +replace github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 \ No newline at end of file diff --git a/modules/light-clients/08-wasm/types/types_test.go b/modules/light-clients/08-wasm/types/types_test.go index ae1f2486790..1b7ca0d3d72 100644 --- a/modules/light-clients/08-wasm/types/types_test.go +++ b/modules/light-clients/08-wasm/types/types_test.go @@ -74,40 +74,6 @@ func setupTestingApp() (ibctesting.TestingApp, map[string]json.RawMessage) { return app, simapp.NewDefaultGenesisState(encCdc.Codec) } -// // SetupWasmTendermint sets up 2 chains and stores the tendermint/cometbft light client wasm contract on both. -// func (suite *TypesTestSuite) SetupWasmTendermint() { -// suite.coordinator = ibctesting.NewCoordinator(suite.T(), 2) -// suite.chainA = suite.coordinator.GetChain(ibctesting.GetChainID(1)) -// suite.chainA.SetWasm(true) -// suite.chainB = suite.coordinator.GetChain(ibctesting.GetChainID(2)) -// suite.chainB.SetWasm(true) - -// // commit some blocks so that QueryProof returns valid proof (cannot return valid query if height <= 1) -// suite.coordinator.CommitNBlocks(suite.chainA, 2) -// suite.coordinator.CommitNBlocks(suite.chainB, 2) - -// suite.ctx = suite.chainA.GetContext().WithBlockGasMeter(sdk.NewInfiniteGasMeter()) -// suite.store = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.ctx, grandpaClientID) - -// wasmContract, err := os.ReadFile("../test_data/ics07_tendermint_cw.wasm.gz") -// suite.Require().NoError(err) - -// msg := types.NewMsgStoreCode(authtypes.NewModuleAddress(govtypes.ModuleName).String(), wasmContract) -// response, err := GetSimApp(suite.chainA).WasmClientKeeper.StoreCode(suite.chainA.GetContext(), msg) -// suite.Require().NoError(err) -// suite.Require().NotNil(response.Checksum) -// suite.codeHash = response.Checksum - -// response, err = GetSimApp(suite.chainB).WasmClientKeeper.StoreCode(suite.chainB.GetContext(), msg) -// suite.Require().NoError(err) -// suite.Require().NotNil(response.Checksum) -// suite.codeHash = response.Checksum - -// suite.coordinator.SetCodeHash(suite.codeHash) -// suite.coordinator.CommitNBlocks(suite.chainA, 2) -// suite.coordinator.CommitNBlocks(suite.chainB, 2) -// } - // SetupWasmGrandpa sets up 1 chain and stores the grandpa light client wasm contract on chain. func (suite *TypesTestSuite) SetupWasmGrandpa() { suite.coordinator = ibctesting.NewCoordinator(suite.T(), 1) diff --git a/modules/light-clients/08-wasm/types/update_test.go b/modules/light-clients/08-wasm/types/update_test.go index b431e4b8e92..314faa32900 100644 --- a/modules/light-clients/08-wasm/types/update_test.go +++ b/modules/light-clients/08-wasm/types/update_test.go @@ -652,91 +652,6 @@ func (suite *TypesTestSuite) TestUpdateStateGrandpa() { // } // } -// func (suite *TypesTestSuite) TestPruneConsensusStateTendermint() { -// suite.SetupWasmTendermint() -// // create path and setup clients -// path := ibctesting.NewPath(suite.chainA, suite.chainB) -// suite.coordinator.SetupClients(path) - -// // get the first height as it will be pruned first. -// var pruneHeight exported.Height -// getFirstHeightCb := func(height exported.Height) bool { -// pruneHeight = height -// return true -// } -// ctx := path.EndpointA.Chain.GetContext() -// clientStore := path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) -// ibctm.IterateConsensusStateAscending(clientStore, getFirstHeightCb) - -// // this height will be expired but not pruned -// err := path.EndpointA.UpdateClient() -// suite.Require().NoError(err) -// expiredHeight := path.EndpointA.GetClientState().GetLatestHeight() - -// // expected values that must still remain in store after pruning -// expectedConsState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, expiredHeight) -// suite.Require().True(ok) -// ctx = path.EndpointA.Chain.GetContext() -// clientStore = path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) -// expectedProcessTime, ok := ibctm.GetProcessedTime(clientStore, expiredHeight) -// suite.Require().True(ok) -// expectedProcessHeight, ok := GetProcessedHeight(clientStore, expiredHeight) -// suite.Require().True(ok) -// expectedConsKey := ibctm.GetIterationKey(clientStore, expiredHeight) -// suite.Require().NotNil(expectedConsKey) - -// // Increment the time by a week -// suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) - -// // create the consensus state that can be used as trusted height for next update -// err = path.EndpointA.UpdateClient() -// suite.Require().NoError(err) - -// // Increment the time by another week, then update the client. -// // This will cause the first two consensus states to become expired. -// suite.coordinator.IncrementTimeBy(7 * 24 * time.Hour) -// err = path.EndpointA.UpdateClient() -// suite.Require().NoError(err) - -// ctx = path.EndpointA.Chain.GetContext() -// clientStore = path.EndpointA.Chain.App.GetIBCKeeper().ClientKeeper.ClientStore(ctx, path.EndpointA.ClientID) - -// // check that the first expired consensus state got deleted along with all associated metadata -// consState, ok := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) -// suite.Require().Nil(consState, "expired consensus state not pruned") -// suite.Require().False(ok) -// // check processed time metadata is pruned -// processTime, ok := ibctm.GetProcessedTime(clientStore, pruneHeight) -// suite.Require().Equal(uint64(0), processTime, "processed time metadata not pruned") -// suite.Require().False(ok) -// processHeight, ok := GetProcessedHeight(clientStore, pruneHeight) -// suite.Require().Zero(processHeight, "processed height metadata not pruned") -// suite.Require().False(ok) - -// // check iteration key metadata is pruned -// consKey := ibctm.GetIterationKey(clientStore, pruneHeight) -// suite.Require().Nil(consKey, "iteration key not pruned") - -// // check that second expired consensus state doesn't get deleted -// // this ensures that there is a cap on gas cost of UpdateClient -// consState, ok = path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, expiredHeight) -// suite.Require().Equal(expectedConsState, consState, "consensus state incorrectly pruned") -// suite.Require().True(ok) -// // check processed time metadata is not pruned -// processTime, ok = ibctm.GetProcessedTime(clientStore, expiredHeight) -// suite.Require().Equal(expectedProcessTime, processTime, "processed time metadata incorrectly pruned") -// suite.Require().True(ok) - -// // check processed height metadata is not pruned -// processHeight, ok = GetProcessedHeight(clientStore, expiredHeight) -// suite.Require().Equal(expectedProcessHeight, processHeight, "processed height metadata incorrectly pruned") -// suite.Require().True(ok) - -// // check iteration key metadata is not pruned -// consKey = ibctm.GetIterationKey(clientStore, expiredHeight) -// suite.Require().Equal(expectedConsKey, consKey, "iteration key incorrectly pruned") -// } - /* func (suite *TypesTestSuite) TestUpdateStateOnMisbehaviourGrandpa() { var ( ok bool From 1fa4fe38d8137bb4afba563656b10e09b835b9b2 Mon Sep 17 00:00:00 2001 From: Charly Date: Wed, 4 Oct 2023 11:25:09 +0200 Subject: [PATCH 11/11] delete testing/wasm.go --- testing/wasm.go | 63 ------------------------------------------------- 1 file changed, 63 deletions(-) delete mode 100644 testing/wasm.go diff --git a/testing/wasm.go b/testing/wasm.go deleted file mode 100644 index 49fd21e3a54..00000000000 --- a/testing/wasm.go +++ /dev/null @@ -1,63 +0,0 @@ -package ibctesting - -// import ( -// "fmt" -// "time" - -// "github.com/stretchr/testify/require" - -// tmtypes "github.com/cometbft/cometbft/types" - -// clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" -// ) - -// // ConstructUpdateWasmClientHeader will construct a valid 08-wasm Header with a zero height -// // to update the light client on the source chain. -// func (chain *TestChain) ConstructUpdateWasmClientHeader(counterparty *TestChain, clientID string) (*wasmtypes.ClientMessage, clienttypes.Height, error) { -// return chain.ConstructUpdateWasmClientHeaderWithTrustedHeight(counterparty, clientID, clienttypes.ZeroHeight()) -// } - -// // ConstructUpdateWasmClientHeaderWithTrustedHeight will construct a valid 08-wasm Header -// // to update the light client on the source chain. -// func (chain *TestChain) ConstructUpdateWasmClientHeaderWithTrustedHeight( -// counterparty *TestChain, -// clientID string, -// trustedHeight clienttypes.Height, -// ) (*wasmtypes.ClientMessage, clienttypes.Height, error) { -// tmHeader, err := chain.ConstructUpdateTMClientHeaderWithTrustedHeight(counterparty, clientID, trustedHeight) -// if err != nil { -// return nil, clienttypes.ZeroHeight(), err -// } - -// tmWasmHeaderData, err := chain.Codec.MarshalInterface(tmHeader) -// if err != nil { -// return nil, clienttypes.ZeroHeight(), err -// } - -// height, ok := tmHeader.GetHeight().(clienttypes.Height) -// if !ok { -// return nil, clienttypes.ZeroHeight(), fmt.Errorf("error casting exported height to clienttypes height") -// } - -// wasmHeader := wasmtypes.ClientMessage{ -// Data: tmWasmHeaderData, -// } - -// return &wasmHeader, height, nil -// } - -// func (chain *TestChain) CreateWasmClientHeader( -// chainID string, -// blockHeight int64, -// trustedHeight clienttypes.Height, -// timestamp time.Time, -// tmValSet, nextVals, tmTrustedVals *tmtypes.ValidatorSet, -// signers map[string]tmtypes.PrivValidator, -// ) *wasmtypes.ClientMessage { -// tmHeader := chain.CreateTMClientHeader(chainID, blockHeight, trustedHeight, timestamp, tmValSet, nextVals, tmTrustedVals, signers) -// tmWasmHeaderData, err := chain.Codec.MarshalInterface(tmHeader) -// require.NoError(chain.TB, err) -// return &wasmtypes.ClientMessage{ -// Data: tmWasmHeaderData, -// } -// }