Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into simapp-refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
faddat committed Jun 21, 2023
2 parents 62966ce + e3b2182 commit 5727edb
Show file tree
Hide file tree
Showing 9 changed files with 380 additions and 119 deletions.
6 changes: 5 additions & 1 deletion docs/dev/go-style-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type middleware struct {
## Importing libraries

- Use [goimports](https://godoc.org/golang.org/x/tools/cmd/goimports).
- Separate imports into blocks: one for the standard lib, one for external libs and one for application libs. For example:
- Separate imports into blocks. For example:

```go
import (
Expand All @@ -79,13 +79,17 @@ import (

// external library imports
"github.com/stretchr/testify/require"

// Cosmos-SDK imports
abci "github.com/cometbft/cometbft/abci/types"

// ibc-go library imports
"github.com/cosmos/ibc-go/modules/core/23-commitment/types"
)
```

Run `make lint-fix` to get the imports ordered and grouped automatically.

## Dependencies

- Dependencies should be pinned by a release tag, or specific commit, to avoid breaking `go get` when external dependencies are updated.
Expand Down
21 changes: 10 additions & 11 deletions docs/ibc/light-clients/setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,29 +101,28 @@ Within the `02-client` submodule, the [`ClientState` is then initialized](https:

In order to successfully create an IBC client using a new client type, it [must be supported](https://github.com/cosmos/ibc-go/blob/v7.0.0/modules/core/02-client/keeper/client.go#L19-L25). Light client support in IBC is gated by on-chain governance. The allow list may be updated by submitting a new governance proposal to update the `02-client` parameter `AllowedClients`.

<!--
- TODO: update when params are managed by ibc-go
- https://github.com/cosmos/ibc-go/issues/2010
-->
See below for example:

```shell
%s tx gov submit-proposal param-change <path/to/proposal.json> --from=<key_or_address>
%s tx gov submit-proposal <path/to/proposal.json> --from <key_or_address>
```

where `proposal.json` contains:

```json
{
"title": "IBC Clients Param Change",
"description": "Update allowed clients",
"changes": [
"summary": "Update allowed clients",
"messages": [
{
"subspace": "ibc",
"key": "AllowedClients",
"value": ["06-solomachine", "07-tendermint", "0x-new-client"]
"@type": "/ibc.core.client.v1.MsgUpdateParams",
"authority": "cosmos1...", // The gov module account address
"params": {
"allowed_clients": ["06-solomachine", "07-tendermint", "0x-new-client"]
}
}
],
"deposit": "1000stake"
"metadata": "AQ==",
"deposit": "100stake"
}
```
90 changes: 90 additions & 0 deletions e2e/tests/interchain_accounts/params_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package interchain_accounts

import (
"context"
"testing"

govtypes "github.com/cosmos/cosmos-sdk/x/gov/types"
paramsproposaltypes "github.com/cosmos/cosmos-sdk/x/params/types/proposal"
"github.com/strangelove-ventures/interchaintest/v7/ibc"
"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/v7/modules/apps/27-interchain-accounts/controller/types"
icatypes "github.com/cosmos/ibc-go/v7/modules/apps/27-interchain-accounts/types"
ibctesting "github.com/cosmos/ibc-go/v7/testing"
)

func TestInterchainAccountsParamsTestSuite(t *testing.T) {
suite.Run(t, new(InterchainAccountsParamsTestSuite))
}

type InterchainAccountsParamsTestSuite struct {
testsuite.E2ETestSuite
}

// QueryControllerParams queries the params for the controller
func (s *InterchainAccountsParamsTestSuite) QueryControllerParams(ctx context.Context, chain ibc.Chain) controllertypes.Params {
queryClient := s.GetChainGRCPClients(chain).ICAControllerQueryClient
res, err := queryClient.Params(ctx, &controllertypes.QueryParamsRequest{})
s.Require().NoError(err)

return *res.Params
}

// TestControllerEnabledParam tests that changing the ControllerEnabled param works as expected
func (s *InterchainAccountsParamsTestSuite) TestControllerEnabledParam() {
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
_, _ = s.SetupChainsRelayerAndChannel(ctx)
chainA, _ := s.GetChains()
chainAVersion := chainA.Config().Images[0].Version

// setup controller account on chainA
controllerAccount := s.CreateUserOnChainA(ctx, testvalues.StartingTokenAmount)
controllerAddress := controllerAccount.FormattedAddress()

t.Run("ensure the controller is enabled", func(t *testing.T) {
params := s.QueryControllerParams(ctx, chainA)
s.Require().True(params.ControllerEnabled)
})

t.Run("disable the controller", func(t *testing.T) {
if testvalues.SelfParamsFeatureReleases.IsSupported(chainAVersion) {
authority, err := s.QueryModuleAccountAddress(ctx, govtypes.ModuleName, chainA)
s.Require().NoError(err)
s.Require().NotNil(authority)

msg := controllertypes.MsgUpdateParams{
Authority: authority.String(),
Params: controllertypes.NewParams(false),
}
s.ExecuteGovProposalV1(ctx, &msg, chainA, controllerAccount, 1)
} else {
changes := []paramsproposaltypes.ParamChange{
paramsproposaltypes.NewParamChange(controllertypes.StoreKey, string(controllertypes.KeyControllerEnabled), "false"),
}

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

t.Run("ensure controller is disabled", func(t *testing.T) {
params := s.QueryControllerParams(ctx, chainA)
s.Require().False(params.ControllerEnabled)
})

t.Run("ensure that broadcasting a MsgRegisterInterchainAccount fails", func(t *testing.T) {
// explicitly set the version string because we don't want to use incentivized channels.
version := icatypes.NewDefaultMetadataString(ibctesting.FirstConnectionID, ibctesting.FirstConnectionID)
msgRegisterAccount := controllertypes.NewMsgRegisterInterchainAccount(ibctesting.FirstConnectionID, controllerAddress, version)

txResp := s.BroadcastMessages(ctx, chainA, controllerAccount, msgRegisterAccount)
s.AssertTxFailure(txResp, controllertypes.ErrControllerSubModuleDisabled)
})
}
25 changes: 7 additions & 18 deletions modules/apps/27-interchain-accounts/host/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,19 @@ import (
)

func (suite *KeeperTestSuite) TestUpdateParams() {
msg := types.MsgUpdateParams{}

testCases := []struct {
name string
malleate func(authority string)
expPass bool
name string
msg *types.MsgUpdateParams
expPass bool
}{
{
"success",
func(authority string) {
msg.Authority = authority
msg.Params = types.DefaultParams()
},
types.NewMsgUpdateParams(suite.chainA.GetSimApp().ICAHostKeeper.GetAuthority(), types.DefaultParams()),
true,
},
{
"invalid authority address",
func(authority string) {
msg.Authority = "authority"
msg.Params = types.DefaultParams()
},
types.NewMsgUpdateParams("authority", types.DefaultParams()),
false,
},
}
Expand All @@ -37,12 +29,9 @@ func (suite *KeeperTestSuite) TestUpdateParams() {
suite.Run(tc.name, func() {
suite.SetupTest()

ICAHostKeeper := &suite.chainA.GetSimApp().ICAHostKeeper
tc.malleate(ICAHostKeeper.GetAuthority()) // malleate mutates test data

ctx := suite.chainA.GetContext()
msgServer := keeper.NewMsgServerImpl(ICAHostKeeper)
res, err := msgServer.UpdateParams(ctx, &msg)
msgServer := keeper.NewMsgServerImpl(&suite.chainA.GetSimApp().ICAHostKeeper)
res, err := msgServer.UpdateParams(ctx, tc.msg)

if tc.expPass {
suite.Require().NoError(err)
Expand Down
8 changes: 8 additions & 0 deletions modules/apps/27-interchain-accounts/host/types/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ import (

var _ sdk.Msg = (*MsgUpdateParams)(nil)

// NewMsgUpdateParams creates a new MsgUpdateParams instance
func NewMsgUpdateParams(authority string, params Params) *MsgUpdateParams {
return &MsgUpdateParams{
Authority: authority,
Params: params,
}
}

// ValidateBasic implements sdk.Msg
func (msg MsgUpdateParams) ValidateBasic() error {
_, err := sdk.AccAddressFromBech32(msg.Authority)
Expand Down
53 changes: 15 additions & 38 deletions modules/apps/27-interchain-accounts/host/types/msgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,57 +12,37 @@ import (
)

func TestMsgUpdateParamsValidateBasic(t *testing.T) {
var msg *types.MsgUpdateParams

testCases := []struct {
name string
malleate func()
expPass bool
name string
msg *types.MsgUpdateParams
expPass bool
}{
{
"success: valid authority address",
func() {
msg = &types.MsgUpdateParams{
Authority: ibctesting.TestAccAddress,
Params: types.DefaultParams(),
}
},
types.NewMsgUpdateParams(sdk.AccAddress(ibctesting.TestAccAddress).String(), types.DefaultParams()),
true,
},
{
"failure: invalid authority address",
func() {
msg = &types.MsgUpdateParams{
Authority: "authority",
}
},
types.NewMsgUpdateParams("authority", types.DefaultParams()),
false,
},
{
"failure: invalid allowed message",
func() {
msg = &types.MsgUpdateParams{
Authority: ibctesting.TestAccAddress,
Params: types.Params{
AllowMessages: []string{""},
},
}
},
types.NewMsgUpdateParams("authority", types.Params{
AllowMessages: []string{""},
}),
false,
},
}

for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
tc.malleate()

err := msg.ValidateBasic()
if tc.expPass {
require.NoError(t, err)
} else {
require.Error(t, err)
}
})
err := tc.msg.ValidateBasic()
if tc.expPass {
require.NoError(t, err)
} else {
require.Error(t, err)
}
}
}

Expand All @@ -77,10 +57,7 @@ func TestMsgUpdateParamsGetSigners(t *testing.T) {
}

for _, tc := range testCases {
msg := types.MsgUpdateParams{
Authority: tc.address.String(),
Params: types.DefaultParams(),
}
msg := types.NewMsgUpdateParams(tc.address.String(), types.DefaultParams())
if tc.expPass {
require.Equal(t, []sdk.AccAddress{tc.address}, msg.GetSigners())
} else {
Expand Down
Loading

0 comments on commit 5727edb

Please sign in to comment.