aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-utils/test
diff options
context:
space:
mode:
Diffstat (limited to 'packages/dev-utils/test')
-rw-r--r--packages/dev-utils/test/blockchain_lifecycle_test.ts27
-rw-r--r--packages/dev-utils/test/rpc_test.ts42
2 files changed, 69 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..4fdc53c87
--- /dev/null
+++ b/packages/dev-utils/test/blockchain_lifecycle_test.ts
@@ -0,0 +1,27 @@
+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();
+ const blockNumberAfter = await web3Wrapper.getBlockNumberAsync();
+ expect(blockNumberAfter).to.be.equal(blockNumberBefore + 1);
+ await blockchainLifecycle.revertAsync();
+ const blockNumberAfterRevert = await web3Wrapper.getBlockNumberAsync();
+ expect(blockNumberAfterRevert).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..2f0e5ff7f
--- /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 blockTimestampBefore = await web3Wrapper.getBlockTimestampAsync(BlockParamLiteral.Latest);
+ await rpc.increaseTimeAsync(TIME_DELTA);
+ await rpc.mineBlockAsync();
+ const blockTimestampAfter = await web3Wrapper.getBlockTimestampAsync(BlockParamLiteral.Latest);
+ expect(blockTimestampAfter).to.be.at.least(blockTimestampBefore + 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);
+ });
+ });
+});