Skip to content

Commit

Permalink
e2e: added ICS27 e2e test with governance. (#2808)
Browse files Browse the repository at this point in the history
  • Loading branch information
chatton authored Nov 23, 2022
1 parent ea6e42b commit 86332d2
Show file tree
Hide file tree
Showing 13 changed files with 223 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/e2e-compatibility-workflow-call.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ jobs:
CHAIN_A_TAG: "${{ matrix.chain-a }}"
CHAIN_B_TAG: "${{ matrix.chain-b }}"
CHAIN_BINARY: "${{ matrix.chain-binary }}"
RLY_TAG: "v2.0.0"
RLY_TAG: "v2.1.2"
2 changes: 1 addition & 1 deletion .github/workflows/e2e-fork.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
- name: Run e2e Test
env:
# see images here https://github.com/cosmos/relayer/pkgs/container/relayer/versions
RLY_TAG: "v2.0.0"
RLY_TAG: "v2.1.2"
run: |
cd e2e
make e2e-test entrypoint=${{ matrix.entrypoint }} test=${{ matrix.test }}
2 changes: 1 addition & 1 deletion .github/workflows/e2e-manual-icad.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ on:
relayer-tag:
description: 'The tag to use for the relayer'
required: true
default: "v2.0.0"
default: "v2.1.2"
type: string


Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/e2e-manual-simd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ on:
- TestConnectionTestSuite
- TestInterchainAccountsTestSuite
- TestInterchainAccountsGroupsTestSuite
- TestInterchainAccountsGovTestSuite
- TestIncentivizedInterchainAccountsTestSuite
chain-image:
description: 'The image to use for chain A'
Expand Down Expand Up @@ -56,7 +57,7 @@ on:
relayer-tag:
description: 'The tag to use for the relayer'
required: true
default: "v2.0.0"
default: "v2.1.2"
type: string


Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e-test-workflow-call.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ on:
relayer-tag:
description: 'The tag to use for the relayer'
required: true
default: "v2.0.0"
default: "v2.1.2"
type: string
build-and-push-docker-image:
description: "Flag to specify if the docker image should be built and pushed beforehand"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/e2e.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
chain-image: ghcr.io/cosmos/ibc-go-simd
chain-a-tag: "${{ needs.determine-image-tag.outputs.simd-tag }}"
chain-b-tag: "${{ needs.determine-image-tag.outputs.simd-tag }}"
relayer-tag: "v2.0.0"
relayer-tag: "v2.1.2"
chain-binary: "simd"
# on regular PRs we won't run interchain account or upgrade tests.
test-exclusions: "TestInterTxTestSuite,TestIncentivizedInterTxTestSuite,TestUpgradeTestSuite"
4 changes: 2 additions & 2 deletions e2e/scripts/run-e2e.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ ENTRY_POINT="${1}"
TEST="${2}"

export CHAIN_A_TAG="${CHAIN_A_TAG:-latest}"
export CHAIN_A_IMAGE="${CHAIN_A_IMAGE:-ibc-go-simd}"
export CHAIN_IMAGE="${CHAIN_IMAGE:-ibc-go-simd}"
export CHAIN_BINARY="${CHAIN_BINARY:-simd}"

# In CI, the docker images will be built separately.
# context for building the image is one directory up.
if [ "${CI:-}" != "true" ]
then
(cd ..; docker build . -t "${CHAIN_A_IMAGE}:${CHAIN_A_TAG}")
(cd ..; docker build . -t "${CHAIN_IMAGE}:${CHAIN_A_TAG}")
fi

go test -v ./tests/... --run ${ENTRY_POINT} -testify.m ^${TEST}$
4 changes: 3 additions & 1 deletion e2e/testconfig/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ const (
defaultBinary = "simd"
// defaultRlyTag is the tag that will be used if no relayer tag is specified.
defaultRlyTag = "main"
// defaultChainTag is the tag that will be used for the chains if none is specified.
defaultChainTag = "main"
)

func getChainImage(binary string) string {
Expand Down Expand Up @@ -69,7 +71,7 @@ func FromEnv() TestConfig {

chainATag, ok := os.LookupEnv(ChainATagEnv)
if !ok {
panic(fmt.Sprintf("must specify %s version for test with environment variable [%s]", chainBinary, ChainATagEnv))
chainATag = defaultChainTag
}

chainBTag, ok := os.LookupEnv(ChainBTagEnv)
Expand Down
1 change: 0 additions & 1 deletion e2e/tests/interchain_accounts/base_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"github.com/cosmos/ibc-go/e2e/testconfig"
"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testvalues"

controllertypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types"
channeltypes "github.com/cosmos/ibc-go/v6/modules/core/04-channel/types"
Expand Down
116 changes: 116 additions & 0 deletions e2e/tests/interchain_accounts/gov_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package interchain_accounts

import (
"context"
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
"github.com/gogo/protobuf/proto"
"github.com/strangelove-ventures/ibctest/v6"
"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"
controllertypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v6/modules/apps/27-interchain-accounts/types"
ibctesting "github.com/cosmos/ibc-go/v6/testing"
)

func TestInterchainAccountsGovTestSuite(t *testing.T) {
suite.Run(t, new(InterchainAccountsGovTestSuite))
}

type InterchainAccountsGovTestSuite struct {
testsuite.E2ETestSuite
}

func (s *InterchainAccountsGovTestSuite) TestInterchainAccountsGovIntegration() {
t := s.T()
ctx := context.TODO()

// setup relayers and connection-0 between two chains
// channel-0 is a transfer channel but it will not be used in this test case
relayer, _ := s.SetupChainsRelayerAndChannel(ctx)
chainA, chainB := s.GetChains()
controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)

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

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

t.Run("execute proposal for MsgRegisterInterchainAccount", func(t *testing.T) {
version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, govModuleAddress.String(), version)
s.ExecuteGovProposalV1(ctx, msgRegisterAccount, chainA, controllerAccount, 1)
})

t.Run("start relayer", func(t *testing.T) {
s.StartRelayer(relayer)
})

s.Require().NoError(test.WaitForBlocks(ctx, 10, chainA, chainB))

var interchainAccAddr string
t.Run("verify interchain account registration success", func(t *testing.T) {
var err error
interchainAccAddr, err = s.QueryInterchainAccount(ctx, chainA, govModuleAddress.String(), ibctesting.FirstConnectionID)
s.Require().NoError(err)
s.Require().NotZero(len(interchainAccAddr))

channels, err := relayer.GetChannels(ctx, s.GetRelayerExecReporter(), chainA.Config().ChainID)
s.Require().NoError(err)
s.Require().Equal(len(channels), 2)
})

t.Run("interchain account executes a bank transfer on behalf of the corresponding owner account", func(t *testing.T) {
t.Run("fund interchain account wallet", func(t *testing.T) {
// fund the host account, so it has some $$ to send
err := chainB.SendFunds(ctx, ibctest.FaucetAccountKeyName, ibc.WalletAmount{
Address: interchainAccAddr,
Amount: testvalues.StartingTokenAmount,
Denom: chainB.Config().Denom,
})
s.Require().NoError(err)
})

t.Run("execute proposal for MsgSendTx", func(t *testing.T) {
msgBankSend := &banktypes.MsgSend{
FromAddress: interchainAccAddr,
ToAddress: chainBAddress,
Amount: sdk.NewCoins(testvalues.DefaultTransferAmount(chainB.Config().Denom)),
}

cdc := testsuite.Codec()
bz, err := icatypes.SerializeCosmosTx(cdc, []proto.Message{msgBankSend})
s.Require().NoError(err)

packetData := icatypes.InterchainAccountPacketData{
Type: icatypes.EXECUTE_TX,
Data: bz,
Memo: "e2e",
}

msgSendTx := controllertypes.NewMsgSendTx(govModuleAddress.String(), ibctesting.FirstConnectionID, uint64(time.Hour.Nanoseconds()), packetData)
s.ExecuteGovProposalV1(ctx, msgSendTx, chainA, controllerAccount, 2)
})

t.Run("verify tokens transferred", func(t *testing.T) {
balance, err := chainB.GetBalance(ctx, chainBAccount.Bech32Address(chainB.Config().Bech32Prefix), chainB.Config().Denom)
s.Require().NoError(err)

_, err = chainB.GetBalance(ctx, interchainAccAddr, chainB.Config().Denom)
s.Require().NoError(err)

expected := testvalues.IBCTransferAmount + testvalues.StartingTokenAmount
s.Require().Equal(expected, balance)
})
})
}
14 changes: 13 additions & 1 deletion e2e/testsuite/codec.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,28 @@ package testsuite

import (
"github.com/cosmos/cosmos-sdk/codec"
authtypes "github.com/cosmos/cosmos-sdk/x/auth/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
govv1beta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"

simappparams "github.com/cosmos/ibc-go/v6/testing/simapp/params"
)

func Codec() *codec.ProtoCodec {
cdc, _ := codecAndEncodingConfig()
return cdc
}

func EncodingConfig() simappparams.EncodingConfig {
_, cfg := codecAndEncodingConfig()
return cfg
}

func codecAndEncodingConfig() (*codec.ProtoCodec, simappparams.EncodingConfig) {
cfg := simappparams.MakeTestEncodingConfig()
banktypes.RegisterInterfaces(cfg.InterfaceRegistry)
govv1beta1.RegisterInterfaces(cfg.InterfaceRegistry)
authtypes.RegisterInterfaces(cfg.InterfaceRegistry)
cdc := codec.NewProtoCodec(cfg.InterfaceRegistry)
return cdc
return cdc, cfg
}
21 changes: 17 additions & 4 deletions e2e/testsuite/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package testsuite
import (
"context"

govtypes "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
govtypesv1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1"
govtypesbeta1 "github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"
"github.com/strangelove-ventures/ibctest/v6/chain/cosmos"
"github.com/strangelove-ventures/ibctest/v6/ibc"
Expand Down Expand Up @@ -120,14 +121,26 @@ func (s *E2ETestSuite) QueryCounterPartyPayee(ctx context.Context, chain ibc.Cha
}

// QueryProposal queries the governance proposal on the given chain with the given proposal ID.
func (s *E2ETestSuite) QueryProposal(ctx context.Context, chain ibc.Chain, proposalID uint64) (govtypes.Proposal, error) {
func (s *E2ETestSuite) QueryProposal(ctx context.Context, chain ibc.Chain, proposalID uint64) (govtypesbeta1.Proposal, error) {
queryClient := s.GetChainGRCPClients(chain).GovQueryClient
res, err := queryClient.Proposal(ctx, &govtypes.QueryProposalRequest{
res, err := queryClient.Proposal(ctx, &govtypesbeta1.QueryProposalRequest{
ProposalId: proposalID,
})
if err != nil {
return govtypes.Proposal{}, err
return govtypesbeta1.Proposal{}, err
}

return res.Proposal, nil
}

func (s *E2ETestSuite) QueryProposalV1(ctx context.Context, chain ibc.Chain, proposalID uint64) (govtypesv1.Proposal, error) {
queryClient := s.GetChainGRCPClients(chain).GovQueryClientV1
res, err := queryClient.Proposal(ctx, &govtypesv1.QueryProposalRequest{
ProposalId: proposalID,
})
if err != nil {
return govtypesv1.Proposal{}, err
}

return *res.Proposal, nil
}
Loading

0 comments on commit 86332d2

Please sign in to comment.