diff options
Diffstat (limited to 'packages/json-schemas')
40 files changed, 1074 insertions, 790 deletions
diff --git a/packages/json-schemas/CHANGELOG.json b/packages/json-schemas/CHANGELOG.json index 3ea1e7512..d78a1c11e 100644 --- a/packages/json-schemas/CHANGELOG.json +++ b/packages/json-schemas/CHANGELOG.json @@ -1,13 +1,176 @@ [ { + "version": "1.0.1-rc.4", + "changes": [ + { + "note": "Allow for additional properties in txData schema", + "pr": 938 + }, + { + "note": "Change hexSchema to match `0x`", + "pr": 937 + }, + { + "note": "Upgrade Relayer API schemas for relayer API V2", + "pr": 916 + } + ], + "timestamp": 1534210131 + }, + { + "version": "1.0.1-rc.3", + "changes": [ + { + "note": "Dependencies updated" + } + ], + "timestamp": 1532619515 + }, + { + "version": "1.0.1-rc.2", + "changes": [ + { + "note": "Dependencies updated" + } + ], + "timestamp": 1532614997 + }, + { + "version": "1.0.1-rc.1", + "changes": [ + { + "note": "Dependencies updated" + } + ], + "timestamp": 1532605697 + }, + { + "timestamp": 1532357734, + "version": "1.0.0", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { + "timestamp": 1532043000, + "version": "1.0.0-rc.1", + "changes": [ + { + "note": "Update schemas for V2 or 0x Protocol", + "pr": 615 + }, + { + "note": "Added CallData schema", + "pr": 821 + }, + { + "note": "Update CallData schema id to CallData", + "pr": 894 + } + ] + }, + { + "timestamp": 1531919263, + "version": "0.8.3", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { + "timestamp": 1531149657, + "version": "0.8.2", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { + "timestamp": 1529397769, + "version": "0.8.1", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { + "version": "0.8.0", + "changes": [ + { + "note": + "Update Order & SignedOrder schemas, remove ECSignature schema and add Hex schema as part of V2 upgrades", + "pr": 615 + } + ], + "timestamp": 1527008794 + }, + { + "timestamp": 1527008794, + "version": "0.7.24", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { + "timestamp": 1525477860, + "version": "0.7.23", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { + "timestamp": 1525428773, + "version": "0.7.22", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { + "timestamp": 1524044013, + "version": "0.7.21", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { + "timestamp": 1523462196, + "version": "0.7.20", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { + "timestamp": 1522673609, + "version": "0.7.19", + "changes": [ + { + "note": "Dependencies updated" + } + ] + }, + { "timestamp": 1522658513, "version": "0.7.18", "changes": [ { "note": "Dependencies updated" } - ], - "isPublished": true + ] }, { "version": "0.7.13", @@ -17,8 +180,7 @@ "pr": 389 } ], - "timestamp": 1518102000, - "isPublished": true + "timestamp": 1518102000 }, { "version": "0.7.0", @@ -28,8 +190,7 @@ "pr": 272 } ], - "timestamp": 1513695600, - "isPublished": true + "timestamp": 1513695600 }, { "version": "0.6.7", @@ -38,7 +199,6 @@ "note": "Re-publish JSON-schema previously published under NPM package 0x-json-schemas" } ], - "timestamp": 1510585200, - "isPublished": true + "timestamp": 1510585200 } ] diff --git a/packages/json-schemas/CHANGELOG.md b/packages/json-schemas/CHANGELOG.md index 6c86a1a81..0ebc3d237 100644 --- a/packages/json-schemas/CHANGELOG.md +++ b/packages/json-schemas/CHANGELOG.md @@ -1,22 +1,90 @@ <!-- -This file is auto-generated using the monorepo-scripts package. Don't edit directly. +changelogUtils.file is auto-generated using the monorepo-scripts package. Don't edit directly. Edit the package's CHANGELOG.json file only. --> CHANGELOG +## v1.0.1-rc.4 - _August 13, 2018_ + + * Allow for additional properties in txData schema (#938) + * Change hexSchema to match `0x` (#937) + * Upgrade Relayer API schemas for relayer API V2 (#916) + +## v1.0.1-rc.3 - _July 26, 2018_ + + * Dependencies updated + +## v1.0.1-rc.2 - _July 26, 2018_ + + * Dependencies updated + +## v1.0.1-rc.1 - _July 26, 2018_ + + * Dependencies updated + +## v1.0.0 - _July 23, 2018_ + + * Dependencies updated + +## v1.0.0-rc.1 - _July 19, 2018_ + + * Update schemas for V2 or 0x Protocol (#615) + * Added CallData schema (#821) + * Update CallData schema id to CallData (#894) + +## v0.8.3 - _July 18, 2018_ + + * Dependencies updated + +## v0.8.2 - _July 9, 2018_ + + * Dependencies updated + +## v0.8.1 - _June 19, 2018_ + + * Dependencies updated + +## v0.8.0 - _May 22, 2018_ + + * Update Order & SignedOrder schemas, remove ECSignature schema and add Hex schema as part of V2 upgrades (#615) + +## v0.7.24 - _May 22, 2018_ + + * Dependencies updated + +## v0.7.23 - _May 4, 2018_ + + * Dependencies updated + +## v0.7.22 - _May 4, 2018_ + + * Dependencies updated + +## v0.7.21 - _April 18, 2018_ + + * Dependencies updated + +## v0.7.20 - _April 11, 2018_ + + * Dependencies updated + +## v0.7.19 - _April 2, 2018_ + + * Dependencies updated + ## v0.7.18 - _April 2, 2018_ * Dependencies updated -## v0.7.13 - _February 9, 2018_ +## v0.7.13 - _February 8, 2018_ * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) -## v0.7.0 - _December 20, 2017_ +## v0.7.0 - _December 19, 2017_ * Rename `subscriptionOptsSchema` to `blockRangeSchema` (#272) -## v0.6.7 - _November 14, 2017_ +## v0.6.7 - _November 13, 2017_ * Re-publish JSON-schema previously published under NPM package 0x-json-schemas diff --git a/packages/json-schemas/README.md b/packages/json-schemas/README.md index 980d17416..ab57833be 100644 --- a/packages/json-schemas/README.md +++ b/packages/json-schemas/README.md @@ -2,7 +2,7 @@ Contains 0x-related json schemas -### Read the [Documentation](0xproject.com/docs/json-schemas). +### Read the [Documentation](https://0xproject.com/docs/json-schemas). ## Installation @@ -32,11 +32,11 @@ If your project is in [TypeScript](https://www.typescriptlang.org/), add the fol ## Contributing -We strongly encourage that the community help us make improvements and determine the future direction of the protocol. To report bugs within this package, please create an issue in this repository. +We welcome improvements and fixes from the wider community! To report bugs within this package, please create an issue in this repository. Please read our [contribution guidelines](../../CONTRIBUTING.md) before getting started. -### Install Dependencies +### Install dependencies If you don't have yarn workspaces enabled (Yarn < v1.0) - enable them: @@ -52,14 +52,22 @@ yarn install ### Build +To build this package and all other monorepo packages that it depends on, run the following from the monorepo root directory: + ```bash -yarn build +PKG=@0xproject/json-schemas yarn build ``` -or +Or continuously rebuild on change: + +```bash +PKG=@0xproject/json-schemas yarn watch +``` + +### Clean ```bash -yarn build:watch +yarn clean ``` ### Lint diff --git a/packages/json-schemas/package.json b/packages/json-schemas/package.json index f546df5ad..40cb71c18 100644 --- a/packages/json-schemas/package.json +++ b/packages/json-schemas/package.json @@ -1,21 +1,25 @@ { "name": "@0xproject/json-schemas", - "version": "0.7.18", + "version": "1.0.1-rc.4", + "engines": { + "node": ">=6.12" + }, "description": "0x-related json schemas", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "scripts": { - "build:watch": "tsc -w", - "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'", - "test": "run-s clean build run_mocha", + "watch_without_deps": "tsc -w", + "lint": "tslint --project .", + "test": "yarn run_mocha", + "rebuild_and_test": "run-s clean build test", "test:coverage": "nyc npm run test --all && yarn coverage:report:lcov", "coverage:report:lcov": "nyc report --reporter=text-lcov > coverage/lcov.info", "test:circleci": "yarn test:coverage", - "run_mocha": "mocha lib/test/**/*_test.js", + "run_mocha": "mocha --require source-map-support/register --require make-promises-safe lib/test/**/*_test.js --exit", "clean": "shx rm -rf lib test_temp scripts", "build": "tsc && copyfiles -u 3 './lib/src/monorepo_scripts/**/*' ./scripts", "manual:postpublish": "yarn build; node ./scripts/postpublish.js", - "docs:stage": "yarn build && node ./scripts/stage_docs.js", + "docs:stage": "node scripts/stage_docs.js", "docs:json": "typedoc --excludePrivate --excludeExternals --target ES5 --json $JSON_FILE_PATH $PROJECT_FILES", "upload_docs_json": "aws s3 cp generated_docs/index.json $S3_URL --profile 0xproject --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers --content-type application/json" }, @@ -24,7 +28,8 @@ "assets": [], "docPublishConfigs": { "extraFileIncludes": [ - "../types/src/index.ts" + "../types/src/index.ts", + "../ethereum-types/src/index.ts" ], "s3BucketPath": "s3://doc-jsons/json-schemas/", "s3StagingBucketPath": "s3://staging-doc-jsons/json-schemas/" @@ -42,14 +47,15 @@ }, "homepage": "https://github.com/0xProject/0x-monorepo/packages/json-schemas/README.md", "dependencies": { - "@0xproject/typescript-typings": "^0.0.2", + "@0xproject/typescript-typings": "^1.0.4", + "@types/node": "^8.0.53", "jsonschema": "^1.2.0", "lodash.values": "^4.3.0" }, "devDependencies": { - "@0xproject/monorepo-scripts": "^0.1.15", - "@0xproject/tslint-config": "^0.4.13", - "@0xproject/utils": "^0.4.4", + "@0xproject/monorepo-scripts": "^1.0.5", + "@0xproject/tslint-config": "^1.0.5", + "@0xproject/utils": "^1.0.5", "@types/lodash.foreach": "^4.5.3", "@types/lodash.values": "^4.3.3", "@types/mocha": "^2.2.42", @@ -57,13 +63,14 @@ "copyfiles": "^1.2.0", "dirty-chai": "^2.0.1", "lodash.foreach": "^4.5.0", - "mocha": "^4.0.1", + "make-promises-safe": "^1.1.0", + "mocha": "^4.1.0", "npm-run-all": "^4.1.2", "nyc": "^11.0.1", "shx": "^0.2.2", - "tslint": "5.8.0", + "tslint": "5.11.0", "typedoc": "0xProject/typedoc", - "typescript": "2.7.1" + "typescript": "2.9.2" }, "publishConfig": { "access": "public" diff --git a/packages/json-schemas/schemas/basic_type_schemas.ts b/packages/json-schemas/schemas/basic_type_schemas.ts index 9d81ff333..a59afaef8 100644 --- a/packages/json-schemas/schemas/basic_type_schemas.ts +++ b/packages/json-schemas/schemas/basic_type_schemas.ts @@ -1,11 +1,17 @@ export const addressSchema = { - id: '/Address', + id: '/addressSchema', type: 'string', pattern: '^0x[0-9a-f]{40}$', }; +export const hexSchema = { + id: '/hexSchema', + type: 'string', + pattern: '^0x(([0-9a-f][0-9a-f])+)?$', +}; + export const numberSchema = { - id: '/Number', + id: '/numberSchema', type: 'string', pattern: '^\\d+(\\.\\d+)?$', }; diff --git a/packages/json-schemas/schemas/block_range_schema.ts b/packages/json-schemas/schemas/block_range_schema.ts index 1f6a63151..9eb242fc6 100644 --- a/packages/json-schemas/schemas/block_range_schema.ts +++ b/packages/json-schemas/schemas/block_range_schema.ts @@ -1,5 +1,5 @@ export const blockParamSchema = { - id: '/BlockParam', + id: '/blockParamSchema', oneOf: [ { type: 'number', @@ -11,10 +11,10 @@ export const blockParamSchema = { }; export const blockRangeSchema = { - id: '/BlockRange', + id: '/blockRangeSchema', properties: { - fromBlock: { $ref: '/BlockParam' }, - toBlock: { $ref: '/BlockParam' }, + fromBlock: { $ref: '/blockParamSchema' }, + toBlock: { $ref: '/blockParamSchema' }, }, type: 'object', }; diff --git a/packages/json-schemas/schemas/call_data_schema.ts b/packages/json-schemas/schemas/call_data_schema.ts new file mode 100644 index 000000000..4c77d9f9d --- /dev/null +++ b/packages/json-schemas/schemas/call_data_schema.ts @@ -0,0 +1,27 @@ +export const callDataSchema = { + id: '/callDataSchema', + properties: { + from: { $ref: '/addressSchema' }, + to: { $ref: '/addressSchema' }, + value: { + oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }], + }, + gas: { + oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }], + }, + gasPrice: { + oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }], + }, + data: { + type: 'string', + pattern: '^0x[0-9a-f]*$', + }, + nonce: { + type: 'number', + minimum: 0, + }, + }, + required: [], + type: 'object', + additionalProperties: false, +}; diff --git a/packages/json-schemas/schemas/ec_signature_schema.ts b/packages/json-schemas/schemas/ec_signature_schema.ts index 71b840dd8..c59532f09 100644 --- a/packages/json-schemas/schemas/ec_signature_schema.ts +++ b/packages/json-schemas/schemas/ec_signature_schema.ts @@ -1,5 +1,5 @@ export const ecSignatureParameterSchema = { - id: '/ECSignatureParameter', + id: '/ecSignatureParameterSchema', type: 'string', pattern: '^0[xX][0-9A-Fa-f]{64}$', }; @@ -12,8 +12,8 @@ export const ecSignatureSchema = { minimum: 27, maximum: 28, }, - r: { $ref: '/ECSignatureParameter' }, - s: { $ref: '/ECSignatureParameter' }, + r: { $ref: '/ecSignatureParameterSchema' }, + s: { $ref: '/ecSignatureParameterSchema' }, }, required: ['v', 'r', 's'], type: 'object', diff --git a/packages/json-schemas/schemas/index_filter_values_schema.ts b/packages/json-schemas/schemas/index_filter_values_schema.ts index 3374d63e0..f3c8cef68 100644 --- a/packages/json-schemas/schemas/index_filter_values_schema.ts +++ b/packages/json-schemas/schemas/index_filter_values_schema.ts @@ -1,7 +1,7 @@ export const indexFilterValuesSchema = { - id: '/IndexFilterValues', + id: '/indexFilterValuesSchema', additionalProperties: { - oneOf: [{ $ref: '/Number' }, { $ref: '/Address' }, { $ref: '/OrderHashSchema' }], + oneOf: [{ $ref: '/numberSchema' }, { $ref: '/addressSchema' }, { $ref: '/orderHashSchema' }], }, type: 'object', }; diff --git a/packages/json-schemas/schemas/order_cancel_schema.ts b/packages/json-schemas/schemas/order_cancel_schema.ts index ad23d01cc..e4edfbca9 100644 --- a/packages/json-schemas/schemas/order_cancel_schema.ts +++ b/packages/json-schemas/schemas/order_cancel_schema.ts @@ -1,10 +1,10 @@ export const orderCancellationRequestsSchema = { - id: '/OrderCancellationRequests', + id: '/orderCancellationRequestsSchema', type: 'array', items: { properties: { - order: { $ref: '/Order' }, - takerTokenCancelAmount: { $ref: '/Number' }, + order: { $ref: '/orderSchema' }, + takerTokenCancelAmount: { $ref: '/numberSchema' }, }, required: ['order', 'takerTokenCancelAmount'], type: 'object', diff --git a/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts b/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts index 61f2c8849..e2c18ef0a 100644 --- a/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts +++ b/packages/json-schemas/schemas/order_fill_or_kill_requests_schema.ts @@ -1,10 +1,10 @@ export const orderFillOrKillRequestsSchema = { - id: '/OrderFillOrKillRequests', + id: '/orderFillOrKillRequestsSchema', type: 'array', items: { properties: { - signedOrder: { $ref: '/SignedOrder' }, - fillTakerAmount: { $ref: '/Number' }, + signedOrder: { $ref: '/signedOrderSchema' }, + fillTakerAmount: { $ref: '/numberSchema' }, }, required: ['signedOrder', 'fillTakerAmount'], type: 'object', diff --git a/packages/json-schemas/schemas/order_fill_requests_schema.ts b/packages/json-schemas/schemas/order_fill_requests_schema.ts index 419d0670f..ea8b35e54 100644 --- a/packages/json-schemas/schemas/order_fill_requests_schema.ts +++ b/packages/json-schemas/schemas/order_fill_requests_schema.ts @@ -1,10 +1,10 @@ export const orderFillRequestsSchema = { - id: '/OrderFillRequests', + id: '/orderFillRequestsSchema', type: 'array', items: { properties: { - signedOrder: { $ref: '/SignedOrder' }, - takerTokenFillAmount: { $ref: '/Number' }, + signedOrder: { $ref: '/signedOrderSchema' }, + takerTokenFillAmount: { $ref: '/numberSchema' }, }, required: ['signedOrder', 'takerTokenFillAmount'], type: 'object', diff --git a/packages/json-schemas/schemas/order_hash_schema.ts b/packages/json-schemas/schemas/order_hash_schema.ts index 6af06927f..9773a88f9 100644 --- a/packages/json-schemas/schemas/order_hash_schema.ts +++ b/packages/json-schemas/schemas/order_hash_schema.ts @@ -1,5 +1,5 @@ export const orderHashSchema = { - id: '/OrderHashSchema', + id: '/orderHashSchema', type: 'string', pattern: '^0x[0-9a-fA-F]{64}$', }; diff --git a/packages/json-schemas/schemas/order_schemas.ts b/packages/json-schemas/schemas/order_schemas.ts index 6f17224ad..eb7fdaf5a 100644 --- a/packages/json-schemas/schemas/order_schemas.ts +++ b/packages/json-schemas/schemas/order_schemas.ts @@ -1,43 +1,47 @@ export const orderSchema = { - id: '/Order', + id: '/orderSchema', properties: { - maker: { $ref: '/Address' }, - taker: { $ref: '/Address' }, - makerFee: { $ref: '/Number' }, - takerFee: { $ref: '/Number' }, - makerTokenAmount: { $ref: '/Number' }, - takerTokenAmount: { $ref: '/Number' }, - makerTokenAddress: { $ref: '/Address' }, - takerTokenAddress: { $ref: '/Address' }, - salt: { $ref: '/Number' }, - feeRecipient: { $ref: '/Address' }, - expirationUnixTimestampSec: { $ref: '/Number' }, - exchangeContractAddress: { $ref: '/Address' }, + makerAddress: { $ref: '/addressSchema' }, + takerAddress: { $ref: '/addressSchema' }, + makerFee: { $ref: '/numberSchema' }, + takerFee: { $ref: '/numberSchema' }, + senderAddress: { $ref: '/addressSchema' }, + makerAssetAmount: { $ref: '/numberSchema' }, + takerAssetAmount: { $ref: '/numberSchema' }, + makerAssetData: { $ref: '/hexSchema' }, + takerAssetData: { $ref: '/hexSchema' }, + salt: { $ref: '/numberSchema' }, + exchangeAddress: { $ref: '/addressSchema' }, + feeRecipientAddress: { $ref: '/addressSchema' }, + expirationTimeSeconds: { $ref: '/numberSchema' }, }, required: [ - 'maker', - 'taker', + 'makerAddress', + 'takerAddress', 'makerFee', 'takerFee', - 'makerTokenAmount', - 'takerTokenAmount', + 'senderAddress', + 'makerAssetAmount', + 'takerAssetAmount', + 'makerAssetData', + 'takerAssetData', 'salt', - 'feeRecipient', - 'expirationUnixTimestampSec', - 'exchangeContractAddress', + 'exchangeAddress', + 'feeRecipientAddress', + 'expirationTimeSeconds', ], type: 'object', }; export const signedOrderSchema = { - id: '/SignedOrder', + id: '/signedOrderSchema', allOf: [ - { $ref: '/Order' }, + { $ref: '/orderSchema' }, { properties: { - ecSignature: { $ref: '/ECSignature' }, + signature: { $ref: '/hexSchema' }, }, - required: ['ecSignature'], + required: ['signature'], }, ], }; diff --git a/packages/json-schemas/schemas/orders_schema.ts b/packages/json-schemas/schemas/orders_schema.ts new file mode 100644 index 000000000..de0abcf00 --- /dev/null +++ b/packages/json-schemas/schemas/orders_schema.ts @@ -0,0 +1,5 @@ +export const ordersSchema = { + id: '/ordersSchema', + type: 'array', + items: { $ref: '/orderSchema' }, +}; diff --git a/packages/json-schemas/schemas/paginated_collection_schema.ts b/packages/json-schemas/schemas/paginated_collection_schema.ts new file mode 100644 index 000000000..16044c70a --- /dev/null +++ b/packages/json-schemas/schemas/paginated_collection_schema.ts @@ -0,0 +1,10 @@ +export const paginatedCollectionSchema = { + id: '/paginatedCollectionSchema', + type: 'object', + properties: { + total: { type: 'number' }, + perPage: { type: 'number' }, + page: { type: 'number' }, + }, + required: ['total', 'perPage', 'page'], +}; diff --git a/packages/json-schemas/schemas/relayer_api_asset_pairs_response_schema.ts b/packages/json-schemas/schemas/relayer_api_asset_pairs_response_schema.ts new file mode 100644 index 000000000..c13396d29 --- /dev/null +++ b/packages/json-schemas/schemas/relayer_api_asset_pairs_response_schema.ts @@ -0,0 +1,38 @@ +export const relayerApiAssetDataPairsResponseSchema = { + id: '/relayerApiAssetDataPairsResponseSchema', + type: 'object', + allOf: [ + { $ref: '/paginatedCollectionSchema' }, + { + properties: { + records: { $ref: '/relayerApiAssetDataPairsSchema' }, + }, + required: ['records'], + }, + ], +}; + +export const relayerApiAssetDataPairsSchema = { + id: '/relayerApiAssetDataPairsSchema', + type: 'array', + items: { + properties: { + assetDataA: { $ref: '/relayerApiAssetDataTradeInfoSchema' }, + assetDataB: { $ref: '/relayerApiAssetDataTradeInfoSchema' }, + }, + required: ['assetDataA', 'assetDataB'], + type: 'object', + }, +}; + +export const relayerApiAssetDataTradeInfoSchema = { + id: '/relayerApiAssetDataTradeInfoSchema', + type: 'object', + properties: { + assetData: { $ref: '/hexSchema' }, + minAmount: { $ref: '/numberSchema' }, + maxAmount: { $ref: '/numberSchema' }, + precision: { type: 'number' }, + }, + required: ['assetData'], +}; diff --git a/packages/json-schemas/schemas/relayer_api_error_response_schema.ts b/packages/json-schemas/schemas/relayer_api_error_response_schema.ts index 27fdb166f..79e33fc85 100644 --- a/packages/json-schemas/schemas/relayer_api_error_response_schema.ts +++ b/packages/json-schemas/schemas/relayer_api_error_response_schema.ts @@ -1,8 +1,8 @@ export const relayerApiErrorResponseSchema = { - id: '/RelayerApiErrorResponse', + id: '/relayerApiErrorResponseSchema', type: 'object', properties: { - code: { type: 'number' }, + code: { type: 'integer', minimum: 100, maximum: 103 }, reason: { type: 'string' }, validationErrors: { type: 'array', @@ -10,7 +10,7 @@ export const relayerApiErrorResponseSchema = { type: 'object', properties: { field: { type: 'string' }, - code: { type: 'number' }, + code: { type: 'integer', minimum: 1000, maximum: 1006 }, reason: { type: 'string' }, }, required: ['field', 'code', 'reason'], diff --git a/packages/json-schemas/schemas/relayer_api_fee_recipients_response_schema.ts b/packages/json-schemas/schemas/relayer_api_fee_recipients_response_schema.ts new file mode 100644 index 000000000..84d39eb20 --- /dev/null +++ b/packages/json-schemas/schemas/relayer_api_fee_recipients_response_schema.ts @@ -0,0 +1,13 @@ +export const relayerApiFeeRecipientsResponseSchema = { + id: '/relayerApiFeeRecipientsResponseSchema', + type: 'object', + allOf: [ + { $ref: '/paginatedCollectionSchema' }, + { + properties: { + records: { $ref: '/addressSchema' }, + }, + required: ['records'], + }, + ], +}; diff --git a/packages/json-schemas/schemas/relayer_api_fees_payload_schema.ts b/packages/json-schemas/schemas/relayer_api_fees_payload_schema.ts deleted file mode 100644 index eaaf777a1..000000000 --- a/packages/json-schemas/schemas/relayer_api_fees_payload_schema.ts +++ /dev/null @@ -1,24 +0,0 @@ -export const relayerApiFeesPayloadSchema = { - id: '/RelayerApiFeesPayload', - type: 'object', - properties: { - exchangeContractAddress: { $ref: '/Address' }, - maker: { $ref: '/Address' }, - taker: { $ref: '/Address' }, - makerTokenAddress: { $ref: '/Address' }, - takerTokenAddress: { $ref: '/Address' }, - makerTokenAmount: { $ref: '/Number' }, - takerTokenAmount: { $ref: '/Number' }, - expirationUnixTimestampSec: { $ref: '/Number' }, - salt: { $ref: '/Number' }, - }, - required: [ - 'exchangeContractAddress', - 'maker', - 'taker', - 'makerTokenAddress', - 'takerTokenAddress', - 'expirationUnixTimestampSec', - 'salt', - ], -}; diff --git a/packages/json-schemas/schemas/relayer_api_fees_response_schema.ts b/packages/json-schemas/schemas/relayer_api_fees_response_schema.ts deleted file mode 100644 index e7440613f..000000000 --- a/packages/json-schemas/schemas/relayer_api_fees_response_schema.ts +++ /dev/null @@ -1,10 +0,0 @@ -export const relayerApiFeesResponseSchema = { - id: '/RelayerApiFeesResponse', - type: 'object', - properties: { - makerFee: { $ref: '/Number' }, - takerFee: { $ref: '/Number' }, - feeRecipient: { $ref: '/Address' }, - }, - required: ['makerFee', 'takerFee', 'feeRecipient'], -}; diff --git a/packages/json-schemas/schemas/relayer_api_orberbook_channel_subscribe_schema.ts b/packages/json-schemas/schemas/relayer_api_orberbook_channel_subscribe_schema.ts deleted file mode 100644 index d93fa73d6..000000000 --- a/packages/json-schemas/schemas/relayer_api_orberbook_channel_subscribe_schema.ts +++ /dev/null @@ -1,23 +0,0 @@ -export const relayerApiOrderbookChannelSubscribeSchema = { - id: '/RelayerApiOrderbookChannelSubscribe', - type: 'object', - properties: { - type: { enum: ['subscribe'] }, - channel: { enum: ['orderbook'] }, - requestId: { type: 'number' }, - payload: { $ref: '/RelayerApiOrderbookChannelSubscribePayload' }, - }, - required: ['type', 'channel', 'requestId', 'payload'], -}; - -export const relayerApiOrderbookChannelSubscribePayload = { - id: '/RelayerApiOrderbookChannelSubscribePayload', - type: 'object', - properties: { - baseTokenAddress: { $ref: '/Address' }, - quoteTokenAddress: { $ref: '/Address' }, - snapshot: { type: 'boolean' }, - limit: { type: 'number' }, - }, - required: ['baseTokenAddress', 'quoteTokenAddress'], -}; diff --git a/packages/json-schemas/schemas/relayer_api_order_config_payload_schema.ts b/packages/json-schemas/schemas/relayer_api_order_config_payload_schema.ts new file mode 100644 index 000000000..8d1d408d6 --- /dev/null +++ b/packages/json-schemas/schemas/relayer_api_order_config_payload_schema.ts @@ -0,0 +1,24 @@ +export const relayerApiOrderConfigPayloadSchema = { + id: '/relayerApiOrderConfigPayloadSchema', + type: 'object', + properties: { + makerAddress: { $ref: '/addressSchema' }, + takerAddress: { $ref: '/addressSchema' }, + makerAssetAmount: { $ref: '/numberSchema' }, + takerAssetAmount: { $ref: '/numberSchema' }, + makerAssetData: { $ref: '/hexSchema' }, + takerAssetData: { $ref: '/hexSchema' }, + exchangeAddress: { $ref: '/addressSchema' }, + expirationTimeSeconds: { $ref: '/numberSchema' }, + }, + required: [ + 'makerAddress', + 'takerAddress', + 'makerAssetAmount', + 'takerAssetAmount', + 'makerAssetData', + 'takerAssetData', + 'exchangeAddress', + 'expirationTimeSeconds', + ], +}; diff --git a/packages/json-schemas/schemas/relayer_api_order_config_response_schema.ts b/packages/json-schemas/schemas/relayer_api_order_config_response_schema.ts new file mode 100644 index 000000000..390d0b262 --- /dev/null +++ b/packages/json-schemas/schemas/relayer_api_order_config_response_schema.ts @@ -0,0 +1,11 @@ +export const relayerApiOrderConfigResponseSchema = { + id: '/relayerApiOrderConfigResponseSchema', + type: 'object', + properties: { + makerFee: { $ref: '/numberSchema' }, + takerFee: { $ref: '/numberSchema' }, + feeRecipientAddress: { $ref: '/addressSchema' }, + senderAddress: { $ref: '/addressSchema' }, + }, + required: ['makerFee', 'takerFee', 'feeRecipientAddress', 'senderAddress'], +}; diff --git a/packages/json-schemas/schemas/relayer_api_order_schema.ts b/packages/json-schemas/schemas/relayer_api_order_schema.ts new file mode 100644 index 000000000..3952e9683 --- /dev/null +++ b/packages/json-schemas/schemas/relayer_api_order_schema.ts @@ -0,0 +1,9 @@ +export const relayerApiOrderSchema = { + id: '/relayerApiOrderSchema', + type: 'object', + properties: { + order: { $ref: '/orderSchema' }, + metaData: { type: 'object' }, + }, + required: ['order', 'metaData'], +}; diff --git a/packages/json-schemas/schemas/relayer_api_orderbook_channel_snapshot_schema.ts b/packages/json-schemas/schemas/relayer_api_orderbook_channel_snapshot_schema.ts deleted file mode 100644 index fe1510d5b..000000000 --- a/packages/json-schemas/schemas/relayer_api_orderbook_channel_snapshot_schema.ts +++ /dev/null @@ -1,21 +0,0 @@ -export const relayerApiOrderbookChannelSnapshotSchema = { - id: '/RelayerApiOrderbookChannelSnapshot', - type: 'object', - properties: { - type: { enum: ['snapshot'] }, - channel: { enum: ['orderbook'] }, - requestId: { type: 'number' }, - payload: { $ref: '/RelayerApiOrderbookChannelSnapshotPayload' }, - }, - required: ['type', 'channel', 'requestId', 'payload'], -}; - -export const relayerApiOrderbookChannelSnapshotPayload = { - id: '/RelayerApiOrderbookChannelSnapshotPayload', - type: 'object', - properties: { - bids: { $ref: '/signedOrdersSchema' }, - asks: { $ref: '/signedOrdersSchema' }, - }, - required: ['bids', 'asks'], -}; diff --git a/packages/json-schemas/schemas/relayer_api_orderbook_channel_update_response_schema.ts b/packages/json-schemas/schemas/relayer_api_orderbook_channel_update_response_schema.ts deleted file mode 100644 index 9a6d83d4c..000000000 --- a/packages/json-schemas/schemas/relayer_api_orderbook_channel_update_response_schema.ts +++ /dev/null @@ -1,11 +0,0 @@ -export const relayerApiOrderbookChannelUpdateSchema = { - id: '/RelayerApiOrderbookChannelUpdate', - type: 'object', - properties: { - type: { enum: ['update'] }, - channel: { enum: ['orderbook'] }, - requestId: { type: 'number' }, - payload: { $ref: '/SignedOrder' }, - }, - required: ['type', 'channel', 'requestId', 'payload'], -}; diff --git a/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts b/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts index 5c409c807..7c0b8e0df 100644 --- a/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts +++ b/packages/json-schemas/schemas/relayer_api_orderbook_response_schema.ts @@ -1,9 +1,9 @@ -export const relayerApiOrderBookResponseSchema = { - id: '/RelayerApiOrderBookResponse', +export const relayerApiOrderbookResponseSchema = { + id: '/relayerApiOrderbookResponseSchema', type: 'object', properties: { - bids: { $ref: '/signedOrdersSchema' }, - asks: { $ref: '/signedOrdersSchema' }, + bids: { $ref: '/relayerApiOrdersResponseSchema' }, + asks: { $ref: '/relayerApiOrdersResponseSchema' }, }, required: ['bids', 'asks'], }; diff --git a/packages/json-schemas/schemas/relayer_api_orders_channel_subscribe_schema.ts b/packages/json-schemas/schemas/relayer_api_orders_channel_subscribe_schema.ts new file mode 100644 index 000000000..a3b9b6d95 --- /dev/null +++ b/packages/json-schemas/schemas/relayer_api_orders_channel_subscribe_schema.ts @@ -0,0 +1,26 @@ +export const relayerApiOrdersChannelSubscribeSchema = { + id: '/relayerApiOrdersChannelSubscribeSchema', + type: 'object', + properties: { + type: { enum: ['subscribe'] }, + channel: { enum: ['orders'] }, + requestId: { type: 'string' }, + payload: { $ref: '/relayerApiOrdersChannelSubscribePayload' }, + }, + required: ['type', 'channel', 'requestId'], +}; + +export const relayerApiOrdersChannelSubscribePayload = { + id: '/relayerApiOrdersChannelSubscribePayload', + type: 'object', + properties: { + makerAssetProxyId: { $ref: '/hexSchema' }, + takerAssetProxyId: { $ref: '/hexSchema' }, + networkId: { type: 'number' }, + makerAssetAddress: { $ref: '/addressSchema' }, + takerAssetAddress: { $ref: '/addressSchema' }, + makerAssetData: { $ref: '/hexSchema' }, + takerAssetData: { $ref: '/hexSchema' }, + traderAssetData: { $ref: '/hexSchema' }, + }, +}; diff --git a/packages/json-schemas/schemas/relayer_api_orders_channel_update_response_schema.ts b/packages/json-schemas/schemas/relayer_api_orders_channel_update_response_schema.ts new file mode 100644 index 000000000..800b818e2 --- /dev/null +++ b/packages/json-schemas/schemas/relayer_api_orders_channel_update_response_schema.ts @@ -0,0 +1,11 @@ +export const relayerApiOrdersChannelUpdateSchema = { + id: '/relayerApiOrdersChannelUpdateSchema', + type: 'object', + properties: { + type: { enum: ['update'] }, + channel: { enum: ['orders'] }, + requestId: { type: 'string' }, + payload: { $ref: '/relayerApiOrdersSchema' }, + }, + required: ['type', 'channel', 'requestId'], +}; diff --git a/packages/json-schemas/schemas/relayer_api_orders_response_schema.ts b/packages/json-schemas/schemas/relayer_api_orders_response_schema.ts new file mode 100644 index 000000000..c10d64ca9 --- /dev/null +++ b/packages/json-schemas/schemas/relayer_api_orders_response_schema.ts @@ -0,0 +1,13 @@ +export const relayerApiOrdersResponseSchema = { + id: '/relayerApiOrdersResponseSchema', + type: 'object', + allOf: [ + { $ref: '/paginatedCollectionSchema' }, + { + properties: { + records: { $ref: '/relayerApiOrdersSchema' }, + }, + required: ['records'], + }, + ], +}; diff --git a/packages/json-schemas/schemas/relayer_api_orders_schema.ts b/packages/json-schemas/schemas/relayer_api_orders_schema.ts new file mode 100644 index 000000000..ba8ce4722 --- /dev/null +++ b/packages/json-schemas/schemas/relayer_api_orders_schema.ts @@ -0,0 +1,5 @@ +export const relayerApiOrdersSchema = { + id: '/relayerApiOrdersSchema', + type: 'array', + items: { $ref: '/relayerApiOrderSchema' }, +}; diff --git a/packages/json-schemas/schemas/relayer_api_token_pairs_response_schema.ts b/packages/json-schemas/schemas/relayer_api_token_pairs_response_schema.ts deleted file mode 100644 index 5009c7955..000000000 --- a/packages/json-schemas/schemas/relayer_api_token_pairs_response_schema.ts +++ /dev/null @@ -1,24 +0,0 @@ -export const relayerApiTokenPairsResponseSchema = { - id: '/RelayerApiTokenPairsResponse', - type: 'array', - items: { - properties: { - tokenA: { $ref: '/RelayerApiTokenTradeInfo' }, - tokenB: { $ref: '/RelayerApiTokenTradeInfo' }, - }, - required: ['tokenA', 'tokenB'], - type: 'object', - }, -}; - -export const relayerApiTokenTradeInfoSchema = { - id: '/RelayerApiTokenTradeInfo', - type: 'object', - properties: { - address: { $ref: '/Address' }, - minAmount: { $ref: '/Number' }, - maxAmount: { $ref: '/Number' }, - precision: { type: 'number' }, - }, - required: ['address'], -}; diff --git a/packages/json-schemas/schemas/signed_orders_schema.ts b/packages/json-schemas/schemas/signed_orders_schema.ts index 34d956836..e2a5aeb56 100644 --- a/packages/json-schemas/schemas/signed_orders_schema.ts +++ b/packages/json-schemas/schemas/signed_orders_schema.ts @@ -1,5 +1,5 @@ export const signedOrdersSchema = { id: '/signedOrdersSchema', type: 'array', - items: { $ref: '/SignedOrder' }, + items: { $ref: '/signedOrderSchema' }, }; diff --git a/packages/json-schemas/schemas/token_schema.ts b/packages/json-schemas/schemas/token_schema.ts index e64565c8b..a0b1ae27f 100644 --- a/packages/json-schemas/schemas/token_schema.ts +++ b/packages/json-schemas/schemas/token_schema.ts @@ -1,10 +1,10 @@ export const tokenSchema = { - id: '/Token', + id: '/tokenSchema', properties: { name: { type: 'string' }, symbol: { type: 'string' }, decimals: { type: 'number' }, - address: { $ref: '/Address' }, + address: { $ref: '/addressSchema' }, }, required: ['name', 'symbol', 'decimals', 'address'], type: 'object', diff --git a/packages/json-schemas/schemas/tx_data_schema.ts b/packages/json-schemas/schemas/tx_data_schema.ts index 4274c553f..c57e18461 100644 --- a/packages/json-schemas/schemas/tx_data_schema.ts +++ b/packages/json-schemas/schemas/tx_data_schema.ts @@ -1,22 +1,22 @@ export const jsNumber = { - id: '/JsNumber', + id: '/jsNumber', type: 'number', minimum: 0, }; export const txDataSchema = { - id: '/TxData', + id: '/txDataSchema', properties: { - from: { $ref: '/Address' }, - to: { $ref: '/Address' }, + from: { $ref: '/addressSchema' }, + to: { $ref: '/addressSchema' }, value: { - oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }], + oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }], }, gas: { - oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }], + oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }], }, gasPrice: { - oneOf: [{ $ref: '/Number' }, { $ref: '/JsNumber' }], + oneOf: [{ $ref: '/numberSchema' }, { $ref: '/jsNumber' }], }, data: { type: 'string', @@ -29,5 +29,4 @@ export const txDataSchema = { }, required: ['from'], type: 'object', - additionalProperties: false, }; diff --git a/packages/json-schemas/src/globals.d.ts b/packages/json-schemas/src/globals.d.ts index 5476b6bd8..94e63a32d 100644 --- a/packages/json-schemas/src/globals.d.ts +++ b/packages/json-schemas/src/globals.d.ts @@ -1,5 +1,3 @@ -declare module 'dirty-chai'; - declare module '*.json' { const json: any; /* tslint:disable */ diff --git a/packages/json-schemas/src/schema_validator.ts b/packages/json-schemas/src/schema_validator.ts index 38ae766e6..3f303137b 100644 --- a/packages/json-schemas/src/schema_validator.ts +++ b/packages/json-schemas/src/schema_validator.ts @@ -7,7 +7,7 @@ import { schemas } from './schemas'; * A validator for [JSON-schemas](http://json-schema.org/) */ export class SchemaValidator { - private _validator: Validator; + private readonly _validator: Validator; /** * Instantiates a SchemaValidator instance */ @@ -23,7 +23,7 @@ export class SchemaValidator { * instances of that schema. * @param schema The schema to add */ - public addSchema(schema: Schema) { + public addSchema(schema: Schema): void { this._validator.addSchema(schema, schema.id); } // In order to validate a complex JS object using jsonschema, we must replace any complex diff --git a/packages/json-schemas/src/schemas.ts b/packages/json-schemas/src/schemas.ts index 5cb07acfe..3bc37f96b 100644 --- a/packages/json-schemas/src/schemas.ts +++ b/packages/json-schemas/src/schemas.ts @@ -1,5 +1,6 @@ -import { addressSchema, numberSchema } from '../schemas/basic_type_schemas'; +import { addressSchema, hexSchema, numberSchema } from '../schemas/basic_type_schemas'; import { blockParamSchema, blockRangeSchema } from '../schemas/block_range_schema'; +import { callDataSchema } from '../schemas/call_data_schema'; import { ecSignatureParameterSchema, ecSignatureSchema } from '../schemas/ec_signature_schema'; import { indexFilterValuesSchema } from '../schemas/index_filter_values_schema'; import { orderCancellationRequestsSchema } from '../schemas/order_cancel_schema'; @@ -7,23 +8,26 @@ import { orderFillOrKillRequestsSchema } from '../schemas/order_fill_or_kill_req import { orderFillRequestsSchema } from '../schemas/order_fill_requests_schema'; import { orderHashSchema } from '../schemas/order_hash_schema'; import { orderSchema, signedOrderSchema } from '../schemas/order_schemas'; -import { relayerApiErrorResponseSchema } from '../schemas/relayer_api_error_response_schema'; -import { relayerApiFeesPayloadSchema } from '../schemas/relayer_api_fees_payload_schema'; -import { relayerApiFeesResponseSchema } from '../schemas/relayer_api_fees_response_schema'; -import { - relayerApiOrderbookChannelSubscribePayload, - relayerApiOrderbookChannelSubscribeSchema, -} from '../schemas/relayer_api_orberbook_channel_subscribe_schema'; +import { ordersSchema } from '../schemas/orders_schema'; +import { paginatedCollectionSchema } from '../schemas/paginated_collection_schema'; import { - relayerApiOrderbookChannelSnapshotPayload, - relayerApiOrderbookChannelSnapshotSchema, -} from '../schemas/relayer_api_orderbook_channel_snapshot_schema'; -import { relayerApiOrderbookChannelUpdateSchema } from '../schemas/relayer_api_orderbook_channel_update_response_schema'; -import { relayerApiOrderBookResponseSchema } from '../schemas/relayer_api_orderbook_response_schema'; + relayerApiAssetDataPairsResponseSchema, + relayerApiAssetDataPairsSchema, + relayerApiAssetDataTradeInfoSchema, +} from '../schemas/relayer_api_asset_pairs_response_schema'; +import { relayerApiErrorResponseSchema } from '../schemas/relayer_api_error_response_schema'; +import { relayerApiFeeRecipientsResponseSchema } from '../schemas/relayer_api_fee_recipients_response_schema'; +import { relayerApiOrderConfigPayloadSchema } from '../schemas/relayer_api_order_config_payload_schema'; +import { relayerApiOrderConfigResponseSchema } from '../schemas/relayer_api_order_config_response_schema'; +import { relayerApiOrderSchema } from '../schemas/relayer_api_order_schema'; +import { relayerApiOrderbookResponseSchema } from '../schemas/relayer_api_orderbook_response_schema'; import { - relayerApiTokenPairsResponseSchema, - relayerApiTokenTradeInfoSchema, -} from '../schemas/relayer_api_token_pairs_response_schema'; + relayerApiOrdersChannelSubscribePayload, + relayerApiOrdersChannelSubscribeSchema, +} from '../schemas/relayer_api_orders_channel_subscribe_schema'; +import { relayerApiOrdersChannelUpdateSchema } from '../schemas/relayer_api_orders_channel_update_response_schema'; +import { relayerApiOrdersResponseSchema } from '../schemas/relayer_api_orders_response_schema'; +import { relayerApiOrdersSchema } from '../schemas/relayer_api_orders_schema'; import { signedOrdersSchema } from '../schemas/signed_orders_schema'; import { tokenSchema } from '../schemas/token_schema'; import { jsNumber, txDataSchema } from '../schemas/tx_data_schema'; @@ -31,8 +35,10 @@ import { jsNumber, txDataSchema } from '../schemas/tx_data_schema'; export const schemas = { numberSchema, addressSchema, - ecSignatureSchema, + callDataSchema, + hexSchema, ecSignatureParameterSchema, + ecSignatureSchema, indexFilterValuesSchema, orderCancellationRequestsSchema, orderFillOrKillRequestsSchema, @@ -41,20 +47,25 @@ export const schemas = { orderSchema, signedOrderSchema, signedOrdersSchema, + ordersSchema, blockParamSchema, blockRangeSchema, tokenSchema, jsNumber, txDataSchema, + paginatedCollectionSchema, relayerApiErrorResponseSchema, - relayerApiFeesPayloadSchema, - relayerApiFeesResponseSchema, - relayerApiOrderBookResponseSchema, - relayerApiTokenPairsResponseSchema, - relayerApiTokenTradeInfoSchema, - relayerApiOrderbookChannelSubscribeSchema, - relayerApiOrderbookChannelSubscribePayload, - relayerApiOrderbookChannelUpdateSchema, - relayerApiOrderbookChannelSnapshotSchema, - relayerApiOrderbookChannelSnapshotPayload, + relayerApiFeeRecipientsResponseSchema, + relayerApiOrderSchema, + relayerApiOrdersSchema, + relayerApiOrderConfigPayloadSchema, + relayerApiOrderConfigResponseSchema, + relayerApiOrderbookResponseSchema, + relayerApiAssetDataPairsResponseSchema, + relayerApiAssetDataTradeInfoSchema, + relayerApiOrdersChannelSubscribeSchema, + relayerApiOrdersChannelSubscribePayload, + relayerApiOrdersChannelUpdateSchema, + relayerApiOrdersResponseSchema, + relayerApiAssetDataPairsSchema, }; diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index 7b058781d..4e0f66ef5 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -13,8 +13,7 @@ const NULL_ADDRESS = '0x0000000000000000000000000000000000000000'; const { numberSchema, addressSchema, - ecSignatureSchema, - ecSignatureParameterSchema, + hexSchema, orderCancellationRequestsSchema, orderFillOrKillRequestsSchema, orderFillRequestsSchema, @@ -27,14 +26,16 @@ const { tokenSchema, jsNumber, txDataSchema, + paginatedCollectionSchema, relayerApiErrorResponseSchema, - relayerApiOrderBookResponseSchema, - relayerApiTokenPairsResponseSchema, - relayerApiFeesPayloadSchema, - relayerApiFeesResponseSchema, - relayerApiOrderbookChannelSubscribeSchema, - relayerApiOrderbookChannelUpdateSchema, - relayerApiOrderbookChannelSnapshotSchema, + relayerApiOrderbookResponseSchema, + relayerApiAssetDataPairsResponseSchema, + relayerApiOrderConfigPayloadSchema, + relayerApiOrderConfigResponseSchema, + relayerApiOrdersChannelSubscribeSchema, + relayerApiOrdersChannelUpdateSchema, + relayerApiOrdersResponseSchema, + relayerApiOrderSchema, } = schemas; describe('Schema', () => { @@ -56,6 +57,11 @@ describe('Schema', () => { } }); }; + const paginatedResponse = { + total: 100, + perPage: 10, + page: 3, + }; describe('#numberSchema', () => { it('should validate valid numbers', () => { const testCases = ['42', '0', '1.3', '0.2', '00.00']; @@ -84,47 +90,15 @@ describe('Schema', () => { validateAgainstSchema(testCases, addressSchema, shouldFail); }); }); - describe('#ecSignatureParameterSchema', () => { - it('should validate valid parameters', () => { - const testCases = [ - '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - '0X40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', - ]; - validateAgainstSchema(testCases, ecSignatureParameterSchema); - }); - it('should fail for invalid parameters', () => { - const testCases = [ - '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3', // shorter - '0xzzzz9190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // invalid characters - '40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x - ]; - const shouldFail = true; - validateAgainstSchema(testCases, ecSignatureParameterSchema, shouldFail); - }); - }); - describe('#ecSignatureSchema', () => { - it('should validate valid signature', () => { - const signature = { - v: 27, - r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', - }; - const testCases = [ - signature, - { - ...signature, - v: 28, - }, - ]; - validateAgainstSchema(testCases, ecSignatureSchema); + describe('#hexSchema', () => { + it('should validate valid hex string', () => { + const testCases = ['0x8b0292b11a196601ed2ce54b665cafeca0347d42', NULL_ADDRESS]; + validateAgainstSchema(testCases, hexSchema); }); - it('should fail for invalid signature', () => { - const v = 27; - const r = '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33'; - const s = '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254'; - const testCases = [{}, { v }, { r, s, v: 31 }]; + it('should fail for invalid hex string', () => { + const testCases = ['0', '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42']; const shouldFail = true; - validateAgainstSchema(testCases, ecSignatureSchema, shouldFail); + validateAgainstSchema(testCases, hexSchema, shouldFail); }); }); describe('#orderHashSchema', () => { @@ -148,7 +122,8 @@ describe('Schema', () => { }); describe('#blockParamSchema', () => { it('should validate valid block param', () => { - const testCases = [42, 'latest', 'pending', 'earliest']; + const blockNumber = 42; + const testCases = [blockNumber, 'latest', 'pending', 'earliest']; validateAgainstSchema(testCases, blockParamSchema); }); it('should fail for invalid block param', () => { @@ -181,6 +156,7 @@ describe('Schema', () => { validateAgainstSchema(testCases, tokenSchema); }); it('should fail for invalid token', () => { + const num = 4; const testCases = [ { ...token, @@ -191,26 +167,60 @@ describe('Schema', () => { decimals: undefined, }, [], - 4, + num, ]; const shouldFail = true; validateAgainstSchema(testCases, tokenSchema, shouldFail); }); }); + describe('#paginatedCollectionSchema', () => { + it('should validate valid paginated collections', () => { + const testCases = [paginatedResponse]; + validateAgainstSchema(testCases, paginatedCollectionSchema); + }); + it('should fail for invalid paginated collections', () => { + const paginatedCollectionNoTotal = { + page: 10, + perPage: 2, + }; + const paginatedCollectionNoPerPage = { + page: 10, + total: 100, + }; + const paginatedCollectionNoPage = { + total: 10, + perPage: 20, + }; + const testCases = [{}, paginatedCollectionNoPage, paginatedCollectionNoPerPage, paginatedCollectionNoTotal]; + const shouldFail = true; + validateAgainstSchema(testCases, paginatedCollectionSchema, shouldFail); + }); + }); describe('order including schemas', () => { const order = { - maker: NULL_ADDRESS, - taker: NULL_ADDRESS, + makerAddress: NULL_ADDRESS, + takerAddress: NULL_ADDRESS, + senderAddress: NULL_ADDRESS, makerFee: '1', takerFee: '2', - makerTokenAmount: '1', - takerTokenAmount: '2', - makerTokenAddress: NULL_ADDRESS, - takerTokenAddress: NULL_ADDRESS, + makerAssetAmount: '1', + takerAssetAmount: '2', + makerAssetData: NULL_ADDRESS, + takerAssetData: NULL_ADDRESS, salt: '67006738228878699843088602623665307406148487219438534730168799356281242528500', - feeRecipient: NULL_ADDRESS, - exchangeContractAddress: NULL_ADDRESS, - expirationUnixTimestampSec: '42', + feeRecipientAddress: NULL_ADDRESS, + exchangeAddress: NULL_ADDRESS, + expirationTimeSeconds: '42', + }; + const relayerApiOrder = { + order, + metaData: { + someMetaData: 5, + }, + }; + const relayerApiOrdersResponse = { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], }; describe('#orderSchema', () => { it('should validate valid order', () => { @@ -236,11 +246,8 @@ describe('Schema', () => { describe('signed order including schemas', () => { const signedOrder = { ...order, - ecSignature: { - v: 27, - r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', - }, + signature: + '0x031b61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', }; describe('#signedOrdersSchema', () => { it('should validate valid signed orders', () => { @@ -262,7 +269,7 @@ describe('Schema', () => { const testCases = [ { ...signedOrder, - ecSignature: undefined, + signature: undefined, }, ]; const shouldFail = true; @@ -341,303 +348,452 @@ describe('Schema', () => { validateAgainstSchema(testCases, orderFillRequestsSchema, shouldFail); }); }); - describe('#relayerApiOrderBookResponseSchema', () => { - it('should validate valid order book responses', () => { - const testCases = [ - { - bids: [], - asks: [], - }, - { - bids: [signedOrder, signedOrder], - asks: [], - }, - { - bids: [], - asks: [signedOrder, signedOrder], - }, - { - bids: [signedOrder], - asks: [signedOrder, signedOrder], - }, - ]; - validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema); + describe('standard relayer api schemas', () => { + describe('#relayerApiOrderSchema', () => { + it('should validate valid relayer api order', () => { + const testCases = [relayerApiOrder]; + validateAgainstSchema(testCases, relayerApiOrderSchema); + }); + it('should fail for invalid relayer api orders', () => { + const testCases = [{}, order, { order }, { order, metaData: 5 }]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrderSchema, shouldFail); + }); }); - it('should fail for invalid order fill requests', () => { - const testCases = [ - {}, - { - bids: [signedOrder, signedOrder], - }, - { - asks: [signedOrder, signedOrder], - }, - { - bids: signedOrder, - asks: [signedOrder, signedOrder], - }, - { - bids: [signedOrder], - asks: signedOrder, - }, - ]; - const shouldFail = true; - validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema, shouldFail); + describe('#relayerApiErrorResponseSchema', () => { + it('should validate valid errorResponse', () => { + const testCases = [ + { + code: 102, + reason: 'Order submission disabled', + }, + { + code: 101, + reason: 'Validation failed', + validationErrors: [ + { + field: 'maker', + code: 1002, + reason: 'Invalid address', + }, + ], + }, + ]; + validateAgainstSchema(testCases, relayerApiErrorResponseSchema); + }); + it('should fail for invalid error responses', () => { + const testCases = [ + {}, + { + code: 102, + }, + { + code: '102', + reason: 'Order submission disabled', + }, + { + reason: 'Order submission disabled', + }, + { + code: 101, + reason: 'Validation failed', + validationErrors: [ + { + field: 'maker', + reason: 'Invalid address', + }, + ], + }, + { + code: 101, + reason: 'Validation failed', + validationErrors: [ + { + field: 'maker', + code: '1002', + reason: 'Invalid address', + }, + ], + }, + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiErrorResponseSchema, shouldFail); + }); }); - }); - describe('#relayerApiOrderbookChannelSubscribeSchema', () => { - it('should validate valid orderbook channel websocket subscribe message', () => { - const testCases = [ - { - type: 'subscribe', - channel: 'orderbook', - requestId: 1, - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: true, - limit: 100, + describe('#relayerApiOrderConfigPayloadSchema', () => { + it('should validate valid fees payloads', () => { + const testCases = [ + { + exchangeAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + makerAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + takerAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + makerAssetData: NULL_ADDRESS, + takerAssetData: NULL_ADDRESS, + makerAssetAmount: '10000000000000000000', + takerAssetAmount: '30000000000000000000', + expirationTimeSeconds: '42', }, - }, - { - type: 'subscribe', - channel: 'orderbook', - requestId: 1, - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + ]; + validateAgainstSchema(testCases, relayerApiOrderConfigPayloadSchema); + }); + it('should fail for invalid fees payloads', () => { + const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; + const testCases = [ + {}, + { + makerAssetAmount: '10000000000000000000', + takerAssetAmount: '30000000000000000000', + makerAssetData: NULL_ADDRESS, + takerAssetData: NULL_ADDRESS, }, - }, - ]; - validateAgainstSchema(testCases, relayerApiOrderbookChannelSubscribeSchema); + { + takerAddress: checksummedAddress, + makerAssetAmount: '10000000000000000000', + takerAssetAmount: '30000000000000000000', + }, + { + makerAssetAmount: 10000000000000000000, + takerAssetAmount: 30000000000000000000, + }, + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrderConfigPayloadSchema, shouldFail); + }); }); - it('should fail for invalid orderbook channel websocket subscribe message', () => { - const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; - const testCases = [ - { - type: 'subscribe', - channel: 'orderbook', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: true, - limit: 100, + describe('#relayerApiOrderConfigResponseSchema', () => { + it('should validate valid fees responses', () => { + const testCases = [ + { + makerFee: '10000000000000000', + takerFee: '30000000000000000', + feeRecipientAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + senderAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', }, - }, - { - type: 'foo', - channel: 'orderbook', - requestId: 1, - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + ]; + validateAgainstSchema(testCases, relayerApiOrderConfigResponseSchema); + }); + it('should fail for invalid fees responses', () => { + const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; + const testCases = [ + {}, + { + makerFee: 10000000000000000, + takerFee: 30000000000000000, }, - }, - { - type: 'subscribe', - channel: 'bar', - requestId: 1, - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + { + feeRecipient: checksummedAddress, + takerToSpecify: checksummedAddress, + makerFee: '10000000000000000', + takerFee: '30000000000000000', }, - }, - { - type: 'subscribe', - channel: 'orderbook', - requestId: 1, - payload: { - baseTokenAddress: checksummedAddress, - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrderConfigResponseSchema, shouldFail); + }); + }); + describe('#relayerAssetDataPairsResponseSchema', () => { + it('should validate valid assetPairs response', () => { + const testCases = [ + { + ...paginatedResponse, + records: [], }, - }, - { - type: 'subscribe', - channel: 'orderbook', - requestId: 1, - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: checksummedAddress, + { + ...paginatedResponse, + records: [ + { + assetDataA: { + assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + minAmount: '0', + maxAmount: '10000000000000000000', + precision: 5, + }, + assetDataB: { + assetData: '0xef7fff64389b814a946f3e92105513705ca6b990', + minAmount: '0', + maxAmount: '50000000000000000000', + precision: 5, + }, + }, + ], }, - }, - { - type: 'subscribe', - channel: 'orderbook', - requestId: 1, - payload: { - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + { + ...paginatedResponse, + records: [ + { + assetDataA: { + assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + }, + assetDataB: { + assetData: '0xef7fff64389b814a946f3e92105513705ca6b990', + }, + }, + ], }, - }, - { - type: 'subscribe', - channel: 'orderbook', - requestId: 1, - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + ]; + validateAgainstSchema(testCases, relayerApiAssetDataPairsResponseSchema); + }); + it('should fail for invalid assetPairs responses', () => { + const testCases = [ + { + ...paginatedResponse, + records: [ + { + assetDataA: { + assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + minAmount: '0', + maxAmount: '10000000000000000000', + precision: 5, + }, + assetDataC: { + assetData: '0xef7fff64389b814a946f3e92105513705ca6b990', + minAmount: '0', + maxAmount: '50000000000000000000', + precision: 5, + }, + }, + ], }, - }, - { - type: 'subscribe', - channel: 'orderbook', - requestId: 1, - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: 'true', - limit: 100, + { + records: [ + { + assetDataA: { + assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + minAmount: '0', + maxAmount: '10000000000000000000', + precision: 5, + }, + assetDataB: { + assetData: '0xef7fff64389b814a946f3e92105513705ca6b990', + minAmount: '0', + maxAmount: '50000000000000000000', + precision: 5, + }, + }, + ], }, - }, - { - type: 'subscribe', - channel: 'orderbook', - requestId: 1, - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: true, - limit: '100', + { + ...paginatedResponse, + records: [ + { + assetDataA: { + minAmount: '0', + maxAmount: '10000000000000000000', + precision: 5, + }, + assetDataB: { + minAmount: '0', + maxAmount: '50000000000000000000', + precision: 5, + }, + }, + ], }, - }, - ]; - const shouldFail = true; - validateAgainstSchema(testCases, relayerApiOrderbookChannelSubscribeSchema, shouldFail); + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiAssetDataPairsResponseSchema, shouldFail); + }); }); - }); - describe('#relayerApiOrderbookChannelSnapshotSchema', () => { - it('should validate valid orderbook channel websocket snapshot message', () => { - const testCases = [ - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - bids: [], - asks: [], + describe('#relayerApiOrdersResponseSchema', () => { + it('should validate valid orders responses', () => { + const testCases = [ + relayerApiOrdersResponse, + { + ...paginatedResponse, + records: [], }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - bids: [signedOrder], - asks: [signedOrder], + ]; + validateAgainstSchema(testCases, relayerApiOrdersResponseSchema); + }); + it('should fail for invalid orders responses', () => { + const testCases = [ + { + records: [relayerApiOrder, relayerApiOrder], }, - }, - ]; - validateAgainstSchema(testCases, relayerApiOrderbookChannelSnapshotSchema); - }); - it('should fail for invalid orderbook channel websocket snapshot message', () => { - const testCases = [ - { - type: 'foo', - channel: 'orderbook', - requestId: 2, - payload: { - bids: [signedOrder], - asks: [signedOrder], + { + ...paginatedResponse, }, - }, - { - type: 'snapshot', - channel: 'bar', - requestId: 2, - payload: { - bids: [signedOrder], - asks: [signedOrder], + { + ...paginatedResponse, + records: [{}, relayerApiOrder], }, - }, - { - type: 'snapshot', - channel: 'orderbook', - payload: { - bids: [signedOrder], - asks: [signedOrder], + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrdersResponseSchema, shouldFail); + }); + }); + describe('#relayerApiOrderbookResponseSchema', () => { + it('should validate valid order book responses', () => { + const testCases = [ + { + bids: { + ...paginatedResponse, + records: [relayerApiOrder], + }, + asks: { + ...paginatedResponse, + records: [], + }, }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: '2', - payload: { - bids: [signedOrder], - asks: [signedOrder], + { + bids: { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], + }, + asks: { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], + }, }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - bids: [signedOrder], + { + bids: { + ...paginatedResponse, + records: [], + }, + asks: { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], + }, }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - asks: [signedOrder], + ]; + validateAgainstSchema(testCases, relayerApiOrderbookResponseSchema); + }); + it('should fail for invalid order fill requests', () => { + const testCases = [ + {}, + { + bids: { + records: [relayerApiOrder], + }, + asks: { + ...paginatedResponse, + records: [], + }, }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - bids: [signedOrder], - asks: [{}], + { + bids: { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], + }, + asks: {}, }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - bids: [{}], - asks: [signedOrder], + { + bids: { + ...paginatedResponse, + }, + asks: { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], + }, }, - }, - ]; - const shouldFail = true; - validateAgainstSchema(testCases, relayerApiOrderbookChannelSnapshotSchema, shouldFail); + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrdersResponseSchema, shouldFail); + }); }); - }); - describe('#relayerApiOrderbookChannelUpdateSchema', () => { - it('should validate valid orderbook channel websocket update message', () => { - const testCases = [ - { - type: 'update', - channel: 'orderbook', - requestId: 2, - payload: signedOrder, - }, - ]; - validateAgainstSchema(testCases, relayerApiOrderbookChannelUpdateSchema); + describe('#relayerApiOrdersChannelSubscribeSchema', () => { + it('should validate valid orders channel websocket subscribe message', () => { + const testCases = [ + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: { + makerAssetProxyId: '0x02571792', + takerAssetProxyId: '0xf47261b0', + }, + }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: {}, + }, + ]; + validateAgainstSchema(testCases, relayerApiOrdersChannelSubscribeSchema); + }); + it('should fail for invalid orders channel websocket subscribe message', () => { + const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; + const testCases = [ + { + type: 'subscribe', + channel: 'orders', + }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: { + makerAssetProxyId: '0x02571792', + takerAssetProxyId: '0xf47261b0', + makerAssetAddress: checksummedAddress, + }, + }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: { + makerAssetProxyId: 'invalidId', + }, + }, + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrdersChannelSubscribeSchema, shouldFail); + }); }); - it('should fail for invalid orderbook channel websocket update message', () => { - const testCases = [ - { - type: 'foo', - channel: 'orderbook', - requestId: 2, - payload: signedOrder, - }, - { - type: 'update', - channel: 'bar', - requestId: 2, - payload: signedOrder, - }, - { - type: 'update', - channel: 'orderbook', - requestId: 2, - payload: {}, - }, - ]; - const shouldFail = true; - validateAgainstSchema(testCases, relayerApiOrderbookChannelUpdateSchema, shouldFail); + describe('#relayerApiOrdersChannelUpdateSchema', () => { + it('should validate valid orders channel websocket update message', () => { + const testCases = [ + { + type: 'update', + channel: 'orders', + requestId: 'randomId', + payload: [relayerApiOrder], + }, + { + type: 'update', + channel: 'orders', + requestId: 'randomId', + payload: [], + }, + ]; + validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema); + }); + it('should fail for invalid orders channel websocket update message', () => { + const testCases = [ + { + type: 'foo', + channel: 'orders', + requestId: 'randomId', + }, + { + type: 'update', + channel: 'bar', + requestId: 2, + payload: [relayerApiOrder], + }, + { + type: 'update', + channel: 'orders', + requestId: 'randomId', + payload: {}, + }, + { + type: 'update', + channel: 'orders', + requestId: 'randomId', + payload: relayerApiErrorResponseSchema, + }, + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema, shouldFail); + }); }); }); }); @@ -657,223 +813,14 @@ describe('Schema', () => { }); }); }); - describe('#relayerApiErrorResponseSchema', () => { - it('should validate valid errorResponse', () => { - const testCases = [ - { - code: 102, - reason: 'Order submission disabled', - }, - { - code: 101, - reason: 'Validation failed', - validationErrors: [ - { - field: 'maker', - code: 1002, - reason: 'Invalid address', - }, - ], - }, - ]; - validateAgainstSchema(testCases, relayerApiErrorResponseSchema); - }); - it('should fail for invalid error responses', () => { - const testCases = [ - {}, - { - code: 102, - }, - { - code: '102', - reason: 'Order submission disabled', - }, - { - reason: 'Order submission disabled', - }, - { - code: 101, - reason: 'Validation failed', - validationErrors: [ - { - field: 'maker', - reason: 'Invalid address', - }, - ], - }, - { - code: 101, - reason: 'Validation failed', - validationErrors: [ - { - field: 'maker', - code: '1002', - reason: 'Invalid address', - }, - ], - }, - ]; - const shouldFail = true; - validateAgainstSchema(testCases, relayerApiErrorResponseSchema, shouldFail); - }); - }); - describe('#relayerApiFeesPayloadSchema', () => { - it('should validate valid fees payloads', () => { - const testCases = [ - { - exchangeContractAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - maker: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - taker: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - makerTokenAmount: '10000000000000000000', - takerTokenAmount: '30000000000000000000', - expirationUnixTimestampSec: '42', - salt: '67006738228878699843088602623665307406148487219438534730168799356281242528500', - }, - ]; - validateAgainstSchema(testCases, relayerApiFeesPayloadSchema); - }); - it('should fail for invalid fees payloads', () => { - const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; - const testCases = [ - {}, - { - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - makerTokenAmount: '10000000000000000000', - takerTokenAmount: '30000000000000000000', - }, - { - taker: checksummedAddress, - makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - makerTokenAmount: '10000000000000000000', - takerTokenAmount: '30000000000000000000', - }, - { - makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - makerTokenAmount: 10000000000000000000, - takerTokenAmount: 30000000000000000000, - }, - ]; - const shouldFail = true; - validateAgainstSchema(testCases, relayerApiFeesPayloadSchema, shouldFail); - }); - }); - describe('#relayerApiFeesResponseSchema', () => { - it('should validate valid fees responses', () => { - const testCases = [ - { - makerFee: '10000000000000000', - takerFee: '30000000000000000', - feeRecipient: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - }, - ]; - validateAgainstSchema(testCases, relayerApiFeesResponseSchema); - }); - it('should fail for invalid fees responses', () => { - const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; - const testCases = [ - {}, - { - makerFee: 10000000000000000, - takerFee: 30000000000000000, - }, - { - feeRecipient: checksummedAddress, - takerToSpecify: checksummedAddress, - makerFee: '10000000000000000', - takerFee: '30000000000000000', - }, - ]; - const shouldFail = true; - validateAgainstSchema(testCases, relayerApiFeesResponseSchema, shouldFail); - }); - }); - describe('#relayerApiTokenPairsResponseSchema', () => { - it('should validate valid tokenPairs response', () => { - const testCases = [ - [], - [ - { - tokenA: { - address: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - minAmount: '0', - maxAmount: '10000000000000000000', - precision: 5, - }, - tokenB: { - address: '0xef7fff64389b814a946f3e92105513705ca6b990', - minAmount: '0', - maxAmount: '50000000000000000000', - precision: 5, - }, - }, - ], - [ - { - tokenA: { - address: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - }, - tokenB: { - address: '0xef7fff64389b814a946f3e92105513705ca6b990', - }, - }, - ], - ]; - validateAgainstSchema(testCases, relayerApiTokenPairsResponseSchema); - }); - it('should fail for invalid tokenPairs responses', () => { - const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; - const testCases = [ - [ - { - tokenA: { - address: checksummedAddress, - }, - tokenB: { - address: checksummedAddress, - }, - }, - ], - [ - { - tokenA: { - address: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - minAmount: 0, - maxAmount: 10000000000000000000, - }, - tokenB: { - address: '0xef7fff64389b814a946f3e92105513705ca6b990', - minAmount: 0, - maxAmount: 50000000000000000000, - }, - }, - ], - [ - { - tokenA: { - address: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - precision: '5', - }, - tokenB: { - address: '0xef7fff64389b814a946f3e92105513705ca6b990', - precision: '5', - }, - }, - ], - ]; - const shouldFail = true; - validateAgainstSchema(testCases, relayerApiTokenPairsResponseSchema, shouldFail); - }); - }); describe('#jsNumberSchema', () => { it('should validate valid js number', () => { + // tslint:disable-next-line:custom-no-magic-numbers const testCases = [1, 42]; validateAgainstSchema(testCases, jsNumber); }); it('should fail for invalid js number', () => { + // tslint:disable-next-line:custom-no-magic-numbers const testCases = [NaN, -1, new BigNumber(1)]; const shouldFail = true; validateAgainstSchema(testCases, jsNumber, shouldFail); @@ -881,13 +828,14 @@ describe('Schema', () => { }); describe('#txDataSchema', () => { it('should validate valid txData', () => { + const bigNumGasAmount = new BigNumber(42); const testCases = [ { from: NULL_ADDRESS, }, { from: NULL_ADDRESS, - gas: new BigNumber(42), + gas: bigNumGasAmount, }, { from: NULL_ADDRESS, @@ -901,10 +849,6 @@ describe('Schema', () => { { gas: new BigNumber(42), }, - { - from: NULL_ADDRESS, - unknownProp: 'here', - }, {}, [], new BigNumber(1), |