-
Notifications
You must be signed in to change notification settings - Fork 734
feat: allow module safe queries in ICA #5785
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
72 commits
Select commit
Hold shift + click to select a range
3224eb1
imp: initial modification of tx.proto
srdtrk 6e1d4de
imp: ran 'make proto-all'
srdtrk d2ce96f
fix: compiler errors
srdtrk 47d8fb1
imp: added query router interface
srdtrk 47fdeed
imp: added queryRouter to icahost keeper
srdtrk adea94e
imp: improved proto definitions
srdtrk 4c9ee5e
imp: ran 'make proto-all'
srdtrk 4846f80
imp: added sdk.Msg helpers
srdtrk ea72aed
feat: basic implementation
srdtrk cf6db81
style: improved field names
srdtrk 322734e
imp: ran 'make proto-all'
srdtrk 0195490
fix: compiler errors
srdtrk 915d515
imp: ran gofumpt
srdtrk 5665d04
feat: tests passing
srdtrk a8fa43a
feat: tests improved
srdtrk 330bd24
test: removed unneeded code
srdtrk f4ac337
imp: improved 'IsModuleSafe' function
srdtrk 67a1870
imp: added IsModuleQuerySafe to msg_server
srdtrk e1853fb
imp: added more test cases
srdtrk 578d006
fix: callbacks compiler
srdtrk d29250b
Merge branch 'main' into serdar/focus-ica-icq
srdtrk 2298e31
Merge branch 'main' into serdar/focus-ica-icq
srdtrk 53cb24e
fix: non determinancy issues
srdtrk cf010ee
fix: added query msg to codec
srdtrk 8782d84
Merge branch 'main' into serdar/focus-ica-icq
srdtrk fe541be
imp: whitelist logic added
srdtrk a75d1be
Merge branch 'main' into serdar/focus-ica-icq
srdtrk 6ef6445
Merge branch 'main' into serdar/focus-ica-icq
srdtrk 4f9dff7
e2e: new test added
srdtrk 3b7f49b
Merge branch 'main' into serdar/focus-ica-icq
srdtrk 75e3fdf
fix: new test
srdtrk 79acd69
fix: test
srdtrk 0243af9
Merge branch 'main' into serdar/focus-ica-icq
srdtrk 8a60e62
fix: e2e
srdtrk 98e850d
fix: e2e
srdtrk 678c98d
imp(e2e): added the QueryTxsByEvents function
srdtrk 49acca4
fix: e2e
srdtrk 78917a1
e2e: lint fix
srdtrk 0b726ee
Merge branch 'main' into serdar/focus-ica-icq
srdtrk 62d7358
fix: e2e
srdtrk 22d0fc8
e2e: debug
srdtrk f61f0c6
fix: e2e
srdtrk 3f24164
test: debug helpers
srdtrk d31dbbb
debug
srdtrk dfbef77
test: added codec_test case
srdtrk a1597a9
imp: additional test case
srdtrk 85038bf
imp: added important unit test
srdtrk 4fa3c28
r4r
srdtrk 91a985a
e2e: debug
srdtrk 197c645
imp: added logs
srdtrk 8dc0dd6
fix: e2e
srdtrk 660e088
fix: e2e
srdtrk b971791
fix: e2e
srdtrk 4bc7934
Merge branch 'main' into serdar/focus-ica-icq
srdtrk 1569f76
imp: added height to proto response
srdtrk 2a553e7
imp: ran 'make proto-all'
srdtrk 0b031b7
imp: added height
srdtrk b746644
e2e: updated e2e to test height
srdtrk 3a55334
imp: review suggestions
srdtrk 4878ea7
e2e: remove unneeded log
srdtrk 8ab8f77
refactor: refactored 'ExtractValueFromEvents'
srdtrk 78e21c9
Merge branch 'main' into serdar/focus-ica-icq
srdtrk 779848b
e2e: review item
srdtrk f2fb96c
imp: review item
srdtrk 15a1ccd
nit: review item
srdtrk d76ff53
docs: added godocs
srdtrk 4083edc
test: unit test for mqsWhitelist added
srdtrk 17531fa
imp: added logging
srdtrk b86b3a4
style: rename to allow list
srdtrk a854551
Merge branch 'main' into serdar/focus-ica-icq
crodriguezvega 72561cc
add changelog
crodriguezvega ec6df04
Merge branch 'main' into serdar/focus-ica-icq
crodriguezvega File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| //go:build !test_e2e | ||
|
|
||
| package interchainaccounts | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/hex" | ||
| "encoding/json" | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/cosmos/gogoproto/proto" | ||
| "github.com/strangelove-ventures/interchaintest/v8/testutil" | ||
| testifysuite "github.com/stretchr/testify/suite" | ||
|
|
||
| sdk "github.com/cosmos/cosmos-sdk/types" | ||
| banktypes "github.com/cosmos/cosmos-sdk/x/bank/types" | ||
|
|
||
| "github.com/cosmos/ibc-go/e2e/testsuite" | ||
| "github.com/cosmos/ibc-go/e2e/testvalues" | ||
| controllertypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/controller/types" | ||
| icahosttypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/host/types" | ||
| icatypes "github.com/cosmos/ibc-go/v8/modules/apps/27-interchain-accounts/types" | ||
| channeltypes "github.com/cosmos/ibc-go/v8/modules/core/04-channel/types" | ||
| ibctesting "github.com/cosmos/ibc-go/v8/testing" | ||
| ) | ||
|
|
||
| func TestInterchainAccountsQueryTestSuite(t *testing.T) { | ||
| testifysuite.Run(t, new(InterchainAccountsQueryTestSuite)) | ||
| } | ||
|
|
||
| type InterchainAccountsQueryTestSuite struct { | ||
| testsuite.E2ETestSuite | ||
| } | ||
|
|
||
| func (s *InterchainAccountsQueryTestSuite) TestInterchainAccountsQuery() { | ||
| t := s.T() | ||
| ctx := context.TODO() | ||
|
|
||
| // setup relayers and connection-0 between two chains | ||
| // channel-0 is a transfer channel but it will not be used in this test case | ||
| relayer, _ := s.SetupChainsRelayerAndChannel(ctx, nil) | ||
| chainA, chainB := s.GetChains() | ||
|
|
||
| // setup 2 accounts: controller account on chain A, a second chain B account. | ||
| // host account will be created when the ICA is registered | ||
| controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) | ||
| controllerAddress := controllerAccount.FormattedAddress() | ||
| chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) | ||
| var hostAccount string | ||
|
|
||
| t.Run("broadcast MsgRegisterInterchainAccount", func(t *testing.T) { | ||
| // explicitly set the version string because we don't want to use incentivized channels. | ||
| version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID) | ||
| msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version, channeltypes.UNORDERED) | ||
|
|
||
| txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount) | ||
| s.AssertTxSuccess(txResp) | ||
| }) | ||
|
|
||
| t.Run("start relayer", func(t *testing.T) { | ||
| s.StartRelayer(relayer) | ||
| }) | ||
|
|
||
| t.Run("verify interchain account", func(t *testing.T) { | ||
| var err error | ||
| hostAccount, err = s.QueryInterchainAccount(ctx, chainA, controllerAddress, ibctesting.FirstConnectionID) | ||
| s.Require().NoError(err) | ||
| s.Require().NotZero(len(hostAccount)) | ||
|
|
||
| channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) | ||
| s.Require().NoError(err) | ||
| s.Require().Len(channels, 2) | ||
| }) | ||
|
|
||
| t.Run("query via interchain account", func(t *testing.T) { | ||
| // the host account need not be funded | ||
| t.Run("broadcast query packet", func(t *testing.T) { | ||
| balanceQuery := banktypes.NewQueryBalanceRequest(chainBAccount.Address(), chainB.Config().Denom) | ||
| queryBz, err := balanceQuery.Marshal() | ||
| s.Require().NoError(err) | ||
|
|
||
| queryMsg := icahosttypes.NewMsgModuleQuerySafe(hostAccount, []*icahosttypes.QueryRequest{ | ||
| { | ||
| Path: "/cosmos.bank.v1beta1.Query/Balance", | ||
| Data: queryBz, | ||
| }, | ||
| }) | ||
|
|
||
| cdc := testsuite.Codec() | ||
| bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{queryMsg}, icatypes.EncodingProtobuf) | ||
| s.Require().NoError(err) | ||
|
|
||
| packetData := icatypes.InterchainAccountPacketData{ | ||
| Type: icatypes.EXECUTE_TX, | ||
| Data: bz, | ||
| Memo: "e2e", | ||
| } | ||
|
|
||
| icaQueryMsg := controllertypes.NewMsgSendTx(controllerAddress, ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData) | ||
|
|
||
| txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, icaQueryMsg) | ||
| s.AssertTxSuccess(txResp) | ||
|
|
||
| s.Require().NoError(testutil.WaitForBlocks(ctx, 10, chainA, chainB)) | ||
| }) | ||
|
|
||
| t.Run("verify query response", func(t *testing.T) { | ||
| var expQueryHeight uint64 | ||
|
|
||
| ack := &channeltypes.Acknowledgement_Result{} | ||
| t.Run("retrieve acknowledgement", func(t *testing.T) { | ||
| txSearchRes, err := s.QueryTxsByEvents( | ||
| ctx, chainB, 1, 1, | ||
| "message.action='/ibc.core.channel.v1.MsgRecvPacket'", "", | ||
| ) | ||
| s.Require().NoError(err) | ||
| s.Require().Len(txSearchRes.Txs, 1) | ||
|
|
||
| expQueryHeight = uint64(txSearchRes.Txs[0].Height) | ||
|
|
||
| ackHexValue, isFound := s.ExtractValueFromEvents( | ||
| txSearchRes.Txs[0].Events, | ||
| channeltypes.EventTypeWriteAck, | ||
| channeltypes.AttributeKeyAckHex, | ||
| ) | ||
| s.Require().True(isFound) | ||
| s.Require().NotEmpty(ackHexValue) | ||
|
|
||
| ackBz, err := hex.DecodeString(ackHexValue) | ||
| s.Require().NoError(err) | ||
|
|
||
| err = json.Unmarshal(ackBz, ack) | ||
| s.Require().NoError(err) | ||
| }) | ||
|
|
||
| icaAck := &sdk.TxMsgData{} | ||
| t.Run("unmarshal ica response", func(t *testing.T) { | ||
| err := proto.Unmarshal(ack.Result, icaAck) | ||
| s.Require().NoError(err) | ||
| s.Require().Len(icaAck.GetMsgResponses(), 1) | ||
| }) | ||
|
|
||
| queryTxResp := &icahosttypes.MsgModuleQuerySafeResponse{} | ||
| t.Run("unmarshal MsgModuleQuerySafeResponse", func(t *testing.T) { | ||
| err := proto.Unmarshal(icaAck.MsgResponses[0].Value, queryTxResp) | ||
| s.Require().NoError(err) | ||
| s.Require().Len(queryTxResp.Responses, 1) | ||
| s.Require().Equal(expQueryHeight, queryTxResp.Height) | ||
| }) | ||
|
|
||
| balanceResp := &banktypes.QueryBalanceResponse{} | ||
| t.Run("unmarshal and verify bank query response", func(t *testing.T) { | ||
| err := proto.Unmarshal(queryTxResp.Responses[0], balanceResp) | ||
| s.Require().NoError(err) | ||
| s.Require().Equal(chainB.Config().Denom, balanceResp.Balance.Denom) | ||
| s.Require().Equal(testvalues.StartingTokenAmount, balanceResp.Balance.Amount.Int64()) | ||
| }) | ||
| }) | ||
| }) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.