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 18 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
4 changes: 2 additions & 2 deletions e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ 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 @@ -159,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 All @@ -169,7 +170,6 @@ require (
go.uber.org/atomic v1.9.0 // indirect
go.uber.org/multierr v1.8.0 // indirect
golang.org/x/crypto v0.0.0-20220525230936-793ad666bf5e // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220617184016-355a448f1bc9 // indirect
golang.org/x/oauth2 v0.0.0-20220411215720-9780585627b5 // indirect
golang.org/x/sync v0.0.0-20220513210516-0976fa681c29 // indirect
Expand Down
2 changes: 2 additions & 0 deletions e2e/testconfig/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"time"

"github.com/cosmos/cosmos-sdk/codec"
simappparams "github.com/cosmos/cosmos-sdk/simapp/params"
Expand Down Expand Up @@ -159,6 +160,7 @@ func newDefaultSimappConfig(cc ChainConfig, name, chainID, denom string) ibc.Cha
GasAdjustment: 1.3,
TrustingPeriod: "508h",
NoHostMount: false,
ModifyGenesis: defaultModifyGenesis(denom),
}
}

Expand Down
8 changes: 6 additions & 2 deletions e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"
dockerclient "github.com/docker/docker/client"
"github.com/strangelove-ventures/ibctest"
Expand All @@ -22,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 @@ -61,7 +63,8 @@ type GRPCClients struct {
ICAQueryClient intertxtypes.QueryClient

// SDK query clients
GovQueryClient govtypes.QueryClient
GovQueryClient govtypes.QueryClient
ParamsQueryClient paramsproposaltypes.QueryClient
}

// path is a pairing of two chains which will be used in a test.
Expand Down Expand Up @@ -300,6 +303,7 @@ func (s *E2ETestSuite) initGRPCClients(chain *cosmos.CosmosChain) {
FeeQueryClient: feetypes.NewQueryClient(grpcConn),
ICAQueryClient: intertxtypes.NewQueryClient(grpcConn),
GovQueryClient: govtypes.NewQueryClient(grpcConn),
ParamsQueryClient: paramsproposaltypes.NewQueryClient(grpcConn),
}
}

Expand Down Expand Up @@ -408,7 +412,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
186 changes: 186 additions & 0 deletions e2e/transfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@ The TransferTestSuite assumes both chainA and chainB support version ics20-1.
import (
"context"
"fmt"
"strconv"
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/strangelove-ventures/ibctest/chain/cosmos"
"github.com/strangelove-ventures/ibctest/ibc"
"github.com/strangelove-ventures/ibctest/test"
Expand All @@ -20,6 +22,7 @@ import (
"github.com/cosmos/ibc-go/e2e/testvalues"
transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"
clienttypes "github.com/cosmos/ibc-go/v5/modules/core/02-client/types"
ibctesting "github.com/cosmos/ibc-go/v5/testing"
)

func TestTransferTestSuite(t *testing.T) {
Expand All @@ -38,6 +41,36 @@ func (s *TransferTestSuite) Transfer(ctx context.Context, chain *cosmos.CosmosCh
return s.BroadcastMessages(ctx, chain, user, msg)
}

// QueryTransferSendEnabledParam queries the on-chain send enabled param for the transfer module
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",
Key: string(transfertypes.KeySendEnabled),
})
s.Require().NoError(err)

enabled, err := strconv.ParseBool(res.Param.Value)
s.Require().NoError(err)

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: "transfer",
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 @@ -208,6 +241,159 @@ func (s *TransferTestSuite) TestMsgTransfer_Timeout_Nonincentivized() {
})
}

// TestSendEnabledParam tests changing ics20 SendEnabled parameter
func (s *TransferTestSuite) TestSendEnabledParam() {
t := s.T()
ctx := context.TODO()

_, channelA := s.SetupChainsRelayerAndChannel(ctx, transferChannelOptions())
chainA, chainB := s.GetChains()

chainADenom := chainA.Config().Denom

chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAAddress := chainAWallet.Bech32Address(chainA.Config().Bech32Prefix)

chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
chainBAddress := chainBWallet.Bech32Address(chainB.Config().Bech32Prefix)

s.Require().NoError(test.WaitForBlocks(ctx, 1, chainA, chainB), "failed to wait for blocks")

t.Run("ensure transfer sending is enabled", func(t *testing.T) {
enabled := s.QueryTransferSendEnabledParam(ctx, chainA)
s.Require().True(enabled)
})

t.Run("ensure packets can be sent", func(t *testing.T) {
transferTxResp, err := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0)
s.Require().NoError(err)
s.AssertValidTxResponse(transferTxResp)
})

t.Run("change send enabled parameter to disabled ", func(t *testing.T) {
changes := []paramsproposaltypes.ParamChange{
paramsproposaltypes.NewParamChange(transfertypes.StoreKey, string(transfertypes.KeySendEnabled), "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.QueryTransferSendEnabledParam(ctx, chainA)
s.Require().False(enabled)
})

t.Run("ensure ics20 transfer fails", func(t *testing.T) {
transferTxResp, err := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferAmount(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0)
s.Require().NoError(err)
s.Require().Equal(transfertypes.ErrSendDisabled.ABCICode(), transferTxResp.Code)
})
}

// 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)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This technically does not assert that the transaction succeeded. When it does, it'll probably be unnecessary to assert that the tokens were escrowed

})

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