-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Labels
enhancementNew feature or requestNew feature or request
Description
What is the feature you would like to see?
The proposed syntax is:
contract.assert_emitted(event: Event).times(number_of_times: u32);
Possible values for number_of_times
:
0
- assert that the event was never emitted <-- (optional) could create a new extension likecontract.assert_never_emitted
that does the same1+
- assert that event was emitted this exact number of times.
To give a dumb, and yet possible example where this would be useful would be a Vault that can execute multiple pending withdrawal requests in one transaction, collecting fees for the Vault owner and emitting something like FeeCollected
for each withdrawal.
#[test]
fn multiple_withdrawals_work(
owner: Account,
alice: Account,
bob: Account
) {
let vault = Contract::<Vault>::new();
// set up the vault
// alice and bob invest in the vault
// alice and bob initiate withdrawal requests
vault.withdraw_pending().expect("ok");
// Assert emitted exactly twice with macro
assert_emitted!(vault, FeeCollected { }, 2);
// or as a contract extension
vault.assert_emitted(FeeCollected { }).times(2);
}
Contribution Guidelines
- I agree to follow this project's Contribution GuidelinesTo pick up a draggable item, press the space bar. While dragging, use the arrow keys to move the item. Press space again to drop the item in its new position, or press escape to cancel.
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity