-
Notifications
You must be signed in to change notification settings - Fork 620
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
Changes from 33 commits
f9ce4fd
5242278
f499db4
59514fe
55eb017
a4922e7
8c4ca90
70a431f
22125d3
314c81d
b2eee55
2c94f5f
6d7407b
5b4aa3c
5462ba6
f23b9b4
776a7ce
efa5e43
dbbf6b9
eb99d94
77a2720
9744005
7868ed2
d5d5dcb
c418302
4cad828
89da39e
3de8fd5
c92a408
f4cd006
49655cc
0505634
c4c033d
0125cdc
d7ff43a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
package keeper_test | ||
|
||
import ( | ||
"errors" | ||
|
||
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" | ||
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/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" | ||
|
@@ -827,7 +831,86 @@ func (suite *KeeperTestSuite) TestUpdateClientParams() { | |
} | ||
|
||
// TestIBCSoftwareUpgrade tests the IBCSoftwareUpgrade rpc handler | ||
func (*KeeperTestSuite) TestIBCSoftwareUpgrade() { | ||
func (suite *KeeperTestSuite) TestIBCSoftwareUpgrade() { | ||
var ( | ||
expError error | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.MsgIBCSoftwareUpgrade | ||
) | ||
testCases := []struct { | ||
name string | ||
malleate func() | ||
}{ | ||
{ | ||
"success: valid authority and client upgrade", | ||
func() {}, | ||
}, | ||
{ | ||
"failure: invalid authority address", | ||
func() { | ||
msg.Signer = suite.chainA.SenderAccount.GetAddress().String() | ||
expError = ibcerrors.ErrUnauthorized | ||
}, | ||
}, | ||
{ | ||
"failure: invalid clientState", | ||
func() { | ||
msg.UpgradedClientState = nil | ||
expError = clienttypes.ErrInvalidClientType | ||
}, | ||
}, | ||
{ | ||
"failure: failed to schedule client upgrade", | ||
func() { | ||
msg.Plan.Height = 0 | ||
expError = sdkerrors.ErrInvalidRequest | ||
}, | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
suite.Run(tc.name, func() { | ||
path := ibctesting.NewPath(suite.chainA, suite.chainB) | ||
suite.coordinator.SetupClients(path) | ||
validAuthority := suite.chainA.App.GetIBCKeeper().GetAuthority() | ||
plan := upgradetypes.Plan{ | ||
Name: "upgrade IBC clients", | ||
Height: 1000, | ||
} | ||
// update trusting period | ||
clientState := ibctm.NewClientState(suite.chainA.ChainID, ibctesting.DefaultTrustLevel, ibctesting.TrustingPeriod+100, ibctesting.UnbondingPeriod, ibctesting.MaxClockDrift, clienttypes.NewHeight(1, 10), commitmenttypes.GetSDKSpecs(), ibctesting.UpgradePath) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could also likely do: clientState := path.EndpointB.GetClientState()
clientState.TrustingPeriod+=100 |
||
var err error | ||
msg, err = clienttypes.NewMsgIBCSoftwareUpgrade( | ||
validAuthority, | ||
plan, | ||
clientState, | ||
) | ||
|
||
suite.Require().NoError(err) | ||
|
||
tc.malleate() | ||
|
||
_, err = keeper.Keeper.IBCSoftwareUpgrade(*suite.chainA.App.GetIBCKeeper(), suite.chainA.GetContext(), msg) | ||
|
||
if expError == nil { | ||
suite.Require().NoError(err) | ||
// upgrade plan is stored | ||
storedPlan, found := suite.chainA.GetSimApp().UpgradeKeeper.GetUpgradePlan(suite.chainA.GetContext()) | ||
suite.Require().True(found) | ||
suite.Require().Equal(plan, storedPlan) | ||
|
||
// upgraded client state is stored | ||
bz, found := suite.chainA.GetSimApp().UpgradeKeeper.GetUpgradedClient(suite.chainA.GetContext(), plan.Height) | ||
suite.Require().True(found) | ||
upgradedClientState, err := clienttypes.UnmarshalClientState(suite.chainA.App.AppCodec(), bz) | ||
suite.Require().NoError(err) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inside |
||
suite.Require().Equal(clientState.ZeroCustomFields(), upgradedClientState) | ||
} else { | ||
suite.Require().True(errors.Is(err, expError)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// TestUpdateConnectionParams tests the UpdateConnectionParams rpc handler | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this test got removed in the last pr merge process.