aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2017-06-09 20:30:42 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2017-06-09 20:30:42 +0800
commit298c6a14b3aff0744989934aa86f1bf23a974a00 (patch)
tree14302c74499137c43b92a9f1eb86180f2a8edf8e /test
parentab40123768a3376bd2b36bd0d85a8e476b89dc10 (diff)
downloaddexon-0x-contracts-298c6a14b3aff0744989934aa86f1bf23a974a00.tar.gz
dexon-0x-contracts-298c6a14b3aff0744989934aa86f1bf23a974a00.tar.zst
dexon-0x-contracts-298c6a14b3aff0744989934aa86f1bf23a974a00.zip
Add tests for address schema
Diffstat (limited to 'test')
-rw-r--r--test/schema_test.ts28
1 files 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);
});
});
});