diff --git a/e2e/interchaintestv8/go.mod b/e2e/interchaintestv8/go.mod index 93a60d0..1e268a0 100644 --- a/e2e/interchaintestv8/go.mod +++ b/e2e/interchaintestv8/go.mod @@ -261,7 +261,7 @@ require ( sigs.k8s.io/yaml v1.4.0 // indirect ) -replace github.com/cosmos/ibc-go/v8 => github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240614115135-d9ec0c8c512d +replace github.com/cosmos/ibc-go/v8 => github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240626084404-83f90bbd2580 replace github.com/strangelove-ventures/interchaintest/v8 => github.com/DimitrisJim/interchaintest/v8 v8.0.0-20240419095404-2c9270423b9a diff --git a/e2e/interchaintestv8/go.sum b/e2e/interchaintestv8/go.sum index ee04b34..d00474a 100644 --- a/e2e/interchaintestv8/go.sum +++ b/e2e/interchaintestv8/go.sum @@ -391,8 +391,8 @@ github.com/cosmos/iavl v1.1.2 h1:zL9FK7C4L/P4IF1Dm5fIwz0WXCnn7Bp1M2FxH0ayM7Y= github.com/cosmos/iavl v1.1.2/go.mod h1:jLeUvm6bGT1YutCaL2fIar/8vGUE8cPZvh/gXEWDaDM= github.com/cosmos/ibc-go/modules/capability v1.0.0 h1:r/l++byFtn7jHYa09zlAdSeevo8ci1mVZNO9+V0xsLE= github.com/cosmos/ibc-go/modules/capability v1.0.0/go.mod h1:D81ZxzjZAe0ZO5ambnvn1qedsFQ8lOwtqicG6liLBco= -github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240614115135-d9ec0c8c512d h1:V9rWzyEvaqutctkhgDe2YDL8i2m0wrDQQBqb/1DqRNY= -github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240614115135-d9ec0c8c512d/go.mod h1:1r6hWEhBg9a8bmWA3wtOeWhf86+9JkmXznLOoU0pCrY= +github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240626084404-83f90bbd2580 h1:CXYlFz54SeXghW2RbhVRz/3zOBtV4AXjomsQlLSLOFM= +github.com/cosmos/ibc-go/v8 v8.0.0-beta.1.0.20240626084404-83f90bbd2580/go.mod h1:1r6hWEhBg9a8bmWA3wtOeWhf86+9JkmXznLOoU0pCrY= github.com/cosmos/ics23/go v0.10.0 h1:iXqLLgp2Lp+EdpIuwXTYIQU+AiHj9mOC2X9ab++bZDM= github.com/cosmos/ics23/go v0.10.0/go.mod h1:ZfJSmng/TBNTBkFemHHHj5YY7VAU/MBU980F4VU1NG0= github.com/cosmos/ledger-cosmos-go v0.13.3 h1:7ehuBGuyIytsXbd4MP43mLeoN2LTOEnk5nvue4rK+yM= diff --git a/e2e/interchaintestv8/ibclite_test.go b/e2e/interchaintestv8/ibclite_test.go index f9a32a1..fb22b55 100644 --- a/e2e/interchaintestv8/ibclite_test.go +++ b/e2e/interchaintestv8/ibclite_test.go @@ -6,6 +6,7 @@ import ( "strconv" "testing" + "github.com/cosmos/gogoproto/proto" "github.com/stretchr/testify/suite" sdkmath "cosmossdk.io/math" @@ -14,6 +15,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" ibctesting "github.com/cosmos/ibc-go/v8/testing" @@ -229,41 +231,62 @@ func (s *IBCLiteTestSuite) TestIBCLiteSetup() { } // This is a test to verify that go clients can prove the state of cosmwasm contracts -// WIP func (s *IBCLiteTestSuite) TestWasmProofs() { ctx := context.Background() s.SetupSuite(ctx) - wasmd, _ := s.ChainA, s.ChainB + wasmd, simd := s.ChainA, s.ChainB s.Require().NoError(s.Relayer.UpdateClients(ctx, s.ExecRep, s.PathName)) // During the setup, we have already committed some state into some contracts. // Our goal is to prove the ICS02_CLIENT_ADDRESS state in ics26Router contract var ( + clientState *ibctm.ClientState proofHeight int64 proof []byte value []byte - // merklePath commitmenttypes.MerklePath + merklePath commitmenttypesv2.MerklePath ) s.Require().True(s.Run("Generate wasm proof", func() { + resp, err := e2esuite.GRPCQuery[clienttypes.QueryClientStateResponse](ctx, simd, &clienttypes.QueryClientStateRequest{ + ClientId: ibctesting.FirstClientID, + }) + s.Require().NoError(err) + + clientState = &ibctm.ClientState{} + err = proto.Unmarshal(resp.ClientState.Value, clientState) + s.Require().NoError(err) + contractAddr, err := s.ics26Router.AccAddress() s.Require().NoError(err) prefixStoreKey := wasmtypes.GetContractStorePrefix(contractAddr) ics02AddrKey := "ics02_client_address" key := cloneAppend(prefixStoreKey, []byte(ics02AddrKey)) + merklePath = commitmenttypes.NewMerklePath(key) + merklePath, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(wasmtypes.StoreKey)), merklePath) + s.Require().NoError(err) - value, proof, proofHeight, err = s.QueryProofs(ctx, wasmd, wasmtypes.StoreKey, key, int64(s.trustedHeight.RevisionHeight)) + value, proof, proofHeight, err = s.QueryProofs(ctx, wasmd, wasmtypes.StoreKey, key, int64(clientState.LatestHeight.RevisionHeight)) s.Require().NoError(err) s.Require().NotEmpty(proof) s.Require().NotEmpty(value) - s.Require().Equal(int64(s.trustedHeight.RevisionHeight), proofHeight) + s.Require().Equal(int64(clientState.LatestHeight.RevisionHeight), proofHeight) s.Require().Equal(value, []byte(`"`+s.ics02Client.Address+`"`)) })) - // TODO: Can't finish this test because ibc-go does not have a way to verify proofs in wasm path: - // https://github.com/cosmos/ibc-go/issues/6496 + s.Require().True(s.Run("Verify wasm proof", func() { + resp, err := e2esuite.GRPCQuery[clienttypes.QueryVerifyMembershipResponse](ctx, simd, &clienttypes.QueryVerifyMembershipRequest{ + ClientId: ibctesting.FirstClientID, + Proof: proof, + Value: value, + MerklePath: merklePath, + ProofHeight: clientState.LatestHeight, + }) + s.Require().NoError(err) + s.Require().True(resp.Success) + })) } func (s *IBCLiteTestSuite) UpdateClientContract(ctx context.Context, tmContract *ics07tendermint.Contract, counterpartyChain *cosmos.CosmosChain) { diff --git a/e2e/interchaintestv8/ics07tendermint_test.go b/e2e/interchaintestv8/ics07tendermint_test.go index 21d8365..d132ef7 100644 --- a/e2e/interchaintestv8/ics07tendermint_test.go +++ b/e2e/interchaintestv8/ics07tendermint_test.go @@ -12,6 +12,7 @@ import ( clienttypes "github.com/cosmos/ibc-go/v8/modules/core/02-client/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" host "github.com/cosmos/ibc-go/v8/modules/core/24-host" ibcexported "github.com/cosmos/ibc-go/v8/modules/core/exported" ibctm "github.com/cosmos/ibc-go/v8/modules/light-clients/07-tendermint" @@ -172,14 +173,14 @@ func (s *ICS07TendermintTestSuite) TestVerifyMembership() { proofHeight int64 proof []byte value []byte - merklePath commitmenttypes.MerklePath + merklePath commitmenttypesv2.MerklePath ) s.Require().True(s.Run("CreateClientStateProof", func() { s.UpdateClientContract(ctx, s.ics07Tendermint, simd) var err error key := host.FullClientStateKey(ibctesting.FirstClientID) - merklePath = commitmenttypes.NewMerklePath(string(key)) + merklePath = commitmenttypes.NewMerklePath(key) merklePath, err = commitmenttypes.ApplyPrefix(commitmenttypes.NewMerklePrefix([]byte(ibcexported.StoreKey)), merklePath) s.Require().NoError(err) @@ -200,7 +201,7 @@ func (s *ICS07TendermintTestSuite) TestVerifyMembership() { RevisionHeight: int(proofHeight), }, Path: ics07tendermint.MerklePath{ - KeyPath: merklePath.KeyPath, + KeyPath: types.ToLegacyMerklePath(&merklePath).KeyPath, }, Proof: base64.StdEncoding.EncodeToString(proof), Value: base64.StdEncoding.EncodeToString(value), @@ -217,7 +218,7 @@ func (s *ICS07TendermintTestSuite) TestVerifyMembership() { RevisionHeight: int(proofHeight), }, Path: ics07tendermint.MerklePath{ - KeyPath: merklePath.KeyPath, + KeyPath: types.ToLegacyMerklePath(&merklePath).KeyPath, }, Proof: base64.StdEncoding.EncodeToString(proof), Value: base64.StdEncoding.EncodeToString(incorrectValue), diff --git a/e2e/interchaintestv8/types/storekeys.go b/e2e/interchaintestv8/types/storekeys.go index 6b3e799..41166a0 100644 --- a/e2e/interchaintestv8/types/storekeys.go +++ b/e2e/interchaintestv8/types/storekeys.go @@ -7,6 +7,7 @@ import ( banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" commitmenttypes "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types" + commitmenttypesv2 "github.com/cosmos/ibc-go/v8/modules/core/23-commitment/types/v2" ) /* @@ -23,8 +24,8 @@ func GetBankBalanceKey(address sdk.AccAddress, denom string) ([]byte, error) { return key, nil } -func ConvertToMerklePath(prefix []byte, key []byte) (*commitmenttypes.MerklePath, error) { - merklePath := commitmenttypes.NewMerklePath(string(key)) +func ConvertToMerklePath(prefix []byte, key []byte) (*commitmenttypesv2.MerklePath, error) { + merklePath := commitmenttypes.NewMerklePath(key) merklePrefix := commitmenttypes.NewMerklePrefix(prefix) path, err := commitmenttypes.ApplyPrefix(merklePrefix, merklePath) if err != nil { @@ -33,3 +34,12 @@ func ConvertToMerklePath(prefix []byte, key []byte) (*commitmenttypes.MerklePath return &path, nil } + +func ToLegacyMerklePath(path *commitmenttypesv2.MerklePath) *commitmenttypes.MerklePath { + legacyPath := commitmenttypes.MerklePath{} + for _, key := range path.KeyPath { + legacyPath.KeyPath = append(legacyPath.KeyPath, string(key)) + } + + return &legacyPath +}