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

Introduces contract demonstrating unit + e2e test event decoding. #1738

Closed
wants to merge 5 commits into from

Conversation

blairmunroakusa
Copy link

I did my best to satisfy the contributor guidelines. Please let me know if anything needs revision.

Fixed typos. (e2e -> E2E)
@blairmunroakusa
Copy link
Author

@ascjones Hey, I don't understand the reason continuous-integration/gitlab-examples-fmt fails. Do you have the cycles to help with that?

SkymanOne
SkymanOne previously approved these changes Apr 10, 2023
@@ -0,0 +1,11 @@
# Testing Events Reference Implementation

Capturing events for ink! end-to-end tests in particular is not clearly documented, nor are there clear reference implementations. This contract contains a minimalist flipflop contract that emits two different events when called. It contains both unit and e2e test modules illustrating one way to check for multiple events in both testing environments.
Copy link
Contributor

Choose a reason for hiding this comment

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

This contract contains a minimalist flipper contract that emits two different events when called. It contains both unit and e2e test modules illustrating one way to check for multiple events in both testing environments.


type Event = <TestingEventDecode as ::ink::reflect::ContractEventBase>::Type;

fn decode_events(emitted_events: Vec<EmittedEvent>) -> Vec<Event> {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is actually a very useful function to be added to e2e create directly. Can you please look into this?

Copy link
Author

Choose a reason for hiding this comment

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

To clarify, do you mean reimplement this decode_events function to work within the ink_e2e test scope? Or do you mean include this particular decode_events function as ink::env::test::decode_events? Or both?

If the former, this would be part of the followup issue regarding improving event decode to not be so awkward.

In any case, this might be something @ganesh1233456 or @alessandro-baldassarre may wish to address individually. I will see to it that the proper issues are created.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think for unit tests, we want to have something like ink::env::test::recorded_events().decode() or ink::env::test::decoded_events(). To check whether the events have been emitted, you can use something like .contains() or similar list functions.

With e2e tests it's a little bit trickier, we probably want to have something like let flip_event = flipflop_result.events.find_decoded::<FlipEvent>() or similar to automatically check whether the event has been emitted, decode it and then assert on its values.


Capturing events for ink! end-to-end tests in particular is not clearly documented, nor are there clear reference implementations. This contract contains a minimalist flipflop contract that emits two different events when called. It contains both unit and e2e test modules illustrating one way to check for multiple events in both testing environments.

The end-to-end event test/check is awkward and could certainly be improved on.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please create a follow-up issue for this?

@SkymanOne
Copy link
Contributor

Please run cargo +nightly fmt to format the code and make CI happy

@SkymanOne SkymanOne dismissed their stale review April 11, 2023 12:16

Working on new features

@SkymanOne SkymanOne marked this pull request as draft April 12, 2023 14:10
@SkymanOne
Copy link
Contributor

Converted to draft as more work to be done.

@ascjones
Copy link
Collaborator

Hi @blairmunroakusa, since you opened this PR we have changed the way we emit events, see #1827.

So have a look at the example I added as part of that PR: https://github.com/paritytech/ink/blob/master/integration-tests/events/lib.rs.

I'll close this for now, but feel free to reopen it or open a new one which is compatible with Events 2.0

@ascjones ascjones closed this Sep 13, 2023
@blairmunroakusa
Copy link
Author

Hey @ascjones @SkymanOne sorry for ghosting :/ ; life got me. When I find the cycles, I will look into following through on this. Thank you for the cordial and educational intro to the Parity world; I appreciate your patience and professionalism, and I look forward to properly contributing when the time is right.

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.

3 participants