From 298c6a14b3aff0744989934aa86f1bf23a974a00 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 14:30:42 +0200 Subject: Add tests for address schema --- test/schema_test.ts | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/test/schema_test.ts b/test/schema_test.ts index d35ed4516..42a47c332 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -3,27 +3,41 @@ import * as _ from 'lodash'; import * as chai from 'chai'; import * as BigNumber from 'bignumber.js'; import promisify = require('es6-promisify'); -import {numberSchema} from '../src/schemas/basic_type_schemas'; +import {constants} from './utils/constants'; import {SchemaValidator} from '../src/utils/schema_validator'; +import {addressSchema, numberSchema} from '../src/schemas/basic_type_schemas'; chai.config.includeStack = true; const expect = chai.expect; describe('Schema', () => { const validator = new SchemaValidator(); + const batchTestSchema = (testCases: any[], schema: any, shouldFail = false) => { + _.forEach(testCases, (testCase: any) => { + expect(validator.validate(testCase, schema).errors).to.be.lengthOf(shouldFail ? 1 : 0); + }); + }; describe('#numberSchema', () => { describe('number regex', () => { it('should validate valid numbers', () => { const testCases = ['42', '0', '1.3', '0.2', '00.00']; - _.forEach(testCases, (testCase: string) => { - expect(validator.validate(testCase as any, numberSchema).errors).to.be.lengthOf(0); - }); + batchTestSchema(testCases, numberSchema); }); it('should fail for invalid numbers', () => { const testCases = ['.3', '1.', 'abacaba', 'и', '1..0']; - _.forEach(testCases, (testCase: string) => { - expect(validator.validate(testCase as any, numberSchema).errors).to.be.lengthOf(1); - }); + batchTestSchema(testCases, numberSchema, true); + }); + }); + }); + describe('#addressSchema', () => { + describe('address regex', () => { + it('should validate valid addresses', () => { + const testCases = ['0x8b0292B11a196601eD2ce54B665CaFEca0347D42', constants.NULL_ADDRESS]; + batchTestSchema(testCases, addressSchema); + }); + it('should fail for invalid addresses', () => { + const testCases = ['0x', '0', '0x00', '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42']; + batchTestSchema(testCases, addressSchema, true); }); }); }); -- cgit From d2df9bb314a1227640112791c6c29c9dd2c77301 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 14:35:03 +0200 Subject: Add ecSignatureParameter test --- test/schema_test.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/test/schema_test.ts b/test/schema_test.ts index 42a47c332..657cd1aad 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -6,6 +6,7 @@ import promisify = require('es6-promisify'); import {constants} from './utils/constants'; import {SchemaValidator} from '../src/utils/schema_validator'; import {addressSchema, numberSchema} from '../src/schemas/basic_type_schemas'; +import {ecSignatureParameter} from '../src/schemas/ec_signature_schema'; chai.config.includeStack = true; const expect = chai.expect; @@ -41,6 +42,25 @@ describe('Schema', () => { }); }); }); + describe('#ecSignatureParameter', () => { + describe('parameter regex', () => { + it('should validate valid parameters', () => { + const testCases = [ + '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', + '0X40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', + ]; + batchTestSchema(testCases, ecSignatureParameter); + }); + it('should fail for invalid parameters', () => { + const testCases = [ + '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3', // shorter + '0xzzzz9190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // invalid characters + '40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x + ]; + batchTestSchema(testCases, ecSignatureParameter, true); + }); + }); + }); describe('BigNumber serialization', () => { it('should correctly serialize BigNumbers', () => { const testCases = { -- cgit From 44f8d189624281b3f97926aa821faf99ad314ae5 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 14:57:13 +0200 Subject: Add ecSignatureSchema tests --- src/schemas/ec_signature_schema.ts | 2 +- test/schema_test.ts | 94 +++++++++++++++++++++++--------------- 2 files changed, 59 insertions(+), 37 deletions(-) diff --git a/src/schemas/ec_signature_schema.ts b/src/schemas/ec_signature_schema.ts index e39a8bd70..df1121989 100644 --- a/src/schemas/ec_signature_schema.ts +++ b/src/schemas/ec_signature_schema.ts @@ -1,4 +1,4 @@ -export const ecSignatureParameter = { +export const ecSignatureParameterSchema = { id: '/ecSignatureParameter', type: 'string', pattern: '^0[xX][0-9A-Fa-f]{64}$', diff --git a/test/schema_test.ts b/test/schema_test.ts index 657cd1aad..1a4275ebb 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -6,7 +6,7 @@ import promisify = require('es6-promisify'); import {constants} from './utils/constants'; import {SchemaValidator} from '../src/utils/schema_validator'; import {addressSchema, numberSchema} from '../src/schemas/basic_type_schemas'; -import {ecSignatureParameter} from '../src/schemas/ec_signature_schema'; +import {ecSignatureParameterSchema, ecSignatureSchema} from '../src/schemas/ec_signature_schema'; chai.config.includeStack = true; const expect = chai.expect; @@ -19,47 +19,69 @@ describe('Schema', () => { }); }; describe('#numberSchema', () => { - describe('number regex', () => { - it('should validate valid numbers', () => { - const testCases = ['42', '0', '1.3', '0.2', '00.00']; - batchTestSchema(testCases, numberSchema); - }); - it('should fail for invalid numbers', () => { - const testCases = ['.3', '1.', 'abacaba', 'и', '1..0']; - batchTestSchema(testCases, numberSchema, true); - }); + it('should validate valid numbers', () => { + const testCases = ['42', '0', '1.3', '0.2', '00.00']; + batchTestSchema(testCases, numberSchema); + }); + it('should fail for invalid numbers', () => { + const testCases = ['.3', '1.', 'abacaba', 'и', '1..0']; + batchTestSchema(testCases, numberSchema, true); }); }); describe('#addressSchema', () => { - describe('address regex', () => { - it('should validate valid addresses', () => { - const testCases = ['0x8b0292B11a196601eD2ce54B665CaFEca0347D42', constants.NULL_ADDRESS]; - batchTestSchema(testCases, addressSchema); - }); - it('should fail for invalid addresses', () => { - const testCases = ['0x', '0', '0x00', '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42']; - batchTestSchema(testCases, addressSchema, true); - }); + it('should validate valid addresses', () => { + const testCases = ['0x8b0292B11a196601eD2ce54B665CaFEca0347D42', constants.NULL_ADDRESS]; + batchTestSchema(testCases, addressSchema); + }); + it('should fail for invalid addresses', () => { + const testCases = ['0x', '0', '0x00', '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42']; + batchTestSchema(testCases, addressSchema, true); }); }); describe('#ecSignatureParameter', () => { - describe('parameter regex', () => { - it('should validate valid parameters', () => { - const testCases = [ - '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - '0X40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', - ]; - batchTestSchema(testCases, ecSignatureParameter); - }); - it('should fail for invalid parameters', () => { - const testCases = [ - '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3', // shorter - '0xzzzz9190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // invalid characters - '40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x - ]; - batchTestSchema(testCases, ecSignatureParameter, true); - }); - }); + it('should validate valid parameters', () => { + const testCases = [ + '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', + '0X40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', + ]; + batchTestSchema(testCases, ecSignatureParameterSchema); + }); + it('should fail for invalid parameters', () => { + const testCases = [ + '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3', // shorter + '0xzzzz9190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // invalid characters + '40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x + ]; + batchTestSchema(testCases, ecSignatureParameterSchema, true); + }); + }); + describe('#ecSignature', () => { + it('should validate valid signature', () => { + const signature = { + v: 27, + r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', + s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', + }; + const testCases = [ + signature, + { + ...signature, + v: 28, + }, + ]; + batchTestSchema(testCases, ecSignatureSchema); + }); + it('should fail for invalid signature', () => { + const v = 27; + const r = '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33'; + const s = '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254'; + const testCases = [ + {}, + {v}, + {r, s, v: 31}, + ]; + batchTestSchema(testCases, ecSignatureSchema, true); + }); }); describe('BigNumber serialization', () => { it('should correctly serialize BigNumbers', () => { -- cgit From b46ebc76ea727056b3fa15ad814ee9dea511f225 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 15:20:30 +0200 Subject: Add tests for TokenSchema --- src/schemas/token_schema.ts | 7 +++++-- src/utils/schema_validator.ts | 4 ++-- test/schema_test.ts | 39 +++++++++++++++++++++++++++++++++++++-- 3 files changed, 44 insertions(+), 6 deletions(-) diff --git a/src/schemas/token_schema.ts b/src/schemas/token_schema.ts index 01702af68..383c28490 100644 --- a/src/schemas/token_schema.ts +++ b/src/schemas/token_schema.ts @@ -4,8 +4,11 @@ export const tokenSchema = { name: {type: 'string'}, symbol: {type: 'string'}, decimals: {type: 'number'}, - address: {type: 'string'}, - url: {type: 'string'}, + address: {$ref: '/addressSchema'}, + url: { + type: 'string', + format: 'uri', + }, }, required: ['name', 'symbol', 'decimals', 'address', 'url'], type: 'object', diff --git a/src/utils/schema_validator.ts b/src/utils/schema_validator.ts index 72f6afffa..755f6e715 100644 --- a/src/utils/schema_validator.ts +++ b/src/utils/schema_validator.ts @@ -1,5 +1,5 @@ import {Validator, ValidatorResult} from 'jsonschema'; -import {ecSignatureSchema, ecSignatureParameter} from '../schemas/ec_signature_schema'; +import {ecSignatureSchema, ecSignatureParameterSchema} from '../schemas/ec_signature_schema'; import {orderSchema, signedOrderSchema} from '../schemas/order_schemas'; import {addressSchema, numberSchema} from '../schemas/basic_type_schemas'; import {tokenSchema} from '../schemas/token_schema'; @@ -22,7 +22,7 @@ export class SchemaValidator { this.validator.addSchema(addressSchema, addressSchema.id); this.validator.addSchema(ecSignatureSchema, ecSignatureSchema.id); this.validator.addSchema(signedOrderSchema, signedOrderSchema.id); - this.validator.addSchema(ecSignatureParameter, ecSignatureParameter.id); + this.validator.addSchema(ecSignatureParameterSchema, ecSignatureParameterSchema.id); this.validator.addSchema(orderFillOrKillRequestsSchema, orderFillOrKillRequestsSchema.id); } public validate(instance: object, schema: Schema): ValidatorResult { diff --git a/test/schema_test.ts b/test/schema_test.ts index 1a4275ebb..5df0094c3 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -5,6 +5,7 @@ import * as BigNumber from 'bignumber.js'; import promisify = require('es6-promisify'); import {constants} from './utils/constants'; import {SchemaValidator} from '../src/utils/schema_validator'; +import {tokenSchema} from '../src/schemas/token_schema'; import {addressSchema, numberSchema} from '../src/schemas/basic_type_schemas'; import {ecSignatureParameterSchema, ecSignatureSchema} from '../src/schemas/ec_signature_schema'; @@ -38,7 +39,7 @@ describe('Schema', () => { batchTestSchema(testCases, addressSchema, true); }); }); - describe('#ecSignatureParameter', () => { + describe('#ecSignatureParameterSchema', () => { it('should validate valid parameters', () => { const testCases = [ '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', @@ -55,7 +56,7 @@ describe('Schema', () => { batchTestSchema(testCases, ecSignatureParameterSchema, true); }); }); - describe('#ecSignature', () => { + describe('#ecSignatureSchema', () => { it('should validate valid signature', () => { const signature = { v: 27, @@ -83,6 +84,40 @@ describe('Schema', () => { batchTestSchema(testCases, ecSignatureSchema, true); }); }); + describe('#tokenSchema', () => { + const token = { + name: 'Zero Ex', + symbol: 'ZRX', + decimals: 100500, + address: '0x8b0292B11a196601eD2ce54B665CaFEca0347D42', + url: 'https://0xproject.com', + }; + it('should validate valid token', () => { + const testCases = [ + token, + ]; + batchTestSchema(testCases, tokenSchema); + }); + it('should fail for invalid token', () => { + const testCases = [ + { + ...token, + address: null, + }, + { + ...token, + decimals: undefined, + }, + [], + 4, + { + ...token, + url: 'not an url', + }, + ]; + batchTestSchema(testCases, tokenSchema, true); + }); + }); describe('BigNumber serialization', () => { it('should correctly serialize BigNumbers', () => { const testCases = { -- cgit From c59efdde1d4143511cefef48323fed56deb69b93 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 15:22:27 +0200 Subject: Rename to validateAgainstSchema --- test/schema_test.ts | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/schema_test.ts b/test/schema_test.ts index 5df0094c3..e40ad1871 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -14,7 +14,7 @@ const expect = chai.expect; describe('Schema', () => { const validator = new SchemaValidator(); - const batchTestSchema = (testCases: any[], schema: any, shouldFail = false) => { + const validateAgainstSchema = (testCases: any[], schema: any, shouldFail = false) => { _.forEach(testCases, (testCase: any) => { expect(validator.validate(testCase, schema).errors).to.be.lengthOf(shouldFail ? 1 : 0); }); @@ -22,21 +22,21 @@ describe('Schema', () => { describe('#numberSchema', () => { it('should validate valid numbers', () => { const testCases = ['42', '0', '1.3', '0.2', '00.00']; - batchTestSchema(testCases, numberSchema); + validateAgainstSchema(testCases, numberSchema); }); it('should fail for invalid numbers', () => { const testCases = ['.3', '1.', 'abacaba', 'и', '1..0']; - batchTestSchema(testCases, numberSchema, true); + validateAgainstSchema(testCases, numberSchema, true); }); }); describe('#addressSchema', () => { it('should validate valid addresses', () => { const testCases = ['0x8b0292B11a196601eD2ce54B665CaFEca0347D42', constants.NULL_ADDRESS]; - batchTestSchema(testCases, addressSchema); + validateAgainstSchema(testCases, addressSchema); }); it('should fail for invalid addresses', () => { const testCases = ['0x', '0', '0x00', '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42']; - batchTestSchema(testCases, addressSchema, true); + validateAgainstSchema(testCases, addressSchema, true); }); }); describe('#ecSignatureParameterSchema', () => { @@ -45,7 +45,7 @@ describe('Schema', () => { '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', '0X40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', ]; - batchTestSchema(testCases, ecSignatureParameterSchema); + validateAgainstSchema(testCases, ecSignatureParameterSchema); }); it('should fail for invalid parameters', () => { const testCases = [ @@ -53,7 +53,7 @@ describe('Schema', () => { '0xzzzz9190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // invalid characters '40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x ]; - batchTestSchema(testCases, ecSignatureParameterSchema, true); + validateAgainstSchema(testCases, ecSignatureParameterSchema, true); }); }); describe('#ecSignatureSchema', () => { @@ -70,7 +70,7 @@ describe('Schema', () => { v: 28, }, ]; - batchTestSchema(testCases, ecSignatureSchema); + validateAgainstSchema(testCases, ecSignatureSchema); }); it('should fail for invalid signature', () => { const v = 27; @@ -81,7 +81,7 @@ describe('Schema', () => { {v}, {r, s, v: 31}, ]; - batchTestSchema(testCases, ecSignatureSchema, true); + validateAgainstSchema(testCases, ecSignatureSchema, true); }); }); describe('#tokenSchema', () => { @@ -96,7 +96,7 @@ describe('Schema', () => { const testCases = [ token, ]; - batchTestSchema(testCases, tokenSchema); + validateAgainstSchema(testCases, tokenSchema); }); it('should fail for invalid token', () => { const testCases = [ @@ -115,7 +115,7 @@ describe('Schema', () => { url: 'not an url', }, ]; - batchTestSchema(testCases, tokenSchema, true); + validateAgainstSchema(testCases, tokenSchema, true); }); }); describe('BigNumber serialization', () => { -- cgit From 47be6a0c3007f139999bb0009e46cbd1be9e3d3f Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 15:41:00 +0200 Subject: Tolerate more than one validation error in tests --- test/schema_test.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/schema_test.ts b/test/schema_test.ts index e40ad1871..a608e867d 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -16,7 +16,11 @@ describe('Schema', () => { const validator = new SchemaValidator(); const validateAgainstSchema = (testCases: any[], schema: any, shouldFail = false) => { _.forEach(testCases, (testCase: any) => { - expect(validator.validate(testCase, schema).errors).to.be.lengthOf(shouldFail ? 1 : 0); + if (shouldFail) { + expect(validator.validate(testCase, schema).errors).to.be.lengthOf.at.least(1); + } else { + expect(validator.validate(testCase, schema).errors).to.be.lengthOf(0); + } }); }; describe('#numberSchema', () => { -- cgit From 14003dd1f3f19c841c5f6b740d5df0148faee4dc Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 16:07:00 +0200 Subject: Add tests for order schema --- test/schema_test.ts | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/test/schema_test.ts b/test/schema_test.ts index a608e867d..392db1c3b 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -6,6 +6,7 @@ import promisify = require('es6-promisify'); import {constants} from './utils/constants'; import {SchemaValidator} from '../src/utils/schema_validator'; import {tokenSchema} from '../src/schemas/token_schema'; +import {orderSchema} from '../src/schemas/order_schemas'; import {addressSchema, numberSchema} from '../src/schemas/basic_type_schemas'; import {ecSignatureParameterSchema, ecSignatureSchema} from '../src/schemas/ec_signature_schema'; @@ -122,6 +123,41 @@ describe('Schema', () => { validateAgainstSchema(testCases, tokenSchema, true); }); }); + describe('#orderSchema', () => { + const order = { + maker: constants.NULL_ADDRESS, + taker: constants.NULL_ADDRESS, + makerFee: 1, + takerFee: 2, + makerTokenAmount: 1, + takerTokenAmount: 2, + makerTokenAddress: constants.NULL_ADDRESS, + takerTokenAddress: constants.NULL_ADDRESS, + salt: 256, + feeRecipient: constants.NULL_ADDRESS, + expirationUnixTimestampSec: 42, + }; + it('should validate valid order', () => { + const testCases = [ + order, + ]; + validateAgainstSchema(testCases, orderSchema); + }); + it('should fail for invalid order', () => { + const testCases = [ + { + ...order, + salt: undefined, + }, + { + ...order, + salt: 'salt', + }, + 'order', + ]; + validateAgainstSchema(testCases, orderSchema, true); + }); + }); describe('BigNumber serialization', () => { it('should correctly serialize BigNumbers', () => { const testCases = { -- cgit From 941df26dff802fc8a73ec289ce84d1e54451668e Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 16:09:55 +0200 Subject: Add tests for signedOrderSchema --- test/schema_test.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/schema_test.ts b/test/schema_test.ts index 392db1c3b..fb5aba321 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -158,6 +158,41 @@ describe('Schema', () => { validateAgainstSchema(testCases, orderSchema, true); }); }); + describe('#signedOrderSchema', () => { + const signedOrder = { + maker: constants.NULL_ADDRESS, + taker: constants.NULL_ADDRESS, + makerFee: 1, + takerFee: 2, + makerTokenAmount: 1, + takerTokenAmount: 2, + makerTokenAddress: constants.NULL_ADDRESS, + takerTokenAddress: constants.NULL_ADDRESS, + salt: 256, + feeRecipient: constants.NULL_ADDRESS, + expirationUnixTimestampSec: 42, + ecSignature: { + v: 27, + r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', + s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', + }, + }; + it('should validate valid order', () => { + const testCases = [ + signedOrder, + ]; + validateAgainstSchema(testCases, orderSchema); + }); + it('should fail for invalid order', () => { + const testCases = [ + { + ...signedOrder, + ecSignature: undefined, + }, + ]; + validateAgainstSchema(testCases, orderSchema, true); + }); + }); describe('BigNumber serialization', () => { it('should correctly serialize BigNumbers', () => { const testCases = { -- cgit From 96ef9dbaafb12bd733fdcf0b9767c1d9b0f2da5b Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 16:12:48 +0200 Subject: Refactor tests --- test/schema_test.ts | 100 ++++++++++++++++++++++++---------------------------- 1 file changed, 47 insertions(+), 53 deletions(-) diff --git a/test/schema_test.ts b/test/schema_test.ts index fb5aba321..29375e9e9 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -123,7 +123,7 @@ describe('Schema', () => { validateAgainstSchema(testCases, tokenSchema, true); }); }); - describe('#orderSchema', () => { + describe('order including schemas', () => { const order = { maker: constants.NULL_ADDRESS, taker: constants.NULL_ADDRESS, @@ -137,60 +137,54 @@ describe('Schema', () => { feeRecipient: constants.NULL_ADDRESS, expirationUnixTimestampSec: 42, }; - it('should validate valid order', () => { - const testCases = [ - order, - ]; - validateAgainstSchema(testCases, orderSchema); - }); - it('should fail for invalid order', () => { - const testCases = [ - { - ...order, - salt: undefined, - }, - { - ...order, - salt: 'salt', - }, - 'order', - ]; - validateAgainstSchema(testCases, orderSchema, true); - }); - }); - describe('#signedOrderSchema', () => { - const signedOrder = { - maker: constants.NULL_ADDRESS, - taker: constants.NULL_ADDRESS, - makerFee: 1, - takerFee: 2, - makerTokenAmount: 1, - takerTokenAmount: 2, - makerTokenAddress: constants.NULL_ADDRESS, - takerTokenAddress: constants.NULL_ADDRESS, - salt: 256, - feeRecipient: constants.NULL_ADDRESS, - expirationUnixTimestampSec: 42, - ecSignature: { - v: 27, - r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', - s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', - }, - }; - it('should validate valid order', () => { - const testCases = [ - signedOrder, - ]; - validateAgainstSchema(testCases, orderSchema); + describe('#orderSchema', () => { + it('should validate valid order', () => { + const testCases = [ + order, + ]; + validateAgainstSchema(testCases, orderSchema); + }); + it('should fail for invalid order', () => { + const testCases = [ + { + ...order, + salt: undefined, + }, + { + ...order, + salt: 'salt', + }, + 'order', + ]; + validateAgainstSchema(testCases, orderSchema, true); + }); }); - it('should fail for invalid order', () => { - const testCases = [ - { - ...signedOrder, - ecSignature: undefined, + describe('signed order including schemas', () => { + const signedOrder = { + ...order, + ecSignature: { + v: 27, + r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33', + s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', }, - ]; - validateAgainstSchema(testCases, orderSchema, true); + }; + describe('#signedOrderSchema', () => { + it('should validate valid order', () => { + const testCases = [ + signedOrder, + ]; + validateAgainstSchema(testCases, orderSchema); + }); + it('should fail for invalid order', () => { + const testCases = [ + { + ...signedOrder, + ecSignature: undefined, + }, + ]; + validateAgainstSchema(testCases, orderSchema, true); + }); + }); }); }); describe('BigNumber serialization', () => { -- cgit From 4b9c681912dbdc427dc7c9cdb4abd34520aaa1d6 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 16:23:15 +0200 Subject: Fix tests and add fillOrKillRequests schema --- test/schema_test.ts | 48 +++++++++++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 11 deletions(-) diff --git a/test/schema_test.ts b/test/schema_test.ts index 29375e9e9..f44e52290 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -6,8 +6,9 @@ import promisify = require('es6-promisify'); import {constants} from './utils/constants'; import {SchemaValidator} from '../src/utils/schema_validator'; import {tokenSchema} from '../src/schemas/token_schema'; -import {orderSchema} from '../src/schemas/order_schemas'; +import {orderSchema, signedOrderSchema} from '../src/schemas/order_schemas'; import {addressSchema, numberSchema} from '../src/schemas/basic_type_schemas'; +import {orderFillOrKillRequestsSchema} from '../src/schemas/order_fill_or_kill_requests_schema'; import {ecSignatureParameterSchema, ecSignatureSchema} from '../src/schemas/ec_signature_schema'; chai.config.includeStack = true; @@ -127,15 +128,15 @@ describe('Schema', () => { const order = { maker: constants.NULL_ADDRESS, taker: constants.NULL_ADDRESS, - makerFee: 1, - takerFee: 2, - makerTokenAmount: 1, - takerTokenAmount: 2, + makerFee: '1', + takerFee: '2', + makerTokenAmount: '1', + takerTokenAmount: '2', makerTokenAddress: constants.NULL_ADDRESS, takerTokenAddress: constants.NULL_ADDRESS, - salt: 256, + salt: '256', feeRecipient: constants.NULL_ADDRESS, - expirationUnixTimestampSec: 42, + expirationUnixTimestampSec: '42', }; describe('#orderSchema', () => { it('should validate valid order', () => { @@ -169,20 +170,45 @@ describe('Schema', () => { }, }; describe('#signedOrderSchema', () => { - it('should validate valid order', () => { + it('should validate valid signed order', () => { const testCases = [ signedOrder, ]; - validateAgainstSchema(testCases, orderSchema); + validateAgainstSchema(testCases, signedOrderSchema); }); - it('should fail for invalid order', () => { + it('should fail for invalid signed order', () => { const testCases = [ { ...signedOrder, ecSignature: undefined, }, ]; - validateAgainstSchema(testCases, orderSchema, true); + validateAgainstSchema(testCases, signedOrderSchema, true); + }); + }); + describe('#orderFillOrKillRequestsSchema', () => { + const orderFillOrKillRequests = [ + { + signedOrder, + fillTakerAmount: 5, + }, + ]; + it('should validate valid order fill or kill requests', () => { + const testCases = [ + orderFillOrKillRequests, + ]; + validateAgainstSchema(testCases, orderFillOrKillRequestsSchema); + }); + it('should fail for invalid order fill or kill requests', () => { + const testCases = [ + [ + { + ...orderFillOrKillRequests[0], + fillTakerAmount: undefined, + }, + ], + ]; + validateAgainstSchema(testCases, orderFillOrKillRequestsSchema, true); }); }); }); -- cgit From 36b866dad280006656646a41f7e58a838dbfafe9 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 16:41:37 +0200 Subject: Fix tests --- src/schemas/token_schema.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/schemas/token_schema.ts b/src/schemas/token_schema.ts index 383c28490..1236e07c1 100644 --- a/src/schemas/token_schema.ts +++ b/src/schemas/token_schema.ts @@ -6,8 +6,15 @@ export const tokenSchema = { decimals: {type: 'number'}, address: {$ref: '/addressSchema'}, url: { - type: 'string', - format: 'uri', + oneOf: [ + { + type: 'string', + format: 'uri', + }, + { + enum: [''], + }, + ], }, }, required: ['name', 'symbol', 'decimals', 'address', 'url'], -- cgit From e74f03b087ab811f76b7aff1452cc2cadd680358 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 16:56:00 +0200 Subject: Add tests for orderCancellationRequestsSchema --- test/schema_test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/schema_test.ts b/test/schema_test.ts index f44e52290..bdafde915 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -10,6 +10,7 @@ import {orderSchema, signedOrderSchema} from '../src/schemas/order_schemas'; import {addressSchema, numberSchema} from '../src/schemas/basic_type_schemas'; import {orderFillOrKillRequestsSchema} from '../src/schemas/order_fill_or_kill_requests_schema'; import {ecSignatureParameterSchema, ecSignatureSchema} from '../src/schemas/ec_signature_schema'; +import {orderCancellationRequestsSchema} from '../src/schemas/order_cancel_schema'; chai.config.includeStack = true; const expect = chai.expect; @@ -211,6 +212,31 @@ describe('Schema', () => { validateAgainstSchema(testCases, orderFillOrKillRequestsSchema, true); }); }); + describe('#orderCancellationRequestsSchema', () => { + const orderCancellationRequests = [ + { + order, + takerTokenCancelAmount: 5, + }, + ]; + it('should validate valid order cancellation requests', () => { + const testCases = [ + orderCancellationRequests, + ]; + validateAgainstSchema(testCases, orderCancellationRequestsSchema); + }); + it('should fail for invalid order cancellation requests', () => { + const testCases = [ + [ + { + ...orderCancellationRequests[0], + takerTokenCancelAmount: undefined, + }, + ], + ]; + validateAgainstSchema(testCases, orderCancellationRequestsSchema, true); + }); + }); }); }); describe('BigNumber serialization', () => { -- cgit From 22547f419b09f49aac3ef81bb6af1db81f495fad Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 16:57:51 +0200 Subject: Add tests for fillOrderRequests schema --- test/schema_test.ts | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/schema_test.ts b/test/schema_test.ts index bdafde915..43f6c6d38 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -11,6 +11,7 @@ import {addressSchema, numberSchema} from '../src/schemas/basic_type_schemas'; import {orderFillOrKillRequestsSchema} from '../src/schemas/order_fill_or_kill_requests_schema'; import {ecSignatureParameterSchema, ecSignatureSchema} from '../src/schemas/ec_signature_schema'; import {orderCancellationRequestsSchema} from '../src/schemas/order_cancel_schema'; +import {orderFillRequestsSchema} from '../src/schemas/order_fill_requests_schema'; chai.config.includeStack = true; const expect = chai.expect; @@ -237,6 +238,31 @@ describe('Schema', () => { validateAgainstSchema(testCases, orderCancellationRequestsSchema, true); }); }); + describe('#orderFillRequestsSchema', () => { + const orderFillRequests = [ + { + signedOrder, + takerTokenCancelAmount: 5, + }, + ]; + it('should validate valid order fill requests', () => { + const testCases = [ + orderFillRequests, + ]; + validateAgainstSchema(testCases, orderFillRequestsSchema); + }); + it('should fail for invalid order fill requests', () => { + const testCases = [ + [ + { + ...orderFillRequests[0], + takerTokenFillAmount: undefined, + }, + ], + ]; + validateAgainstSchema(testCases, orderFillRequestsSchema, true); + }); + }); }); }); describe('BigNumber serialization', () => { -- cgit From 135df646782d7e08a83dabc25ad31b06c5765cf1 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 17:05:41 +0200 Subject: Fix tests --- test/schema_test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/schema_test.ts b/test/schema_test.ts index 43f6c6d38..49dc2c1d0 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -242,7 +242,7 @@ describe('Schema', () => { const orderFillRequests = [ { signedOrder, - takerTokenCancelAmount: 5, + takerTokenFillAmount: 5, }, ]; it('should validate valid order fill requests', () => { -- cgit From 727f6ad2307e340ed4146af0154098737206a288 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 19:49:35 +0200 Subject: Fix bugs in schemas --- src/schemas/order_cancel_schema.ts | 2 +- src/schemas/order_fill_or_kill_requests_schema.ts | 2 +- src/schemas/order_fill_requests_schema.ts | 2 +- test/schema_test.ts | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/schemas/order_cancel_schema.ts b/src/schemas/order_cancel_schema.ts index 5cc8f745c..04b2c179f 100644 --- a/src/schemas/order_cancel_schema.ts +++ b/src/schemas/order_cancel_schema.ts @@ -4,7 +4,7 @@ export const orderCancellationRequestsSchema = { items: { properties: { order: {$ref: '/orderSchema'}, - takerTokenCancelAmount: {type: '/numberSchema'}, + takerTokenCancelAmount: {$ref: '/numberSchema'}, }, required: ['order', 'takerTokenCancelAmount'], type: 'object', diff --git a/src/schemas/order_fill_or_kill_requests_schema.ts b/src/schemas/order_fill_or_kill_requests_schema.ts index 4db7113de..6f7878c45 100644 --- a/src/schemas/order_fill_or_kill_requests_schema.ts +++ b/src/schemas/order_fill_or_kill_requests_schema.ts @@ -4,7 +4,7 @@ export const orderFillOrKillRequestsSchema = { items: { properties: { signedOrder: {$ref: '/signedOrderSchema'}, - fillTakerAmount: {type: '/numberSchema'}, + fillTakerAmount: {$ref: '/numberSchema'}, }, required: ['signedOrder', 'fillTakerAmount'], type: 'object', diff --git a/src/schemas/order_fill_requests_schema.ts b/src/schemas/order_fill_requests_schema.ts index 44f4e33e2..0f3ee1e99 100644 --- a/src/schemas/order_fill_requests_schema.ts +++ b/src/schemas/order_fill_requests_schema.ts @@ -4,7 +4,7 @@ export const orderFillRequestsSchema = { items: { properties: { signedOrder: {$ref: '/signedOrderSchema'}, - takerTokenFillAmount: {type: '/numberSchema'}, + takerTokenFillAmount: {$ref: '/numberSchema'}, }, required: ['signedOrder', 'takerTokenFillAmount'], type: 'object', diff --git a/test/schema_test.ts b/test/schema_test.ts index 49dc2c1d0..e20e4f31d 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -192,7 +192,7 @@ describe('Schema', () => { const orderFillOrKillRequests = [ { signedOrder, - fillTakerAmount: 5, + fillTakerAmount: '5', }, ]; it('should validate valid order fill or kill requests', () => { @@ -217,7 +217,7 @@ describe('Schema', () => { const orderCancellationRequests = [ { order, - takerTokenCancelAmount: 5, + takerTokenCancelAmount: '5', }, ]; it('should validate valid order cancellation requests', () => { @@ -242,7 +242,7 @@ describe('Schema', () => { const orderFillRequests = [ { signedOrder, - takerTokenFillAmount: 5, + takerTokenFillAmount: '5', }, ]; it('should validate valid order fill requests', () => { -- cgit From ba27da965b9ee59224a1561cbacb0d1db0800177 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 9 Jun 2017 20:11:56 +0200 Subject: Address feedback --- test/schema_test.ts | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/test/schema_test.ts b/test/schema_test.ts index e20e4f31d..376ac5d6f 100644 --- a/test/schema_test.ts +++ b/test/schema_test.ts @@ -34,7 +34,8 @@ describe('Schema', () => { }); it('should fail for invalid numbers', () => { const testCases = ['.3', '1.', 'abacaba', 'и', '1..0']; - validateAgainstSchema(testCases, numberSchema, true); + const shouldFail = true; + validateAgainstSchema(testCases, numberSchema, shouldFail); }); }); describe('#addressSchema', () => { @@ -44,7 +45,8 @@ describe('Schema', () => { }); it('should fail for invalid addresses', () => { const testCases = ['0x', '0', '0x00', '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42']; - validateAgainstSchema(testCases, addressSchema, true); + const shouldFail = true; + validateAgainstSchema(testCases, addressSchema, shouldFail); }); }); describe('#ecSignatureParameterSchema', () => { @@ -61,7 +63,8 @@ describe('Schema', () => { '0xzzzz9190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // invalid characters '40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x ]; - validateAgainstSchema(testCases, ecSignatureParameterSchema, true); + const shouldFail = true; + validateAgainstSchema(testCases, ecSignatureParameterSchema, shouldFail); }); }); describe('#ecSignatureSchema', () => { @@ -89,7 +92,8 @@ describe('Schema', () => { {v}, {r, s, v: 31}, ]; - validateAgainstSchema(testCases, ecSignatureSchema, true); + const shouldFail = true; + validateAgainstSchema(testCases, ecSignatureSchema, shouldFail); }); }); describe('#tokenSchema', () => { @@ -123,7 +127,8 @@ describe('Schema', () => { url: 'not an url', }, ]; - validateAgainstSchema(testCases, tokenSchema, true); + const shouldFail = true; + validateAgainstSchema(testCases, tokenSchema, shouldFail); }); }); describe('order including schemas', () => { @@ -159,7 +164,8 @@ describe('Schema', () => { }, 'order', ]; - validateAgainstSchema(testCases, orderSchema, true); + const shouldFail = true; + validateAgainstSchema(testCases, orderSchema, shouldFail); }); }); describe('signed order including schemas', () => { @@ -185,7 +191,8 @@ describe('Schema', () => { ecSignature: undefined, }, ]; - validateAgainstSchema(testCases, signedOrderSchema, true); + const shouldFail = true; + validateAgainstSchema(testCases, signedOrderSchema, shouldFail); }); }); describe('#orderFillOrKillRequestsSchema', () => { @@ -210,7 +217,8 @@ describe('Schema', () => { }, ], ]; - validateAgainstSchema(testCases, orderFillOrKillRequestsSchema, true); + const shouldFail = true; + validateAgainstSchema(testCases, orderFillOrKillRequestsSchema, shouldFail); }); }); describe('#orderCancellationRequestsSchema', () => { @@ -235,7 +243,8 @@ describe('Schema', () => { }, ], ]; - validateAgainstSchema(testCases, orderCancellationRequestsSchema, true); + const shouldFail = true; + validateAgainstSchema(testCases, orderCancellationRequestsSchema, shouldFail); }); }); describe('#orderFillRequestsSchema', () => { @@ -260,7 +269,8 @@ describe('Schema', () => { }, ], ]; - validateAgainstSchema(testCases, orderFillRequestsSchema, true); + const shouldFail = true; + validateAgainstSchema(testCases, orderFillRequestsSchema, shouldFail); }); }); }); -- cgit