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

[ECO-247] Add event emission unit tests, with uncovered cancel reasons #366

Merged
merged 27 commits into from Aug 1, 2023

Conversation

alnoki
Copy link
Member

@alnoki alnoki commented Jul 24, 2023

Background

#321 and several associated follow up PRs added comprehensive event emissions for market events like PlaceLimitOrderEvent. At the time, however, event emissions could not verified using the Move unit testing framework, and several minor issues were uncovered through discussions/manual testing:

Aptos Labs recently enabled unit testing of events in Move via aptos-labs/aptos-core#9181, and as such this PR updates the Move unit testing suite to test event emissions.

Methodology

Before this PR, Move code was already tested to 100% coverage, and as such this PR simply adds event assert statements to the existing coverage suite where applicable. Notably, this includes all non-expected-failure tests listed under the doc comments for:

  • market::match()
  • market::place_limit_order()
  • market::place_market_order(),
  • market::swap_between_coinstores()
  • market::swap_coins()
  • market::swap_generic()

Auxiliary event scenarios are also validated for manual order size changes and manual order cancellations, as well as registry events.

Gaps addressed

The two issues listed under background are now tested for and would have been quickly caught if event testing had been available at the time of submission of #321. Two additional edge cases were discovered during testing for this PR, both of which are cancel reasons that only apply to swaps. All applicable cancel reasons for all scenarios (limit order, market order, swap, manual cancel, eviction, self match maker and taker cancel) are now tested. The cancel reason logic and associated documentation is included in this PR per:

  • CANCEL_REASON_TOO_SMALL_TO_FILL_LOT: dd968e9
  • CANCEL_REASON_VIOLATED_LIMIT_PRICE: a894fdb

@vercel
Copy link

vercel bot commented Jul 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
econia ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 1, 2023 0:57am

@alnoki alnoki marked this pull request as draft July 24, 2023 21:07
@vercel vercel bot temporarily deployed to Preview July 24, 2023 21:37 Inactive
@vercel vercel bot temporarily deployed to Preview July 24, 2023 21:46 Inactive
@alnoki alnoki force-pushed the eco-247-add-event-emission-unit-tests branch from 0a58de1 to 1c8b386 Compare July 24, 2023 21:47
@vercel vercel bot temporarily deployed to Preview July 24, 2023 21:47 Inactive
@alnoki alnoki force-pushed the eco-247-add-event-emission-unit-tests branch from 1c8b386 to 5fdd6b5 Compare July 24, 2023 21:48
@vercel vercel bot temporarily deployed to Preview July 24, 2023 21:49 Inactive
@vercel vercel bot temporarily deployed to Preview July 24, 2023 22:07 Inactive
@vercel vercel bot temporarily deployed to Preview July 24, 2023 22:29 Inactive
@vercel vercel bot temporarily deployed to Preview July 25, 2023 20:54 Inactive
@vercel vercel bot temporarily deployed to Preview July 25, 2023 22:34 Inactive
@vercel vercel bot temporarily deployed to Preview July 25, 2023 22:47 Inactive
@vercel vercel bot temporarily deployed to Preview July 26, 2023 00:14 Inactive
@vercel vercel bot temporarily deployed to Preview July 26, 2023 00:48 Inactive
@vercel vercel bot temporarily deployed to Preview July 28, 2023 01:36 Inactive
@vercel vercel bot temporarily deployed to Preview July 28, 2023 01:37 Inactive
@vercel vercel bot temporarily deployed to Preview July 28, 2023 02:06 Inactive
@vercel vercel bot temporarily deployed to Preview July 28, 2023 02:20 Inactive
The last commit tested Move code to 100% coverage, which
was only possible by commenting out inline keywords and
using a non-mainnet dependency per:

aptos-labs/aptos-core#9154
aptos-labs/aptos-core#9181
@alnoki alnoki force-pushed the eco-247-add-event-emission-unit-tests branch from 912b399 to 12730d8 Compare July 28, 2023 02:24
@vercel vercel bot temporarily deployed to Preview July 28, 2023 02:25 Inactive
@vercel vercel bot temporarily deployed to Preview July 28, 2023 02:31 Inactive
@alnoki alnoki marked this pull request as ready for review July 28, 2023 02:42
@alnoki alnoki changed the title [ECO-247] Add event emission unit tests [ECO-247] Add event emission unit tests, with uncovered cancel reasons Jul 28, 2023
@alnoki alnoki marked this pull request as draft July 28, 2023 16:48
@alnoki alnoki requested a review from qdrs July 28, 2023 16:55
Copy link
Contributor

@elliottdehn elliottdehn left a comment

Choose a reason for hiding this comment

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

See note about adding a helper to unify the assertions being made at each location, perhaps have it accept a structure that makes it very clear what's being asserted. I'd call it assert_events or something. We want to know for a fact that all events that were emitted have been asserted, and all events that weren't emitted were also asserted--and the way to do that would be a unifying helper that asserts all of the event streams.

src/move/econia/sources/market.move Show resolved Hide resolved
src/move/econia/sources/market.move Show resolved Hide resolved
src/move/econia/sources/user.move Show resolved Hide resolved
src/move/econia/sources/market.move Show resolved Hide resolved
src/move/econia/sources/market.move Show resolved Hide resolved
@elliottdehn
Copy link
Contributor

elliottdehn commented Jul 28, 2023

I would also advise you to write out above the assertion what's being expected, i.e:

- Expect Cancel event emitted to maker resulting from X.
- Expect no other events emitted to taker or maker resulting from Y, Z.

It's hard to review this in GitHub because you have to click several times to see what the test name is in order to figure out what SHOULD be asserted and then check that this is correct. Just a note though. I'll have to pull it down to review it anyway.

@alnoki
Copy link
Member Author

alnoki commented Jul 28, 2023

I would also advise you to write out above the assertion what's being expected, i.e:

- Expect Cancel event emitted to maker resulting from X.
- Expect no other events emitted to taker or maker resulting from Y, Z.

It's hard to review this in GitHub because you have to click several times to see what the test name is in order to figure out what SHOULD be asserted and then check that this is correct. Just a note though. I'll have to pull it down to review it anyway.

This should be much easier to review in VS Code using the pull requests extension https://marketplace.visualstudio.com/items?itemName=GitHub.vscode-pull-request-github

That way you can open the same editor side by side and review the function badge name

Copy link
Contributor

@elliottdehn elliottdehn left a comment

Choose a reason for hiding this comment

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

I feel comfortable approving this after reviewing most (75%) of the changes closely because for something to be wrong in the specific case of an assert statement two things would have to be true:

  • You're asserting something as true that shouldn't be.
  • The code is doing the wrong thing and satisfying the assertion.

I wasn't able to find any missing cases or incorrect assertions.

src/move/econia/sources/market.move Show resolved Hide resolved
src/move/econia/sources/market.move Show resolved Hide resolved
src/move/econia/sources/market.move Show resolved Hide resolved
src/move/econia/sources/market.move Show resolved Hide resolved
src/move/econia/sources/market.move Outdated Show resolved Hide resolved
@vercel vercel bot temporarily deployed to Preview August 1, 2023 00:57 Inactive
@alnoki alnoki marked this pull request as ready for review August 1, 2023 14:56
@alnoki alnoki merged commit 9e59912 into main Aug 1, 2023
2 checks passed
@alnoki alnoki deleted the eco-247-add-event-emission-unit-tests branch August 1, 2023 14:56
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

3 participants