galacticcouncil / galacticcouncil/hydration-node
Improve event assertions
- Dominant language
- Rust
- Stars
- 208
- Forks
- 109
- Avg merge
- 6d 3h
- Merged PRs (30d)
- 3
Description
We assert Swapped events in way too many places, leading to many failing tests once some implementation changes.
Such tests are still useful but we should heavily minimize them, or at least not asserting for specific values.
In most, relevant integration tests, we could just check the Operation stack instead of the whole Swapped event.
Some helper macros:
```
#[macro_export]
macro_rules! assert_operation_stack {
($event:expr, [$($expected:expr),*]) => {
if let pallet_broadcast::Event::Swapped { operation_stack, .. } = $event {
assert_eq!(&operation_stack[..], &[$($expected),*]);
} else {
panic!("Expected Swapped event");
}
}
}
///Used for cases when some params of operation stack types are not known in advance
#[macro_export]
macro_rules! assert_operation_stack_pattern {
($event:expr, [$($pattern:pat),*]) => {
if let pallet_broadcast::Event::Swapped { operation_stack, .. } = $event {
assert!(matches!(&operation_stack[..],
[
$($pattern),*
]
));
} else {
panic!("Expected Swapped event");
}
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.