Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

Improved election pallet testing #12327

Merged
merged 22 commits into from
Oct 4, 2022

Conversation

Szegoo
Copy link
Contributor

@Szegoo Szegoo commented Sep 22, 2022

Closes: #12184

  • Replaced some roll_to(25) with roll_to_unsigned
  • Added an extra check for events at the end of each test.
  • Replaced some roll_to(15) with roll_to_signed
  • Make sure the emitted events are correct.

NOTE: I did go through the event assertions to see if the emitted events are correct and it seems like they are to me.

Polkadot address: 126X27SbhrV19mBFawys3ovkyBS87SGfYwtwa8J2FjHrtbmA

@Szegoo
Copy link
Contributor Author

Szegoo commented Sep 23, 2022

@kianenigma PTAL.

@kianenigma kianenigma added A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit. labels Sep 24, 2022
Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

Looks mostly good, some small changes needed.

Copy link
Contributor

@kianenigma kianenigma left a comment

Choose a reason for hiding this comment

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

Would like to see events in other tests as well, namely at least one that finished with compute: Signed (signed.rs)

@Szegoo Szegoo requested a review from kianenigma October 3, 2022 10:57
@Szegoo
Copy link
Contributor Author

Szegoo commented Oct 3, 2022

Accidentally removed the review request for @ruseinov and @Ank4n :/

@Ank4n Ank4n requested review from ruseinov and Ank4n October 3, 2022 11:18
@@ -1879,7 +1879,7 @@ mod tests {
assert!(MultiPhase::snapshot().is_some());
assert_eq!(MultiPhase::round(), 1);

roll_to(25);
roll_to_unsigned();
Copy link
Contributor

@Ank4n Ank4n Oct 3, 2022

Choose a reason for hiding this comment

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

Referring to line 1877.

I think if we are using this pattern then we should not use the exact block numbers explicitly in the code anymore.
What I mean is, the test should read something like this

roll_to_signed();
some_assertions();

roll_by(9); // instead of roll_to(24), go forward by 9 blocks
assertions_phase_still_signed();

roll_to_unsigned();
some_assertions();

My reasoning for this is, if we still have to keep track of block numbers, it defeats the purpose of using the pattern roll_to_event()

Since we are actively moving forward till a certain phase is reached, we probably don't need this assertions at block 24 anyway. If there is a logical assertion needed here, may be it could be done a bit differently. For example, block_unsigned_phase - block_signed_phase == 10

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

The goal is to have as much "separation of concerns" as possible. There is one tests somewhere in there that checks roll_to(x) manually (called phase_rotation_works). All other tests should spend the minimum amount of mental effort to deal with phase related stuff, so I would stick to roll_to_signed and roll_to_unsigned for the sake of simplicity.

Copy link
Contributor

@Ank4n Ank4n Oct 4, 2022

Choose a reason for hiding this comment

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

I am agreeing with the pattern. I agree we can keep manual roll over for this test. There are still few more roll_to() checks that I think we can get rid of.

@kianenigma
Copy link
Contributor

/tip medium

@substrate-tip-bot
Copy link

@kianenigma A medium tip was successfully submitted for Szegoo (126X27SbhrV19mBFawys3ovkyBS87SGfYwtwa8J2FjHrtbmA on polkadot).

https://polkadot.js.org/apps/?rpc=wss%3A%2F%2Frpc.polkadot.io#/treasury/tips tip

@kianenigma
Copy link
Contributor

PS: https://github.com/polkadot-fellows/manifesto

Copy link
Contributor

@Ank4n Ank4n left a comment

Choose a reason for hiding this comment

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

LGTM! Nice work. :)

@Ank4n
Copy link
Contributor

Ank4n commented Oct 4, 2022

bot rebase

@paritytech-processbot
Copy link

Rebased

@Ank4n
Copy link
Contributor

Ank4n commented Oct 4, 2022

bot merge

@paritytech-processbot paritytech-processbot bot merged commit 241b0d0 into paritytech:master Oct 4, 2022
ordian added a commit that referenced this pull request Oct 5, 2022
* master: (42 commits)
  Adapt `pallet-contracts` to WeightV2 (#12421)
  Improved election pallet testing (#12327)
  Bump prost to 0.11+ (#12419)
  Use saturating add for alliance::disband witness data (#12418)
  [Fix] Rename VoterBagsList -> VoterList to match pdot (#12416)
  client/beefy: small code improvements (#12414)
  BEEFY: Simplify hashing for pallet-beefy-mmr (#12393)
  Add @koute to `docs/CODEOWNERS` and update stale paths (#12408)
  docs/CODEOWNERS: add @acatangiu as MMR owner (#12406)
  Remove unnecessary Clone trait bounds on CountedStorageMap (#12402)
  Fix `Weight::is_zero` (#12396)
  Beefy on-demand justifications as a custom RequestResponse protocol (#12124)
  Remove contracts RPCs (#12358)
  pallet-mmr: generate historical proofs (#12324)
  unsafe_pruning flag removed (#12385)
  Carry over where clauses defined in Config to Call and Hook (#12388)
  Properly set the max proof size weight on defaults and tests (#12383)
  BEEFY: impl TypeInfo for SignedCommitment (#12382)
  bounding staking: `BoundedElectionProvider` trait (#12362)
  New Pallet: Root offences (#11943)
  ...
ark0f pushed a commit to gear-tech/substrate that referenced this pull request Feb 27, 2023
* Improved election pallet testing

* fmt

* remove comment

* more checks

* fixes in logic

* roll_to_signed

* switch to roll_to_signed

* Update frame/election-provider-multi-phase/src/mock.rs

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>

* remove useless checks

* remove warning

* add checks to signed.rs

* add some checks to unsigned.rs

* fmt

* use roll_to_signed and roll_to_unsigned

* remove nonsense

* remove even more nonsense

* fix

* fix

* remove useless checks

Co-authored-by: Kian Paimani <5588131+kianenigma@users.noreply.github.com>
Co-authored-by: parity-processbot <>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A0-please_review Pull request needs code review. B0-silent Changes should not be mentioned in any release notes C1-low PR touches the given topic and has a low impact on builders. D2-notlive 💤 PR contains changes in a runtime directory that is not deployed to a chain that requires an audit.
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Improve election pallet testing setup and checks
3 participants