From 8cd2ba3ad637915ab335d87d530f754d104bbdd4 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Mon, 12 Feb 2018 18:15:14 +0100 Subject: Add tests for dev-utils package --- packages/dev-utils/test/rpc_test.ts | 42 +++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 packages/dev-utils/test/rpc_test.ts (limited to 'packages/dev-utils/test/rpc_test.ts') 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); + }); + }); +}); -- cgit v1.2.3 From 8704c34a0fa22d5e46d1cbbf53c4ea9c3e54218c Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Wed, 14 Feb 2018 11:54:20 -0800 Subject: Fix a typo --- packages/dev-utils/test/rpc_test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'packages/dev-utils/test/rpc_test.ts') diff --git a/packages/dev-utils/test/rpc_test.ts b/packages/dev-utils/test/rpc_test.ts index 2869fdbc5..2f0e5ff7f 100644 --- a/packages/dev-utils/test/rpc_test.ts +++ b/packages/dev-utils/test/rpc_test.ts @@ -22,11 +22,11 @@ describe('RPC tests', () => { describe('#increaseTimeAsync', () => { it('increases time when called', async () => { const TIME_DELTA = 1000; - const blockTimestamtBefore = await web3Wrapper.getBlockTimestampAsync(BlockParamLiteral.Latest); + const blockTimestampBefore = 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); + const blockTimestampAfter = await web3Wrapper.getBlockTimestampAsync(BlockParamLiteral.Latest); + expect(blockTimestampAfter).to.be.at.least(blockTimestampBefore + TIME_DELTA); }); }); describe('#takeSnapshotAsync/revertSnapshotAsync', () => { -- cgit v1.2.3