aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-utils
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-02-16 11:09:53 +0800
committerFabio Berger <me@fabioberger.com>2018-02-16 11:09:53 +0800
commite2b51c5dc46b30b21e0561689de1f9a3d0127554 (patch)
treec8f93b5700961a46b16e49e52d159c989c11102d /packages/dev-utils
parentb610b7c1923dcc56883c5167393122ceaed26708 (diff)
parentb75fdd6b66a30196d53331827733b863bed770f0 (diff)
downloaddexon-sol-tools-e2b51c5dc46b30b21e0561689de1f9a3d0127554.tar
dexon-sol-tools-e2b51c5dc46b30b21e0561689de1f9a3d0127554.tar.gz
dexon-sol-tools-e2b51c5dc46b30b21e0561689de1f9a3d0127554.tar.bz2
dexon-sol-tools-e2b51c5dc46b30b21e0561689de1f9a3d0127554.tar.lz
dexon-sol-tools-e2b51c5dc46b30b21e0561689de1f9a3d0127554.tar.xz
dexon-sol-tools-e2b51c5dc46b30b21e0561689de1f9a3d0127554.tar.zst
dexon-sol-tools-e2b51c5dc46b30b21e0561689de1f9a3d0127554.zip
Merge branch 'development' of github.com:0xProject/0x.js into development
* 'development' of github.com:0xProject/0x.js: (24 commits) Rename variables Update CHANGELOG Add npm config for contracts list Run prettier Fix checks, add contract list to compile script in package.json Add contracts to compiler options Add missing public types from connect docs Change imports order Change default page params in connect to page 1 and perPage 100 Add docs staging to 0x.js package Fix a typo Add an assertion Add PR numbers Fix entry points Add tests for dev-utils package Move subproviders from dev-utils to subproviders Add missing CHANGELOG entry Add support for intersection types in docs Add stagedocs script to connect package web3 typings fix - web3.net.peerCount returns number ...
Diffstat (limited to 'packages/dev-utils')
-rw-r--r--packages/dev-utils/CHANGELOG.md4
-rw-r--r--packages/dev-utils/package.json15
-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, 88 insertions, 66 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/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"
]