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

tests(app): ✨ add integration test coverage for undelegation #4110

Merged

Conversation

cratelyn
Copy link
Contributor

@cratelyn cratelyn commented Mar 26, 2024

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.

@cratelyn cratelyn added the A-mock-consensus Area: Relates to the mock consensus engine label Mar 26, 2024
@cratelyn cratelyn added this to the Sprint 3 milestone Mar 26, 2024
@cratelyn cratelyn self-assigned this Mar 26, 2024
@cratelyn cratelyn changed the title tests(app): ✨ add an integration test for undelegation tests(app): ✨ add integration tests for undelegation Mar 26, 2024
@cratelyn cratelyn force-pushed the kate/mock-consensus-staking-claim-undelegation-tokens-pt-ii branch from 3f97710 to 9604f01 Compare March 27, 2024 01:26
@cratelyn cratelyn force-pushed the kate/mock-consensus-staking-claim-undelegation-tokens-pt-ii branch from 9604f01 to 3790595 Compare March 27, 2024 01:51
cratelyn added a commit that referenced this pull request Mar 27, 2024
i found myself rewriting `client.notes.values().filter(|_| ..)`
repeatedly. this helps test cases grab notes of a particular asset type.
@cratelyn cratelyn force-pushed the kate/mock-consensus-staking-claim-undelegation-tokens-pt-ii branch from 3790595 to b083423 Compare March 27, 2024 16:17
@cratelyn cratelyn force-pushed the kate/mock-consensus-staking-claim-undelegation-tokens-pt-ii branch from b083423 to 79f08dd Compare March 27, 2024 16:50
@cratelyn cratelyn force-pushed the kate/mock-consensus-staking-claim-undelegation-tokens-pt-ii branch from 79f08dd to 05c307a Compare March 27, 2024 16:53
@cratelyn cratelyn force-pushed the kate/mock-consensus-staking-claim-undelegation-tokens-pt-ii branch from 05c307a to 63cf0d5 Compare March 27, 2024 16:54
@cratelyn cratelyn changed the title tests(app): ✨ add integration tests for undelegation tests(app): ✨ add integration test coverage for undelegation Mar 27, 2024
@cratelyn cratelyn marked this pull request as ready for review March 27, 2024 17:10
@cratelyn cratelyn requested a review from erwanor March 27, 2024 17:17
Copy link
Member

@erwanor erwanor left a 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.
Copy link
Member

@hdevalence hdevalence left a 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

Comment on lines 49 to 57
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<()> {
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

b513ddb

i've reverted this in b513ddb

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'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.
@cratelyn cratelyn force-pushed the kate/mock-consensus-staking-claim-undelegation-tokens-pt-ii branch from 7bcd43c to b513ddb Compare March 28, 2024 16:13
@cratelyn cratelyn requested a review from hdevalence March 28, 2024 18:24
@cratelyn cratelyn dismissed hdevalence’s stale review April 1, 2024 13:46

changes requested were made/reverted in b513ddb

@cratelyn cratelyn merged commit ca16ab1 into main Apr 1, 2024
7 checks passed
@cratelyn cratelyn deleted the kate/mock-consensus-staking-claim-undelegation-tokens-pt-ii branch April 1, 2024 13:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-mock-consensus Area: Relates to the mock consensus engine
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants