Skip to content

Commit

Permalink
test: 03-connection e2e test param change (#2139)
Browse files Browse the repository at this point in the history
* test: adding initial test boilerplate

* fix: test

* extend test to add token transfer

* change to send from B to A and add test matrix

* add test matrices

* fix imports

* fix some more imports

* review comments

* compare uint64 instead of string

* review comments

* fix test

Co-authored-by: Carlos Rodriguez <carlos@interchain.io>
Co-authored-by: Carlos Rodriguez <crodveg@gmail.com>
  • Loading branch information
3 people authored Oct 27, 2022
1 parent 6105db4 commit 5cafc24
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .github/compatibility-test-matrices/release-v5.0.x/connection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"chain-a": ["release-v5.0.x", "v4.1.0", "v3.3.0", "v2.4.0"],
"chain-b": ["release-v5.0.x", "v4.1.0", "v3.3.0", "v2.4.0"],
"entrypoint": ["TestConnectionTestSuite"],
"test": [
"TestMaxExpectedTimePerBlockParam"
],
"chain-binary": ["simd"],
"chain-image": ["ghcr.io/cosmos/ibc-go-simd"]
}
10 changes: 10 additions & 0 deletions .github/compatibility-test-matrices/release-v6.0.x/connection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"chain-a": ["release-v6.0.x", "v5.0.0", "v4.1.0", "v3.3.0", "v2.4.0"],
"chain-b": ["release-v6.0.x", "v5.0.0", "v4.1.0", "v3.3.0", "v2.4.0"],
"entrypoint": ["TestConnectionTestSuite"],
"test": [
"TestMaxExpectedTimePerBlockParam"
],
"chain-binary": ["simd"],
"chain-image": ["ghcr.io/cosmos/ibc-go-simd"]
}
1 change: 1 addition & 0 deletions .github/workflows/e2e-manual-simd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ on:
options:
- TestTransferTestSuite
- TestIncentivizedTransferTestSuite
- TestConnectionTestSuite
- TestInterchainAccountsTestSuite
- TestInterchainAccountsGroupsTestSuite
- TestIncentivizedInterchainAccountsTestSuite
Expand Down
132 changes: 132 additions & 0 deletions e2e/tests/core/03-connection/connection_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
package connection

import (
"context"
"fmt"
"strconv"
"strings"
"testing"
"time"

paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/strangelove-ventures/ibctest/v6/ibc"
"github.com/strangelove-ventures/ibctest/v6/test"
"github.com/stretchr/testify/suite"

"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testvalues"
transfertypes "github.com/cosmos/ibc-go/v6/modules/apps/transfer/types"
connectiontypes "github.com/cosmos/ibc-go/v6/modules/core/03-connection/types"
host "github.com/cosmos/ibc-go/v6/modules/core/24-host"
ibctesting "github.com/cosmos/ibc-go/v6/testing"
)

func TestConnectionTestSuite(t *testing.T) {
suite.Run(t, new(ConnectionTestSuite))
}

type ConnectionTestSuite struct {
testsuite.E2ETestSuite
}

// QueryMaxExpectedTimePerBlockParam queries the on-chain max expected time per block param for 03-connection
func (s *ConnectionTestSuite) QueryMaxExpectedTimePerBlockParam(ctx context.Context, chain ibc.Chain) uint64 {
queryClient := s.GetChainGRCPClients(chain).ParamsQueryClient
res, err := queryClient.Params(ctx, &paramsproposaltypes.QueryParamsRequest{
Subspace: host.ModuleName,
Key: string(connectiontypes.KeyMaxExpectedTimePerBlock),
})
s.Require().NoError(err)

// removing additional strings that are used for amino
delay := strings.ReplaceAll(res.Param.Value, "\"", "")
time, err := strconv.ParseUint(delay, 10, 64)
s.Require().NoError(err)

return time
}

// TestMaxExpectedTimePerBlockParam tests changing the MaxExpectedTimePerBlock param using a governance proposal
func (s *ConnectionTestSuite) TestMaxExpectedTimePerBlockParam() {
t := s.T()
ctx := context.TODO()

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

chainBDenom := chainB.Config().Denom
chainAIBCToken := testsuite.GetIBCToken(chainBDenom, channelA.PortID, channelA.ChannelID)

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 delay is set to the default of 30 seconds", func(t *testing.T) {
expectedDelay := uint64(30 * time.Second)
delay := s.QueryMaxExpectedTimePerBlockParam(ctx, chainA)
s.Require().Equal(expectedDelay, delay)
})

t.Run("change the delay to 60 seconds", func(t *testing.T) {
delay := fmt.Sprintf(`"%d"`, 1*time.Minute)
changes := []paramsproposaltypes.ParamChange{
paramsproposaltypes.NewParamChange(host.ModuleName, string(connectiontypes.KeyMaxExpectedTimePerBlock), delay),
}

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

t.Run("validate the param was successfully changed", func(t *testing.T) {
expectedDelay := uint64(1 * time.Minute)
delay := s.QueryMaxExpectedTimePerBlockParam(ctx, chainA)
s.Require().Equal(expectedDelay, delay)
})

t.Run("ensure packets can be received, send from chainB to chainA", func(t *testing.T) {
t.Run("send tokens 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)
})
})
}

// transferChannelOptions configures both of the chains to have non-incentivized transfer channels.
func transferChannelOptions() func(options *ibc.CreateChannelOptions) {
return func(opts *ibc.CreateChannelOptions) {
opts.Version = transfertypes.Version
opts.SourcePortName = transfertypes.PortID
opts.DestPortName = transfertypes.PortID
}
}

0 comments on commit 5cafc24

Please sign in to comment.