From 4aff9515d807feb5fc30431d109d503a6c52f0cd Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 31 Jul 2018 16:37:51 -0700 Subject: Get schema tests running (not crashiing) --- packages/json-schemas/test/schema_test.ts | 205 ++++++++---------------------- 1 file changed, 53 insertions(+), 152 deletions(-) (limited to 'packages/json-schemas/test/schema_test.ts') 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', () => { -- cgit v1.2.3 From 63e869f6d01663a22773d244920362921dbcdcdc Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 31 Jul 2018 17:04:22 -0700 Subject: Add paginated collection test case --- packages/json-schemas/test/schema_test.ts | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index a6bbf12e6..03c0e950b 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -167,6 +167,34 @@ describe('Schema', () => { validateAgainstSchema(testCases, tokenSchema, shouldFail); }); }); + describe('#paginatedCollectionSchema', () => { + const paginatedResponse = { + total: 100, + perPage: 10, + page: 3, + }; + 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 = { makerAddress: NULL_ADDRESS, @@ -329,7 +357,7 @@ describe('Schema', () => { asks: [signedOrder, signedOrder], }, ]; - validateAgainstSchema(testCases, relayerApiOrdersResponseSchema); + validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema); }); it('should fail for invalid order fill requests', () => { const testCases = [ -- cgit v1.2.3 From a78d35f84ee896e70385476fcc8ee2c9db9931bd Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 31 Jul 2018 17:22:26 -0700 Subject: Add test for relayerApiOrderSchema --- packages/json-schemas/test/schema_test.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index 03c0e950b..e8ccd4ec6 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -5,6 +5,8 @@ import forEach = require('lodash.foreach'); import 'mocha'; import { schemas, SchemaValidator } from '../src/index'; +import { validate } from 'jsonschema'; +import { relayerApiOrderSchema } from '../schemas/relayer_api_order_schema'; chai.config.includeStack = true; chai.use(dirtyChai); @@ -211,6 +213,10 @@ describe('Schema', () => { exchangeAddress: NULL_ADDRESS, expirationTimeSeconds: '42', }; + const relayerApiOrder = { + order, + remainingFillableAmount: '50000000000000', + }; describe('#orderSchema', () => { it('should validate valid order', () => { const testCases = [order]; @@ -232,6 +238,17 @@ describe('Schema', () => { validateAgainstSchema(testCases, orderSchema, shouldFail); }); }); + 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, remainingFillableAmount: 5 }]; + const shouldFail = true; + validateAgainstSchema(testCases, shouldFail); + }); + }); describe('signed order including schemas', () => { const signedOrder = { ...order, -- cgit v1.2.3 From 63e088730ac2eef63c2da7e05a19904e964259e9 Mon Sep 17 00:00:00 2001 From: fragosti Date: Tue, 31 Jul 2018 17:46:57 -0700 Subject: Group all standard relayer api tests together --- packages/json-schemas/test/schema_test.ts | 811 +++++++++++++++--------------- 1 file changed, 406 insertions(+), 405 deletions(-) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index e8ccd4ec6..57ef25172 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -5,8 +5,6 @@ import forEach = require('lodash.foreach'); import 'mocha'; import { schemas, SchemaValidator } from '../src/index'; -import { validate } from 'jsonschema'; -import { relayerApiOrderSchema } from '../schemas/relayer_api_order_schema'; chai.config.includeStack = true; chai.use(dirtyChai); @@ -37,6 +35,7 @@ const { relayerApiOrdersChannelSubscribeSchema, relayerApiOrdersChannelUpdateSchema, relayerApiOrdersResponseSchema, + relayerApiOrderSchema, } = schemas; describe('Schema', () => { @@ -238,17 +237,6 @@ describe('Schema', () => { validateAgainstSchema(testCases, orderSchema, shouldFail); }); }); - 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, remainingFillableAmount: 5 }]; - const shouldFail = true; - validateAgainstSchema(testCases, shouldFail); - }); - }); describe('signed order including schemas', () => { const signedOrder = { ...order, @@ -354,203 +342,427 @@ 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, remainingFillableAmount: 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, relayerApiOrdersResponseSchema, 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('#relayerApiOrdersChannelSubscribeSchema', () => { - it('should validate valid orders channel websocket subscribe message', () => { - const testCases = [ - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: true, - limit: 100, + describe('#relayerApiOrderConfigPayloadSchema', () => { + 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', }, - }, - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + ]; + validateAgainstSchema(testCases, relayerApiOrderConfigPayloadSchema); + }); + it('should fail for invalid fees payloads', () => { + const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; + const testCases = [ + {}, + { + takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', + makerTokenAmount: '10000000000000000000', + takerTokenAmount: '30000000000000000000', }, - }, - ]; - validateAgainstSchema(testCases, relayerApiOrdersChannelSubscribeSchema); + { + taker: checksummedAddress, + makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', + makerTokenAmount: '10000000000000000000', + takerTokenAmount: '30000000000000000000', + }, + { + makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', + makerTokenAmount: 10000000000000000000, + takerTokenAmount: 30000000000000000000, + }, + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrderConfigPayloadSchema, shouldFail); + }); }); - it('should fail for invalid orders channel websocket subscribe message', () => { - const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; - const testCases = [ - { - type: 'subscribe', - channel: 'orders', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: true, - limit: 100, + describe('#relayerApiOrderConfigResponseSchema', () => { + it('should validate valid fees responses', () => { + const testCases = [ + { + makerFee: '10000000000000000', + takerFee: '30000000000000000', + feeRecipient: '0x323b5d4c32345ced77393b3530b1eed0f346429d', }, - }, - { - type: 'foo', - channel: 'orders', - requestId: 'randomId', - 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: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + { + feeRecipient: checksummedAddress, + takerToSpecify: checksummedAddress, + makerFee: '10000000000000000', + takerFee: '30000000000000000', }, - }, - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - baseTokenAddress: checksummedAddress, - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrderConfigResponseSchema, shouldFail); + }); + }); + describe('#relayerAssetDataPairsResponseSchema', () => { + it('should validate valid assetPairs 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, relayerApiAssetDataPairsResponseSchema); + }); + it('should fail for invalid assetPairs 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, relayerApiAssetDataPairsResponseSchema, shouldFail); + }); + }); + describe('#relayerApiOrderBookResponseSchema', () => { + it('should validate valid order book responses', () => { + const testCases = [ + { + bids: [], + asks: [], }, - }, - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: checksummedAddress, + { + bids: [signedOrder, signedOrder], + asks: [], }, - }, - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + { + bids: [], + asks: [signedOrder, signedOrder], }, - }, - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + { + bids: [signedOrder], + asks: [signedOrder, signedOrder], }, - }, - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: 'true', - limit: 100, + ]; + validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema); + }); + it('should fail for invalid order fill requests', () => { + const testCases = [ + {}, + { + bids: [signedOrder, signedOrder], }, - }, - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: true, - limit: '100', + { + asks: [signedOrder, signedOrder], }, - }, - ]; - const shouldFail = true; - validateAgainstSchema(testCases, relayerApiOrdersChannelSubscribeSchema, shouldFail); + { + bids: signedOrder, + asks: [signedOrder, signedOrder], + }, + { + bids: [signedOrder], + asks: signedOrder, + }, + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrdersResponseSchema, shouldFail); + }); }); - }); - describe('#relayerApiOrdersChannelUpdateSchema', () => { - it('should validate valid orders channel websocket update message', () => { - const testCases = [ - { - type: 'update', - channel: 'orders', - requestId: 2, - payload: signedOrder, - }, - ]; - validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema); + describe('#relayerApiOrdersChannelSubscribeSchema', () => { + it('should validate valid orders channel websocket subscribe message', () => { + const testCases = [ + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: { + baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + snapshot: true, + limit: 100, + }, + }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: { + baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + }, + }, + ]; + validateAgainstSchema(testCases, relayerApiOrdersChannelSubscribeSchema); + }); + it('should fail for invalid orders channel websocket subscribe message', () => { + const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; + const testCases = [ + { + type: 'subscribe', + channel: 'orders', + payload: { + baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + snapshot: true, + limit: 100, + }, + }, + { + type: 'foo', + channel: 'orders', + requestId: 'randomId', + payload: { + baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + }, + }, + { + type: 'subscribe', + channel: 'bar', + requestId: 'randomId', + payload: { + baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + }, + }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: { + baseTokenAddress: checksummedAddress, + quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + }, + }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: { + baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + quoteTokenAddress: checksummedAddress, + }, + }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: { + quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + }, + }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: { + baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + }, + }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: { + baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + snapshot: 'true', + limit: 100, + }, + }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: { + baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + snapshot: true, + limit: '100', + }, + }, + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrdersChannelSubscribeSchema, shouldFail); + }); }); - it('should fail for invalid orders channel websocket update message', () => { - const testCases = [ - { - type: 'foo', - channel: 'orders', - requestId: 2, - payload: signedOrder, - }, - { - type: 'update', - channel: 'bar', - requestId: 2, - payload: signedOrder, - }, - { - type: 'update', - channel: 'orders', - requestId: 2, - payload: {}, - }, - ]; - const shouldFail = true; - validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema, shouldFail); + describe('#relayerApiOrdersChannelUpdateSchema', () => { + it('should validate valid orders channel websocket update message', () => { + const testCases = [ + { + type: 'update', + channel: 'orders', + requestId: 2, + payload: signedOrder, + }, + ]; + validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema); + }); + it('should fail for invalid orders channel websocket update message', () => { + const testCases = [ + { + type: 'foo', + channel: 'orders', + requestId: 2, + payload: signedOrder, + }, + { + type: 'update', + channel: 'bar', + requestId: 2, + payload: signedOrder, + }, + { + type: 'update', + channel: 'orders', + requestId: 2, + payload: {}, + }, + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema, shouldFail); + }); }); }); }); @@ -570,217 +782,6 @@ 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('#relayerApiOrderConfigPayloadSchema', () => { - 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, relayerApiOrderConfigPayloadSchema); - }); - 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, relayerApiOrderConfigPayloadSchema, shouldFail); - }); - }); - describe('#relayerApiOrderConfigResponseSchema', () => { - it('should validate valid fees responses', () => { - const testCases = [ - { - makerFee: '10000000000000000', - takerFee: '30000000000000000', - feeRecipient: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - }, - ]; - validateAgainstSchema(testCases, relayerApiOrderConfigResponseSchema); - }); - 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, relayerApiOrderConfigResponseSchema, shouldFail); - }); - }); - describe('#relayerAssetDataPairsResponseSchema', () => { - it('should validate valid assetPairs 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, relayerApiAssetDataPairsResponseSchema); - }); - it('should fail for invalid assetPairs 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, relayerApiAssetDataPairsResponseSchema, shouldFail); - }); - }); describe('#jsNumberSchema', () => { it('should validate valid js number', () => { // tslint:disable-next-line:custom-no-magic-numbers -- cgit v1.2.3 From 86eafeb82623c40c621edaa3e1f59bd3b0eee4bb Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 1 Aug 2018 11:44:59 -0700 Subject: Add tests for asset pair endpoint --- packages/json-schemas/test/schema_test.ts | 194 +++++++++++++++++------------- 1 file changed, 109 insertions(+), 85 deletions(-) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index 57ef25172..0af948df7 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -57,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']; @@ -169,11 +174,6 @@ describe('Schema', () => { }); }); describe('#paginatedCollectionSchema', () => { - const paginatedResponse = { - total: 100, - perPage: 10, - page: 3, - }; it('should validate valid paginated collections', () => { const testCases = [paginatedResponse]; validateAgainstSchema(testCases, paginatedCollectionSchema); @@ -418,15 +418,14 @@ describe('Schema', () => { 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', + exchangeAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + makerAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + takerAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + makerAssetData: NULL_ADDRESS, + takerAssetData: NULL_ADDRESS, + makerAssetAmount: '10000000000000000000', + takerAssetAmount: '30000000000000000000', + expirationTimeSeconds: '42', }, ]; validateAgainstSchema(testCases, relayerApiOrderConfigPayloadSchema); @@ -436,22 +435,19 @@ describe('Schema', () => { const testCases = [ {}, { - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - makerTokenAmount: '10000000000000000000', - takerTokenAmount: '30000000000000000000', + makerAssetAmount: '10000000000000000000', + takerAssetAmount: '30000000000000000000', + makerAssetData: NULL_ADDRESS, + takerAssetData: NULL_ADDRESS, }, { - taker: checksummedAddress, - makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - makerTokenAmount: '10000000000000000000', - takerTokenAmount: '30000000000000000000', + takerAddress: checksummedAddress, + makerAssetAmount: '10000000000000000000', + takerAssetAmount: '30000000000000000000', }, { - makerTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - takerTokenAddress: '0xef7fff64389b814a946f3e92105513705ca6b990', - makerTokenAmount: 10000000000000000000, - takerTokenAmount: 30000000000000000000, + makerAssetAmount: 10000000000000000000, + takerAssetAmount: 30000000000000000000, }, ]; const shouldFail = true; @@ -464,7 +460,8 @@ describe('Schema', () => { { makerFee: '10000000000000000', takerFee: '30000000000000000', - feeRecipient: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + feeRecipientAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + senderAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', }, ]; validateAgainstSchema(testCases, relayerApiOrderConfigResponseSchema); @@ -491,75 +488,102 @@ describe('Schema', () => { describe('#relayerAssetDataPairsResponseSchema', () => { it('should validate valid assetPairs response', () => { const testCases = [ - [], - [ - { - tokenA: { - address: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - minAmount: '0', - maxAmount: '10000000000000000000', - precision: 5, - }, - tokenB: { - address: '0xef7fff64389b814a946f3e92105513705ca6b990', - minAmount: '0', - maxAmount: '50000000000000000000', - precision: 5, - }, - }, - ], - [ - { - tokenA: { - address: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + { + ...paginatedResponse, + records: [], + }, + { + ...paginatedResponse, + records: [ + { + assetDataA: { + assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + minAmount: '0', + maxAmount: '10000000000000000000', + precision: 5, + }, + assetDataB: { + assetData: '0xef7fff64389b814a946f3e92105513705ca6b990', + minAmount: '0', + maxAmount: '50000000000000000000', + precision: 5, + }, }, - tokenB: { - address: '0xef7fff64389b814a946f3e92105513705ca6b990', + ], + }, + { + ...paginatedResponse, + records: [ + { + assetDataA: { + assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + }, + assetDataB: { + assetData: '0xef7fff64389b814a946f3e92105513705ca6b990', + }, }, - }, - ], + ], + }, ]; validateAgainstSchema(testCases, relayerApiAssetDataPairsResponseSchema); }); it('should fail for invalid assetPairs 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, + { + ...paginatedResponse, + records: [ + { + assetDataA: { + assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + minAmount: '0', + maxAmount: '10000000000000000000', + precision: 5, + }, + assetDataC: { + assetData: '0xef7fff64389b814a946f3e92105513705ca6b990', + minAmount: '0', + maxAmount: '50000000000000000000', + precision: 5, + }, }, - }, - ], - [ - { - tokenA: { - address: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - precision: '5', + ], + }, + { + records: [ + { + assetDataA: { + assetData: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + minAmount: '0', + maxAmount: '10000000000000000000', + precision: 5, + }, + assetDataB: { + assetData: '0xef7fff64389b814a946f3e92105513705ca6b990', + minAmount: '0', + maxAmount: '50000000000000000000', + precision: 5, + }, }, - tokenB: { - address: '0xef7fff64389b814a946f3e92105513705ca6b990', - precision: '5', + ], + }, + { + ...paginatedResponse, + records: [ + { + assetDataA: { + minAmount: '0', + maxAmount: '10000000000000000000', + precision: 5, + }, + assetDataB: { + minAmount: '0', + maxAmount: '50000000000000000000', + precision: 5, + }, }, - }, - ], + ], + }, ]; const shouldFail = true; validateAgainstSchema(testCases, relayerApiAssetDataPairsResponseSchema, shouldFail); -- cgit v1.2.3 From 8351f5998ab3960461b255826778ff279991c184 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 1 Aug 2018 13:27:01 -0700 Subject: Add relayerApiOrdersResponseTest --- packages/json-schemas/test/schema_test.ts | 33 +++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index 0af948df7..119c13388 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -5,6 +5,7 @@ import forEach = require('lodash.foreach'); import 'mocha'; import { schemas, SchemaValidator } from '../src/index'; +import { validate } from 'jsonschema'; chai.config.includeStack = true; chai.use(dirtyChai); @@ -216,6 +217,10 @@ describe('Schema', () => { order, remainingFillableAmount: '50000000000000', }; + const relayerApiOrdersResponse = { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], + }; describe('#orderSchema', () => { it('should validate valid order', () => { const testCases = [order]; @@ -589,6 +594,34 @@ describe('Schema', () => { validateAgainstSchema(testCases, relayerApiAssetDataPairsResponseSchema, shouldFail); }); }); + describe('#relayerApiOrdersResponseSchema', () => { + it('should validate valid orders responses', () => { + const testCases = [ + relayerApiOrdersResponse, + { + ...paginatedResponse, + records: [], + }, + ]; + validateAgainstSchema(testCases, relayerApiOrdersResponseSchema); + }); + it('should fail for invalid orders responses', () => { + const testCases = [ + { + records: [relayerApiOrder, relayerApiOrder], + }, + { + ...paginatedResponse, + }, + { + ...paginatedResponse, + records: [{}, relayerApiOrder], + }, + ]; + const shouldFail = true; + validateAgainstSchema(testCases, relayerApiOrdersResponseSchema, shouldFail); + }); + }); describe('#relayerApiOrderBookResponseSchema', () => { it('should validate valid order book responses', () => { const testCases = [ -- cgit v1.2.3 From 48aaf228558ae7312d314a0c1f5bd920428eb39d Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 1 Aug 2018 13:34:10 -0700 Subject: Update order book schema test --- packages/json-schemas/test/schema_test.ts | 61 ++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 18 deletions(-) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index 119c13388..7b090ad87 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -626,20 +626,34 @@ describe('Schema', () => { it('should validate valid order book responses', () => { const testCases = [ { - bids: [], - asks: [], - }, - { - bids: [signedOrder, signedOrder], - asks: [], + bids: { + ...paginatedResponse, + records: [relayerApiOrder], + }, + asks: { + ...paginatedResponse, + records: [], + }, }, { - bids: [], - asks: [signedOrder, signedOrder], + bids: { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], + }, + asks: { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], + }, }, { - bids: [signedOrder], - asks: [signedOrder, signedOrder], + bids: { + ...paginatedResponse, + records: [], + }, + asks: { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], + }, }, ]; validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema); @@ -648,18 +662,29 @@ describe('Schema', () => { const testCases = [ {}, { - bids: [signedOrder, signedOrder], - }, - { - asks: [signedOrder, signedOrder], + bids: { + records: [relayerApiOrder], + }, + asks: { + ...paginatedResponse, + records: [], + }, }, { - bids: signedOrder, - asks: [signedOrder, signedOrder], + bids: { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], + }, + asks: {}, }, { - bids: [signedOrder], - asks: signedOrder, + bids: { + ...paginatedResponse, + }, + asks: { + ...paginatedResponse, + records: [relayerApiOrder, relayerApiOrder], + }, }, ]; const shouldFail = true; -- cgit v1.2.3 From 962d6e71b6cbe7f4e267bfb16d3c9fb4de511a22 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 1 Aug 2018 13:52:40 -0700 Subject: update orders channel subscribe schema --- packages/json-schemas/test/schema_test.ts | 86 +++++-------------------------- 1 file changed, 12 insertions(+), 74 deletions(-) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index 7b090ad87..0b520f6e3 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -698,22 +698,22 @@ describe('Schema', () => { type: 'subscribe', channel: 'orders', requestId: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: true, - limit: 100, - }, }, { type: 'subscribe', channel: 'orders', requestId: 'randomId', payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', + makerAssetProxyId: '0x02571792', + takerAssetProxyId: '0xf47261b0', }, }, + { + type: 'subscribe', + channel: 'orders', + requestId: 'randomId', + payload: {}, + }, ]; validateAgainstSchema(testCases, relayerApiOrdersChannelSubscribeSchema); }); @@ -723,74 +723,15 @@ describe('Schema', () => { { type: 'subscribe', channel: 'orders', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: true, - limit: 100, - }, - }, - { - type: 'foo', - channel: 'orders', - requestId: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - }, - }, - { - type: 'subscribe', - channel: 'bar', - requestId: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - }, - }, - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - baseTokenAddress: checksummedAddress, - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - }, - }, - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: checksummedAddress, - }, - }, - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - }, - }, - { - type: 'subscribe', - channel: 'orders', - requestId: 'randomId', - payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - }, }, { type: 'subscribe', channel: 'orders', requestId: 'randomId', payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: 'true', - limit: 100, + makerAssetProxyId: '0x02571792', + takerAssetProxyId: '0xf47261b0', + makerAssetAddress: checksummedAddress, }, }, { @@ -798,10 +739,7 @@ describe('Schema', () => { channel: 'orders', requestId: 'randomId', payload: { - baseTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - quoteTokenAddress: '0x323b5d4c32345ced77393b3530b1eed0f346429d', - snapshot: true, - limit: '100', + makerAssetProxyId: 'invalidId', }, }, ]; -- cgit v1.2.3 From f8a252d1427a6dddffa3cdb177ebc6ffd9cb774c Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 1 Aug 2018 13:55:16 -0700 Subject: All schema tests padding --- packages/json-schemas/test/schema_test.ts | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index 0b520f6e3..e1538ba56 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -753,8 +753,14 @@ describe('Schema', () => { { type: 'update', channel: 'orders', - requestId: 2, - payload: signedOrder, + requestId: 'randomId', + payload: [relayerApiOrder], + }, + { + type: 'update', + channel: 'orders', + requestId: 'randomId', + payload: [], }, ]; validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema); @@ -764,21 +770,26 @@ describe('Schema', () => { { type: 'foo', channel: 'orders', - requestId: 2, - payload: signedOrder, + requestId: 'randomId', }, { type: 'update', channel: 'bar', requestId: 2, - payload: signedOrder, + payload: [relayerApiOrder], }, { type: 'update', channel: 'orders', - requestId: 2, + requestId: 'randomId', payload: {}, }, + { + type: 'update', + channel: 'orders', + requestId: 'randomId', + payload: relayerApiErrorResponseSchema, + }, ]; const shouldFail = true; validateAgainstSchema(testCases, relayerApiOrdersChannelUpdateSchema, shouldFail); -- cgit v1.2.3 From 1ce6579c3a05264f93957b0c2d845a1351f4a3b1 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 2 Aug 2018 15:25:40 -0700 Subject: Create asset_pairs SRA endpoint (and establish conventions) --- packages/json-schemas/test/schema_test.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index e1538ba56..ebce30e59 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -5,7 +5,6 @@ import forEach = require('lodash.foreach'); import 'mocha'; import { schemas, SchemaValidator } from '../src/index'; -import { validate } from 'jsonschema'; chai.config.includeStack = true; chai.use(dirtyChai); -- cgit v1.2.3 From c9e1b7c5dc4eebf447fdc97568f08db0e2546904 Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 8 Aug 2018 11:57:16 -0700 Subject: Change remainingFillableAmount to metaData --- packages/json-schemas/test/schema_test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index 01fa53045..1f59f4da2 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -214,7 +214,9 @@ describe('Schema', () => { }; const relayerApiOrder = { order, - remainingFillableAmount: '50000000000000', + metaData: { + someMetaData: 5, + }, }; const relayerApiOrdersResponse = { ...paginatedResponse, @@ -353,7 +355,7 @@ describe('Schema', () => { validateAgainstSchema(testCases, relayerApiOrderSchema); }); it('should fail for invalid relayer api orders', () => { - const testCases = [{}, order, { order }, { order, remainingFillableAmount: 5 }]; + const testCases = [{}, order, { order }, { order, metaData: 5 }]; const shouldFail = true; validateAgainstSchema(testCases, relayerApiOrderSchema, shouldFail); }); -- cgit v1.2.3 From cc67c0df51037d093567b82fa4ca7962c5c3bfdd Mon Sep 17 00:00:00 2001 From: fragosti Date: Wed, 8 Aug 2018 14:18:24 -0700 Subject: Correct orderbook typo --- packages/json-schemas/test/schema_test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index 1f59f4da2..61ef3d7ac 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -28,7 +28,7 @@ const { txDataSchema, paginatedCollectionSchema, relayerApiErrorResponseSchema, - relayerApiOrderBookResponseSchema, + relayerApiOrderbookResponseSchema, relayerApiAssetDataPairsResponseSchema, relayerApiOrderConfigPayloadSchema, relayerApiOrderConfigResponseSchema, @@ -623,7 +623,7 @@ describe('Schema', () => { validateAgainstSchema(testCases, relayerApiOrdersResponseSchema, shouldFail); }); }); - describe('#relayerApiOrderBookResponseSchema', () => { + describe('#relayerApiOrderbookResponseSchema', () => { it('should validate valid order book responses', () => { const testCases = [ { @@ -657,7 +657,7 @@ describe('Schema', () => { }, }, ]; - validateAgainstSchema(testCases, relayerApiOrderBookResponseSchema); + validateAgainstSchema(testCases, relayerApiOrderbookResponseSchema); }); it('should fail for invalid order fill requests', () => { const testCases = [ -- cgit v1.2.3 From 2f66f26048af6e1edb415fd632dbb2e078cb8597 Mon Sep 17 00:00:00 2001 From: fragosti Date: Thu, 9 Aug 2018 16:41:43 -0700 Subject: Fix linting issues --- packages/json-schemas/test/schema_test.ts | 1 - 1 file changed, 1 deletion(-) (limited to 'packages/json-schemas/test/schema_test.ts') diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts index 61ef3d7ac..39cdec8a2 100644 --- a/packages/json-schemas/test/schema_test.ts +++ b/packages/json-schemas/test/schema_test.ts @@ -534,7 +534,6 @@ describe('Schema', () => { validateAgainstSchema(testCases, relayerApiAssetDataPairsResponseSchema); }); it('should fail for invalid assetPairs responses', () => { - const checksummedAddress = '0xA2b31daCf30a9C50ca473337c01d8A201ae33e32'; const testCases = [ { ...paginatedResponse, -- cgit v1.2.3