aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-utils/test
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-02-13 01:15:14 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-02-15 03:51:26 +0800
commit8cd2ba3ad637915ab335d87d530f754d104bbdd4 (patch)
tree7b10a27d3943dae81bed7e3e95bf6c77de99846c /packages/dev-utils/test
parentdbad7d18691e787bfc1c8e63a0e712f652486865 (diff)
downloaddexon-sol-tools-8cd2ba3ad637915ab335d87d530f754d104bbdd4.tar.gz
dexon-sol-tools-8cd2ba3ad637915ab335d87d530f754d104bbdd4.tar.zst
dexon-sol-tools-8cd2ba3ad637915ab335d87d530f754d104bbdd4.zip
Add tests for dev-utils package
Diffstat (limited to 'packages/dev-utils/test')
-rw-r--r--packages/dev-utils/test/blockchain_lifecycle_test.ts25
-rw-r--r--packages/dev-utils/test/rpc_test.ts42
2 files changed, 67 insertions, 0 deletions
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);
+ });
+ });
+});