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

02-client refactor: Adding VerifyClientMessage helper fn #1119

Merged
merged 26 commits into from
Mar 28, 2022

Conversation

seantking
Copy link
Contributor

@seantking seantking commented Mar 15, 2022

Description

This PR focuses on refactoring the CheckHeaderAndUpdateState tests into a separate VerifyHeader & 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 the TestCheckHeaderAndUpdateState fn as the refactoring is blocked by this PR.

  • Renaming checkValidity to VerifyClientMessage and exposing on ClientState
  • VerifyClientMessage now validates a Header or a Misbehaviour
  • Using VerifyClientMessage in both CheckMisbehaviourAndUpdateState & CheckHeaderAndUpdateState
  • Make private verifyHeader fn

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.

  • Targeted PR against correct branch (see CONTRIBUTING.md)
  • Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
  • Code follows the module structure standards.
  • Wrote unit and integration tests
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/)
  • Added relevant godoc comments.
  • Added a relevant changelog entry to the Unreleased section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer
  • Review Codecov Report in the comment section below once CI passes

@seantking seantking force-pushed the sean/issue#879-create-verify-helper-fn branch from 5b76483 to 70c2973 Compare March 24, 2022 07:57
@seantking seantking force-pushed the sean/issue#879-create-verify-helper-fn branch from 70c2973 to b04e491 Compare March 24, 2022 07:58
Copy link
Contributor

@colin-axner colin-axner left a comment

Choose a reason for hiding this comment

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

Great work!

modules/light-clients/07-tendermint/types/update.go Outdated Show resolved Hide resolved
modules/light-clients/07-tendermint/types/update.go Outdated Show resolved Hide resolved
modules/light-clients/07-tendermint/types/update.go Outdated Show resolved Hide resolved
modules/light-clients/07-tendermint/types/update_test.go Outdated Show resolved Hide resolved
modules/light-clients/07-tendermint/types/update_test.go Outdated Show resolved Hide resolved
modules/light-clients/07-tendermint/types/update_test.go Outdated Show resolved Hide resolved
@seantking seantking marked this pull request as ready for review March 25, 2022 15:40
Copy link
Member

@damiannolan damiannolan left a 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,
Copy link
Member

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,
Copy link
Member

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) {
Copy link
Member

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() {
Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Contributor

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

Copy link
Contributor Author

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

Copy link
Contributor

@colin-axner colin-axner left a 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

modules/light-clients/07-tendermint/types/update.go Outdated Show resolved Hide resolved
revisionHeight := int64(height.RevisionHeight)

// create modified heights to use for test-cases
altVal := tmtypes.NewValidator(altPubKey, revisionHeight)
Copy link
Contributor

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

modules/light-clients/07-tendermint/types/update_test.go Outdated Show resolved Hide resolved
modules/light-clients/07-tendermint/types/update_test.go Outdated Show resolved Hide resolved
modules/light-clients/07-tendermint/types/update_test.go Outdated Show resolved Hide resolved
Copy link
Contributor

@colin-axner colin-axner left a 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>
@seantking seantking enabled auto-merge (squash) March 28, 2022 16:16
@seantking seantking merged commit fadd9d0 into 02-client-refactor Mar 28, 2022
@seantking seantking deleted the sean/issue#879-create-verify-helper-fn branch March 28, 2022 16:24
seunlanlege pushed a commit to ComposableFi/ibc-go that referenced this pull request Aug 9, 2022
* 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>
CosmosCar pushed a commit to caelus-labs/ibc-go that referenced this pull request Nov 6, 2023
<!--
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants