diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-06-06 07:20:38 +0800 |
---|---|---|
committer | Alex Browne <stephenalexbrowne@gmail.com> | 2018-06-07 03:40:31 +0800 |
commit | d6d7f4e875b161aa7284467a61f67989f76ec89e (patch) | |
tree | d0287504809489cec96a9673ffac41429cf14cd7 /packages/web3-wrapper/src/web3_wrapper.ts | |
parent | 63caddea62453863de84a4b53e14fe3e61d3008f (diff) | |
download | dexon-sol-tools-d6d7f4e875b161aa7284467a61f67989f76ec89e.tar dexon-sol-tools-d6d7f4e875b161aa7284467a61f67989f76ec89e.tar.gz dexon-sol-tools-d6d7f4e875b161aa7284467a61f67989f76ec89e.tar.bz2 dexon-sol-tools-d6d7f4e875b161aa7284467a61f67989f76ec89e.tar.lz dexon-sol-tools-d6d7f4e875b161aa7284467a61f67989f76ec89e.tar.xz dexon-sol-tools-d6d7f4e875b161aa7284467a61f67989f76ec89e.tar.zst dexon-sol-tools-d6d7f4e875b161aa7284467a61f67989f76ec89e.zip |
Update more things to work with both Geth and Ganache
Diffstat (limited to 'packages/web3-wrapper/src/web3_wrapper.ts')
-rw-r--r-- | packages/web3-wrapper/src/web3_wrapper.ts | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index a19253449..6c9fa980e 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -21,6 +21,13 @@ import { Web3WrapperErrors } from './types'; const BASE_TEN = 10; +// These are unique identifiers contained in the response of the +// web3_clientVersion call. +export const uniqueVersionIds = { + geth: 'Geth', + ganache: 'EthereumJS TestRPC', +}; + /** * A wrapper around the Web3.js 0.x library that provides a consistent, clean promise-based interface. */ @@ -254,12 +261,20 @@ export class Web3Wrapper { await this._sendRawPayloadAsync<string>({ method: 'evm_mine', params: [] }); } /** - * Increase the next blocks timestamp on TestRPC/Ganache local node + * Increase the next blocks timestamp on TestRPC/Ganache or Geth local node. + * Will throw if provider is neither TestRPC/Ganache or Geth. * @param timeDelta Amount of time to add in seconds */ public async increaseTimeAsync(timeDelta: number): Promise<number> { - // TODO(albrow): Detect Geth vs. Ganache and use appropriate endpoint. - return this._sendRawPayloadAsync<number>({ method: 'debug_increaseTime', params: [timeDelta] }); + // Detect Geth vs. Ganache and use appropriate endpoint. + const version = await this.getNodeVersionAsync(); + if (_.includes(version, uniqueVersionIds.geth)) { + return this._sendRawPayloadAsync<number>({ method: 'debug_increaseTime', params: [timeDelta] }); + } else if (_.includes(version, uniqueVersionIds.ganache)) { + return this._sendRawPayloadAsync<number>({ method: 'evm_increaseTime', params: [timeDelta] }); + } else { + throw new Error(`Unknown client version: ${version}`); + } } /** * Retrieve smart contract logs for a given filter |