-
Notifications
You must be signed in to change notification settings - Fork 616
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
02-client refactor: Adding VerifyClientMessage helper fn #1119
02-client refactor: Adding VerifyClientMessage helper fn #1119
Conversation
5b76483
to
70c2973
Compare
70c2973
to
b04e491
Compare
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.
Great work!
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.
Awesome work, in general looks great, left a couple of small comments. Appreciate the amount of the work that went into the tests here 💯
// VerifyClientMessage checks if the clientMessage is of type Header or Misbehaviour and verifies the message | ||
func (cs *ClientState) VerifyClientMessage( | ||
ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryCodec, | ||
header exported.ClientMessage, |
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.
Would suggest this to be named clientMsg
// - header timestamp is less than or equal to the consensus state timestamp | ||
func (cs *ClientState) verifyHeader( | ||
ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryCodec, | ||
tmHeader exported.ClientMessage, currentTimestamp time.Time, |
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.
I think you could change exported.ClientMessage
to *Header
ctx sdk.Context, clientStore sdk.KVStore, cdc codec.BinaryCodec, | ||
header exported.ClientMessage, | ||
) error { | ||
switch header.(type) { |
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.
And here do msg := clientMsg.(type)
types "github.com/cosmos/ibc-go/v3/modules/light-clients/07-tendermint/types" | ||
ibctesting "github.com/cosmos/ibc-go/v3/testing" | ||
ibctestingmock "github.com/cosmos/ibc-go/v3/testing/mock" | ||
tmtypes "github.com/tendermint/tendermint/types" | ||
) | ||
|
||
func (suite *TendermintTestSuite) TestCheckHeaderAndUpdateState() { |
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.
I guess we can remove this test function after we get these PRs in! :)
Just a note for a follow up
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.
We need to get the Revision
stuff settled first. I've left the test cases for that in this test fn for now.
revisionHeight := int64(height.RevisionHeight) | ||
|
||
// create modified heights to use for test-cases | ||
altVal := tmtypes.NewValidator(altPubKey, revisionHeight) |
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.
Isn't the second argument supposed to be voting power?
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.
yes. I'd remove revisionHeight
and replace with 100
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.
good catch. This was leftover from the previous test
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.
Excellent work! Just a few test cases that need fixing
revisionHeight := int64(height.RevisionHeight) | ||
|
||
// create modified heights to use for test-cases | ||
altVal := tmtypes.NewValidator(altPubKey, revisionHeight) |
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.
yes. I'd remove revisionHeight
and replace with 100
Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com>
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.
Wahoo! :)
* refactor: move misbehaviour validation into verifyMisbehaviour function * begin writing misbehaviour tests * fix misbehaviour test * continue adding misbehaviour test cases * add more test cases to verifyMisbehaviour test * add changing validator set tests * finish rest of tests except revision height testing * Update modules/light-clients/07-tendermint/types/misbehaviour_handle_test.go Co-authored-by: Damian Nolan <damiannolan@gmail.com> * add back misbehaviour type assertion Co-authored-by: Damian Nolan <damiannolan@gmail.com>
* refactor: Adding VerifyClientMessage helper fn to ClientState * refactor: creating verifyHeader priv fn and respective test * refactor: adding initial test cases * refactor: add more test cases * nit: move fns * remove clientState var * refactor: adding different val set test case * refactor: add test case for header with next height and diff validator set * refactor: adding remaining test cases * chore: uncomment previous tests: * fix: chainA -> chainB * chore: comment * refactor: remove consState from api + fix tests * refactor: add verifyHeader to clientState * fix: incorret trusted validators for concensus state test * Update modules/light-clients/07-tendermint/types/update_test.go Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> * chore: add comment * fix: params * refactor: remove timestamp from api * refactor: switch and type * fix: remove height+1 * 02-client refactor: add tests for verifyMisbehaviour (cosmos#1166) * refactor: move misbehaviour validation into verifyMisbehaviour function * begin writing misbehaviour tests * fix misbehaviour test * continue adding misbehaviour test cases * add more test cases to verifyMisbehaviour test * add changing validator set tests * finish rest of tests except revision height testing * Update modules/light-clients/07-tendermint/types/misbehaviour_handle_test.go Co-authored-by: Damian Nolan <damiannolan@gmail.com> * add back misbehaviour type assertion Co-authored-by: Damian Nolan <damiannolan@gmail.com> Co-authored-by: colin axnér <25233464+colin-axner@users.noreply.github.com> Co-authored-by: Damian Nolan <damiannolan@gmail.com>
<!-- Please read and fill out this form before submitting your PR. Please make sure you have reviewed our contributors guide before submitting your first PR. --> ## Overview Closes: cosmos#1119 <!-- Please provide an explanation of the PR, including the appropriate context, background, goal, and rationale. If there is an issue with this information, please provide a tl;dr and link the issue. --> ## Checklist <!-- Please complete the checklist to ensure that the PR is ready to be reviewed. IMPORTANT: PRs should be left in Draft until the below checklist is completed. --> - [ ] New and updated code has appropriate documentation - [ ] New and updated code has new and/or updated testing - [ ] Required CI checks are passing - [ ] Visual proof for any user facing features like CLI or documentation updates - [ ] Linked issues closed with keywords
Description
This PR focuses on refactoring the
CheckHeaderAndUpdateState
tests into a separateVerifyHeader
&VerifyMisbehavior
test suite. The bulk of the work has involved rewiring the test cases to take advantage of the latest ibctesting library capabilities.The test cases for verifying headers with different
Revision numbers
have been left in theTestCheckHeaderAndUpdateState
fn as the refactoring is blocked by this PR.checkValidity
toVerifyClientMessage
and exposing onClientState
VerifyClientMessage
now validates a Header or a MisbehaviourVerifyClientMessage
in bothCheckMisbehaviourAndUpdateState
&CheckHeaderAndUpdateState
partially closes: #879
Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.
docs/
) or specification (x/<module>/spec/
)godoc
comments.Unreleased
section inCHANGELOG.md
Files changed
in the Github PR explorerCodecov Report
in the comment section below once CI passes