diff options
author | Alex Browne <stephenalexbrowne@gmail.com> | 2018-05-22 04:56:32 +0800 |
---|---|---|
committer | Alex Browne <stephenalexbrowne@gmail.com> | 2018-06-07 03:39:39 +0800 |
commit | 577156fe5f63e581b101682d13b7e70e7a9336e5 (patch) | |
tree | 202d928d4888825a4ea1f24e2fd03368643c2966 /packages/web3-wrapper/src/web3_wrapper.ts | |
parent | da3f783a9ff69b059b1a98f502d980660d6bacab (diff) | |
download | dexon-0x-contracts-577156fe5f63e581b101682d13b7e70e7a9336e5.tar.gz dexon-0x-contracts-577156fe5f63e581b101682d13b7e70e7a9336e5.tar.zst dexon-0x-contracts-577156fe5f63e581b101682d13b7e70e7a9336e5.zip |
Use Geth for contract tests
Diffstat (limited to 'packages/web3-wrapper/src/web3_wrapper.ts')
-rw-r--r-- | packages/web3-wrapper/src/web3_wrapper.ts | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/packages/web3-wrapper/src/web3_wrapper.ts b/packages/web3-wrapper/src/web3_wrapper.ts index 3de152df1..d922c80cd 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -281,7 +281,6 @@ export class Web3Wrapper { }; const payload = { jsonrpc: '2.0', - id: this._jsonRpcRequestId++, method: 'eth_getLogs', params: [serializedFilter], }; @@ -403,8 +402,44 @@ export class Web3Wrapper { } return receipt; } + /** + * Start the CPU mining process with the given number of threads and + * generate a new DAG if need be. + * @param threads The number of threads to mine on. + */ + public async minerStartAsync(threads: number = 1): Promise<void> { + await this._sendRawPayloadAsync<boolean>({ + method: 'miner_start', + params: [threads], + }); + } + /** + * Stop the CPU mining process. + * @param threads The number of threads to mine on. + */ + public async minerStopAsync(): Promise<void> { + await this._sendRawPayloadAsync<boolean>({ method: 'miner_stop', params: [] }); + } + /** + * Returns true if client is actively mining new blocks. + * @returns A boolean indicating whether the node is currently mining. + */ + public async isMiningAsync(): Promise<boolean> { + const isMining = await promisify<boolean>(this._web3.eth.getMining)(); + return isMining; + } + /** + * Sets the current head of the local chain by block number. Note, this is a + * destructive action and may severely damage your chain. Use with extreme + * caution. + * @param blockNumber The block number to reset to. + */ + public async setHeadAsync(blockNumber: number): Promise<void> { + await this._sendRawPayloadAsync<void>({ method: 'debug_setHead', params: [this._web3.toHex(blockNumber)] }); + } private async _sendRawPayloadAsync<A>(payload: Partial<JSONRPCRequestPayload>): Promise<A> { const sendAsync = this._web3.currentProvider.sendAsync.bind(this._web3.currentProvider); + payload.id = this._jsonRpcRequestId++; const response = await promisify<JSONRPCResponsePayload>(sendAsync)(payload); const result = response.result; return result; |