-
Notifications
You must be signed in to change notification settings - Fork 15
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
test: Solana's delta-based-ingress electoral System #5445
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5445 +/- ##
=====================================
- Coverage 72% 71% -0%
=====================================
Files 494 494
Lines 87706 87627 -79
Branches 87706 87627 -79
=====================================
- Hits 62712 62652 -60
+ Misses 22383 22364 -19
Partials 2611 2611 ☔ View full report in Codecov by Sentry. |
state-chain/pallets/cf-elections/src/electoral_systems/tests/delta_based_ingress.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/tests/delta_based_ingress.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/blockchain/delta_based_ingress.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/tests/delta_based_ingress.rs
Outdated
Show resolved
Hide resolved
details.asset, | ||
ingress_total.amount - previous_amount, | ||
); | ||
log::warn!("Deposit channels on Solana chain has reverted! Account: {:?}, Asset: {:?}, amount: {:?}", account, details.asset, previous_amount - ingress_total.amount); |
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 think it's better to provide the previous and ingress total amounts separately here, easier to debug, we can do the subtraction ourselves if required
state-chain/pallets/cf-elections/src/electoral_systems/mocks/access.rs
Outdated
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/mocks/access.rs
Outdated
Show resolved
Hide resolved
(1u32, Asset::Sol, 1_000u64), | ||
(2u32, Asset::SolUsdc, 2_000u64), |
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.
Could we change these values on the channel_state_final
slightly? at the moment it looks like it's just duplicating them, which isn't actually the case, it's dependent on the channel_state_final
, which by coincidence makes it look duplicated - just makes it easier to tell that the test is water-tight
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.
Done
most_recent: None, | ||
new: channel_state_ingressed().to_state(), | ||
}) | ||
.test_on_finalize(&699, |_| (), vec![Check::assert_unchanged()]) |
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.
this is quite confusing on first read, 699 is a magic value here. ideally it's related to the local test state. So we can say "channel.block_number - 1", that way it's clear exactly what the test is trying to convey
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.
This could probably be made a lot easier by having the utility functions a bit flatter, i.e. rather than on the DepositChannels
struct. So for example,
We define at the top of the test:
let first_channel = DepositChannel { ... };
let initial_channels = vec![first_channel, ...];
// then here we can do:
.force_consensus_update(ConsensusStatus::Gained {
most_recent: None,
new: channels_to_state(initial_channels),
})
// NB: Now there's no magic number, it's clear what case we're testing
.test_on_finalize(&first_channel.block_number - 1)
So we have a flat channels_to_state
which allows us to more easily construct the test conditions locally, so the assertions aren't dependent on global state.
The same applies to the other tests too, for things like expected ingress value, they look like magic numbers.
state-chain/pallets/cf-elections/src/electoral_systems/blockchain/delta_based_ingress.rs
Show resolved
Hide resolved
state-chain/pallets/cf-elections/src/electoral_systems/tests/delta_based_ingress.rs
Show resolved
Hide resolved
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.
Nice tests 🚀 thanks for knocking this one off 🫡
let deposit_channel_pending_updated_block = DepositChannel { | ||
account: 1u32, | ||
asset: Asset::Sol, | ||
total_ingressed: 1_000u64, | ||
block_number: 499u64, | ||
close_block: 1_000u64, | ||
}; | ||
let deposit_channel_pending_updated_amount = DepositChannel { | ||
account: 1u32, | ||
asset: Asset::Sol, | ||
total_ingressed: 999u64, | ||
block_number: 500u64, | ||
close_block: 1_000u64, | ||
}; |
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.
nit: would switch the order of these two definitions so it matches the test flow
@@ -221,6 +221,9 @@ register_checks! { | |||
ended_at_state(_pre, post, election_state: BTreeMap<AccountId, ChannelTotalIngressedFor<MockIngressSink>>) { | |||
assert_eq!(*post.election_state.get(post.election_identifiers[0].unique_monotonic()).unwrap(), election_state, "Expected election state incorrect."); | |||
}, | |||
ended_at_empty_state(_pre, post) { |
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.
👍 nice additional safety check
Improved the mock system for the tests. Fixed a bug where on revert, on_finalize will cause underflow panic Deposit an event on ingress reverts
Improved test and the use of Checks Added tests for recycled deposit channels.
…ption. `get` still returns Option. `set` still takes Option, removes the value if None is passed in. State map now returns decoded state map instead of raw encoded. Adjusted function names accordingly.
bd973e5
to
ff2e596
Compare
Pull Request
Closes: PRO-1581
Checklist
Please conduct a thorough self-review before opening the PR.
Summary
Added unit tests for the delta based ingress electoral system.
Improved the mock system for the tests.
Fixed a bug where on revert, on_finalize will cause underflow panic
Log a warning on ingress reverts