aboutsummaryrefslogtreecommitdiffstats
path: root/packages/json-schemas/test/schema_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/json-schemas/test/schema_test.ts')
-rw-r--r--packages/json-schemas/test/schema_test.ts87
1 files changed, 28 insertions, 59 deletions
diff --git a/packages/json-schemas/test/schema_test.ts b/packages/json-schemas/test/schema_test.ts
index 7b058781d..379f92442 100644
--- a/packages/json-schemas/test/schema_test.ts
+++ b/packages/json-schemas/test/schema_test.ts
@@ -2,6 +2,7 @@ import { BigNumber } from '@0xproject/utils';
import * as chai from 'chai';
import * as dirtyChai from 'dirty-chai';
import forEach = require('lodash.foreach');
+import 'make-promises-safe';
import 'mocha';
import { schemas, SchemaValidator } from '../src/index';
@@ -13,8 +14,7 @@ const NULL_ADDRESS = '0x0000000000000000000000000000000000000000';
const {
numberSchema,
addressSchema,
- ecSignatureSchema,
- ecSignatureParameterSchema,
+ hexSchema,
orderCancellationRequestsSchema,
orderFillOrKillRequestsSchema,
orderFillRequestsSchema,
@@ -84,47 +84,15 @@ describe('Schema', () => {
validateAgainstSchema(testCases, addressSchema, shouldFail);
});
});
- describe('#ecSignatureParameterSchema', () => {
- it('should validate valid parameters', () => {
- const testCases = [
- '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
- '0X40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
- ];
- validateAgainstSchema(testCases, ecSignatureParameterSchema);
- });
- it('should fail for invalid parameters', () => {
- const testCases = [
- '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3', // shorter
- '0xzzzz9190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // invalid characters
- '40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254', // no 0x
- ];
- const shouldFail = true;
- validateAgainstSchema(testCases, ecSignatureParameterSchema, shouldFail);
- });
- });
- describe('#ecSignatureSchema', () => {
- it('should validate valid signature', () => {
- const signature = {
- v: 27,
- r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
- s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
- };
- const testCases = [
- signature,
- {
- ...signature,
- v: 28,
- },
- ];
- validateAgainstSchema(testCases, ecSignatureSchema);
+ describe('#hexSchema', () => {
+ it('should validate valid hex string', () => {
+ const testCases = ['0x8b0292b11a196601ed2ce54b665cafeca0347d42', NULL_ADDRESS];
+ validateAgainstSchema(testCases, hexSchema);
});
- it('should fail for invalid signature', () => {
- const v = 27;
- const r = '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33';
- const s = '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254';
- const testCases = [{}, { v }, { r, s, v: 31 }];
+ it('should fail for invalid hex string', () => {
+ const testCases = ['0x', '0', '0xzzzzzzB11a196601eD2ce54B665CaFEca0347D42'];
const shouldFail = true;
- validateAgainstSchema(testCases, ecSignatureSchema, shouldFail);
+ validateAgainstSchema(testCases, hexSchema, shouldFail);
});
});
describe('#orderHashSchema', () => {
@@ -148,7 +116,8 @@ describe('Schema', () => {
});
describe('#blockParamSchema', () => {
it('should validate valid block param', () => {
- const testCases = [42, 'latest', 'pending', 'earliest'];
+ const blockNumber = 42;
+ const testCases = [blockNumber, 'latest', 'pending', 'earliest'];
validateAgainstSchema(testCases, blockParamSchema);
});
it('should fail for invalid block param', () => {
@@ -181,6 +150,7 @@ describe('Schema', () => {
validateAgainstSchema(testCases, tokenSchema);
});
it('should fail for invalid token', () => {
+ const num = 4;
const testCases = [
{
...token,
@@ -191,7 +161,7 @@ describe('Schema', () => {
decimals: undefined,
},
[],
- 4,
+ num,
];
const shouldFail = true;
validateAgainstSchema(testCases, tokenSchema, shouldFail);
@@ -199,18 +169,17 @@ describe('Schema', () => {
});
describe('order including schemas', () => {
const order = {
- maker: NULL_ADDRESS,
- taker: NULL_ADDRESS,
+ makerAddress: NULL_ADDRESS,
+ takerAddress: NULL_ADDRESS,
makerFee: '1',
takerFee: '2',
- makerTokenAmount: '1',
- takerTokenAmount: '2',
- makerTokenAddress: NULL_ADDRESS,
- takerTokenAddress: NULL_ADDRESS,
+ makerAssetAmount: '1',
+ takerAssetAmount: '2',
+ makerAssetData: NULL_ADDRESS,
+ takerAssetData: NULL_ADDRESS,
salt: '67006738228878699843088602623665307406148487219438534730168799356281242528500',
- feeRecipient: NULL_ADDRESS,
- exchangeContractAddress: NULL_ADDRESS,
- expirationUnixTimestampSec: '42',
+ feeRecipientAddress: NULL_ADDRESS,
+ expirationTimeSeconds: '42',
};
describe('#orderSchema', () => {
it('should validate valid order', () => {
@@ -236,11 +205,8 @@ describe('Schema', () => {
describe('signed order including schemas', () => {
const signedOrder = {
...order,
- ecSignature: {
- v: 27,
- r: '0x61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc33',
- s: '0x40349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
- },
+ signature:
+ '0x031b61a3ed31b43c8780e905a260a35faefcc527be7516aa11c0256729b5b351bc3340349190569279751135161d22529dc25add4f6069af05be04cacbda2ace2254',
};
describe('#signedOrdersSchema', () => {
it('should validate valid signed orders', () => {
@@ -262,7 +228,7 @@ describe('Schema', () => {
const testCases = [
{
...signedOrder,
- ecSignature: undefined,
+ signature: undefined,
},
];
const shouldFail = true;
@@ -870,10 +836,12 @@ describe('Schema', () => {
});
describe('#jsNumberSchema', () => {
it('should validate valid js number', () => {
+ // tslint:disable-next-line:custom-no-magic-numbers
const testCases = [1, 42];
validateAgainstSchema(testCases, jsNumber);
});
it('should fail for invalid js number', () => {
+ // tslint:disable-next-line:custom-no-magic-numbers
const testCases = [NaN, -1, new BigNumber(1)];
const shouldFail = true;
validateAgainstSchema(testCases, jsNumber, shouldFail);
@@ -881,13 +849,14 @@ describe('Schema', () => {
});
describe('#txDataSchema', () => {
it('should validate valid txData', () => {
+ const bigNumGasAmount = new BigNumber(42);
const testCases = [
{
from: NULL_ADDRESS,
},
{
from: NULL_ADDRESS,
- gas: new BigNumber(42),
+ gas: bigNumGasAmount,
},
{
from: NULL_ADDRESS,