From 3cc30f91a99578b626d95811a26ee7b19f404455 Mon Sep 17 00:00:00 2001 From: Alex Browne Date: Mon, 11 Jun 2018 17:04:47 -0700 Subject: Speedup awaitTransactionMinedAsync and reduce polling interval in contracts tests --- packages/web3-wrapper/src/web3_wrapper.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (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 780695091..5d2eedcb3 100644 --- a/packages/web3-wrapper/src/web3_wrapper.ts +++ b/packages/web3-wrapper/src/web3_wrapper.ts @@ -402,6 +402,21 @@ export class Web3Wrapper { pollingIntervalMs: number = 1000, timeoutMs?: number, ): Promise { + // Immediately check if the transaction has already been mined. + let transactionReceipt = await this.getTransactionReceiptAsync(txHash); + if (!_.isNull(transactionReceipt)) { + const logsWithDecodedArgs = _.map( + transactionReceipt.logs, + this.abiDecoder.tryToDecodeLogOrNoop.bind(this.abiDecoder), + ); + const transactionReceiptWithDecodedLogArgs: TransactionReceiptWithDecodedLogs = { + ...transactionReceipt, + logs: logsWithDecodedArgs, + }; + return transactionReceiptWithDecodedLogArgs; + } + + // Otherwise, check again every pollingIntervalMs. let wasTimeoutExceeded = false; if (timeoutMs) { setTimeout(() => (wasTimeoutExceeded = true), timeoutMs); @@ -416,7 +431,7 @@ export class Web3Wrapper { return reject(Web3WrapperErrors.TransactionMiningTimeout); } - const transactionReceipt = await this.getTransactionReceiptAsync(txHash); + transactionReceipt = await this.getTransactionReceiptAsync(txHash); if (!_.isNull(transactionReceipt)) { intervalUtils.clearAsyncExcludingInterval(intervalId); const logsWithDecodedArgs = _.map( -- cgit