aboutsummaryrefslogtreecommitdiffstats
path: root/packages/sol-cov/src
diff options
context:
space:
mode:
Diffstat (limited to 'packages/sol-cov/src')
-rw-r--r--packages/sol-cov/src/collect_contract_data.ts21
-rw-r--r--packages/sol-cov/src/coverage_manager.ts10
2 files changed, 17 insertions, 14 deletions
diff --git a/packages/sol-cov/src/collect_contract_data.ts b/packages/sol-cov/src/collect_contract_data.ts
index 1d8bc7178..3d8a45cec 100644
--- a/packages/sol-cov/src/collect_contract_data.ts
+++ b/packages/sol-cov/src/collect_contract_data.ts
@@ -8,25 +8,22 @@ import { ContractData } from './types';
export const collectContractsData = (artifactsPath: string, sourcesPath: string, networkId: number) => {
const artifactsGlob = `${artifactsPath}/**/*.json`;
const artifactFileNames = glob.sync(artifactsGlob, { absolute: true });
- const contractsDataIfExists: Array<ContractData | {}> = _.map(artifactFileNames, artifactFileName => {
+ const contractsData: ContractData[] = [];
+ _.forEach(artifactFileNames, artifactFileName => {
const artifact = JSON.parse(fs.readFileSync(artifactFileName).toString());
- const sources = artifact.networks[networkId].sources;
- const contractName = artifact.contract_name;
+ const sources = _.keys(artifact.sources);
+ const contractName = artifact.contractName;
// We don't compute coverage for dependencies
const sourceCodes = _.map(sources, (source: string) => fs.readFileSync(source).toString());
- if (_.isUndefined(artifact.networks[networkId])) {
- throw new Error(`No ${contractName} artifacts found for networkId ${networkId}`);
- }
const contractData = {
sourceCodes,
sources,
- sourceMap: artifact.networks[networkId].source_map,
- sourceMapRuntime: artifact.networks[networkId].source_map_runtime,
- runtimeBytecode: artifact.networks[networkId].runtime_bytecode,
- bytecode: artifact.networks[networkId].bytecode,
+ bytecode: artifact.compilerOutput.evm.bytecode.object,
+ sourceMap: artifact.compilerOutput.evm.bytecode.sourceMap,
+ runtimeBytecode: artifact.compilerOutput.evm.deployedBytecode.object,
+ sourceMapRuntime: artifact.compilerOutput.evm.deployedBytecode.sourceMap,
};
- return contractData;
+ contractsData.push(contractData);
});
- const contractsData = _.filter(contractsDataIfExists, contractData => !_.isEmpty(contractData)) as ContractData[];
return contractsData;
};
diff --git a/packages/sol-cov/src/coverage_manager.ts b/packages/sol-cov/src/coverage_manager.ts
index 230ccc3c9..509c1cb99 100644
--- a/packages/sol-cov/src/coverage_manager.ts
+++ b/packages/sol-cov/src/coverage_manager.ts
@@ -130,7 +130,10 @@ export class CoverageManager {
for (const traceInfo of this._traceInfos) {
if (traceInfo.address !== constants.NEW_CONTRACT) {
// Runtime transaction
- const runtimeBytecode = (traceInfo as TraceInfoExistingContract).runtimeBytecode;
+ let runtimeBytecode = (traceInfo as TraceInfoExistingContract).runtimeBytecode;
+ if (runtimeBytecode.startsWith('0x')) {
+ runtimeBytecode = runtimeBytecode.slice(2);
+ }
const contractData = _.find(this._contractsData, { runtimeBytecode }) as ContractData;
if (_.isUndefined(contractData)) {
throw new Error(`Transaction to an unknown address: ${traceInfo.address}`);
@@ -154,7 +157,10 @@ export class CoverageManager {
}
} else {
// Contract creation transaction
- const bytecode = (traceInfo as TraceInfoNewContract).bytecode;
+ let bytecode = (traceInfo as TraceInfoNewContract).bytecode;
+ if (bytecode.startsWith('0x')) {
+ bytecode = bytecode.slice(2);
+ }
const contractData = _.find(this._contractsData, contractDataCandidate =>
bytecode.startsWith(contractDataCandidate.bytecode),
) as ContractData;