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

chore: adding initial localhost client testing #3085

Merged
merged 8 commits into from
Feb 2, 2023

Conversation

damiannolan
Copy link
Contributor

@damiannolan damiannolan commented Jan 30, 2023

Description

  • Adds unit testing for 09-localhost client
  • Fix verify membership/non-membership key paths to omit prefix

closes: #XXXX

Commit Message / Changelog Entry

chore: adding initial localhost client testing

see the guidelines for commit messages. (view raw markdown for examples)


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 and Go style guide.
  • Wrote unit and integration tests.
  • Updated relevant documentation (docs/) or specification (x/<module>/spec/).
  • Added relevant godoc comments.
  • Provide a commit message to be used for the changelog entry in the PR description for review.
  • Re-reviewed Files changed in the Github PR explorer.
  • Review Codecov Report in the comment section below once CI passes.

Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

Looking good so far, I'll take a more in depth look at the test cases once the PR is marked ready for review!

Comment on lines 94 to 104
merklePath, ok := path.(commitmenttypes.MerklePath)
if !ok {
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path)
}

// todo: revisit this
if len(merklePath.GetKeyPath()) != 2 && merklePath.KeyPath[0] != exported.StoreKey {
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path)
}

bz := store.Get([]byte(merklePath.KeyPath[1]))
Copy link
Contributor

Choose a reason for hiding this comment

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

could be a good candidate for an unexported function.

func readPathBytes(path exported.Path,) ([]byte, error) {...}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think its more or less ok as is, given its a relatively small method compared to solomachine or tm

Comment on lines 131 to 141
merklePath, ok := path.(commitmenttypes.MerklePath)
if !ok {
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path)
}

// todo: revisit this
if len(merklePath.GetKeyPath()) != 2 && merklePath.KeyPath[0] != exported.StoreKey {
return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path)
}

bz := store.Get([]byte(merklePath.KeyPath[1]))
Copy link
Contributor

Choose a reason for hiding this comment

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

could use the function I suggested above here too

@damiannolan damiannolan marked this pull request as ready for review February 1, 2023 13:47
@damiannolan
Copy link
Contributor Author

Created #3099 to address error returns in a follow-up PR.

@@ -23,11 +24,6 @@ func NewClientState(chainID string, height clienttypes.Height) exported.ClientSt
}
}

// GetChainID returns the client state chain ID.
func (cs ClientState) GetChainID() string {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

seems unnecessary and unused

return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path)
}

bz := store.Get([]byte(merklePath.KeyPath[1]))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

merklePath.KeyPath is a []string where the first element of the key path "/ibc/" (the prefix that is applied here), but here we pass the core IBC store for verification, so we can trim the prefix or use keyPath[1] (i.e. the key path without the prefix)

Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we should include this reasoning in a comment alongside these checks.

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 call, done!

Copy link
Member

Choose a reason for hiding this comment

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

Should we verify that the store is prefixed by KeyPath[0]? I don't know if there's an easy way to do that

Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

Really nice work with these tests, and nice job catching the ibc prefix issue! 👍

return sdkerrors.Wrapf(clienttypes.ErrFailedChannelStateVerification, "todo: update error -- not found for path %s", path)
}

bz := store.Get([]byte(merklePath.KeyPath[1]))
Copy link
Contributor

Choose a reason for hiding this comment

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

I feel like we should include this reasoning in a comment alongside these checks.

Copy link
Contributor

@chatton chatton left a comment

Choose a reason for hiding this comment

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

ack changes 👍

@@ -153,8 +169,10 @@ func (cs ClientState) UpdateStateOnMisbehaviour(_ sdk.Context, _ codec.BinaryCod
func (cs ClientState) UpdateState(ctx sdk.Context, cdc codec.BinaryCodec, clientStore sdk.KVStore, clientMsg exported.ClientMessage) []exported.Height {
height := clienttypes.GetSelfHeight(ctx)

clientState := NewClientState(ctx.ChainID(), height)
clientStore.Set([]byte(host.KeyClientState), clienttypes.MustMarshalClientState(cdc, clientState))
cs.ChainId = ctx.ChainID()
Copy link
Member

Choose a reason for hiding this comment

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

Maybe should be a separate PR. But do we need the chainID if the function got removed above

@damiannolan damiannolan merged commit 72fcd65 into 09-localhost Feb 2, 2023
@damiannolan damiannolan deleted the damian/localhost-unit-testing branch February 2, 2023 14:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done 🥳
Development

Successfully merging this pull request may close these issues.

3 participants