Skip to content

Commit

Permalink
add e2e for transfer send enabled param (#2123)
Browse files Browse the repository at this point in the history
## Description

```
make e2e-test suite=TransferTestSuite test=TestSendEnabledParam
```

ref: #2014 

---

Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

- [x] Targeted PR against correct branch (see [CONTRIBUTING.md](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#pr-targeting))
- [x] Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
- [ ] Code follows the [module structure standards](https://github.com/cosmos/cosmos-sdk/blob/master/docs/building-modules/structure.md).
- [ ] Wrote unit and integration [tests](https://github.com/cosmos/ibc-go/blob/master/CONTRIBUTING.md#testing)
- [ ] Updated relevant documentation (`docs/`) or specification (`x/<module>/spec/`)
- [ ] Added relevant `godoc` [comments](https://blog.golang.org/godoc-documenting-go-code).
- [ ] Added a relevant changelog entry to the `Unreleased` section in `CHANGELOG.md`
- [ ] Re-reviewed `Files changed` in the Github PR explorer
- [ ] Review `Codecov Report` in the comment section below once CI passes
  • Loading branch information
colin-axner authored Aug 25, 2022
1 parent 65f9cae commit 915d974
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 2 deletions.
2 changes: 1 addition & 1 deletion e2e/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/strangelove-ventures/ibctest v0.0.0-20220824150312-9d02bdb119b0
github.com/stretchr/testify v1.8.0
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 @@ -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
1 change: 1 addition & 0 deletions e2e/testconfig/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ func newDefaultSimappConfig(cc ChainConfig, name, chainID, denom string) ibc.Cha
GasAdjustment: 1.3,
TrustingPeriod: "508h",
NoHostMount: false,
ModifyGenesis: defaultModifyGenesis(denom),
}
}

Expand Down
5 changes: 4 additions & 1 deletion 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 Down Expand Up @@ -61,7 +62,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 +302,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
68 changes: 68 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,21 @@ 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
}

// 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 +226,56 @@ 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)
})
}

// 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

0 comments on commit 915d974

Please sign in to comment.