aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-06-09 21:20:30 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-06-09 21:20:30 +0800
commitb46ebc76ea727056b3fa15ad814ee9dea511f225 (patch)
treeb4cf214c25245cb35c5d9f7b84fb9ce4eb9f419d
parent44f8d189624281b3f97926aa821faf99ad314ae5 (diff)
downloaddexon-sol-tools-b46ebc76ea727056b3fa15ad814ee9dea511f225.tar
dexon-sol-tools-b46ebc76ea727056b3fa15ad814ee9dea511f225.tar.gz
dexon-sol-tools-b46ebc76ea727056b3fa15ad814ee9dea511f225.tar.bz2
dexon-sol-tools-b46ebc76ea727056b3fa15ad814ee9dea511f225.tar.lz
dexon-sol-tools-b46ebc76ea727056b3fa15ad814ee9dea511f225.tar.xz
dexon-sol-tools-b46ebc76ea727056b3fa15ad814ee9dea511f225.tar.zst
dexon-sol-tools-b46ebc76ea727056b3fa15ad814ee9dea511f225.zip
Add tests for TokenSchema
-rw-r--r--src/schemas/token_schema.ts7
-rw-r--r--src/utils/schema_validator.ts4
-rw-r--r--test/schema_test.ts39
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 = {