diff options
author | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-23 02:18:09 +0800 |
---|---|---|
committer | Leonid Logvinov <logvinov.leon@gmail.com> | 2018-05-23 06:27:17 +0800 |
commit | 447b305e3c50145696be715bc6f43523b0770220 (patch) | |
tree | 028d3afaf361b8eb019cb028fbb4ec50c027a39d /packages/sol-cov | |
parent | 0c53d276f8f4725feeae48fc3534ab63db8fcafb (diff) | |
download | dexon-sol-tools-447b305e3c50145696be715bc6f43523b0770220.tar dexon-sol-tools-447b305e3c50145696be715bc6f43523b0770220.tar.gz dexon-sol-tools-447b305e3c50145696be715bc6f43523b0770220.tar.bz2 dexon-sol-tools-447b305e3c50145696be715bc6f43523b0770220.tar.lz dexon-sol-tools-447b305e3c50145696be715bc6f43523b0770220.tar.xz dexon-sol-tools-447b305e3c50145696be715bc6f43523b0770220.tar.zst dexon-sol-tools-447b305e3c50145696be715bc6f43523b0770220.zip |
Suppport subcalls in constructor
Diffstat (limited to 'packages/sol-cov')
-rw-r--r-- | packages/sol-cov/src/coverage_subprovider.ts | 36 |
1 files changed, 26 insertions, 10 deletions
diff --git a/packages/sol-cov/src/coverage_subprovider.ts b/packages/sol-cov/src/coverage_subprovider.ts index 3fd45bbd1..45b479c0e 100644 --- a/packages/sol-cov/src/coverage_subprovider.ts +++ b/packages/sol-cov/src/coverage_subprovider.ts @@ -123,16 +123,32 @@ export class CoverageSubprovider extends Subprovider { const jsonRPCResponsePayload = await this.emitPayloadAsync(payload); const trace: TransactionTrace = jsonRPCResponsePayload.result; if (address === constants.NEW_CONTRACT) { - // TODO handle calls to external contracts and contract creations from within the constructor - const structLogsOnDepth0 = _.filter(trace.structLogs, { depth: 0 }); - const coveredPcs = _.map(structLogsOnDepth0, log => log.pc); - const traceInfo: TraceInfoNewContract = { - coveredPcs, - txHash, - address: address as 'NEW_CONTRACT', - bytecode: data as string, - }; - this._coverageManager.appendTraceInfo(traceInfo); + const tracesByContractAddress = getTracesByContractAddress(trace.structLogs, address); + for (const subcallAddress of _.keys(tracesByContractAddress)) { + let traceInfo: TraceInfoNewContract | TraceInfoExistingContract; + if (subcallAddress === 'NEW_CONTRACT') { + const traceForThatSubcall = tracesByContractAddress[subcallAddress]; + const coveredPcs = _.map(traceForThatSubcall, log => log.pc); + traceInfo = { + coveredPcs, + txHash, + address: address as 'NEW_CONTRACT', + bytecode: data as string, + }; + } else { + payload = { method: 'eth_getCode', params: [subcallAddress, BlockParamLiteral.Latest] }; + const runtimeBytecode = (await this.emitPayloadAsync(payload)).result; + const traceForThatSubcall = tracesByContractAddress[subcallAddress]; + const coveredPcs = _.map(traceForThatSubcall, log => log.pc); + traceInfo = { + coveredPcs, + txHash, + address: subcallAddress, + runtimeBytecode, + }; + } + this._coverageManager.appendTraceInfo(traceInfo); + } } else { const tracesByContractAddress = getTracesByContractAddress(trace.structLogs, address); for (const subcallAddress of _.keys(tracesByContractAddress)) { |