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

fix(evmutil): register MsgConvertCosmosCoinToERC20 on amino #1599

Merged
merged 4 commits into from
May 27, 2023

Conversation

rhuairahrighairidh
Copy link
Member

@rhuairahrighairidh rhuairahrighairidh commented May 25, 2023

Description

Noticed the new MsgConvertCosmosCoinToERC20 wasn't registered on amino. So added a test to help catch this in the future by checking all msgs registered on the proto codec are on amino. It's not perfect, we should ideally check msg.GetSignBytes returns properly encoded msgs (it uses a local amino, not the app's amino). But it did catch a pre-existing issue where we hadn't setup the registration in module.go.

Also added this to the list of gotchas with link to explainer. It's unlikely to cause issues but can in very particular cases mess with tx signing.

Checklist

  • Changelog has been updated as necessary.

@@ -63,6 +69,64 @@ func TestExport(t *testing.T) {
assert.Len(t, exportedApp.Validators, 1) // no validators set in default genesis
}

// TestLegacyMsgAreAminoRegistered checks if all known msg types are registered on the app's amino codec.
// It doesn't check if they are registered on the module codecs used for signature checking.
Copy link
Contributor

Choose a reason for hiding this comment

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

is refers to the ModuleCdc right?

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, I was thinking we could add tests to the modules to cover them. But if we replace them with a global codec as they've done in v0.46 (cosmos/cosmos-sdk#11240) we could run this test on that global codec.

Copy link
Contributor

@DracoLi DracoLi left a comment

Choose a reason for hiding this comment

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

great test addition

Copy link
Member

@pirtleshell pirtleshell left a comment

Choose a reason for hiding this comment

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

i register this type in the upcoming PR with the handler implementation. 😄 maybe that's unorthodox!? but this is a great test guaranteeing we're registering messages as soon as they're introduced.

}

// Check the msg is registered in amino by checking a repeat registration call panics.
panicValue, ok := catchPanic(func() {
Copy link
Member

@pirtleshell pirtleshell May 25, 2023

Choose a reason for hiding this comment

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

super clever way to check the messages are registered 👍 🥇

nit: you can probably use require.PanicsWithValue (or PanicsWithError) to test this.

Copy link
Member Author

Choose a reason for hiding this comment

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

thanks, I started with PanicsWithValue/Error but the panic returns an error msg containing the go type name of the msg (eg "types.MsgPlaceBid"). I couldn't think of a way to reconstruct it to do the comparison.


for i, msgName := range msgProtoNames {
// skip external unregistered msgs
if msgName == sdk.MsgTypeURL(&evmtypes.MsgEthereumTx{}) ||
Copy link
Member

Choose a reason for hiding this comment

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

i'd love if this was a list called unregisteredMsgs or something similar

Copy link
Member Author

Choose a reason for hiding this comment

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

agreed, it's a bit confusing, changed to protoRegisteredMsgs as at this point it's unclear if these msgs are all registered on amino or not

@rhuairahrighairidh rhuairahrighairidh merged commit 1459170 into master May 27, 2023
@rhuairahrighairidh rhuairahrighairidh deleted the ro-add-amino-registration-test branch May 27, 2023 02:06
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.

5 participants