-
Notifications
You must be signed in to change notification settings - Fork 586
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
chore: 07-tendermint set client/consensus states in UpdateState #1199
Changes from 2 commits
81eee38
f98617f
45bf66a
f601fe8
4212e66
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ import ( | |
"fmt" | ||
"time" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
clienttypes "github.com/cosmos/ibc-go/v3/modules/core/02-client/types" | ||
commitmenttypes "github.com/cosmos/ibc-go/v3/modules/core/23-commitment/types" | ||
host "github.com/cosmos/ibc-go/v3/modules/core/24-host" | ||
|
@@ -397,11 +398,10 @@ func (suite *TendermintTestSuite) TestVerifyHeader() { | |
|
||
func (suite *TendermintTestSuite) TestUpdateState() { | ||
var ( | ||
path *ibctesting.Path | ||
clientMessage exported.ClientMessage | ||
pruneHeight clienttypes.Height | ||
updatedClientState *types.ClientState // TODO: retrieve from state after 'UpdateState' call | ||
updatedConsensusState *types.ConsensusState // TODO: retrieve from state after 'UpdateState' call | ||
path *ibctesting.Path | ||
clientMessage exported.ClientMessage | ||
clientStore sdk.KVStore | ||
pruneHeight clienttypes.Height | ||
) | ||
|
||
testCases := []struct { | ||
|
@@ -415,7 +415,7 @@ func (suite *TendermintTestSuite) TestUpdateState() { | |
suite.Require().True(path.EndpointA.GetClientState().GetLatestHeight().LT(clientMessage.GetHeight())) | ||
}, | ||
func() { | ||
suite.Require().True(path.EndpointA.GetClientState().GetLatestHeight().LT(updatedClientState.GetLatestHeight())) // new update, updated client state should have changed | ||
suite.Require().True(path.EndpointA.GetClientState().GetLatestHeight().EQ(clientMessage.GetHeight())) // new update, updated client state should have changed | ||
}, true, | ||
}, | ||
{ | ||
|
@@ -429,6 +429,9 @@ func (suite *TendermintTestSuite) TestUpdateState() { | |
suite.Require().True(path.EndpointA.GetClientState().GetLatestHeight().GT(clientMessage.GetHeight())) | ||
}, | ||
func() { | ||
bz := clientStore.Get(host.ClientStateKey()) | ||
updatedClientState := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), bz) | ||
|
||
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. should this go in malleate? I'm not sure these checks perform any actual checks now since 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. Right, yeah I get you! Could you expand on what you're suggesting for moving to malleate? I'm not sure I follow, malleate will be called before 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.
These test cases are asserting the client state didn't get updated (since we updated to a previous height). So yes, I am suggesting we construct the expected client state in malleate and then ensure the client state doesn't change after calling 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. Ah yes, sorry overlooked that when I wrote the comment. I've updated as you suggested to retrieve the "previous" states before update in malleate and check for equality in expResult! :)) |
||
suite.Require().Equal(path.EndpointA.GetClientState(), updatedClientState) // fill in height, no change to client state | ||
}, true, | ||
}, | ||
|
@@ -444,6 +447,12 @@ func (suite *TendermintTestSuite) TestUpdateState() { | |
suite.Require().Equal(path.EndpointA.GetClientState().GetLatestHeight(), clientMessage.GetHeight()) | ||
}, | ||
func() { | ||
bz := clientStore.Get(host.ClientStateKey()) | ||
updatedClientState := clienttypes.MustUnmarshalClientState(suite.chainA.App.AppCodec(), bz) | ||
|
||
bz = clientStore.Get(host.ConsensusStateKey(clientMessage.GetHeight())) | ||
updatedConsensusState := clienttypes.MustUnmarshalConsensusState(suite.chainA.App.AppCodec(), bz) | ||
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. ditto on moving into malleate 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. Done 👍 |
||
|
||
suite.Require().Equal(path.EndpointA.GetClientState(), updatedClientState) | ||
suite.Require().Equal(path.EndpointA.GetConsensusState(clientMessage.GetHeight()), updatedConsensusState) | ||
}, true, | ||
|
@@ -474,7 +483,7 @@ func (suite *TendermintTestSuite) TestUpdateState() { | |
suite.Require().NoError(err) | ||
}, | ||
func() { | ||
suite.Require().True(path.EndpointA.GetClientState().GetLatestHeight().LT(updatedClientState.GetLatestHeight())) // new update, updated client state should have changed | ||
suite.Require().True(path.EndpointA.GetClientState().GetLatestHeight().EQ(clientMessage.GetHeight())) // new update, updated client state should have changed | ||
|
||
// ensure consensus state was pruned | ||
_, found := path.EndpointA.Chain.GetConsensusState(path.EndpointA.ClientID, pruneHeight) | ||
|
@@ -511,8 +520,8 @@ func (suite *TendermintTestSuite) TestUpdateState() { | |
tmClientState, ok := clientState.(*types.ClientState) | ||
suite.Require().True(ok) | ||
|
||
clientStore := suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) | ||
updatedClientState, updatedConsensusState, err = tmClientState.UpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage) | ||
clientStore = suite.chainA.App.GetIBCKeeper().ClientKeeper.ClientStore(suite.chainA.GetContext(), path.EndpointA.ClientID) | ||
_, _, err = tmClientState.UpdateState(suite.chainA.GetContext(), suite.chainA.App.AppCodec(), clientStore, clientMessage) | ||
|
||
if tc.expPass { | ||
suite.Require().NoError(err) | ||
|
@@ -523,13 +532,14 @@ func (suite *TendermintTestSuite) TestUpdateState() { | |
Root: commitmenttypes.NewMerkleRoot(header.Header.GetAppHash()), | ||
NextValidatorsHash: header.Header.NextValidatorsHash, | ||
} | ||
|
||
bz := clientStore.Get(host.ConsensusStateKey(header.GetHeight())) | ||
updatedConsensusState := clienttypes.MustUnmarshalConsensusState(suite.chainA.App.AppCodec(), bz) | ||
|
||
suite.Require().Equal(expConsensusState, updatedConsensusState) | ||
|
||
} else { | ||
suite.Require().Error(err) | ||
suite.Require().Nil(updatedClientState) | ||
suite.Require().Nil(updatedConsensusState) | ||
|
||
} | ||
|
||
// perform custom checks | ||
|
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.
Updated to make private / unexported