From f3d5690d56c3e4c7243f72049c98cfde799413af Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Mon, 29 May 2017 23:52:10 +0200 Subject: Add tests for getTokensAsync including schema validation --- test/token_registry_wrapper_test.ts | 43 +++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 test/token_registry_wrapper_test.ts (limited to 'test') diff --git a/test/token_registry_wrapper_test.ts b/test/token_registry_wrapper_test.ts new file mode 100644 index 000000000..cd435c48c --- /dev/null +++ b/test/token_registry_wrapper_test.ts @@ -0,0 +1,43 @@ +import * as _ from 'lodash'; +import 'mocha'; +import * as chai from 'chai'; +import chaiAsPromised = require('chai-as-promised'); +import * as Web3 from 'web3'; +import {web3Factory} from './utils/web3_factory'; +import {ZeroEx} from '../src/0x.js'; +import {BlockchainLifecycle} from './utils/blockchain_lifecycle'; +import {Token} from '../src/types'; +import {SchemaValidator} from '../src/utils/schema_validator'; +import {tokenSchema} from '../src/schemas/token_schema'; + +const expect = chai.expect; +chai.use(chaiAsPromised); +const blockchainLifecycle = new BlockchainLifecycle(); + +const TOKEN_REGISTRY_SIZE_AFTER_MIGRATION = 7; + +describe('TokenRegistryWrapper', () => { + let zeroEx: ZeroEx; + before(async () => { + const web3 = web3Factory.create(); + zeroEx = new ZeroEx(web3); + }); + beforeEach(async () => { + await blockchainLifecycle.startAsync(); + }); + afterEach(async () => { + await blockchainLifecycle.revertAsync(); + }); + describe('#getTokensAsync', () => { + it('should return all the tokens added to the tokenRegistry during the migration', async () => { + const tokens = await zeroEx.tokenRegistry.getTokensAsync(); + expect(tokens.length).to.be.equal(TOKEN_REGISTRY_SIZE_AFTER_MIGRATION); + + const schemaValidator = new SchemaValidator(); + _.each(tokens, token => { + const validationResult = schemaValidator.validate(token, tokenSchema); + expect(validationResult.errors.length).to.be.equal(0); + }); + }); + }); +}); -- cgit From 4d63a4d02a68974df75c9cae85d43c0ba628c740 Mon Sep 17 00:00:00 2001 From: Fabio Berger Date: Tue, 30 May 2017 10:49:34 +0200 Subject: use to.have.lengthOf --- test/token_registry_wrapper_test.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/token_registry_wrapper_test.ts b/test/token_registry_wrapper_test.ts index cd435c48c..c91555d8b 100644 --- a/test/token_registry_wrapper_test.ts +++ b/test/token_registry_wrapper_test.ts @@ -31,12 +31,12 @@ describe('TokenRegistryWrapper', () => { describe('#getTokensAsync', () => { it('should return all the tokens added to the tokenRegistry during the migration', async () => { const tokens = await zeroEx.tokenRegistry.getTokensAsync(); - expect(tokens.length).to.be.equal(TOKEN_REGISTRY_SIZE_AFTER_MIGRATION); + expect(tokens).to.have.lengthOf(TOKEN_REGISTRY_SIZE_AFTER_MIGRATION); const schemaValidator = new SchemaValidator(); _.each(tokens, token => { const validationResult = schemaValidator.validate(token, tokenSchema); - expect(validationResult.errors.length).to.be.equal(0); + expect(validationResult.errors).to.have.lengthOf(0); }); }); }); -- cgit