galacticcouncil / galacticcouncil/hydration-node

Improve event assertions

Open
#1,002 0 comments 0 reactions 0 assignees View on GitHub
area/runtime priority/medium type/change-request
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.