Skip to content

Commit

Permalink
Merge branch 'main' into damian/2053-impl-sdk-msg-interface-register-acc
Browse files Browse the repository at this point in the history
  • Loading branch information
damiannolan authored Aug 24, 2022
2 parents 7160c2f + 0fa2978 commit 85f32bf
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 871 deletions.
8 changes: 8 additions & 0 deletions .github/mergify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ pull_request_rules:
backport:
branches:
- release/v5.0.x
- name: backport patches to v5.1.x branch
conditions:
- base=main
- label=backport-to-v5.1.x
actions:
backport:
branches:
- release/v5.1.x
- name: backport patches to v6.0.x branch
conditions:
- base=main
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
* (transfer) [\#2034](https://github.com/cosmos/ibc-go/pull/2034) Transfer Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper.
* (05-port) [\#2025](https://github.com/cosmos/ibc-go/pull/2025) Port Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper.
* (04-channel) [\#2024](https://github.com/cosmos/ibc-go/pull/2024) Channel Keeper now expects a keeper which fulfills the expected `ScopedKeeper` interface for the capability keeper.
* (apps/27-interchain-accounts) [\#2058](https://github.com/cosmos/ibc-go/pull/2058) Added `MessageRouter` interface and replaced `*baseapp.MsgServiceRouter` with it. The controller and host keepers of apps/27-interchain-accounts have been updated to use it.

### State Machine Breaking

Expand Down
19 changes: 17 additions & 2 deletions e2e/interchain_accounts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@ import (
"github.com/strangelove-ventures/ibctest/ibc"
"github.com/strangelove-ventures/ibctest/test"
"github.com/stretchr/testify/suite"
"golang.org/x/mod/semver"

sdk "github.com/cosmos/cosmos-sdk/types"
banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
intertxtypes "github.com/cosmos/interchain-accounts/x/inter-tx/types"

"github.com/cosmos/ibc-go/e2e/testconfig"
"github.com/cosmos/ibc-go/e2e/testsuite"
"github.com/cosmos/ibc-go/e2e/testvalues"

Expand All @@ -33,6 +35,7 @@ type InterchainAccountsTestSuite struct {
// RegisterInterchainAccount will attempt to register an interchain account on the counterparty chain.
func (s *InterchainAccountsTestSuite) RegisterInterchainAccount(ctx context.Context, chain *cosmos.CosmosChain, user *ibctest.User, msgRegisterAccount *intertxtypes.MsgRegisterAccount) error {
txResp, err := s.BroadcastMessages(ctx, chain, user, msgRegisterAccount)
s.Require().NoError(err)
s.AssertValidTxResponse(txResp)
return err
}
Expand All @@ -44,6 +47,18 @@ func (s *InterchainAccountsTestSuite) RegisterCounterPartyPayee(ctx context.Cont
return s.BroadcastMessages(ctx, chain, user, msg)
}

// getICAVersion returns the version which should be used in the MsgRegisterAccount broadcast from the
// controller chain.
func getICAVersion(chainAVersion, chainBVersion string) string {
chainBIsGreaterThanChainA := semver.Compare(chainAVersion, chainBVersion) == -1
if chainBIsGreaterThanChainA {
// allow version to be specified by the controller chain
return ""
}
// explicitly set the version string because the host chain might not yet support incentivized channels.
return icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
}

func (s *InterchainAccountsTestSuite) TestMsgSubmitTx_SuccessfulTransfer() {
t := s.T()
ctx := context.TODO()
Expand All @@ -60,7 +75,7 @@ func (s *InterchainAccountsTestSuite) TestMsgSubmitTx_SuccessfulTransfer() {
var hostAccount string

t.Run("register interchain account", func(t *testing.T) {
version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
version := getICAVersion(testconfig.GetChainATag(), testconfig.GetChainBTag())
msgRegisterAccount := intertxtypes.NewMsgRegisterAccount(controllerAccount.Bech32Address(chainA.Config().Bech32Prefix), ibctesting.FirstConnectionID, version)
err := s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterAccount)
s.Require().NoError(err)
Expand Down Expand Up @@ -154,7 +169,7 @@ func (s *InterchainAccountsTestSuite) TestMsgSubmitTx_FailedTransfer_Insufficien
var hostAccount string

t.Run("register interchain account", func(t *testing.T) {
version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
version := getICAVersion(testconfig.GetChainATag(), testconfig.GetChainBTag())
msgRegisterAccount := intertxtypes.NewMsgRegisterAccount(controllerAccount.Bech32Address(chainA.Config().Bech32Prefix), ibctesting.FirstConnectionID, version)
err := s.RegisterInterchainAccount(ctx, chainA, controllerAccount, msgRegisterAccount)
s.Require().NoError(err)
Expand Down
16 changes: 16 additions & 0 deletions e2e/testconfig/testconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,22 @@ func FromEnv() TestConfig {
}
}

func GetChainATag() string {
chainATag, ok := os.LookupEnv(ChainATagEnv)
if !ok {
panic(fmt.Sprintf("no environment variable specified for %s", ChainATagEnv))
}
return chainATag
}

func GetChainBTag() string {
chainBTag, ok := os.LookupEnv(ChainBTagEnv)
if !ok {
return GetChainATag()
}
return chainBTag
}

// ChainOptions stores chain configurations for the chains that will be
// created for the tests. They can be modified by passing ChainOptionConfiguration
// to E2ETestSuite.GetChains.
Expand Down
12 changes: 10 additions & 2 deletions e2e/testsuite/testsuite.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ const (
ChainARelayerName = "rlyA"
// ChainBRelayerName is the name given to the relayer wallet on ChainB
ChainBRelayerName = "rlyB"

// emptyLogs is the string value returned from `BroadcastMessages`. There are some situations in which
// the result is empty, when this happens we include the raw logs instead to get as much information
// amount the failure as possible.
emptyLogs = "[]"
)

// E2ETestSuite has methods and functionality which can be shared among all test suites.
Expand Down Expand Up @@ -297,6 +302,9 @@ func (s *E2ETestSuite) initGRPCClients(chain *cosmos.CosmosChain) {
// has non-empty values.
func (s *E2ETestSuite) AssertValidTxResponse(resp sdk.TxResponse) {
respLogsMsg := resp.Logs.String()
if respLogsMsg == emptyLogs {
respLogsMsg = resp.RawLog
}
s.Require().NotEqual(int64(0), resp.GasUsed, respLogsMsg)
s.Require().NotEqual(int64(0), resp.GasWanted, respLogsMsg)
s.Require().NotEmpty(resp.Events, respLogsMsg)
Expand All @@ -322,8 +330,8 @@ func (s *E2ETestSuite) createCosmosChains(chainOptions testconfig.ChainOptions)
logger := zaptest.NewLogger(s.T())

// TODO(chatton): allow for controller over number of validators and full nodes.
chainA := cosmos.NewCosmosChain(s.T().Name(), *chainOptions.ChainAConfig, 1, 0, logger)
chainB := cosmos.NewCosmosChain(s.T().Name(), *chainOptions.ChainBConfig, 1, 0, logger)
chainA := cosmos.NewCosmosChain(s.T().Name(), *chainOptions.ChainAConfig, 4, 1, logger)
chainB := cosmos.NewCosmosChain(s.T().Name(), *chainOptions.ChainBConfig, 4, 1, logger)

return chainA, chainB
}
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ require (
gopkg.in/yaml.v2 v2.4.0
)

require github.com/zondax/hid v0.9.1-0.20220302062450-5552068d2266 // indirect

require (
github.com/zondax/hid v0.9.1-0.20220302062450-5552068d2266 // indirect
cloud.google.com/go v0.100.2 // indirect
cloud.google.com/go/compute v1.6.1 // indirect
cloud.google.com/go/iam v0.3.0 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"strings"

baseapp "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -30,14 +29,14 @@ type Keeper struct {

scopedKeeper icatypes.ScopedKeeper

msgRouter *baseapp.MsgServiceRouter
msgRouter icatypes.MessageRouter
}

// NewKeeper creates a new interchain accounts controller Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
ics4Wrapper icatypes.ICS4Wrapper, channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper,
scopedKeeper icatypes.ScopedKeeper, msgRouter *baseapp.MsgServiceRouter,
scopedKeeper icatypes.ScopedKeeper, msgRouter icatypes.MessageRouter,
) Keeper {
// set KeyTable if it has not already been set
if !paramSpace.HasKeyTable() {
Expand Down
5 changes: 2 additions & 3 deletions modules/apps/27-interchain-accounts/host/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"
"strings"

baseapp "github.com/cosmos/cosmos-sdk/baseapp"
"github.com/cosmos/cosmos-sdk/codec"
storetypes "github.com/cosmos/cosmos-sdk/store/types"
sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -30,14 +29,14 @@ type Keeper struct {

scopedKeeper icatypes.ScopedKeeper

msgRouter *baseapp.MsgServiceRouter
msgRouter icatypes.MessageRouter
}

// NewKeeper creates a new interchain accounts host Keeper instance
func NewKeeper(
cdc codec.BinaryCodec, key storetypes.StoreKey, paramSpace paramtypes.Subspace,
channelKeeper icatypes.ChannelKeeper, portKeeper icatypes.PortKeeper,
accountKeeper icatypes.AccountKeeper, scopedKeeper icatypes.ScopedKeeper, msgRouter *baseapp.MsgServiceRouter,
accountKeeper icatypes.AccountKeeper, scopedKeeper icatypes.ScopedKeeper, msgRouter icatypes.MessageRouter,
) Keeper {
// ensure ibc interchain accounts module account is set
if addr := accountKeeper.GetModuleAddress(icatypes.ModuleName); addr == nil {
Expand Down
12 changes: 12 additions & 0 deletions modules/apps/27-interchain-accounts/types/router.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package types

import (
baseapp "github.com/cosmos/cosmos-sdk/baseapp"
sdk "github.com/cosmos/cosmos-sdk/types"
)

// MessageRouter ADR 031 request type routing
// https://github.com/cosmos/cosmos-sdk/blob/main/docs/architecture/adr-031-msg-service.md
type MessageRouter interface {
Handler(msg sdk.Msg) baseapp.MsgServiceHandler
}
6 changes: 0 additions & 6 deletions modules/core/05-port/module.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package port

import (
"github.com/gogo/protobuf/grpc"
"github.com/spf13/cobra"

"github.com/cosmos/ibc-go/v5/modules/core/05-port/types"
Expand All @@ -17,8 +16,3 @@ func Name() string {
func GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}

// RegisterQueryService registers the gRPC query service for IBC ports.
func RegisterQueryService(server grpc.Server, queryServer types.QueryServer) {
types.RegisterQueryServer(server, queryServer)
}
9 changes: 0 additions & 9 deletions modules/core/05-port/types/query.go

This file was deleted.

Loading

0 comments on commit 85f32bf

Please sign in to comment.