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

test: 03-connection e2e test param change #2139

Merged
merged 23 commits into from
Oct 27, 2022
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
758ec75
test: adding initial test boilerplate
seantking Aug 29, 2022
c3be6f3
fix: test
seantking Aug 29, 2022
84f0606
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
Oct 5, 2022
6e7275f
extend test to add token transfer
Oct 6, 2022
5ac0db1
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
Oct 6, 2022
09028ef
change to send from B to A and add test matrix
Oct 6, 2022
2c1d601
add test matrices
Oct 6, 2022
a6d7586
fix imports
Oct 6, 2022
baac64e
fix some more imports
Oct 6, 2022
0b83140
review comments
Oct 6, 2022
472e69d
compare uint64 instead of string
Oct 6, 2022
2844004
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
Oct 7, 2022
09199b6
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
Oct 10, 2022
67769c1
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
crodriguezvega Oct 13, 2022
bb1de4a
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
Oct 14, 2022
3793f09
review comments
crodriguezvega Oct 14, 2022
a0e4f2d
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
Oct 14, 2022
34055f0
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
Oct 25, 2022
a0da722
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
Oct 25, 2022
068f80d
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
Oct 26, 2022
43ea2f4
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
Oct 26, 2022
25a6b76
fix test
Oct 26, 2022
efcf84a
Merge branch 'main' into sean/issue#2121-03-connection-param-e2e
Oct 27, 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
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"]
}
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
chain-image:
description: 'The image to use for chain A'
required: true
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, "\"", "")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't exactly sure why the Value is double wrapped in quotes but based on an error I received when I don't add them it is something to do with the legacy amino implementation.

cc: @colin-axner

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a good question. I'm not sure either (didn't realized this was the case). I guess we can fix this during param migrations

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