From cdb165af7f421f06647bcd61205acc3d33c24155 Mon Sep 17 00:00:00 2001 From: Leonid Logvinov Date: Fri, 8 Jun 2018 14:36:07 -0700 Subject: Remove some copy-paste code --- .../sol-cov/src/trace_collection_subprovider.ts | 42 ++++------------------ 1 file changed, 6 insertions(+), 36 deletions(-) (limited to 'packages/sol-cov/src/trace_collection_subprovider.ts') diff --git a/packages/sol-cov/src/trace_collection_subprovider.ts b/packages/sol-cov/src/trace_collection_subprovider.ts index a6af7d4d2..7500e5bd3 100644 --- a/packages/sol-cov/src/trace_collection_subprovider.ts +++ b/packages/sol-cov/src/trace_collection_subprovider.ts @@ -90,7 +90,7 @@ export class TraceCollectionSubprovider extends Subprovider { next(); } else { const callData = payload.params[0]; - next(this._onCallExecutedAsync.bind(this, callData)); + next(this._onCallOrGasEstimateExecutedAsync.bind(this, callData)); } return; @@ -99,7 +99,7 @@ export class TraceCollectionSubprovider extends Subprovider { next(); } else { const estimateGasData = payload.params[0]; - next(this._onGasEstimateAsync.bind(this, estimateGasData)); + next(this._onCallOrGasEstimateExecutedAsync.bind(this, estimateGasData)); } return; @@ -153,22 +153,13 @@ export class TraceCollectionSubprovider extends Subprovider { } cb(); } - private async _onCallExecutedAsync( + private async _onCallOrGasEstimateExecutedAsync( callData: Partial, err: Error | null, callResult: string, cb: Callback, ): Promise { - await this._recordCallTraceAsync(callData); - cb(); - } - private async _onGasEstimateAsync( - estimateGasData: Partial, - err: Error | null, - estimateGasResult: string, - cb: Callback, - ): Promise { - await this._recordEstimateGasTraceAsync(estimateGasData); + await this._recordCallOrGasEstimateTraceAsync(callData); cb(); } private async _recordTxTraceAsync(address: string, data: string | undefined, txHash: string): Promise { @@ -217,13 +208,14 @@ export class TraceCollectionSubprovider extends Subprovider { } } } - private async _recordCallTraceAsync(callData: Partial): Promise { + private async _recordCallOrGasEstimateTraceAsync(callData: Partial): Promise { // We don't want other transactions to be exeucted during snashotting period, that's why we lock the // transaction execution for all transactions except our fake ones. await this._lock.acquire(); const blockchainLifecycle = new BlockchainLifecycle(this._web3Wrapper); await blockchainLifecycle.startAsync(); const fakeTxData: MaybeFakeTxData = { + gas: BLOCK_GAS_LIMIT, isFakeTransaction: true, // This transaction (and only it) is allowed to come through when the lock is locked ...callData, from: callData.from || this._defaultFromAddress, @@ -238,26 +230,4 @@ export class TraceCollectionSubprovider extends Subprovider { await blockchainLifecycle.revertAsync(); this._lock.release(); } - private async _recordEstimateGasTraceAsync(estimateGasData: Partial): Promise { - // We don't want other transactions to be exeucted during snashotting period, that's why we lock the - // transaction execution for all transactions except our fake ones. - await this._lock.acquire(); - const blockchainLifecycle = new BlockchainLifecycle(this._web3Wrapper); - await blockchainLifecycle.startAsync(); - const fakeTxData: MaybeFakeTxData = { - isFakeTransaction: true, // This transaction (and only it) is allowed to come through when the lock is locked - ...estimateGasData, - from: estimateGasData.from || this._defaultFromAddress, - gas: BLOCK_GAS_LIMIT, - }; - try { - const txHash = await this._web3Wrapper.sendTransactionAsync(fakeTxData); - await this._web3Wrapper.awaitTransactionMinedAsync(txHash); - } catch (err) { - // Even if this transaction failed - we've already recorded it's trace. - _.noop(); - } - await blockchainLifecycle.revertAsync(); - this._lock.release(); - } } -- cgit v1.2.3