aboutsummaryrefslogtreecommitdiffstats
path: root/packages/dev-utils/src/blockchain_lifecycle.ts
diff options
context:
space:
mode:
authorFabio Berger <me@fabioberger.com>2018-06-07 18:21:44 +0800
committerFabio Berger <me@fabioberger.com>2018-06-07 18:21:44 +0800
commit10478a6b2fd1f2a01597a88afde9cf582640a849 (patch)
tree3ebbb29656cf59b2547ec3c5a3c5b90ee6264483 /packages/dev-utils/src/blockchain_lifecycle.ts
parentcf8fdd3a701f21bfc3b2ec8397fa65948f5cdc78 (diff)
parente0bc01eea1c20e0afda296f331c6a475e062b59c (diff)
downloaddexon-sol-tools-10478a6b2fd1f2a01597a88afde9cf582640a849.tar
dexon-sol-tools-10478a6b2fd1f2a01597a88afde9cf582640a849.tar.gz
dexon-sol-tools-10478a6b2fd1f2a01597a88afde9cf582640a849.tar.bz2
dexon-sol-tools-10478a6b2fd1f2a01597a88afde9cf582640a849.tar.lz
dexon-sol-tools-10478a6b2fd1f2a01597a88afde9cf582640a849.tar.xz
dexon-sol-tools-10478a6b2fd1f2a01597a88afde9cf582640a849.tar.zst
dexon-sol-tools-10478a6b2fd1f2a01597a88afde9cf582640a849.zip
Merge branch 'v2-prototype' into refactor/move-spawn-switch-to-utils
* v2-prototype: (66 commits) Run prettier Remove unused variable Fix linting issues Change shouldRenderHeader prop to shouldHideHeader Get build and tests to pass typo Apply prettier Update contracts tests after rebase Apply various fixes based on PR feedback Document debug_increaseTime method and fix typo in devnet README Use an enum for ProviderType in contracts/src/utils/web3_wrapper Update contracts package README Update relevant changelogs Remove global gas estimate buffer Add Async suffix to relevant assertions Fix linter errors Update package.json and yarn.lock Update more things to work with both Geth and Ganache Small fixes and cleanup Add additional gas to calls to fillOrderNoThrow ... # Conflicts: # packages/order-watcher/src/order_watcher/order_watcher.ts # packages/react-docs/src/components/type.tsx # packages/website/ts/components/ui/lifecycle_raised_button.tsx # packages/website/ts/components/wallet/wallet.tsx
Diffstat (limited to 'packages/dev-utils/src/blockchain_lifecycle.ts')
-rw-r--r--packages/dev-utils/src/blockchain_lifecycle.ts55
1 files changed, 45 insertions, 10 deletions
diff --git a/packages/dev-utils/src/blockchain_lifecycle.ts b/packages/dev-utils/src/blockchain_lifecycle.ts
index 3e35de861..4bb136097 100644
--- a/packages/dev-utils/src/blockchain_lifecycle.ts
+++ b/packages/dev-utils/src/blockchain_lifecycle.ts
@@ -1,5 +1,10 @@
-import { Web3Wrapper } from '@0xproject/web3-wrapper';
-import * as Web3 from 'web3';
+import { uniqueVersionIds, Web3Wrapper } from '@0xproject/web3-wrapper';
+import { includes } from 'lodash';
+
+enum NodeType {
+ Geth = 'GETH',
+ Ganache = 'GANACHE',
+}
export class BlockchainLifecycle {
private _web3Wrapper: Web3Wrapper;
@@ -8,17 +13,47 @@ export class BlockchainLifecycle {
this._web3Wrapper = web3Wrapper;
this._snapshotIdsStack = [];
}
- // TODO: In order to run these tests on an actual node, we should check if we are running against
- // TestRPC, if so, use snapshots, otherwise re-deploy contracts before every test
public async startAsync(): Promise<void> {
- const snapshotId = await this._web3Wrapper.takeSnapshotAsync();
- this._snapshotIdsStack.push(snapshotId);
+ const nodeType = await this._getNodeTypeAsync();
+ switch (nodeType) {
+ case NodeType.Ganache:
+ const snapshotId = await this._web3Wrapper.takeSnapshotAsync();
+ this._snapshotIdsStack.push(snapshotId);
+ break;
+ case NodeType.Geth:
+ const blockNumber = await this._web3Wrapper.getBlockNumberAsync();
+ this._snapshotIdsStack.push(blockNumber);
+ break;
+ default:
+ throw new Error(`Unknown node type: ${nodeType}`);
+ }
}
public async revertAsync(): Promise<void> {
- const snapshotId = this._snapshotIdsStack.pop() as number;
- const didRevert = await this._web3Wrapper.revertSnapshotAsync(snapshotId);
- if (!didRevert) {
- throw new Error(`Snapshot with id #${snapshotId} failed to revert`);
+ const nodeType = await this._getNodeTypeAsync();
+ switch (nodeType) {
+ case NodeType.Ganache:
+ const snapshotId = this._snapshotIdsStack.pop() as number;
+ const didRevert = await this._web3Wrapper.revertSnapshotAsync(snapshotId);
+ if (!didRevert) {
+ throw new Error(`Snapshot with id #${snapshotId} failed to revert`);
+ }
+ break;
+ case NodeType.Geth:
+ const blockNumber = this._snapshotIdsStack.pop() as number;
+ await this._web3Wrapper.setHeadAsync(blockNumber);
+ break;
+ default:
+ throw new Error(`Unknown node type: ${nodeType}`);
+ }
+ }
+ private async _getNodeTypeAsync(): Promise<NodeType> {
+ const version = await this._web3Wrapper.getNodeVersionAsync();
+ if (includes(version, uniqueVersionIds.geth)) {
+ return NodeType.Geth;
+ } else if (includes(version, uniqueVersionIds.ganache)) {
+ return NodeType.Ganache;
+ } else {
+ throw new Error(`Unknown client version: ${version}`);
}
}
}