aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-06-09 05:36:07 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-06-09 05:56:46 +0800
commitcdb165af7f421f06647bcd61205acc3d33c24155 (patch)
treec3b4f8736061b0f1848f68290f610b4b32383c5e /packages/sol-cov
parent88a3f8e4aa8a48aea4fd92a15f6e872de8ee4a6a (diff)
downloaddexon-sol-tools-cdb165af7f421f06647bcd61205acc3d33c24155.tar
dexon-sol-tools-cdb165af7f421f06647bcd61205acc3d33c24155.tar.gz
dexon-sol-tools-cdb165af7f421f06647bcd61205acc3d33c24155.tar.bz2
dexon-sol-tools-cdb165af7f421f06647bcd61205acc3d33c24155.tar.lz
dexon-sol-tools-cdb165af7f421f06647bcd61205acc3d33c24155.tar.xz
dexon-sol-tools-cdb165af7f421f06647bcd61205acc3d33c24155.tar.zst
dexon-sol-tools-cdb165af7f421f06647bcd61205acc3d33c24155.zip
Remove some copy-paste code
Diffstat (limited to 'packages/sol-cov')
-rw-r--r--packages/sol-cov/src/trace_collection_subprovider.ts42
1 files changed, 6 insertions, 36 deletions
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<CallData>,
err: Error | null,
callResult: string,
cb: Callback,
): Promise<void> {
- await this._recordCallTraceAsync(callData);
- cb();
- }
- private async _onGasEstimateAsync(
- estimateGasData: Partial<TxData>,
- err: Error | null,
- estimateGasResult: string,
- cb: Callback,
- ): Promise<void> {
- await this._recordEstimateGasTraceAsync(estimateGasData);
+ await this._recordCallOrGasEstimateTraceAsync(callData);
cb();
}
private async _recordTxTraceAsync(address: string, data: string | undefined, txHash: string): Promise<void> {
@@ -217,13 +208,14 @@ export class TraceCollectionSubprovider extends Subprovider {
}
}
}
- private async _recordCallTraceAsync(callData: Partial<CallData>): Promise<void> {
+ private async _recordCallOrGasEstimateTraceAsync(callData: Partial<CallData>): Promise<void> {
// 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<TxData>): Promise<void> {
- // 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();
- }
}