Add tests for TokenSchema
This commit is contained in:
@@ -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',
|
||||
|
@@ -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 {
|
||||
|
@@ -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 = {
|
||||
|
Reference in New Issue
Block a user