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

Improve event assertions #1002

Open
dmoka opened this issue Jan 24, 2025 · 0 comments
Open

Improve event assertions #1002

dmoka opened this issue Jan 24, 2025 · 0 comments

Comments

@dmoka
Copy link
Contributor

dmoka commented Jan 24, 2025

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");
        }
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant