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: transfer receive enabled param test #2071

Merged
merged 21 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
97466e5
scaffolding
colin-axner Aug 22, 2022
f087399
Merge branch 'main' of github.com:cosmos/ibc-go into colin/2014-e2e-i…
colin-axner Aug 22, 2022
c3e8320
add foundations to param change test
colin-axner Aug 22, 2022
0888316
bump ibctest version
colin-axner Aug 22, 2022
a883413
add partially working modify genesis
colin-axner Aug 22, 2022
bf179dd
testing passing :tada:
colin-axner Aug 24, 2022
d8c88a9
test fix
colin-axner Aug 24, 2022
0a5d8ef
Merge branch 'main' of github.com:cosmos/ibc-go into colin/2014-e2e-i…
colin-axner Aug 24, 2022
9a1e3ff
add back go.mod fix
colin-axner Aug 24, 2022
04374f7
revert go.mod change
colin-axner Aug 24, 2022
04c0a97
simplify modify genesis
colin-axner Aug 24, 2022
1fac572
Merge branch 'main' of github.com:cosmos/ibc-go into colin/2014-e2e-i…
colin-axner Aug 24, 2022
b3aa8f4
split params tests
colin-axner Aug 25, 2022
f6b7a5d
Merge branch 'main' of github.com:cosmos/ibc-go into colin/2014-e2e-i…
colin-axner Aug 25, 2022
c53c10d
remove unnecessary var
colin-axner Aug 25, 2022
8b29cf7
Merge branch 'main' of github.com:cosmos/ibc-go into colin/2014-e2e-i…
colin-axner Aug 25, 2022
60bedf4
update gov exec to wait for voting period
colin-axner Aug 25, 2022
60a922f
fix merge conflict
colin-axner Aug 25, 2022
9267b1b
Merge branch 'main' of github.com:cosmos/ibc-go into colin/2014-e2e-i…
colin-axner Aug 29, 2022
303824f
remove hardcoding
colin-axner Aug 29, 2022
e49bd55
Merge branch 'main' into colin/2014-e2e-ibctransfer-params
colin-axner Aug 29, 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
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