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 | |
parent | 0c53d276f8f4725feeae48fc3534ab63db8fcafb (diff) | |
download | dexon-0x-contracts-447b305e3c50145696be715bc6f43523b0770220.tar.gz dexon-0x-contracts-447b305e3c50145696be715bc6f43523b0770220.tar.zst dexon-0x-contracts-447b305e3c50145696be715bc6f43523b0770220.zip |
Suppport subcalls in constructor
-rw-r--r-- | packages/0x.js/test/artifacts_test.ts | 4 | ||||
-rw-r--r-- | packages/sol-cov/src/coverage_subprovider.ts | 36 |
2 files changed, 28 insertions, 12 deletions
diff --git a/packages/0x.js/test/artifacts_test.ts b/packages/0x.js/test/artifacts_test.ts index ca554a4f5..982fb8e63 100644 --- a/packages/0x.js/test/artifacts_test.ts +++ b/packages/0x.js/test/artifacts_test.ts @@ -15,7 +15,7 @@ const TIMEOUT = 10000; describe('Artifacts', () => { describe('contracts are deployed on kovan', () => { const kovanRpcUrl = constants.KOVAN_RPC_URL; - const provider = web3Factory.create({ rpcUrl: kovanRpcUrl }).currentProvider; + const provider = web3Factory.getRpcProvider({ rpcUrl: kovanRpcUrl }); const config = { networkId: constants.KOVAN_NETWORK_ID, }; @@ -32,7 +32,7 @@ describe('Artifacts', () => { }); describe('contracts are deployed on ropsten', () => { const ropstenRpcUrl = constants.ROPSTEN_RPC_URL; - const provider = web3Factory.create({ rpcUrl: ropstenRpcUrl }).currentProvider; + const provider = web3Factory.getRpcProvider({ rpcUrl: ropstenRpcUrl }); const config = { networkId: constants.ROPSTEN_NETWORK_ID, }; 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)) { |