aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-utils
diff options
context:
space:
mode:
authorLeonid <logvinov.leon@gmail.com>2018-02-21 02:55:10 +0800
committerGitHub <noreply@github.com>2018-02-21 02:55:10 +0800
commitf60b00d116e525e5b789684e68b1541cedba1665 (patch)
tree9c8f33bafb1fb2eef5bfcaaefed781ccae6ffba9 /packages/dev-utils
parent76afb6b1163182446a1f3646b4bc89b5dc271738 (diff)
parent3a36e0621f0ad0c77c14a04bdaa85131b57ef0ea (diff)
downloaddexon-sol-tools-f60b00d116e525e5b789684e68b1541cedba1665.tar
dexon-sol-tools-f60b00d116e525e5b789684e68b1541cedba1665.tar.gz
dexon-sol-tools-f60b00d116e525e5b789684e68b1541cedba1665.tar.bz2
dexon-sol-tools-f60b00d116e525e5b789684e68b1541cedba1665.tar.lz
dexon-sol-tools-f60b00d116e525e5b789684e68b1541cedba1665.tar.xz
dexon-sol-tools-f60b00d116e525e5b789684e68b1541cedba1665.tar.zst
dexon-sol-tools-f60b00d116e525e5b789684e68b1541cedba1665.zip
Merge branch 'development' into feature/web3-abi-v2-types
Diffstat (limited to 'packages/dev-utils')
-rw-r--r--packages/dev-utils/CHANGELOG.md4
-rw-r--r--packages/dev-utils/package.json21
-rw-r--r--packages/dev-utils/src/subproviders/empty_wallet_subprovider.ts27
-rw-r--r--packages/dev-utils/src/subproviders/fake_gas_estimate_subprovider.ts34
-rw-r--r--packages/dev-utils/src/web3_factory.ts3
-rw-r--r--packages/dev-utils/test/blockchain_lifecycle_test.ts27
-rw-r--r--packages/dev-utils/test/rpc_test.ts42
-rw-r--r--packages/dev-utils/tsconfig.json2
8 files changed, 91 insertions, 69 deletions
diff --git a/packages/dev-utils/CHANGELOG.md b/packages/dev-utils/CHANGELOG.md
index ad0830f0e..41f59d3af 100644
--- a/packages/dev-utils/CHANGELOG.md
+++ b/packages/dev-utils/CHANGELOG.md
@@ -1,5 +1,9 @@
# CHANGELOG
+## v0.1.0 - _February 16, 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..515edc353 100644
--- a/packages/dev-utils/package.json
+++ b/packages/dev-utils/package.json
@@ -1,14 +1,17 @@
{
"name": "@0xproject/dev-utils",
- "version": "0.0.13",
+ "version": "0.1.0",
"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": {
@@ -21,8 +24,13 @@
"homepage": "https://github.com/0xProject/0x.js/packages/dev-utils/README.md",
"devDependencies": {
"@0xproject/tslint-config": "^0.4.9",
- "@0xproject/types": "^0.2.2",
+ "@0xproject/types": "^0.2.3",
+ "@0xproject/web3-wrapper": "^0.1.14",
"@types/lodash": "^4.14.86",
+ "@types/mocha": "^2.2.42",
+ "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",
@@ -31,7 +39,8 @@
"typescript": "2.7.1"
},
"dependencies": {
- "@0xproject/utils": "^0.3.3",
+ "@0xproject/subproviders": "^0.5.0",
+ "@0xproject/utils": "^0.3.4",
"ethereumjs-util": "^5.1.2",
"lodash": "^4.17.4",
"request-promise-native": "^1.0.5",
diff --git a/packages/dev-utils/src/subproviders/empty_wallet_subprovider.ts b/packages/dev-utils/src/subproviders/empty_wallet_subprovider.ts
deleted file mode 100644
index 8c1fdfdb2..000000000
--- a/packages/dev-utils/src/subproviders/empty_wallet_subprovider.ts
+++ /dev/null
@@ -1,27 +0,0 @@
-import { JSONRPCPayload } from '@0xproject/types';
-
-/*
- * This class implements the web3-provider-engine subprovider interface and returns
- * that the provider has no addresses when queried.
- * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js
- */
-export class EmptyWalletSubprovider {
- // This method needs to be here to satisfy the interface but linter wants it to be static.
- // tslint:disable-next-line:prefer-function-over-method
- public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) {
- switch (payload.method) {
- case 'eth_accounts':
- end(null, []);
- return;
-
- default:
- next();
- return;
- }
- }
- // Required to implement this method despite not needing it for this subprovider
- // tslint:disable-next-line:prefer-function-over-method
- public setEngine(engine: any) {
- // noop
- }
-}
diff --git a/packages/dev-utils/src/subproviders/fake_gas_estimate_subprovider.ts b/packages/dev-utils/src/subproviders/fake_gas_estimate_subprovider.ts
deleted file mode 100644
index b455a0ed7..000000000
--- a/packages/dev-utils/src/subproviders/fake_gas_estimate_subprovider.ts
+++ /dev/null
@@ -1,34 +0,0 @@
-import { JSONRPCPayload } from '@0xproject/types';
-
-/*
- * This class implements the web3-provider-engine subprovider interface and returns
- * the constant gas estimate when queried.
- * HACK: We need this so that our tests don't use testrpc gas estimation which sometimes kills the node.
- * Source: https://github.com/trufflesuite/ganache-cli/issues/417
- * Source: https://github.com/trufflesuite/ganache-cli/issues/437
- * Source: https://github.com/MetaMask/provider-engine/blob/master/subproviders/subprovider.js
- */
-export class FakeGasEstimateSubprovider {
- private _constantGasAmount: number;
- constructor(constantGasAmount: number) {
- this._constantGasAmount = constantGasAmount;
- }
- // This method needs to be here to satisfy the interface but linter wants it to be static.
- // tslint:disable-next-line:prefer-function-over-method
- public handleRequest(payload: JSONRPCPayload, next: () => void, end: (err: Error | null, result: any) => void) {
- switch (payload.method) {
- case 'eth_estimateGas':
- end(null, this._constantGasAmount);
- return;
-
- default:
- next();
- return;
- }
- }
- // Required to implement this method despite not needing it for this subprovider
- // tslint:disable-next-line:prefer-function-over-method
- public setEngine(engine: any) {
- // noop
- }
-}
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"
]