From f14179de3b26b0d9454dc79f4237e536135713e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?colin=20axn=C3=A9r?= <25233464+colin-axner@users.noreply.github.com> Date: Mon, 29 Aug 2022 16:32:05 +0200 Subject: [PATCH] e2e: transfer receive enabled param test (#2071) * scaffolding * add foundations to param change test * bump ibctest version * add partially working modify genesis * testing passing :tada: * test fix * add back go.mod fix * revert go.mod change * simplify modify genesis * split params tests * remove unnecessary var * update gov exec to wait for voting period * fix merge conflict * remove hardcoding --- e2e/go.mod | 2 +- e2e/tests/transfer/base_test.go | 120 +++++++++++++++++++++++++++++++- e2e/testsuite/testsuite.go | 3 +- 3 files changed, 122 insertions(+), 3 deletions(-) diff --git a/e2e/go.mod b/e2e/go.mod index 28d80c1fb43..31dcc00ae23 100644 --- a/e2e/go.mod +++ b/e2e/go.mod @@ -11,6 +11,7 @@ require ( github.com/docker/docker v20.10.17+incompatible github.com/strangelove-ventures/ibctest v0.0.0-20220824150312-9d02bdb119b0 github.com/stretchr/testify v1.8.0 + github.com/tendermint/tendermint v0.34.20 go.uber.org/zap v1.21.0 golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 google.golang.org/grpc v1.48.0 @@ -160,7 +161,6 @@ require ( github.com/tendermint/btcd v0.1.1 // indirect github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 // indirect github.com/tendermint/go-amino v0.16.0 // indirect - github.com/tendermint/tendermint v0.34.20 // indirect github.com/tendermint/tm-db v0.6.7 // indirect github.com/ulikunitz/xz v0.5.8 // indirect github.com/vedhavyas/go-subkey v1.0.3 // indirect diff --git a/e2e/tests/transfer/base_test.go b/e2e/tests/transfer/base_test.go index 71ebb559369..72f3111ed14 100644 --- a/e2e/tests/transfer/base_test.go +++ b/e2e/tests/transfer/base_test.go @@ -41,7 +41,7 @@ func (s *TransferTestSuite) Transfer(ctx context.Context, chain *cosmos.CosmosCh func (s *TransferTestSuite) QueryTransferSendEnabledParam(ctx context.Context, chain ibc.Chain) bool { queryClient := s.GetChainGRCPClients(chain).ParamsQueryClient res, err := queryClient.Params(ctx, ¶msproposaltypes.QueryParamsRequest{ - Subspace: "transfer", + Subspace: transfertypes.StoreKey, Key: string(transfertypes.KeySendEnabled), }) s.Require().NoError(err) @@ -52,6 +52,21 @@ func (s *TransferTestSuite) QueryTransferSendEnabledParam(ctx context.Context, c return enabled } +// QueryTransferSendEnabledParam queries the on-chain receive enabled param for the transfer module +func (s *TransferTestSuite) QueryTransferReceiveEnabledParam(ctx context.Context, chain ibc.Chain) bool { + queryClient := s.GetChainGRCPClients(chain).ParamsQueryClient + res, err := queryClient.Params(ctx, ¶msproposaltypes.QueryParamsRequest{ + Subspace: transfertypes.StoreKey, + Key: string(transfertypes.KeyReceiveEnabled), + }) + s.Require().NoError(err) + + enabled, err := strconv.ParseBool(res.Param.Value) + s.Require().NoError(err) + + return enabled +} + // TestMsgTransfer_Succeeds_Nonincentivized will test sending successful IBC transfers from chainA to chainB. // The transfer will occur over a basic transfer channel (non incentivized) and both native and non-native tokens // will be sent forwards and backwards in the IBC transfer timeline (both chains will act as source and receiver chains). @@ -272,6 +287,109 @@ func (s *TransferTestSuite) TestSendEnabledParam() { }) } +// TestReceiveEnabledParam tests changing ics20 ReceiveEnabled parameter +func (s *TransferTestSuite) TestReceiveEnabledParam() { + t := s.T() + ctx := context.TODO() + + relayer, channelA := s.SetupChainsRelayerAndChannel(ctx, transferChannelOptions()) + chainA, chainB := s.GetChains() + + chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount) + chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount) + + var ( + chainBDenom = chainB.Config().Denom + chainAIBCToken = s.getIBCToken(chainBDenom, channelA.PortID, channelA.ChannelID) // IBC token sent to chainA + + chainAAddress = chainAWallet.Bech32Address(chainA.Config().Bech32Prefix) + chainBAddress = chainBWallet.Bech32Address(chainB.Config().Bech32Prefix) + ) + + s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks") + + t.Run("ensure transfer receive is enabled", func(t *testing.T) { + enabled := s.QueryTransferReceiveEnabledParam(ctx, chainA) + s.Require().True(enabled) + }) + + t.Run("ensure packets can be received, send from chainB to chainA", func(t *testing.T) { + t.Run("send from chainB to chainA", func(t *testing.T) { + transferTxResp, err := s.Transfer(ctx, chainB, chainBWallet, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, testvalues.DefaultTransferAmount(chainBDenom), chainBAddress, chainAAddress, s.GetTimeoutHeight(ctx, chainA), 0) + s.Require().NoError(err) + s.AssertValidTxResponse(transferTxResp) + }) + + t.Run("tokens are escrowed", func(t *testing.T) { + actualBalance, err := s.GetChainBNativeBalance(ctx, chainBWallet) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("packets are relayed", func(t *testing.T) { + s.AssertPacketRelayed(ctx, chainA, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, 1) + + actualBalance, err := chainA.GetBalance(ctx, chainAAddress, chainAIBCToken.IBCDenom()) + s.Require().NoError(err) + + expected := testvalues.IBCTransferAmount + s.Require().Equal(expected, actualBalance) + }) + + t.Run("stop relayer", func(t *testing.T) { + s.StopRelayer(ctx, relayer) + }) + }) + + t.Run("change send enabled parameter to disabled ", func(t *testing.T) { + changes := []paramsproposaltypes.ParamChange{ + paramsproposaltypes.NewParamChange(transfertypes.StoreKey, string(transfertypes.KeyReceiveEnabled), "false"), + } + + proposal := paramsproposaltypes.NewParameterChangeProposal(ibctesting.Title, ibctesting.Description, changes) + s.ExecuteGovProposal(ctx, chainA, chainAWallet, proposal) + }) + + t.Run("ensure transfer params are disabled", func(t *testing.T) { + enabled := s.QueryTransferReceiveEnabledParam(ctx, chainA) + s.Require().False(enabled) + }) + + t.Run("ensure ics20 transfer fails", func(t *testing.T) { + t.Run("send from chainB to chainA", func(t *testing.T) { + transferTxResp, err := s.Transfer(ctx, chainB, chainBWallet, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, testvalues.DefaultTransferAmount(chainBDenom), chainBAddress, chainAAddress, s.GetTimeoutHeight(ctx, chainA), 0) + s.Require().NoError(err) + s.AssertValidTxResponse(transferTxResp) + }) + + t.Run("tokens are escrowed", func(t *testing.T) { + actualBalance, err := s.GetChainBNativeBalance(ctx, chainBWallet) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount - (testvalues.IBCTransferAmount * 2) // second send + s.Require().Equal(expected, actualBalance) + }) + + t.Run("start relayer", func(t *testing.T) { + s.StartRelayer(relayer) + }) + + t.Run("tokens are unescrowed in failed acknowledgement", func(t *testing.T) { + actualBalance, err := s.GetChainBNativeBalance(ctx, chainBWallet) + s.Require().NoError(err) + + expected := testvalues.StartingTokenAmount - testvalues.IBCTransferAmount // only first send marked + s.Require().Equal(expected, actualBalance) + }) + }) +} + // transferChannelOptions configures both of the chains to have non-incentivized transfer channels. func transferChannelOptions() func(options *ibc.CreateChannelOptions) { return func(opts *ibc.CreateChannelOptions) { diff --git a/e2e/testsuite/testsuite.go b/e2e/testsuite/testsuite.go index f2f5860c94f..a6c8aaae72f 100644 --- a/e2e/testsuite/testsuite.go +++ b/e2e/testsuite/testsuite.go @@ -23,6 +23,7 @@ import ( "google.golang.org/grpc/credentials/insecure" "github.com/cosmos/ibc-go/e2e/testconfig" + "github.com/cosmos/ibc-go/e2e/testvalues" feetypes "github.com/cosmos/ibc-go/v5/modules/apps/29-fee/types" clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types" @@ -430,7 +431,7 @@ func (s *E2ETestSuite) ExecuteGovProposal(ctx context.Context, chain *cosmos.Cos s.Require().NoError(err) s.Require().Equal(govtypes.StatusVotingPeriod, proposal.Status) - time.Sleep(time.Second * 30) // pass proposal + time.Sleep(testvalues.VotingPeriod) // pass proposal proposal, err = s.QueryProposal(ctx, chain, 1) s.Require().NoError(err)