From 5b64b3ea937326978b5742ec1b3692ebe5c41991 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 2 Jul 2018 18:44:37 -0700 Subject: Improve robustness of revert reason assertions --- packages/dev-utils/src/blockchain_lifecycle.ts | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'packages/dev-utils/src') diff --git a/packages/dev-utils/src/blockchain_lifecycle.ts b/packages/dev-utils/src/blockchain_lifecycle.ts index 587332f1a..abca6d386 100644 --- a/packages/dev-utils/src/blockchain_lifecycle.ts +++ b/packages/dev-utils/src/blockchain_lifecycle.ts @@ -1,11 +1,5 @@ import { logUtils } from '@0xproject/utils'; -import { uniqueVersionIds, Web3Wrapper } from '@0xproject/web3-wrapper'; -import { includes } from 'lodash'; - -enum NodeType { - Geth = 'GETH', - Ganache = 'GANACHE', -} +import { NodeType, Web3Wrapper } from '@0xproject/web3-wrapper'; // HACK(albrow): 🐉 We have to do this so that debug.setHead works correctly. // (Geth does not seem to like debug.setHead(0), so by sending some transactions @@ -23,7 +17,7 @@ export class BlockchainLifecycle { this._snapshotIdsStack = []; } public async startAsync(): Promise { - const nodeType = await this._getNodeTypeAsync(); + const nodeType = await this._web3Wrapper.getNodeTypeAsync(); switch (nodeType) { case NodeType.Ganache: const snapshotId = await this._web3Wrapper.takeSnapshotAsync(); @@ -44,7 +38,7 @@ export class BlockchainLifecycle { } } public async revertAsync(): Promise { - const nodeType = await this._getNodeTypeAsync(); + const nodeType = await this._web3Wrapper.getNodeTypeAsync(); switch (nodeType) { case NodeType.Ganache: const snapshotId = this._snapshotIdsStack.pop() as number; @@ -61,16 +55,6 @@ export class BlockchainLifecycle { throw new Error(`Unknown node type: ${nodeType}`); } } - private async _getNodeTypeAsync(): Promise { - 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}`); - } - } private async _mineMinimumBlocksAsync(): Promise { logUtils.warn('WARNING: minimum block number for tests not met. Mining additional blocks...'); if (this._addresses.length === 0) { -- cgit v1.2.3 From dc956020ef7c6d3f1880263700422b31253c8da3 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 3 Jul 2018 12:55:05 -0700 Subject: Move NodeType caching out of web3-wrapper and into our internal code --- packages/dev-utils/src/blockchain_lifecycle.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'packages/dev-utils/src') diff --git a/packages/dev-utils/src/blockchain_lifecycle.ts b/packages/dev-utils/src/blockchain_lifecycle.ts index abca6d386..9bd65ee5d 100644 --- a/packages/dev-utils/src/blockchain_lifecycle.ts +++ b/packages/dev-utils/src/blockchain_lifecycle.ts @@ -1,5 +1,6 @@ import { logUtils } from '@0xproject/utils'; import { NodeType, Web3Wrapper } from '@0xproject/web3-wrapper'; +import * as _ from 'lodash'; // HACK(albrow): 🐉 We have to do this so that debug.setHead works correctly. // (Geth does not seem to like debug.setHead(0), so by sending some transactions @@ -12,12 +13,13 @@ export class BlockchainLifecycle { private _web3Wrapper: Web3Wrapper; private _snapshotIdsStack: number[]; private _addresses: string[] = []; + private _nodeType: NodeType | undefined; constructor(web3Wrapper: Web3Wrapper) { this._web3Wrapper = web3Wrapper; this._snapshotIdsStack = []; } public async startAsync(): Promise { - const nodeType = await this._web3Wrapper.getNodeTypeAsync(); + const nodeType = await this._getNodeTypeAsync(); switch (nodeType) { case NodeType.Ganache: const snapshotId = await this._web3Wrapper.takeSnapshotAsync(); @@ -38,7 +40,7 @@ export class BlockchainLifecycle { } } public async revertAsync(): Promise { - const nodeType = await this._web3Wrapper.getNodeTypeAsync(); + const nodeType = await this._getNodeTypeAsync(); switch (nodeType) { case NodeType.Ganache: const snapshotId = this._snapshotIdsStack.pop() as number; @@ -76,4 +78,10 @@ export class BlockchainLifecycle { } logUtils.warn('Done mining the minimum number of blocks.'); } + private async _getNodeTypeAsync(): Promise { + if (_.isUndefined(this._nodeType)) { + this._nodeType = await this._web3Wrapper.getNodeTypeAsync(); + } + return this._nodeType; + } } -- cgit v1.2.3