-
-
Notifications
You must be signed in to change notification settings - Fork 293
feat: define swap QuoteResponse V2 schema validators #9724
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
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
158b79f
wip
micaelae 06bb224
Revert "wip"
micaelae 3397c50
feat: v2 schema
micaelae e9fc1d7
chore: changelog
micaelae 66750d1
v2
micaelae 370fb4d
Merge branch 'main' into swaps4546-v2-schema
micaelae 7321ae0
chore: undo Stellar testnet removal
micaelae 8bd9439
chore: update comment
micaelae e8b7fa7
chore: rename NumberStringSchema -> PositiveNumberStringSchema
micaelae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
packages/bridge-controller/src/validators/amount-and-asset.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { type, optional, union, string, Infer } from '@metamask/superstruct'; | ||
|
|
||
| import { BridgeAssetV2Schema } from './bridge-asset.js'; | ||
| import { PositiveNumberStringSchema, FloatStringSchema } from './number.js'; | ||
|
|
||
| export const AmountsAndAssetSchema = type({ | ||
| /* | ||
| * The atomic amount of the asset | ||
| * @example "1000000000000000000" | ||
| */ | ||
| amount: PositiveNumberStringSchema, | ||
| asset: BridgeAssetV2Schema, | ||
| /* | ||
| * The normalized amount of the asset | ||
| * @example "1.5" | ||
| */ | ||
| normalizedAmount: optional(FloatStringSchema), | ||
| // TODO remove string and fix usd in backend | ||
| usd: optional(union([FloatStringSchema, string()])), | ||
| /* | ||
| * The value of the asset in the currency, calculated based on usd value | ||
| * @example "0.15" | ||
| */ | ||
| valueInCurrency: optional(FloatStringSchema), | ||
| }); | ||
| export type AmountsAndAsset = Infer<typeof AmountsAndAssetSchema>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/bridge-controller/src/validators/quote-response.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import { KnownCaipNamespace } from '@metamask/utils'; | ||
|
|
||
| import { mockBridgeQuotesErc20Erc20V2Migration } from '../../tests/mock-quotes-erc20-erc20-migration-v2.js'; | ||
| import { validateQuoteResponse } from './quote-response.js'; | ||
|
|
||
| describe('quote-response-v2', () => { | ||
| describe('validateQuoteResponse', () => { | ||
| it('should return a validation error for an invalid quote response', () => { | ||
| const quoteResponse = { | ||
| quote: { | ||
| requestId: '123', | ||
| }, | ||
| }; | ||
|
|
||
| expect(() => | ||
| validateQuoteResponse(quoteResponse), | ||
| ).toThrowErrorMatchingInlineSnapshot( | ||
| `"At path: quote.src -- Expected an object, but received: undefined"`, | ||
| ); | ||
| }); | ||
|
|
||
| it('should validate a valid quote response', () => { | ||
| const quoteResponse = mockBridgeQuotesErc20Erc20V2Migration[0]; | ||
| expect(validateQuoteResponse(quoteResponse)).toBe(true); | ||
| }); | ||
|
|
||
| it('should return false when quote namespace is not supported', () => { | ||
| const quoteResponse = mockBridgeQuotesErc20Erc20V2Migration[0]; | ||
| quoteResponse.quote.src.asset.assetId = `${KnownCaipNamespace.Wallet}:123/token:test`; | ||
| expect(validateQuoteResponse(quoteResponse)).toBe(false); | ||
| }); | ||
| }); | ||
| }); |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.