diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-13 01:15:14 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-02-15 03:51:26 +0800 |
commit | 8cd2ba3ad637915ab335d87d530f754d104bbdd4 (patch) | |
tree | 7b10a27d3943dae81bed7e3e95bf6c77de99846c | |
parent | dbad7d18691e787bfc1c8e63a0e712f652486865 (diff) | |
download | dexon-sol-tools-8cd2ba3ad637915ab335d87d530f754d104bbdd4.tar dexon-sol-tools-8cd2ba3ad637915ab335d87d530f754d104bbdd4.tar.gz dexon-sol-tools-8cd2ba3ad637915ab335d87d530f754d104bbdd4.tar.bz2 dexon-sol-tools-8cd2ba3ad637915ab335d87d530f754d104bbdd4.tar.lz dexon-sol-tools-8cd2ba3ad637915ab335d87d530f754d104bbdd4.tar.xz dexon-sol-tools-8cd2ba3ad637915ab335d87d530f754d104bbdd4.tar.zst dexon-sol-tools-8cd2ba3ad637915ab335d87d530f754d104bbdd4.zip |
Add tests for dev-utils package
-rw-r--r-- | packages/dev-utils/package.json | 10 | ||||
-rw-r--r-- | packages/dev-utils/test/blockchain_lifecycle_test.ts | 25 | ||||
-rw-r--r-- | packages/dev-utils/test/rpc_test.ts | 42 | ||||
-rw-r--r-- | packages/dev-utils/tsconfig.json | 1 |
4 files changed, 77 insertions, 1 deletions
diff --git a/packages/dev-utils/package.json b/packages/dev-utils/package.json index aec7c9b4e..7c155423c 100644 --- a/packages/dev-utils/package.json +++ b/packages/dev-utils/package.json @@ -7,8 +7,11 @@ "scripts": { "build:watch": "tsc -w", "build": "tsc", + "test": "run-s clean build run_mocha", + "test:circleci": "yarn test", + "run_mocha": "mocha lib/test/**/*_test.js --bail --exit", "clean": "shx rm -rf lib", - "lint": "tslint --project . 'src/**/*.ts'" + "lint": "tslint --project . 'src/**/*.ts' 'test/**/*.ts'" }, "license": "Apache-2.0", "repository": { @@ -20,9 +23,14 @@ }, "homepage": "https://github.com/0xProject/0x.js/packages/dev-utils/README.md", "devDependencies": { + "@types/mocha": "^2.2.42", "@0xproject/tslint-config": "^0.4.9", "@0xproject/types": "^0.2.2", + "@0xproject/web3-wrapper": "^0.1.13", "@types/lodash": "^4.14.86", + "chai": "^4.0.1", + "chai-typescript-typings": "^0.0.3", + "mocha": "^4.0.1", "npm-run-all": "^4.1.2", "shx": "^0.2.2", "tslint": "5.8.0", diff --git a/packages/dev-utils/test/blockchain_lifecycle_test.ts b/packages/dev-utils/test/blockchain_lifecycle_test.ts new file mode 100644 index 000000000..14712faa0 --- /dev/null +++ b/packages/dev-utils/test/blockchain_lifecycle_test.ts @@ -0,0 +1,25 @@ +import { BlockParamLiteral } from '@0xproject/types'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import * as chai from 'chai'; +import 'mocha'; + +import { BlockchainLifecycle, RPC, web3Factory } from '../src'; + +const expect = chai.expect; + +describe('BlockchainLifecycle tests', () => { + const web3 = web3Factory.create(); + const web3Wrapper = new Web3Wrapper(web3.currentProvider); + const rpc = new RPC(); + const blockchainLifecycle = new BlockchainLifecycle(); + describe('#startAsync/revertAsync', () => { + it('reverts changes in between', async () => { + const blockNumberBefore = await web3Wrapper.getBlockNumberAsync(); + await blockchainLifecycle.startAsync(); + await rpc.mineBlockAsync(); + await blockchainLifecycle.revertAsync(); + const blockNumberAfter = await web3Wrapper.getBlockNumberAsync(); + expect(blockNumberAfter).to.be.equal(blockNumberBefore); + }); + }); +}); diff --git a/packages/dev-utils/test/rpc_test.ts b/packages/dev-utils/test/rpc_test.ts new file mode 100644 index 000000000..2869fdbc5 --- /dev/null +++ b/packages/dev-utils/test/rpc_test.ts @@ -0,0 +1,42 @@ +import { BlockParamLiteral } from '@0xproject/types'; +import { Web3Wrapper } from '@0xproject/web3-wrapper'; +import * as chai from 'chai'; +import 'mocha'; + +import { RPC, web3Factory } from '../src'; + +const expect = chai.expect; + +describe('RPC tests', () => { + const web3 = web3Factory.create(); + const web3Wrapper = new Web3Wrapper(web3.currentProvider); + const rpc = new RPC(); + describe('#mineBlockAsync', () => { + it('increases block number when called', async () => { + const blockNumberBefore = await web3Wrapper.getBlockNumberAsync(); + await rpc.mineBlockAsync(); + const blockNumberAfter = await web3Wrapper.getBlockNumberAsync(); + expect(blockNumberAfter).to.be.equal(blockNumberBefore + 1); + }); + }); + describe('#increaseTimeAsync', () => { + it('increases time when called', async () => { + const TIME_DELTA = 1000; + const blockTimestamtBefore = await web3Wrapper.getBlockTimestampAsync(BlockParamLiteral.Latest); + await rpc.increaseTimeAsync(TIME_DELTA); + await rpc.mineBlockAsync(); + const blockTimestamtAfter = await web3Wrapper.getBlockTimestampAsync(BlockParamLiteral.Latest); + expect(blockTimestamtAfter).to.be.at.least(blockTimestamtBefore + TIME_DELTA); + }); + }); + describe('#takeSnapshotAsync/revertSnapshotAsync', () => { + it('reverts changes in between', async () => { + const blockNumberBefore = await web3Wrapper.getBlockNumberAsync(); + const snapshotId = await rpc.takeSnapshotAsync(); + await rpc.mineBlockAsync(); + await rpc.revertSnapshotAsync(snapshotId); + const blockNumberAfter = await web3Wrapper.getBlockNumberAsync(); + expect(blockNumberAfter).to.be.equal(blockNumberBefore); + }); + }); +}); diff --git a/packages/dev-utils/tsconfig.json b/packages/dev-utils/tsconfig.json index e26b6e14d..ace978fea 100644 --- a/packages/dev-utils/tsconfig.json +++ b/packages/dev-utils/tsconfig.json @@ -7,6 +7,7 @@ "./src/**/*", "./test/**/*", "../../node_modules/types-bn/index.d.ts", + "../../node_modules/chai-typescript-typings/index.d.ts", "../../node_modules/web3-typescript-typings/index.d.ts", "../../node_modules/types-ethereumjs-util/index.d.ts" ] |