-
Notifications
You must be signed in to change notification settings - Fork 312
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
tests(app): ✨ add integration test coverage for undelegation #4110
tests(app): ✨ add integration test coverage for undelegation #4110
Conversation
3f97710
to
9604f01
Compare
9604f01
to
3790595
Compare
i found myself rewriting `client.notes.values().filter(|_| ..)` repeatedly. this helps test cases grab notes of a particular asset type.
3790595
to
b083423
Compare
b083423
to
79f08dd
Compare
79f08dd
to
05c307a
Compare
05c307a
to
63cf0d5
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.
+1 on structure / scope, added some comments
@erwanor notes: > Just two ideas, it would be good to check: > - the rate at which delegation <> undelegation token gets converted > (by dividing the amounts and comparing it against the stated > validator rate) > > - the rate at which undelegation <> staking token gets converted (so > that later we can pull that logic to check that slashing events > effect that rate correctly) as a step in that direction, i've captured the amounts from each note, and the validator rate. we will investigate this more tomorrow. ``` [crates/core/app/tests/app_can_undelegate_from_a_validator.rs:379:9] staking_note_amount = 1000000000 [crates/core/app/tests/app_can_undelegate_from_a_validator.rs:380:9] staking_note_2_amount = 1000000000 [crates/core/app/tests/app_can_undelegate_from_a_validator.rs:381:9] delegate_note_amount = 1000000000 [crates/core/app/tests/app_can_undelegate_from_a_validator.rs:382:9] undelegate_note_amount = 1001000000000 [crates/core/app/tests/app_can_undelegate_from_a_validator.rs:384:9] staking_note_amount / delegate_note_amount = 1 [crates/core/app/tests/app_can_undelegate_from_a_validator.rs:385:9] delegate_note_amount / undelegate_note_amount = 0 [crates/core/app/tests/app_can_undelegate_from_a_validator.rs:386:9] staking_note_2_amount / staking_note_amount = 1 [crates/core/app/tests/app_can_undelegate_from_a_validator.rs:392:9] validator_rate = Some( RateData { identity_key: penumbravalid1lg6ede74e4jsrnee8cvf9d9xe5n2ps2na8pga8jvpcqp3kpe5yrsvla0pu, validator_reward_rate: 49974986, validator_exchange_rate: 300100244731, }, ) test app_can_undelegate_from_a_validator ... ok ```
#4110 (comment) use `compute_unbonding_height` instead of manually calculating the unbonding height.
see: #4110 (comment) emitting tracing events makes the body of `check_and_execute` more verbose. in an effort to help maintain the pleasant quality of `anyhow::ensure` listing invariants we care about, this explores outlining that logic into helper methods of `Undelegate`. this is in some respects a little "louder", but makes the `check_and_execute` a succinct list of calls: ```rust // # Invariant: the undelegation must have been prepared for the current epoch. self.check_that_undelegate_was_prepared_for_current_epoch(&state) .await?; // # Invariant: The unbonded amount must be correctly computed. self.check_that_unbonded_amount_is_correctly_computed(&state) .await?; ``` NB: git doesn't handle this sort of code motion with grace. view this diff via side-by-side view, if possible.
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 should not restructure the ActionHandler impls
impl Undelegate { | ||
/// Returns `Ok(())` if this delegation is from the current epoch. | ||
/// | ||
/// This ensures that the unbonding delay is enforced correctly. Additionally, it helps us | ||
/// provide a more helpful error message if an epoch boundary was crossed. | ||
async fn check_that_undelegate_was_prepared_for_current_epoch( | ||
&self, | ||
state: &impl StateWrite, | ||
) -> Result<()> { |
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 should not structure the code this way.
It spreads the consensus critical part of the ActionHandler out into different places, rather than than having it in one place where it can be inspected locally.
And it leaks the internals of that implementation into a public interface, with methods that may or may not appear depending on compile settings, because the Undelegate type must be independent of the component implementation.
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.
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 going to mark this as resolved, now that this change has been reverted.
This reverts commit 232ee82. #4110 (review) #4110 (comment) > We should not structure the code this way. > > It spreads the consensus critical part of the ActionHandler out into > different places, rather than than having it in one place where it can > be inspected locally. > > And it leaks the internals of that implementation into a public > interface, with methods that may or may not appear depending on > compile settings, because the Undelegate type must be independent of > the component implementation.
7bcd43c
to
b513ddb
Compare
changes requested were made/reverted in b513ddb
this introduces additional test coverage for the staking component, examining the mock client's notes during delegation, the unbonding period, and after claiming an undelegation.
ActionPlan: From<UndelegateClaimPlan>
#4115