Skip to content
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

Merged
merged 39 commits into from
Aug 17, 2022
Merged
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
8f44301
feat(test): adding support for backwards compatibility testing
chatton Aug 8, 2022
f470bcf
Merge branch 'main' into cian/issue#1911-support-backwards-compatibil…
chatton Aug 8, 2022
2297280
chore: made names of variables more descriptive
chatton Aug 8, 2022
4c30485
Merge branch 'cian/issue#1911-support-backwards-compatibility-tests' …
chatton Aug 8, 2022
cd6363c
wip: adding demo interchain accounts test
chatton Aug 9, 2022
d87a711
wip
chatton Aug 9, 2022
a9ceda1
merge main
chatton Aug 10, 2022
2ec4c73
wip
chatton Aug 10, 2022
39eff2f
chore: merge main
chatton Aug 12, 2022
17d5840
chore: pass -p events to relayer
chatton Aug 12, 2022
1c79319
wip: temporarily setting env vars in the test
chatton Aug 12, 2022
1db8103
chore: adding Make command to run test
chatton Aug 12, 2022
57067fb
work in progress ICA test using s.BroadcastMessages
charleenfei Aug 15, 2022
6890de3
chore: refactoring register ica account to broadcast message
chatton Aug 15, 2022
d147af9
wip update to test host account
charleenfei Aug 15, 2022
917a6a5
chore: converting query interchain account to grpc query call
chatton Aug 15, 2022
27cd4f8
chore: specify empty version string explicitly
chatton Aug 15, 2022
4afd01e
merge sample-test branch
chatton Aug 15, 2022
f452e8b
wip
charleenfei Aug 15, 2022
e0e33f1
Merge branch 'cian/refactor-register-ica' into cian/issue#1941-add-in…
charleenfei Aug 15, 2022
eb4bcb5
wip bank transfer
charleenfei Aug 15, 2022
85370a8
wip
charleenfei Aug 15, 2022
d96c0d5
cleanup tests
charleenfei Aug 16, 2022
83eaa6f
rm init env versions, handle unhappy path
charleenfei Aug 16, 2022
5328362
setup env
charleenfei Aug 16, 2022
289af25
chore: adding comment to outline temprorary usage of setting env vars
chatton Aug 16, 2022
0094b36
chore: merge main
chatton Aug 16, 2022
bd9ebc4
chore: removing unused code
chatton Aug 16, 2022
61a444e
chore: exporting GetRelayerExecReporter method
chatton Aug 16, 2022
50c9375
chore: adding wait for blocks
chatton Aug 16, 2022
bb08d13
chore: updating names of test functions
chatton Aug 16, 2022
f9de6e6
chore: updating test name
chatton Aug 16, 2022
e688082
chore: corrected typo
chatton Aug 16, 2022
cf8a8bc
chrore: split test into two separate test cases
chatton Aug 16, 2022
a6e4b06
e2e: adding incentivized interchain accounts tests
damiannolan Aug 17, 2022
789cef4
group and restructure
damiannolan Aug 17, 2022
01dc214
Revert "group and restructure"
damiannolan Aug 17, 2022
6559549
Merge branch 'main' into damian/incentivized-ica-bank-send
damiannolan Aug 17, 2022
62b81d7
removing unnecessary whitespace
damiannolan Aug 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
211 changes: 207 additions & 4 deletions e2e/interchain_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand All @@ -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(
Copy link
Contributor

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

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think these are duplicates of the functions belonging to FeeMiddlewareTestSuite

If they are needed in two test suites, maybe they should go into testsuite.E2ETestSuite?

Either that or we could extract a type that has these functions and compose both of the other test suites of that type.

Copy link
Member Author

Choose a reason for hiding this comment

The 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?

Copy link
Contributor

Choose a reason for hiding this comment

The 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()
Expand Down Expand Up @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 s.StartRelayer(relayer)

})

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)
})
})
}