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

msg server function and tests for MsgScheduleIBCClientUpgrade #4442

Merged
merged 35 commits into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
f9ce4fd
add protos and keeper function placeholder
charleenfei Aug 22, 2023
5242278
add keeper functions/tests, msgs and tests
charleenfei Aug 23, 2023
f499db4
fix linter
charleenfei Aug 23, 2023
59514fe
bring back msg_server placeholders
charleenfei Aug 23, 2023
55eb017
add msg_server function and tests
charleenfei Aug 23, 2023
a4922e7
fix linter
charleenfei Aug 23, 2023
8c4ca90
Merge branch 'charly/issue#3673-add-message-and-rpc-handler-to-upgrad…
charleenfei Aug 23, 2023
70a431f
update msg name, make changes in testing
charleenfei Aug 24, 2023
22125d3
Merge branch 'charly/issue#3673-add-message-and-rpc-handler-to-upgrad…
charleenfei Aug 24, 2023
314c81d
fix linter, update to new msg name
charleenfei Aug 24, 2023
b2eee55
update test bool, method name
charleenfei Aug 28, 2023
2c94f5f
capitalisation
charleenfei Aug 28, 2023
6d7407b
Merge branch 'charly/issue#3673-add-message-and-rpc-handler-to-upgrad…
charleenfei Aug 28, 2023
5b4aa3c
update test bool
charleenfei Aug 28, 2023
5462ba6
update testcase
charleenfei Aug 28, 2023
f23b9b4
Merge branch 'charly/issue#3673-add-message-and-rpc-handler-to-upgrad…
charleenfei Aug 28, 2023
776a7ce
added check that message implements sdk.Msg interface
crodriguezvega Aug 29, 2023
efa5e43
update authority -> signers
charleenfei Aug 29, 2023
dbbf6b9
Merge branch 'feat/govv1' into charly/issue#3673-add-message-and-rpc-…
charleenfei Aug 29, 2023
eb99d94
merge
charleenfei Aug 29, 2023
77a2720
fix merge conflicts
charleenfei Aug 29, 2023
9744005
Merge branch 'charly/issue#3673-add-message-and-rpc-handler-to-upgrad…
charleenfei Aug 29, 2023
7868ed2
update authority -> signer
charleenfei Aug 29, 2023
d5d5dcb
add tests back in
charleenfei Aug 29, 2023
c418302
fix merge shenanigans
charleenfei Aug 29, 2023
4cad828
add check for tm client type
charleenfei Aug 29, 2023
89da39e
msgs
charleenfei Aug 29, 2023
3de8fd5
Merge branch 'feat/govv1' into charly/issue#3673-msg-server
charleenfei Aug 29, 2023
c92a408
move params tests back to reduce diffs
charleenfei Aug 29, 2023
f4cd006
merge shenanigans
charleenfei Aug 29, 2023
49655cc
update tests per comments
charleenfei Aug 29, 2023
0505634
linter fix
charleenfei Aug 29, 2023
c4c033d
Merge branch 'feat/govv1' into charly/issue#3673-msg-server
charleenfei Aug 30, 2023
0125cdc
go mod tidy
charleenfei Aug 30, 2023
d7ff43a
pr comments
charleenfei Aug 30, 2023
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
Prev Previous commit
Next Next commit
add msg_server function and tests
  • Loading branch information
charleenfei committed Aug 23, 2023
commit 55eb017170568833084befbb5b0223d83be82a96
17 changes: 15 additions & 2 deletions modules/core/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,21 @@ func (k Keeper) UpdateClientParams(goCtx context.Context, msg *clienttypes.MsgUp

// ScheduleIBCClientUpgrade defines a rpc handler method for MsgScheduleIBCClientUpgrade.
func (k Keeper) ScheduleIBCClientUpgrade(goCtx context.Context, msg *clienttypes.MsgScheduleIBCClientUpgrade) (*clienttypes.MsgScheduleIBCClientUpgradeResponse, error) {
// TODO
return nil, nil
if k.GetAuthority() != msg.Authority {
return nil, errorsmod.Wrapf(ibcerrors.ErrUnauthorized, "expected %s, got %s", k.GetAuthority(), msg.Authority)
}

ctx := sdk.UnwrapSDKContext(goCtx)
upgradedClientState, err := clienttypes.UnpackClientState(msg.UpgradedClientState)
if err != nil {
return nil, errorsmod.Wrapf(clienttypes.ErrInvalidClientType, "cannot unpack client state: %s", err)
}

if err = k.ClientKeeper.ScheduleIBCClientUpgrade(ctx, msg.Plan, upgradedClientState); err != nil {
return nil, errorsmod.Wrapf(err, "cannot schedule IBC client upgrade")
}

return &clienttypes.MsgScheduleIBCClientUpgradeResponse{}, nil
}

// UpdateConnectionParams defines a rpc handler method for MsgUpdateParams for the 03-connection submodule.
Expand Down
72 changes: 72 additions & 0 deletions modules/core/keeper/msg_server_test.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package keeper_test

import (
"errors"

sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types"
connectiontypes "github.com/cosmos/ibc-go/v7/modules/core/03-connection/types"
channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types"
commitmenttypes "github.com/cosmos/ibc-go/v7/modules/core/23-commitment/types"
host "github.com/cosmos/ibc-go/v7/modules/core/24-host"
ibcerrors "github.com/cosmos/ibc-go/v7/modules/core/errors"
"github.com/cosmos/ibc-go/v7/modules/core/exported"
"github.com/cosmos/ibc-go/v7/modules/core/keeper"
ibctm "github.com/cosmos/ibc-go/v7/modules/light-clients/07-tendermint"
Expand Down Expand Up @@ -828,6 +833,73 @@ func (suite *KeeperTestSuite) TestUpdateClientParams() {

// TestScheduleIBCClientUpgrade tests the ScheduleIBCClientUpgrade rpc handler
func (suite *KeeperTestSuite) TestScheduleIBCClientUpgrade() {
var (
expError error
Copy link
Contributor

Choose a reason for hiding this comment

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

super nit: I like defining the expError on the testCases, it makes it more explicit what we expect to occur and avoids potential mishaps of not setting an expected error

msg *clienttypes.MsgScheduleIBCClientUpgrade
)
testCases := []struct {
name string
malleate func()
expPass bool
Copy link
Contributor

Choose a reason for hiding this comment

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

same as other PR, we can refactor this to be expError and use expPass := expError == nil in the test body! 👍

}{
{
"success: valid authority and client upgrade",
func() {},
true,
},
{
"failure: invalid authority address",
func() {
msg.Authority = suite.chainA.SenderAccount.GetAddress().String()
expError = ibcerrors.ErrUnauthorized
},
false,
},
{
"failure: invalid clientState",
func() {
msg.UpgradedClientState = nil
expError = clienttypes.ErrInvalidClientType
},
false,
},
{
"failure: failed to schedule client upgrade",
func() {
msg.Plan.Height = 0
expError = sdkerrors.ErrInvalidRequest
},
false,
},
}

for _, tc := range testCases {
tc := tc
suite.Run(tc.name, func() {
suite.SetupTest()
validAuthority := suite.chainA.App.GetIBCKeeper().GetAuthority()
var err error
msg, err = clienttypes.NewMsgScheduleIBCClientUpgrade(
validAuthority,
upgradetypes.Plan{
Name: "upgrade IBC clients",
Height: 1000,
},
ibctm.NewClientState(suite.chainA.ChainID, ibctesting.DefaultTrustLevel, ibctesting.TrustingPeriod, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, types.NewHeight(1, 10), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath),
)

suite.Require().NoError(err)

tc.malleate()

_, err = keeper.Keeper.ScheduleIBCClientUpgrade(*suite.chainA.App.GetIBCKeeper(), suite.chainA.GetContext(), msg)
if tc.expPass {
suite.Require().NoError(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Inside expPass we can also check that there exists an upgrade plan in the x/upgrade store and upgraded client state in the upgradePath

} else {
suite.Require().True(errors.Is(err, expError))
}
})
}
}

// TestUpdateConnectionParams tests the UpdateConnectionParams rpc handler
Expand Down