Skip to content

Commit

Permalink
chore: move param tests into their own files
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton committed Jul 3, 2024
1 parent 18eca24 commit 7091425
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 187 deletions.
187 changes: 0 additions & 187 deletions e2e/tests/transfer/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,11 @@ import (
sdkmath "cosmossdk.io/math"

sdk "github.com/cosmos/cosmos-sdk/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"

"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testsuite/query"
"github.com/cosmos/ibc-go/e2e/testvalues"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

func TestTransferTestSuite(t *testing.T) {
Expand Down Expand Up @@ -496,190 +493,6 @@ func (s *TransferTestSuite) TestMsgTransfer_Timeout_Nonincentivized() {
})
}

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

testName := t.Name()
// TODO: t.Parallel()
s.SetupTransferPath(testName)

chainA, chainB := s.GetChains()

channelA := s.GetChainAChannelForTest(testName)
chainAVersion := chainA.Config().Images[0].Version
chainADenom := chainA.Config().Denom

chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAAddress := chainAWallet.FormattedAddress()

chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
chainBAddress := chainBWallet.FormattedAddress()

isSelfManagingParams := testvalues.SelfParamsFeatureReleases.IsSupported(chainAVersion)

govModuleAddress, err := query.ModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
s.Require().NoError(err)
s.Require().NotNil(govModuleAddress)

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.QueryTransferParams(ctx, chainA).SendEnabled
s.Require().True(enabled)
})

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

t.Run("change send enabled parameter to disabled", func(t *testing.T) {
if isSelfManagingParams {
msg := transfertypes.NewMsgUpdateParams(govModuleAddress.String(), transfertypes.NewParams(false, true))
s.ExecuteAndPassGovV1Proposal(ctx, msg, chainA, chainAWallet)
} else {
changes := []paramsproposaltypes.ParamChange{
paramsproposaltypes.NewParamChange(transfertypes.StoreKey, string(transfertypes.KeySendEnabled), "false"),
}

proposal := paramsproposaltypes.NewParameterChangeProposal(ibctesting.Title, ibctesting.Description, changes)
s.ExecuteAndPassGovV1Beta1Proposal(ctx, chainA, chainAWallet, proposal)
}
})

t.Run("ensure transfer params are disabled", func(t *testing.T) {
enabled := s.QueryTransferParams(ctx, chainA).SendEnabled
s.Require().False(enabled)
})

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

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

testName := t.Name()
t.Parallel()
s.SetupTransferPath(testName)

chainA, chainB := s.GetChains()

relayer := s.GetRelayerForTest(testName)
channelA := s.GetChainAChannelForTest(testName)

chainAVersion := chainA.Config().Images[0].Version

chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)

var (
chainBDenom = chainB.Config().Denom
chainAIBCToken = testsuite.GetIBCToken(chainBDenom, channelA.PortID, channelA.ChannelID) // IBC token sent to chainA

chainAAddress = chainAWallet.FormattedAddress()
chainBAddress = chainBWallet.FormattedAddress()
)

isSelfManagingParams := testvalues.SelfParamsFeatureReleases.IsSupported(chainAVersion)

govModuleAddress, err := query.ModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
s.Require().NoError(err)
s.Require().NotNil(govModuleAddress)

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.QueryTransferParams(ctx, chainA).ReceiveEnabled
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 := s.Transfer(ctx, chainB, chainBWallet, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, testvalues.DefaultTransferCoins(chainBDenom), chainBAddress, chainAAddress, s.GetTimeoutHeight(ctx, chainA), 0, "")
s.AssertTxSuccess(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, testName)
})

t.Run("packets are relayed", func(t *testing.T) {
s.AssertPacketRelayed(ctx, chainA, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, 1)
actualBalance, err := query.Balance(ctx, chainA, chainAAddress, chainAIBCToken.IBCDenom())

s.Require().NoError(err)

expected := testvalues.IBCTransferAmount
s.Require().Equal(expected, actualBalance.Int64())
})

t.Run("stop relayer", func(t *testing.T) {
s.StopRelayer(ctx, relayer)
})
})

t.Run("change receive enabled parameter to disabled ", func(t *testing.T) {
if isSelfManagingParams {
msg := transfertypes.NewMsgUpdateParams(govModuleAddress.String(), transfertypes.NewParams(false, false))
s.ExecuteAndPassGovV1Proposal(ctx, msg, chainA, chainAWallet)
} else {
changes := []paramsproposaltypes.ParamChange{
paramsproposaltypes.NewParamChange(transfertypes.StoreKey, string(transfertypes.KeyReceiveEnabled), "false"),
}

proposal := paramsproposaltypes.NewParameterChangeProposal(ibctesting.Title, ibctesting.Description, changes)
s.ExecuteAndPassGovV1Beta1Proposal(ctx, chainA, chainAWallet, proposal)
}
})

t.Run("ensure transfer params are disabled", func(t *testing.T) {
enabled := s.QueryTransferParams(ctx, chainA).ReceiveEnabled
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 := s.Transfer(ctx, chainB, chainBWallet, channelA.Counterparty.PortID, channelA.Counterparty.ChannelID, testvalues.DefaultTransferCoins(chainBDenom), chainBAddress, chainAAddress, s.GetTimeoutHeight(ctx, chainA), 0, "")
s.AssertTxSuccess(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, testName)
})

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)
})
})
}

// This can be used to test sending with a transfer packet with a memo given different combinations of
// ibc-go versions.
//
Expand Down
100 changes: 100 additions & 0 deletions e2e/tests/transfer/send_enabled_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//go:build !test_e2e

package transfer

import (
"context"
"testing"

"testing"

test "github.com/strangelove-ventures/interchaintest/v8/testutil"
testifysuite "github.com/stretchr/testify/suite"

govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"

"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testsuite/query"
"github.com/cosmos/ibc-go/e2e/testvalues"
transfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
ibctesting "github.com/cosmos/ibc-go/v8/testing"
)

func TestTransferTestSuiteSendEnabled(t *testing.T) {
testifysuite.Run(t, new(TransferTestSuiteSendEnabled))
}

type TransferTestSuiteSendEnabled struct {
TransferTestSuite
}

func (s *TransferTestSuiteSendEnabled) SetupSuite() {
s.SetupChains(context.TODO(), nil, func(options *testsuite.ChainOptions) {
options.RelayerCount = 1
})
}

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

testName := t.Name()
// TODO: t.Parallel()
s.SetupTransferPath(testName)

chainA, chainB := s.GetChains()

channelA := s.GetChainAChannelForTest(testName)
chainAVersion := chainA.Config().Images[0].Version
chainADenom := chainA.Config().Denom

chainAWallet := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
chainAAddress := chainAWallet.FormattedAddress()

chainBWallet := s.CreateUserOnChainB(ctx, testvalues.StartingTokenAmount)
chainBAddress := chainBWallet.FormattedAddress()

isSelfManagingParams := testvalues.SelfParamsFeatureReleases.IsSupported(chainAVersion)

govModuleAddress, err := query.ModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
s.Require().NoError(err)
s.Require().NotNil(govModuleAddress)

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.QueryTransferParams(ctx, chainA).SendEnabled
s.Require().True(enabled)
})

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

t.Run("change send enabled parameter to disabled", func(t *testing.T) {
if isSelfManagingParams {
msg := transfertypes.NewMsgUpdateParams(govModuleAddress.String(), transfertypes.NewParams(false, true))
s.ExecuteAndPassGovV1Proposal(ctx, msg, chainA, chainAWallet)
} else {
changes := []paramsproposaltypes.ParamChange{
paramsproposaltypes.NewParamChange(transfertypes.StoreKey, string(transfertypes.KeySendEnabled), "false"),
}

proposal := paramsproposaltypes.NewParameterChangeProposal(ibctesting.Title, ibctesting.Description, changes)
s.ExecuteAndPassGovV1Beta1Proposal(ctx, chainA, chainAWallet, proposal)
}
})

t.Run("ensure transfer params are disabled", func(t *testing.T) {
enabled := s.QueryTransferParams(ctx, chainA).SendEnabled
s.Require().False(enabled)
})

t.Run("ensure ics20 transfer fails", func(t *testing.T) {
transferTxResp := s.Transfer(ctx, chainA, chainAWallet, channelA.PortID, channelA.ChannelID, testvalues.DefaultTransferCoins(chainADenom), chainAAddress, chainBAddress, s.GetTimeoutHeight(ctx, chainB), 0, "")
s.AssertTxFailure(transferTxResp, transfertypes.ErrSendDisabled)
})
}
Loading

0 comments on commit 7091425

Please sign in to comment.