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 /packages/dev-utils/test/rpc_test.ts | |
parent | dbad7d18691e787bfc1c8e63a0e712f652486865 (diff) | |
download | dexon-0x-contracts-8cd2ba3ad637915ab335d87d530f754d104bbdd4.tar.gz dexon-0x-contracts-8cd2ba3ad637915ab335d87d530f754d104bbdd4.tar.zst dexon-0x-contracts-8cd2ba3ad637915ab335d87d530f754d104bbdd4.zip |
Add tests for dev-utils package
Diffstat (limited to 'packages/dev-utils/test/rpc_test.ts')
-rw-r--r-- | packages/dev-utils/test/rpc_test.ts | 42 |
1 files changed, 42 insertions, 0 deletions
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); + }); + }); +}); |