diff options
author | Leonid <logvinov.leon@gmail.com> | 2018-02-15 07:13:12 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-15 07:13:12 +0800 |
commit | e22788abe86b9ccee48bdccfc0a226b3292267c0 (patch) | |
tree | 46499be4ae9cd55409047752ffc1f27b96c8c423 | |
parent | 0dfb36e6759e67a82ed720bf31185aadfbea2c63 (diff) | |
parent | bbfbfcda85d14a60711837989bf35cc22c0c3394 (diff) | |
download | dexon-sol-tools-e22788abe86b9ccee48bdccfc0a226b3292267c0.tar dexon-sol-tools-e22788abe86b9ccee48bdccfc0a226b3292267c0.tar.gz dexon-sol-tools-e22788abe86b9ccee48bdccfc0a226b3292267c0.tar.bz2 dexon-sol-tools-e22788abe86b9ccee48bdccfc0a226b3292267c0.tar.lz dexon-sol-tools-e22788abe86b9ccee48bdccfc0a226b3292267c0.tar.xz dexon-sol-tools-e22788abe86b9ccee48bdccfc0a226b3292267c0.tar.zst dexon-sol-tools-e22788abe86b9ccee48bdccfc0a226b3292267c0.zip |
Merge pull request #392 from 0xProject/feature/subproviders_move
Move subproviders from dev-utils to subproviders package and add tests for dev-utils
-rw-r--r-- | packages/dev-utils/CHANGELOG.md | 4 | ||||
-rw-r--r-- | packages/dev-utils/package.json | 15 | ||||
-rw-r--r-- | packages/dev-utils/src/web3_factory.ts | 3 | ||||
-rw-r--r-- | packages/dev-utils/test/blockchain_lifecycle_test.ts | 27 | ||||
-rw-r--r-- | packages/dev-utils/test/rpc_test.ts | 42 | ||||
-rw-r--r-- | packages/dev-utils/tsconfig.json | 2 | ||||
-rw-r--r-- | packages/subproviders/CHANGELOG.md | 4 | ||||
-rw-r--r-- | packages/subproviders/src/index.ts | 2 | ||||
-rw-r--r-- | packages/subproviders/src/subproviders/empty_wallet_subprovider.ts (renamed from packages/dev-utils/src/subproviders/empty_wallet_subprovider.ts) | 0 | ||||
-rw-r--r-- | packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts (renamed from packages/dev-utils/src/subproviders/fake_gas_estimate_subprovider.ts) | 0 |
10 files changed, 94 insertions, 5 deletions
diff --git a/packages/dev-utils/CHANGELOG.md b/packages/dev-utils/CHANGELOG.md index ad0830f0e..c10c0a334 100644 --- a/packages/dev-utils/CHANGELOG.md +++ b/packages/dev-utils/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v0.1.0 - _TBD, 2018_ + + * Remove subproviders (#392) + ## v0.0.12 - _February 9, 2018_ * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) diff --git a/packages/dev-utils/package.json b/packages/dev-utils/package.json index d17f4f179..5d2ac7030 100644 --- a/packages/dev-utils/package.json +++ b/packages/dev-utils/package.json @@ -2,13 +2,16 @@ "name": "@0xproject/dev-utils", "version": "0.0.13", "description": "0x dev TS utils", - "main": "lib/index.js", - "types": "lib/index.d.ts", + "main": "lib/src/index.js", + "types": "lib/src/index.d.ts", "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", @@ -32,6 +40,7 @@ }, "dependencies": { "@0xproject/utils": "^0.3.3", + "@0xproject/subproviders": "^0.4.2", "ethereumjs-util": "^5.1.2", "lodash": "^4.17.4", "request-promise-native": "^1.0.5", diff --git a/packages/dev-utils/src/web3_factory.ts b/packages/dev-utils/src/web3_factory.ts index 26c26e03d..b0e0e4d3f 100644 --- a/packages/dev-utils/src/web3_factory.ts +++ b/packages/dev-utils/src/web3_factory.ts @@ -6,8 +6,7 @@ import ProviderEngine = require('web3-provider-engine'); import RpcSubprovider = require('web3-provider-engine/subproviders/rpc'); -import { EmptyWalletSubprovider } from './subproviders/empty_wallet_subprovider'; -import { FakeGasEstimateSubprovider } from './subproviders/fake_gas_estimate_subprovider'; +import { EmptyWalletSubprovider, FakeGasEstimateSubprovider } from '@0xproject/subproviders'; import { constants } from './constants'; 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); + }); + }); +}); diff --git a/packages/dev-utils/tsconfig.json b/packages/dev-utils/tsconfig.json index bdf315d59..ace978fea 100644 --- a/packages/dev-utils/tsconfig.json +++ b/packages/dev-utils/tsconfig.json @@ -5,7 +5,9 @@ }, "include": [ "./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" ] diff --git a/packages/subproviders/CHANGELOG.md b/packages/subproviders/CHANGELOG.md index f2c028aea..e970c69bd 100644 --- a/packages/subproviders/CHANGELOG.md +++ b/packages/subproviders/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +## v0.5.0 - _TBD, 2018_ + + * Add EmptyWalletSubprovider and FakeGasEstimateSubprovider (#392) + ## v0.4.1 - _February 9, 2018_ * Fix publishing issue where .npmignore was not properly excluding undesired content (#389) diff --git a/packages/subproviders/src/index.ts b/packages/subproviders/src/index.ts index 67d52ee25..4da405ec0 100644 --- a/packages/subproviders/src/index.ts +++ b/packages/subproviders/src/index.ts @@ -6,6 +6,8 @@ import { import { LedgerEthereumClient } from './types'; +export { EmptyWalletSubprovider } from './subproviders/empty_wallet_subprovider'; +export { FakeGasEstimateSubprovider } from './subproviders/fake_gas_estimate_subprovider'; export { InjectedWeb3Subprovider } from './subproviders/injected_web3'; export { RedundantRPCSubprovider } from './subproviders/redundant_rpc'; export { LedgerSubprovider } from './subproviders/ledger'; diff --git a/packages/dev-utils/src/subproviders/empty_wallet_subprovider.ts b/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts index 8c1fdfdb2..8c1fdfdb2 100644 --- a/packages/dev-utils/src/subproviders/empty_wallet_subprovider.ts +++ b/packages/subproviders/src/subproviders/empty_wallet_subprovider.ts diff --git a/packages/dev-utils/src/subproviders/fake_gas_estimate_subprovider.ts b/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts index b455a0ed7..b455a0ed7 100644 --- a/packages/dev-utils/src/subproviders/fake_gas_estimate_subprovider.ts +++ b/packages/subproviders/src/subproviders/fake_gas_estimate_subprovider.ts |