aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src/coverage_subprovider.ts
diff options
context:
space:
mode:
authorLeonid Logvinov <logvinov.leon@gmail.com>2018-03-09 22:11:30 +0800
committerLeonid Logvinov <logvinov.leon@gmail.com>2018-03-12 10:37:28 +0800
commit98f32d6f1ff3c94544cc3ad8bdf1df02daca3d74 (patch)
tree2852f08fddd4487695ecf9e7f6fa099a15ca1637 /packages/sol-cov/src/coverage_subprovider.ts
parent62f45f7b41fdd984025ba70008c682eeded2fadb (diff)
downloaddexon-sol-tools-98f32d6f1ff3c94544cc3ad8bdf1df02daca3d74.tar
dexon-sol-tools-98f32d6f1ff3c94544cc3ad8bdf1df02daca3d74.tar.gz
dexon-sol-tools-98f32d6f1ff3c94544cc3ad8bdf1df02daca3d74.tar.bz2
dexon-sol-tools-98f32d6f1ff3c94544cc3ad8bdf1df02daca3d74.tar.lz
dexon-sol-tools-98f32d6f1ff3c94544cc3ad8bdf1df02daca3d74.tar.xz
dexon-sol-tools-98f32d6f1ff3c94544cc3ad8bdf1df02daca3d74.tar.zst
dexon-sol-tools-98f32d6f1ff3c94544cc3ad8bdf1df02daca3d74.zip
Stop making an assumption that contract code is immutable
Diffstat (limited to 'packages/sol-cov/src/coverage_subprovider.ts')
-rw-r--r--packages/sol-cov/src/coverage_subprovider.ts24
1 files changed, 21 insertions, 3 deletions
diff --git a/packages/sol-cov/src/coverage_subprovider.ts b/packages/sol-cov/src/coverage_subprovider.ts
index ef425ee81..d3783abb2 100644
--- a/packages/sol-cov/src/coverage_subprovider.ts
+++ b/packages/sol-cov/src/coverage_subprovider.ts
@@ -5,6 +5,7 @@ import * as Web3 from 'web3';
import { constants } from './constants';
import { CoverageManager } from './coverage_manager';
+import { TraceInfoExistingContract, TraceInfoNewContract } from './types';
/*
* This class implements the web3-provider-engine subprovider interface and collects traces of all transactions that were sent and all calls that were executed.
@@ -84,15 +85,32 @@ export class CoverageSubprovider extends Subprovider {
cb();
}
private async _recordTxTraceAsync(address: string, data: string | undefined, txHash: string): Promise<void> {
- this._coverageManager.setTxDataByHash(txHash, data || '');
- const payload = {
+ let payload = {
method: 'debug_traceTransaction',
params: [txHash, { disableMemory: true, disableStack: true, disableStorage: true }], // TODO For now testrpc just ignores those parameters https://github.com/trufflesuite/ganache-cli/issues/489
};
const jsonRPCResponsePayload = await this.emitPayloadAsync(payload);
const trace: Web3.TransactionTrace = jsonRPCResponsePayload.result;
const coveredPcs = _.map(trace.structLogs, log => log.pc);
- this._coverageManager.appendTraceInfo(address, { coveredPcs, txHash });
+ if (address === constants.NEW_CONTRACT) {
+ const traceInfo: TraceInfoNewContract = {
+ coveredPcs,
+ txHash,
+ address,
+ bytecode: data as string,
+ };
+ this._coverageManager.appendTraceInfo(traceInfo);
+ } else {
+ payload = { method: 'eth_getCode', params: [address, 'latest'] };
+ const runtimeBytecode = (await this.emitPayloadAsync(payload)).result;
+ const traceInfo: TraceInfoExistingContract = {
+ coveredPcs,
+ txHash,
+ address,
+ runtimeBytecode,
+ };
+ this._coverageManager.appendTraceInfo(traceInfo);
+ }
}
private async _recordCallTraceAsync(callData: Partial<Web3.CallData>, blockNumber: Web3.BlockParam): Promise<void> {
const snapshotId = Number((await this.emitPayloadAsync({ method: 'evm_snapshot' })).result);