-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Refactor x/staking Validation and Delegation tests based on MsgCreateValidator.Pubkey type change. #7526
Conversation
a5978f0
to
e7dca72
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.
I love PRs that have a negative line diff, so 👍 for now. But a lot of tests still need to be fixed, will review again once that's the case.
// PackAny is a checked and safe version of UnsafePackAny. It assures that | ||
// `x` implements the proto.Message interface and uses it to serialize `x`. | ||
// TODO: should be moved away: https://github.com/cosmos/cosmos-sdk/issues/7479 | ||
func PackAny(x interface{}) (*Any, error) { |
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.
func PackAny(x interface{}) (*Any, error) { | |
func LegacyPackAny(x interface{}) (*Any, error) { |
The name should clearly indicate that this is only for legacy code. I would even add a deprecated comment.
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've market this function as deprecated.
I must say that I'm using that the |
This Changeset introduces set of improvements for writing tests. The idea is to create a testing subpackage which will provide functions to make tests more dev-friendly and wrap higher level use-cases. Here is a show-up of of creating a service for staking module for tests. This PR also changes the `x/staking/types.MsgCreateValidator.Pubkey` from string to types.Any. This change motivated the other change to show the pattern I'm describing here.
312d579
to
1a29257
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.
You need to implement UnpackInterfaces
method on MsgCreateValidator
since it now contains an Any
.
EDIT: done in 11924dd
Codecov Report
@@ Coverage Diff @@
## master #7526 +/- ##
==========================================
- Coverage 54.15% 54.15% -0.01%
==========================================
Files 606 606
Lines 38164 38187 +23
==========================================
+ Hits 20669 20680 +11
- Misses 15399 15410 +11
- Partials 2096 2097 +1 |
There was one remaining failing test which I just fixed, so I think all tests should be passing now. I left out migrating I added this to the description of #7477 so we don't forget. |
Thank you for helping with fixing tests. |
There are few other things failing, but the crux is solved (Protobuf decoding) 💪 |
I fixed the remaining 2 tests and renamed |
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.
utACK
x/staking/types/msg_test.go
Outdated
// description := Description{} | ||
// commission1 := NewCommissionRates(sdk.ZeroDec(), sdk.ZeroDec(), sdk.ZeroDec()) | ||
// msg, err := NewMsgCreateValidator(valAddr1, pk1, coinPos, description, commission1, sdk.OneInt()) | ||
// require.NoError(t, err) |
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.
let's not leave this uncommented
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.
Ah, thanks for spotting.
} | ||
|
||
default: | ||
// We only allow ed25519 pubkeys to be bech32-ed right now. |
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 only allow ed25519 pubkeys to be bech32-ed right now. |
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'm removing this in other PR.
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.
Looks good to me overall, although I believe new testslashing
and teststaking
folders names are a bit redundant given that they're already in x/slashing
and x/staking
resp. Why not using a more concise name?
I was already explaning that in few places. The problem is that we want to use very generic names (helper, test, common.... 😦 ) but we put there context specific code (eg, things related to given module, or codec). This causes name clashes and abuses package aliases.
TL;DR: cointinuing this practice is rather diminishing the quality of code, DevX and tooling support. |
…Validator.Pubkey type change. (#7526) * testing: refactore Validation and Delegation handling of x/staking This Changeset introduces set of improvements for writing tests. The idea is to create a testing subpackage which will provide functions to make tests more dev-friendly and wrap higher level use-cases. Here is a show-up of of creating a service for staking module for tests. This PR also changes the `x/staking/types.MsgCreateValidator.Pubkey` from string to types.Any. This change motivated the other change to show the pattern I'm describing here. * add validator checks * type change fixes * use deprecated * adding test slashing * new network comment update * working on tests * Fix TestMsgPkDecode test * Add UnpackInterfaces to MsgCreateValidator * Fix tests * Convert bech32 pubkey to proto * Fix test * fix v039/migrate_test/TestMigrate * fix tests * testslashing: rename Service to Helper * file rename * update TestMsgDecode Co-authored-by: blushi <marie.gauthier63@gmail.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Cory Levinson <cjlevinson@gmail.com>
…Validator.Pubkey type change. (cosmos#7526) * testing: refactore Validation and Delegation handling of x/staking This Changeset introduces set of improvements for writing tests. The idea is to create a testing subpackage which will provide functions to make tests more dev-friendly and wrap higher level use-cases. Here is a show-up of of creating a service for staking module for tests. This PR also changes the `x/staking/types.MsgCreateValidator.Pubkey` from string to types.Any. This change motivated the other change to show the pattern I'm describing here. * add validator checks * type change fixes * use deprecated * adding test slashing * new network comment update * working on tests * Fix TestMsgPkDecode test * Add UnpackInterfaces to MsgCreateValidator * Fix tests * Convert bech32 pubkey to proto * Fix test * fix v039/migrate_test/TestMigrate * fix tests * testslashing: rename Service to Helper * file rename * update TestMsgDecode Co-authored-by: blushi <marie.gauthier63@gmail.com> Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com> Co-authored-by: Cory Levinson <cjlevinson@gmail.com>
This Changeset introduces set of improvements for writing tests based on
MsgCreateValidator.Pubkey
type change fromstring
toAny
The changes here are driven by the tests updates related to message creation
in x/staking.
Motivation
Lot of tests in the SDK don't have any abstraction. This makes tests hard to maintain. Common symptoms are:
As presented in this case, a small change in the code (type change and introducing one return error) can lead to many changes in the tests.
Solution
The idea is to create a testing subpackage which will provide functions
to make tests more dev-friendly and wrap higher level use-cases.
Here is a show-up of of creating a testing service for staking module. That service encapsulates common logic, handles the error checks.
Related to
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