Fix assert_expected_events macro in xcm_emulator #4306
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR aims to fix
assert_expected_events
by only settingmeet_conditions
variable when we detect a matching event and have evaluated all conditions specified by user. This fixes an issue whereassert_expected_events
will not panic in case our event is not the last event in theChain::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 eventuser_event
we declared in thevec!
along with conditions, it does following:match_conditions
variable with initial value of true.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 matchesuser_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.
meet_conditions
isfalse
and we received the event, it pushes an error string inmessage
vector.