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/web3-wrapper/src/web3_wrapper.ts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'packages/web3-wrapper/src/web3_wrapper.ts') diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index 6ea69883c..e4df31def 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -31,6 +31,12 @@ export const uniqueVersionIds = { ganache: 'EthereumJS TestRPC', }; +// NodeType represents the type of the backing Ethereum node. +export enum NodeType { + Geth = 'GETH', + Ganache = 'GANACHE', +} + /** * A wrapper around the Web3.js 0.x library that provides a consistent, clean promise-based interface. */ @@ -489,6 +495,21 @@ export class Web3Wrapper { public async setHeadAsync(blockNumber: number): Promise { await this._sendRawPayloadAsync({ method: 'debug_setHead', params: [this._web3.toHex(blockNumber)] }); } + /** + * Returns either NodeType.Geth or NodeType.Ganache depending on the type of + * the backing Ethereum node. Throws for any other type of node. This + * function caches the result and so subsequent calls are fast. + */ + public async getNodeTypeAsync(): Promise { + const version = await this.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 _sendRawPayloadAsync(payload: Partial): Promise { const sendAsync = this._web3.currentProvider.sendAsync.bind(this._web3.currentProvider); const payloadWithDefaults = { -- cgit v1.2.3 From c5fcea1dbd5e64e72eb5cf360558de9f9b886a16 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Tue, 3 Jul 2018 10:40:54 -0700 Subject: Actually cache node type in web3-wrapper --- packages/web3-wrapper/src/web3_wrapper.ts | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'packages/web3-wrapper/src/web3_wrapper.ts') diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index e4df31def..c2754a13e 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -49,6 +49,7 @@ export class Web3Wrapper { private _web3: Web3; private _txDefaults: Partial; private _jsonRpcRequestId: number; + private _nodeType: NodeType | undefined; /** * Check if an address is a valid Ethereum address * @param address Address to check @@ -501,10 +502,15 @@ export class Web3Wrapper { * function caches the result and so subsequent calls are fast. */ public async getNodeTypeAsync(): Promise { + if (!_.isUndefined(this._nodeType)) { + return this._nodeType; + } const version = await this.getNodeVersionAsync(); if (_.includes(version, uniqueVersionIds.geth)) { + this._nodeType = NodeType.Geth; return NodeType.Geth; } else if (_.includes(version, uniqueVersionIds.ganache)) { + this._nodeType = NodeType.Ganache; return NodeType.Ganache; } else { throw new Error(`Unknown client version: ${version}`); -- 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/web3-wrapper/src/web3_wrapper.ts | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'packages/web3-wrapper/src/web3_wrapper.ts') diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index c2754a13e..b79ade278 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -49,7 +49,6 @@ export class Web3Wrapper { private _web3: Web3; private _txDefaults: Partial; private _jsonRpcRequestId: number; - private _nodeType: NodeType | undefined; /** * Check if an address is a valid Ethereum address * @param address Address to check @@ -498,19 +497,13 @@ export class Web3Wrapper { } /** * Returns either NodeType.Geth or NodeType.Ganache depending on the type of - * the backing Ethereum node. Throws for any other type of node. This - * function caches the result and so subsequent calls are fast. + * the backing Ethereum node. Throws for any other type of node. */ public async getNodeTypeAsync(): Promise { - if (!_.isUndefined(this._nodeType)) { - return this._nodeType; - } const version = await this.getNodeVersionAsync(); if (_.includes(version, uniqueVersionIds.geth)) { - this._nodeType = NodeType.Geth; return NodeType.Geth; } else if (_.includes(version, uniqueVersionIds.ganache)) { - this._nodeType = NodeType.Ganache; return NodeType.Ganache; } else { throw new Error(`Unknown client version: ${version}`); -- cgit v1.2.3