mirror of https://github.com/embarklabs/embark.git
parent
749c32cf07
commit
df3435f02b
|
@ -30,7 +30,7 @@ export class ContractEnhanced {
|
|||
private coverageFilepath: string;
|
||||
private functionsBodyLocation: {[id: number]: Location} = {};
|
||||
|
||||
constructor(public filepath: string) {
|
||||
constructor(public filepath: string, public solcVersion: string) {
|
||||
this.id = nextId();
|
||||
this.source = fs.readFileSync(filepath, "utf-8");
|
||||
this.originalSource = this.source;
|
||||
|
|
|
@ -18,7 +18,6 @@ export default class Coverage {
|
|||
|
||||
constructor(private embark: Embark, options: any) {
|
||||
fs.ensureDirSync(coverageContractsPath());
|
||||
|
||||
const contractsDirConfig = this.embark.config.embarkConfig.contracts;
|
||||
this.contractsDir = Array.isArray(contractsDirConfig) ? contractsDirConfig : [contractsDirConfig];
|
||||
|
||||
|
@ -33,12 +32,13 @@ export default class Coverage {
|
|||
}
|
||||
|
||||
private getContracts() {
|
||||
const solcVersion = this.embark.config.embarkConfig.versions.solc;
|
||||
const filepaths = this.contractsDir.reduce((acc: string[], pattern: string) => (
|
||||
acc.concat(globule.find(pattern, { prefixBase: false, srcBase: fs.dappPath() }))
|
||||
), []);
|
||||
|
||||
return filepaths.filter((filepath) => fs.statSync(filepath).isFile())
|
||||
.map((filepath) => new ContractEnhanced(filepath));
|
||||
.map((filepath) => new ContractEnhanced(filepath, solcVersion));
|
||||
}
|
||||
|
||||
private instrumentContracts() {
|
||||
|
|
|
@ -1,10 +1,15 @@
|
|||
import * as semver from "semver";
|
||||
import { ContractEnhanced } from "./contractEnhanced";
|
||||
import { encrypt } from "./eventId";
|
||||
import { InjectionPoint } from "./types";
|
||||
|
||||
const EMIT_VERSION = "0.4.21";
|
||||
|
||||
export class Injector {
|
||||
private isEmitSupported: boolean;
|
||||
|
||||
constructor(private contract: ContractEnhanced) {
|
||||
this.isEmitSupported = semver.gte(this.contract.solcVersion, EMIT_VERSION);
|
||||
}
|
||||
|
||||
public process(injectionPoint: InjectionPoint) {
|
||||
|
@ -17,7 +22,7 @@ export class Injector {
|
|||
}
|
||||
|
||||
private statement(injectionPoint: InjectionPoint) {
|
||||
const data = `emit __StatementCoverage(${encrypt(this.contract.id, injectionPoint.id)});`;
|
||||
const data = `${this.isEmitSupported ? "emit" : ""} __StatementCoverage(${encrypt(this.contract.id, injectionPoint.id)});`;
|
||||
this.insertAt(injectionPoint.location.start.line - 1, data);
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ export interface Embark {
|
|||
config: {
|
||||
contracts: string;
|
||||
};
|
||||
versions: {
|
||||
solc: string;
|
||||
}
|
||||
};
|
||||
reloadConfig(): void;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue