-
Notifications
You must be signed in to change notification settings - Fork 637
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
E2E: adding incentivized interchain accounts bank send test #2023
Changes from all commits
8f44301
f470bcf
2297280
4c30485
cd6363c
d87a711
a9ceda1
2ec4c73
39eff2f
17d5840
1c79319
1db8103
57067fb
6890de3
d147af9
917a6a5
27cd4f8
4afd01e
f452e8b
e0e33f1
eb4bcb5
85370a8
d96c0d5
83eaa6f
5328362
289af25
0094b36
bd9ebc4
61a444e
50c9375
bb08d13
f9de6e6
e688082
cf8a8bc
a6e4b06
789cef4
01dc214
6559549
62b81d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ import ( | |
"github.com/cosmos/ibc-go/e2e/testconfig" | ||
"github.com/cosmos/ibc-go/e2e/testsuite" | ||
"github.com/cosmos/ibc-go/e2e/testvalues" | ||
|
||
feetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types" | ||
ibctesting "github.com/cosmos/ibc-go/v5/testing" | ||
) | ||
|
||
|
@@ -40,6 +42,44 @@ func (s *InterchainAccountsTestSuite) RegisterInterchainAccount(ctx context.Cont | |
return err | ||
} | ||
|
||
// QueryIncentivizedPacketsForChannel queries the incentivized packets on the specified channel. | ||
func (s *InterchainAccountsTestSuite) QueryIncentivizedPacketsForChannel( | ||
ctx context.Context, | ||
chain *cosmos.CosmosChain, | ||
portId, | ||
channelId string, | ||
) ([]*feetypes.IdentifiedPacketFees, error) { | ||
queryClient := s.GetChainGRCPClients(chain).FeeQueryClient | ||
res, err := queryClient.IncentivizedPacketsForChannel(ctx, &feetypes.QueryIncentivizedPacketsForChannelRequest{ | ||
PortId: portId, | ||
ChannelId: channelId, | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return res.IncentivizedPackets, err | ||
} | ||
|
||
// RegisterCounterPartyPayee broadcasts a MsgRegisterCounterpartyPayee message. | ||
func (s *InterchainAccountsTestSuite) RegisterCounterPartyPayee(ctx context.Context, chain *cosmos.CosmosChain, | ||
user *ibctest.User, portID, channelID, relayerAddr, counterpartyPayeeAddr string) (sdk.TxResponse, error) { | ||
msg := feetypes.NewMsgRegisterCounterpartyPayee(portID, channelID, relayerAddr, counterpartyPayeeAddr) | ||
return s.BroadcastMessages(ctx, chain, user, msg) | ||
} | ||
|
||
// QueryCounterPartyPayee queries the counterparty payee of the given chain and relayer address on the specified channel. | ||
func (s *InterchainAccountsTestSuite) QueryCounterPartyPayee(ctx context.Context, chain ibc.Chain, relayerAddress, channelID string) (string, error) { | ||
queryClient := s.GetChainGRCPClients(chain).FeeQueryClient | ||
res, err := queryClient.CounterpartyPayee(ctx, &feetypes.QueryCounterpartyPayeeRequest{ | ||
ChannelId: channelID, | ||
Relayer: relayerAddress, | ||
}) | ||
if err != nil { | ||
return "", err | ||
} | ||
return res.CounterpartyPayee, nil | ||
} | ||
|
||
Comment on lines
+46
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Think these are duplicates of the functions belonging to If they are needed in two test suites, maybe they should go into Either that or we could extract a type that has these functions and compose both of the other test suites of that type. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I agree. Do you think we should do this in a follow up PR? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I think that's no problem! |
||
func (s *InterchainAccountsTestSuite) TestMsgSubmitTx_SuccessfulTransfer() { | ||
t := s.T() | ||
ctx := context.TODO() | ||
|
@@ -208,18 +248,181 @@ func (s *InterchainAccountsTestSuite) TestMsgSubmitTx_FailedTransfer_Insufficien | |
s.Require().NoError(err) | ||
}) | ||
|
||
t.Run("verify balance is the same", func(t *testing.T) { | ||
balance, err := chainB.GetBalance(ctx, chainBAccount.Bech32Address(chainB.Config().Bech32Prefix), chainB.Config().Denom) | ||
s.Require().NoError(err) | ||
|
||
expected := testvalues.StartingTokenAmount | ||
s.Require().Equal(expected, balance) | ||
}) | ||
}) | ||
} | ||
Comment on lines
248
to
+259
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why was the packet relay assertion removed? Without knowing that the packet was relayed, we can't be certain that the balance didn't change because a failed transfer or because the packet wasn't relayed since we are checking the receiving balance and not the sender |
||
|
||
func (s *InterchainAccountsTestSuite) TestMsgSubmitTx_SuccessfulBankSend_Incentivized() { | ||
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) | ||
chainA, chainB := s.GetChains() | ||
|
||
var ( | ||
chainADenom = chainA.Config().Denom | ||
interchainAcc = "" | ||
testFee = testvalues.DefaultFee(chainADenom) | ||
) | ||
|
||
t.Run("relayer wallets recovered", func(t *testing.T) { | ||
err := s.RecoverRelayerWallets(ctx, relayer) | ||
s.Require().NoError(err) | ||
}) | ||
|
||
chainARelayerWallet, chainBRelayerWallet, err := s.GetRelayerWallets(relayer) | ||
t.Run("relayer wallets fetched", func(t *testing.T) { | ||
s.Require().NoError(err) | ||
}) | ||
|
||
s.Require().NoError(test.WaitForBlocks(ctx, 5, chainA, chainB), "failed to wait for blocks") | ||
|
||
chainARelayerUser, chainBRelayerUser := s.GetRelayerUsers(ctx) | ||
relayerAStartingBalance, err := s.GetChainANativeBalance(ctx, chainARelayerUser) | ||
s.Require().NoError(err) | ||
t.Logf("relayer A user starting with balance: %d", relayerAStartingBalance) | ||
|
||
controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) | ||
chainBAccount := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) | ||
|
||
t.Run("register interchain account", func(t *testing.T) { | ||
version := "" // allow app to handle the version as appropriate. | ||
msgRegisterAccount := intertxtypes.NewMsgRegisterAccount(controllerAccount.Bech32Address(chainA.Config().Bech32Prefix), ibctesting.FirstConnectionID, version) | ||
err := s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterAccount) | ||
s.Require().NoError(err) | ||
}) | ||
|
||
t.Run("start relayer", func(t *testing.T) { | ||
s.StartRelayer(relayer) | ||
}) | ||
|
||
var channelOutput ibc.ChannelOutput | ||
t.Run("verify interchain account", func(t *testing.T) { | ||
var err error | ||
interchainAcc, err = s.QueryInterchainAccount(ctx, chainA, controllerAccount.Bech32Address(chainA.Config().Bech32Prefix), ibctesting.FirstConnectionID) | ||
s.Require().NoError(err) | ||
s.Require().NotZero(len(interchainAcc)) | ||
|
||
channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) | ||
s.Require().NoError(err) | ||
s.Require().Equal(len(channels), 2) | ||
|
||
// interchain accounts channel at index: 0 | ||
channelOutput = channels[0] | ||
}) | ||
|
||
t.Run("execute interchain account bank send through controller", func(t *testing.T) { | ||
t.Run("fund interchain account wallet on host chainB", func(t *testing.T) { | ||
// fund the interchain account so it has some $$ to send | ||
err := chainB.SendFunds(ctx, ibctest.FaucetAccountKeyName, ibc.WalletAmount{ | ||
Address: interchainAcc, | ||
Amount: testvalues.StartingTokenAmount, | ||
Denom: chainB.Config().Denom, | ||
}) | ||
s.Require().NoError(err) | ||
}) | ||
|
||
t.Run("register counterparty payee", func(t *testing.T) { | ||
resp, err := s.RegisterCounterPartyPayee(ctx, chainB, chainBRelayerUser, channelOutput.Counterparty.PortID, channelOutput.Counterparty.ChannelID, chainBRelayerWallet.Address, chainARelayerWallet.Address) | ||
s.Require().NoError(err) | ||
s.AssertValidTxResponse(resp) | ||
}) | ||
|
||
t.Run("verify counterparty payee", func(t *testing.T) { | ||
address, err := s.QueryCounterPartyPayee(ctx, chainB, chainBRelayerWallet.Address, channelOutput.Counterparty.ChannelID) | ||
s.Require().NoError(err) | ||
s.Require().Equal(chainARelayerWallet.Address, address) | ||
}) | ||
|
||
t.Run("no incentivized packets", func(t *testing.T) { | ||
packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) | ||
s.Require().NoError(err) | ||
s.Require().Empty(packets) | ||
}) | ||
|
||
t.Run("stop relayer", func(t *testing.T) { | ||
err := relayer.StopRelayer(ctx, s.GetRelayerExecReporter()) | ||
s.Require().NoError(err) | ||
Comment on lines
+352
to
+353
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for simplicity, I wonder if we should just make this a suite function so it matches |
||
}) | ||
|
||
t.Run("broadcast incentivized MsgSubmitTx", func(t *testing.T) { | ||
msgPayPacketFee := &feetypes.MsgPayPacketFee{ | ||
Fee: testvalues.DefaultFee(chainADenom), | ||
SourcePortId: channelOutput.PortID, | ||
SourceChannelId: channelOutput.ChannelID, | ||
Signer: controllerAccount.Bech32Address(chainA.Config().Bech32Prefix), | ||
} | ||
|
||
msgSend := &banktypes.MsgSend{ | ||
FromAddress: interchainAcc, | ||
ToAddress: chainBAccount.Bech32Address(chainB.Config().Bech32Prefix), | ||
Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)), | ||
} | ||
|
||
msgSubmitTx, err := intertxtypes.NewMsgSubmitTx(msgSend, ibctesting.FirstConnectionID, controllerAccount.Bech32Address(chainA.Config().Bech32Prefix)) | ||
s.Require().NoError(err) | ||
|
||
resp, err := s.BroadcastMessages(ctx, chainA, controllerAccount, msgPayPacketFee, msgSubmitTx) | ||
s.AssertValidTxResponse(resp) | ||
s.Require().NoError(err) | ||
|
||
s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB)) | ||
}) | ||
|
||
t.Run("there should be incentivized packets", func(t *testing.T) { | ||
packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) | ||
s.Require().NoError(err) | ||
s.Require().Len(packets, 1) | ||
actualFee := packets[0].PacketFees[0].Fee | ||
|
||
s.Require().True(actualFee.RecvFee.IsEqual(testFee.RecvFee)) | ||
s.Require().True(actualFee.AckFee.IsEqual(testFee.AckFee)) | ||
s.Require().True(actualFee.TimeoutFee.IsEqual(testFee.TimeoutFee)) | ||
}) | ||
|
||
t.Run("start relayer", func(t *testing.T) { | ||
s.StartRelayer(relayer) | ||
}) | ||
|
||
t.Run("packets are relayed", func(t *testing.T) { | ||
channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID) | ||
packets, err := s.QueryIncentivizedPacketsForChannel(ctx, chainA, channelOutput.PortID, channelOutput.ChannelID) | ||
s.Require().NoError(err) | ||
s.AssertPacketRelayed(ctx, chainA, channels[1].PortID, channels[1].ChannelID, 1) | ||
s.Require().Empty(packets) | ||
}) | ||
|
||
t.Run("verify balance is the same", func(t *testing.T) { | ||
t.Run("verify interchain account sent tokens", func(t *testing.T) { | ||
balance, err := chainB.GetBalance(ctx, chainBAccount.Bech32Address(chainB.Config().Bech32Prefix), chainB.Config().Denom) | ||
s.Require().NoError(err) | ||
|
||
expected := testvalues.StartingTokenAmount | ||
_, err = chainB.GetBalance(ctx, interchainAcc, chainB.Config().Denom) | ||
s.Require().NoError(err) | ||
|
||
expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount | ||
s.Require().Equal(expected, balance) | ||
}) | ||
|
||
t.Run("timeout fee is refunded", func(t *testing.T) { | ||
actualBalance, err := s.GetChainANativeBalance(ctx, controllerAccount) | ||
s.Require().NoError(err) | ||
|
||
expected := testvalues.StartingTokenAmount - testFee.AckFee.AmountOf(chainADenom).Int64() - testFee.RecvFee.AmountOf(chainADenom).Int64() | ||
s.Require().Equal(expected, actualBalance) | ||
}) | ||
|
||
t.Run("relayerA is paid ack and recv fee", func(t *testing.T) { | ||
actualBalance, err := s.GetChainANativeBalance(ctx, chainARelayerUser) | ||
s.Require().NoError(err) | ||
|
||
expected := relayerAStartingBalance + testFee.AckFee.AmountOf(chainADenom).Int64() + testFee.RecvFee.AmountOf(chainADenom).Int64() | ||
s.Require().Equal(expected, actualBalance) | ||
}) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should put all incentivized tests under one test suite. Since ics29 was added in v4 but ics27 was added in v3. We will want to do base ics27 tests using v3 for cross compatibility purposes, but incentivization tests should only occur as far back as v4