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

Fix assert_expected_events macro in xcm_emulator #4306

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ParthDesai
Copy link
Contributor

Description

This PR aims to fix assert_expected_events by only setting meet_conditions variable when we detect a matching event and have evaluated all conditions specified by user. This fixes an issue where assert_expected_events will not panic in case our event is not the last event in the Chain::System::events() vector.

Context

assert_expected_events first fetch events emitted by runtime lets call it system_events ; It also intializes message variable as vector of string that contains the panic message. For every event user_event we declared in the vec! along with conditions, it does following:

  1. Declare match_conditions variable with initial value of true.
  2. Start for loop to iterate through system_events. For each system event, it does following in the for loop block:
    a. re-initialize match_conditions to true // <-- This is the bug, it simply over-writes past conditions match failures without checking current event matches user_event and also without evaluating any conditions.
    b. if match is found, it tries to check if conditions are satisfied, if any one of the condition is not satisfied meet_conditions variable is set to false.
  3. If meet_conditions is false and we received the event, it pushes an error string in message vector.

@ParthDesai ParthDesai force-pushed the fix-assert-expected-events-macro branch from cbfaf9c to 8e12b0b Compare April 26, 2024 09:50
@paritytech-cicd-pr
Copy link

The CI pipeline was cancelled due to failure one of the required jobs.
Job name: test-linux-stable 3/3
Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/6066962

@acatangiu
Copy link
Contributor

Can you add a unit-test showcasing the fixed scenario? A regression test that fails without your fix and passes with it. It will also help reviewers better understand the problem.

@ParthDesai
Copy link
Contributor Author

Can you add a unit-test showcasing the fixed scenario? A regression test that fails without your fix and passes with it. It will also help reviewers better understand the problem.

Tried to write unit test, but problem is the macro expects implementation of Chain trait and I could not find a test/mock implementation of Chain trait in which I can inject some system event and then call this macro. Can you point me to right direction here?

Copy link
Member

@liamaharon liamaharon left a comment

Choose a reason for hiding this comment

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

test? I see above review already mentioned this, taking a look

@franciscoaguirre
Copy link
Contributor

@ParthDesai It's true we don't have a special emulated chain for these types of things, it should probably go in the xcm-emulator.
You could create an emulated chain as a mock to test this, like the ones we have in cumulus/parachains/integration-tests/emulated/chains/relays/westend/src/lib.rs

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

Successfully merging this pull request may close these issues.

None yet

5 participants