Skip to content

Commit

Permalink
e2e: transfer receive enabled param test (#2071)
Browse files Browse the repository at this point in the history
* scaffolding

* add foundations to param change test

* bump ibctest version

* add partially working modify genesis

* testing passing 🎉

* 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
  • Loading branch information
colin-axner authored Aug 29, 2022
1 parent b7d8359 commit f14179d
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 3 deletions.
2 changes: 1 addition & 1 deletion e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
120 changes: 119 additions & 1 deletion e2e/tests/transfer/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, &paramsproposaltypes.QueryParamsRequest{
Subspace: "transfer",
Subspace: transfertypes.StoreKey,
Key: string(transfertypes.KeySendEnabled),
})
s.Require().NoError(err)
Expand All @@ -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, &paramsproposaltypes.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).
Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit f14179d

Please sign in to comment.