diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-08-01 07:37:51 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-08-01 07:37:51 +0800 |
commit | 4aff9515d807feb5fc30431d109d503a6c52f0cd (patch) | |
tree | 49c98689c083cdb0fd3992768d924a92ccfbd243 /packages | |
parent | 162fe797fcd4c41d8d84184ca5c0352c8342937b (diff) | |
download | dexon-sol-tools-4aff9515d807feb5fc30431d109d503a6c52f0cd.tar dexon-sol-tools-4aff9515d807feb5fc30431d109d503a6c52f0cd.tar.gz dexon-sol-tools-4aff9515d807feb5fc30431d109d503a6c52f0cd.tar.bz2 dexon-sol-tools-4aff9515d807feb5fc30431d109d503a6c52f0cd.tar.lz dexon-sol-tools-4aff9515d807feb5fc30431d109d503a6c52f0cd.tar.xz dexon-sol-tools-4aff9515d807feb5fc30431d109d503a6c52f0cd.tar.zst dexon-sol-tools-4aff9515d807feb5fc30431d109d503a6c52f0cd.zip |
Get schema tests running (not crashiing)
Diffstat (limited to 'packages')
-rw-r--r-- | packages/json-schemas/schemas/paginated_collection_schema.ts | 4 | ||||
-rw-r--r-- | packages/json-schemas/src/schemas.ts | 12 | ||||
-rw-r--r-- | packages/json-schemas/test/schema_test.ts | 205 | ||||
-rw-r--r-- | packages/sra-api/package.json | 9 | ||||
-rw-r--r-- | packages/sra-api/src/api.ts | 51 |
5 files changed, 121 insertions, 160 deletions
diff --git a/packages/json-schemas/schemas/paginated_collection_schema.ts b/packages/json-schemas/schemas/paginated_collection_schema.ts index 5dd82ab3d..2c29ef4e0 100644 --- a/packages/json-schemas/schemas/paginated_collection_schema.ts +++ b/packages/json-schemas/schemas/paginated_collection_schema.ts @@ -3,8 +3,8 @@ export const paginatedCollectionSchema = { type: 'object', properties: { total: { $ref: '/Number' }, - per_page: { $ref: '/Number' }, + perPage: { $ref: '/Number' }, page: { $ref: '/Number' }, }, - required: ['total', 'per_page', 'page'], + required: ['total', 'perPage', 'page'], }; diff --git a/packages/json-schemas/src/schemas.ts b/packages/json-schemas/src/schemas.ts index a06729617..defe55bda 100644 --- a/packages/json-schemas/src/schemas.ts +++ b/packages/json-schemas/src/schemas.ts @@ -9,6 +9,7 @@ import { orderFillRequestsSchema } from '../schemas/order_fill_requests_schema'; import { orderHashSchema } from '../schemas/order_hash_schema'; import { orderSchema, signedOrderSchema } from '../schemas/order_schemas'; import { ordersSchema } from '../schemas/orders_schema'; +import { paginatedCollectionSchema } from '../schemas/paginated_collection_schema'; import { relayerApiAssetDataPairsResponseSchema, relayerApiAssetDataTradeInfoSchema, @@ -22,6 +23,9 @@ import { 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 { relayerApiOrderSchema } from '../schemas/relayer_api_order_schema'; import { signedOrdersSchema } from '../schemas/signed_orders_schema'; import { tokenSchema } from '../schemas/token_schema'; import { jsNumber, txDataSchema } from '../schemas/tx_data_schema'; @@ -47,13 +51,17 @@ export const schemas = { tokenSchema, jsNumber, txDataSchema, + paginatedCollectionSchema, relayerApiErrorResponseSchema, + relayerApiOrderSchema, + relayerApiOrdersSchema, relayerApiOrderConfigPayloadSchema, relayerApiOrderConfigResponseSchema, relayerApiOrderBookResponseSchema, - relayerApiAssetPairsResponseSchema, - relayerApiAssetTradeInfoSchema, + relayerApiAssetDataPairsResponseSchema, + relayerApiAssetDataTradeInfoSchema, relayerApiOrdersChannelSubscribeSchema, relayerApiOrdersChannelSubscribePayload, relayerApiOrdersChannelUpdateSchema, + relayerApiOrdersResponseSchema, }; diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index d202b5643..a6bbf12e6 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -26,14 +26,15 @@ const { tokenSchema, jsNumber, txDataSchema, + paginatedCollectionSchema, relayerApiErrorResponseSchema, relayerApiOrderBookResponseSchema, - relayerApiTokenPairsResponseSchema, - relayerApiFeesPayloadSchema, - relayerApiFeesResponseSchema, - relayerApiOrderbookChannelSubscribeSchema, - relayerApiOrderbookChannelUpdateSchema, - relayerApiOrderbookChannelSnapshotSchema, + relayerApiAssetDataPairsResponseSchema, + relayerApiOrderConfigPayloadSchema, + relayerApiOrderConfigResponseSchema, + relayerApiOrdersChannelSubscribeSchema, + relayerApiOrdersChannelUpdateSchema, + relayerApiOrdersResponseSchema, } = schemas; describe('Schema', () => { @@ -328,7 +329,7 @@ describe('Schema', () => { asks: [signedOrder, signedOrder], }, ]; - validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema); + validateAgainstSchema(testCases, relayerApiOrdersResponseSchema); }); it('should fail for invalid order fill requests', () => { const testCases = [ @@ -349,16 +350,16 @@ describe('Schema', () => { }, ]; const shouldFail = true; - validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema, shouldFail); + validateAgainstSchema(testCases, relayerApiOrdersResponseSchema, shouldFail); }); }); - describe('#relayerApiOrderbookChannelSubscribeSchema', () => { - it('should validate valid orderbook channel websocket subscribe message', () => { + describe('#relayerApiOrdersChannelSubscribeSchema', () => { + it('should validate valid orders channel websocket subscribe message', () => { const testCases = [ { type: 'subscribe', - channel: 'orderbook', - requestId: 1, + channel: 'orders', + requestId: 'randomId', payload: { baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', @@ -368,22 +369,22 @@ describe('Schema', () => { }, { type: 'subscribe', - channel: 'orderbook', - requestId: 1, + channel: 'orders', + requestId: 'randomId', payload: { baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', }, }, ]; - validateAgainstSchema(testCases, relayerApiOrderbookChannelSubscribeSchema); + validateAgainstSchema(testCases, relayerApiOrdersChannelSubscribeSchema); }); - it('should fail for invalid orderbook channel websocket subscribe message', () => { + it('should fail for invalid orders channel websocket subscribe message', () => { const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; const testCases = [ { type: 'subscribe', - channel: 'orderbook', + channel: 'orders', payload: { baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', @@ -393,8 +394,8 @@ describe('Schema', () => { }, { type: 'foo', - channel: 'orderbook', - requestId: 1, + channel: 'orders', + requestId: 'randomId', payload: { baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', @@ -403,7 +404,7 @@ describe('Schema', () => { { type: 'subscribe', channel: 'bar', - requestId: 1, + requestId: 'randomId', payload: { baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', @@ -411,8 +412,8 @@ describe('Schema', () => { }, { type: 'subscribe', - channel: 'orderbook', - requestId: 1, + channel: 'orders', + requestId: 'randomId', payload: { baseTokenAddress: checksummedAddress, quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', @@ -420,8 +421,8 @@ describe('Schema', () => { }, { type: 'subscribe', - channel: 'orderbook', - requestId: 1, + channel: 'orders', + requestId: 'randomId', payload: { baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', quoteTokenAddress: checksummedAddress, @@ -429,24 +430,24 @@ describe('Schema', () => { }, { type: 'subscribe', - channel: 'orderbook', - requestId: 1, + channel: 'orders', + requestId: 'randomId', payload: { quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', }, }, { type: 'subscribe', - channel: 'orderbook', - requestId: 1, + channel: 'orders', + requestId: 'randomId', payload: { baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', }, }, { type: 'subscribe', - channel: 'orderbook', - requestId: 1, + channel: 'orders', + requestId: 'randomId', payload: { baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', @@ -456,8 +457,8 @@ describe('Schema', () => { }, { type: 'subscribe', - channel: 'orderbook', - requestId: 1, + channel: 'orders', + requestId: 'randomId', payload: { baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', @@ -467,126 +468,26 @@ describe('Schema', () => { }, ]; const shouldFail = true; - validateAgainstSchema(testCases, relayerApiOrderbookChannelSubscribeSchema, shouldFail); + validateAgainstSchema(testCases, relayerApiOrdersChannelSubscribeSchema, shouldFail); }); }); - describe('#relayerApiOrderbookChannelSnapshotSchema', () => { - it('should validate valid orderbook channel websocket snapshot message', () => { - const testCases = [ - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - bids: [], - asks: [], - }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - bids: [signedOrder], - asks: [signedOrder], - }, - }, - ]; - 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], - }, - }, - { - type: 'snapshot', - channel: 'bar', - requestId: 2, - payload: { - bids: [signedOrder], - asks: [signedOrder], - }, - }, - { - type: 'snapshot', - channel: 'orderbook', - payload: { - bids: [signedOrder], - asks: [signedOrder], - }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: '2', - payload: { - bids: [signedOrder], - asks: [signedOrder], - }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - bids: [signedOrder], - }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - asks: [signedOrder], - }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - bids: [signedOrder], - asks: [{}], - }, - }, - { - type: 'snapshot', - channel: 'orderbook', - requestId: 2, - payload: { - bids: [{}], - asks: [signedOrder], - }, - }, - ]; - const shouldFail = true; - validateAgainstSchema(testCases, relayerApiOrderbookChannelSnapshotSchema, shouldFail); - }); - }); - describe('#relayerApiOrderbookChannelUpdateSchema', () => { - it('should validate valid orderbook channel websocket update message', () => { + describe('#relayerApiOrdersChannelUpdateSchema', () => { + it('should validate valid orders channel websocket update message', () => { const testCases = [ { type: 'update', - channel: 'orderbook', + channel: 'orders', requestId: 2, payload: signedOrder, }, ]; - validateAgainstSchema(testCases, relayerApiOrderbookChannelUpdateSchema); + validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema); }); - it('should fail for invalid orderbook channel websocket update message', () => { + it('should fail for invalid orders channel websocket update message', () => { const testCases = [ { type: 'foo', - channel: 'orderbook', + channel: 'orders', requestId: 2, payload: signedOrder, }, @@ -598,13 +499,13 @@ describe('Schema', () => { }, { type: 'update', - channel: 'orderbook', + channel: 'orders', requestId: 2, payload: {}, }, ]; const shouldFail = true; - validateAgainstSchema(testCases, relayerApiOrderbookChannelUpdateSchema, shouldFail); + validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema, shouldFail); }); }); }); @@ -684,7 +585,7 @@ describe('Schema', () => { validateAgainstSchema(testCases, relayerApiErrorResponseSchema, shouldFail); }); }); - describe('#relayerApiFeesPayloadSchema', () => { + describe('#relayerApiOrderConfigPayloadSchema', () => { it('should validate valid fees payloads', () => { const testCases = [ { @@ -699,7 +600,7 @@ describe('Schema', () => { salt: '67006738228878699843088602623665307406148487219438534730168799356281242528500', }, ]; - validateAgainstSchema(testCases, relayerApiFeesPayloadSchema); + validateAgainstSchema(testCases, relayerApiOrderConfigPayloadSchema); }); it('should fail for invalid fees payloads', () => { const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; @@ -725,10 +626,10 @@ describe('Schema', () => { }, ]; const shouldFail = true; - validateAgainstSchema(testCases, relayerApiFeesPayloadSchema, shouldFail); + validateAgainstSchema(testCases, relayerApiOrderConfigPayloadSchema, shouldFail); }); }); - describe('#relayerApiFeesResponseSchema', () => { + describe('#relayerApiOrderConfigResponseSchema', () => { it('should validate valid fees responses', () => { const testCases = [ { @@ -737,7 +638,7 @@ describe('Schema', () => { feeRecipient: '0x323b5d4c32345ced77393b3530b1eed0f346429d', }, ]; - validateAgainstSchema(testCases, relayerApiFeesResponseSchema); + validateAgainstSchema(testCases, relayerApiOrderConfigResponseSchema); }); it('should fail for invalid fees responses', () => { const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; @@ -755,11 +656,11 @@ describe('Schema', () => { }, ]; const shouldFail = true; - validateAgainstSchema(testCases, relayerApiFeesResponseSchema, shouldFail); + validateAgainstSchema(testCases, relayerApiOrderConfigResponseSchema, shouldFail); }); }); - describe('#relayerApiTokenPairsResponseSchema', () => { - it('should validate valid tokenPairs response', () => { + describe('#relayerAssetDataPairsResponseSchema', () => { + it('should validate valid assetPairs response', () => { const testCases = [ [], [ @@ -789,9 +690,9 @@ describe('Schema', () => { }, ], ]; - validateAgainstSchema(testCases, relayerApiTokenPairsResponseSchema); + validateAgainstSchema(testCases, relayerApiAssetDataPairsResponseSchema); }); - it('should fail for invalid tokenPairs responses', () => { + it('should fail for invalid assetPairs responses', () => { const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; const testCases = [ [ @@ -832,7 +733,7 @@ describe('Schema', () => { ], ]; const shouldFail = true; - validateAgainstSchema(testCases, relayerApiTokenPairsResponseSchema, shouldFail); + validateAgainstSchema(testCases, relayerApiAssetDataPairsResponseSchema, shouldFail); }); }); describe('#jsNumberSchema', () => { diff --git a/packages/sra-api/package.json b/packages/sra-api/package.json index 61fa392fb..9a0ab4971 100644 --- a/packages/sra-api/package.json +++ b/packages/sra-api/package.json @@ -4,15 +4,14 @@ "engines": { "node": ">=6.12" }, - "description": "Standard Relayer API Swagger Spec", + "description": "Standard Relayer API Open API Spec", "main": "lib/src/index.js", "types": "lib/src/index.d.ts", "scripts": { "serve": "redoc-cli serve lib/api.json --watch", - "develop": "run-p build-json:watch serve", + "watch_without_deps": "run-p build-json:watch serve", "lint": "tslint --project .", "test": "yarn run_mocha", - "redoc-cli": "redoc-cli", "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", @@ -33,7 +32,9 @@ "url": "https://github.com/0xProject/0x-monorepo/issues" }, "homepage": "https://github.com/0xProject/0x-monorepo/packages/sra-api/README.md", - "dependencies": {}, + "dependencies": { + "@0xproject/json-schemas": "1.0.1-rc.3" + }, "devDependencies": { "@0xproject/tslint-config": "^1.0.4", "@loopback/openapi-v3-types": "^0.8.2", diff --git a/packages/sra-api/src/api.ts b/packages/sra-api/src/api.ts index c05311516..fd64ab1d7 100644 --- a/packages/sra-api/src/api.ts +++ b/packages/sra-api/src/api.ts @@ -1,3 +1,4 @@ +import { schemas } from '@0xproject/json-schemas'; import { OpenApiSpec } from '@loopback/openapi-v3-types'; export const api: OpenApiSpec = { @@ -14,6 +15,55 @@ export const api: OpenApiSpec = { // TODO: Use relayer registry information here? ], paths: { + '/orders': { + get: { + summary: 'List all pets', + operationId: 'listPets2', + tags: ['pets'], + parameters: [ + { + name: 'limit', + in: 'query', + description: 'How many items to return at one time (max 100)', + required: false, + schema: { + type: 'integer', + format: 'int32', + }, + }, + ], + responses: { + '200': { + description: 'An paged array of pets', + headers: { + 'x-next': { + description: 'A link to the next page of responses', + schema: { + type: 'string', + }, + }, + }, + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/Pets', + }, + }, + }, + }, + default: { + description: 'unexpected error', + content: { + 'application/json': { + schema: { + $ref: '#/components/schemas/Error', + }, + }, + }, + }, + }, + }, + }, '/pets': { get: { summary: 'List all pets', @@ -141,6 +191,7 @@ export const api: OpenApiSpec = { }, }, }, + // Orderbook: schemas.relayerApiOrderBookResponseSchema, Pets: { type: 'array', items: { |