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

Add OrderSchema tests #1302

Merged
merged 10 commits into from
Mar 15, 2024
Merged

Add OrderSchema tests #1302

merged 10 commits into from
Mar 15, 2024

Conversation

fmrsabino
Copy link
Collaborator

@fmrsabino fmrsabino commented Mar 14, 2024

Summary

  • Adds unit tests to OrderSchema.

Changes

  • Changes .default('unknown') to .catch('unknown') in the OrderSchema as the default value would only be set if no value was provided. If an unknown value is provided we should still set the respective value as unknown.

- Adds `SwapOrderMapper` – this mapper will attempt to decode transactions that represent a `preSignature` CoW Swap order.
- Successful decoding depends on multiple conditions. If any of the following conditions occurs, the transaction is mapped to a custom transaction instead (i.e.: without any decoding in place):
  * Transaction data is null
  * Order UID cannot be retrieved
  * Buy or Sell token info cannot be retrieved
  * Unsupported order statuses (statuses which are not `fulfilled`, `open`, `cancelled` or `expired`).
- Adds an `orderBuilder` to support creating multiple instances of `Order` with different properties.
- The decoding of CoW Swap orders is only available if `FF_SWAPS_DECODING` is enabled.
@fmrsabino fmrsabino self-assigned this Mar 14, 2024
@fmrsabino fmrsabino requested a review from a team as a code owner March 14, 2024 14:56
@coveralls
Copy link

coveralls commented Mar 14, 2024

Pull Request Test Coverage Report for Build 8295780648

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.01%) to 93.642%

Totals Coverage Status
Change from base Build 8283676068: -0.01%
Covered Lines: 6482
Relevant Lines: 6689

💛 - Coveralls

Copy link
Member

@iamacook iamacook left a comment

Choose a reason for hiding this comment

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

Can we also add test conditions for:

  • Address checksumming of sellToken, buyToken, receiver, from, owner, onChainUser and onchainUser.sender
  • Defaulting to null for receiver, from, quoteId, availableBalance, ethflowData, onchainUser, executedSurplusFee and fullAppData.

I've also noticed that there are some hexadecimal values that could use the HexSchema in the OrderSchema that could then be tested as well: signature and ethflowData.refundTxHash.

fmrsabino and others added 2 commits March 14, 2024 16:08
Base automatically changed from decode-transactions to main March 14, 2024 15:50
@fmrsabino fmrsabino requested a review from iamacook March 14, 2024 16:01
src/domain/swaps/entities/schemas/order.schema.spec.ts Outdated Show resolved Hide resolved
expect(result.success && result.data.kind).toBe('unknown');
});

it.each<keyof Order>([
Copy link
Member

Choose a reason for hiding this comment

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

Nice type usage!

@fmrsabino fmrsabino requested a review from iamacook March 15, 2024 11:59
@fmrsabino fmrsabino merged commit 7acc229 into main Mar 15, 2024
16 checks passed
@fmrsabino fmrsabino deleted the order-schema-tests branch March 15, 2024 12:07
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