Allow nested contract directories

uport
Alex Rea 8 years ago
parent 83181ce642
commit 3fa1afaffd
  1. 9
      coverageMap.js
  2. 12
      package.json
  3. 16
      runCoveredTests.js

@ -70,23 +70,22 @@ module.exports = class CoverageMap {
const event = JSON.parse(events[idx]);
if (event.topics.indexOf(lineTopic) >= 0) {
const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
const canonicalContractPath = path.resolve(pathPrefix + path.basename(data[0]));
const canonicalContractPath = data[0];
this.coverage[canonicalContractPath].l[data[1].toNumber()] += 1;
} else if (event.topics.indexOf(functionTopic) >= 0) {
const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
const canonicalContractPath = path.resolve(pathPrefix + path.basename(data[0]));
const canonicalContractPath = data[0];
this.coverage[canonicalContractPath].f[data[1].toNumber()] += 1;
} else if (event.topics.indexOf(branchTopic) >= 0) {
const data = SolidityCoder.decodeParams(['string', 'uint256', 'uint256'], event.data.replace('0x', ''));
const canonicalContractPath = path.resolve(pathPrefix + path.basename(data[0]));
const canonicalContractPath = data[0];
this.coverage[canonicalContractPath].b[data[1].toNumber()][data[2].toNumber()] += 1;
} else if (event.topics.indexOf(statementTopic) >= 0) {
const data = SolidityCoder.decodeParams(['string', 'uint256'], event.data.replace('0x', ''));
const canonicalContractPath = path.resolve(pathPrefix + path.basename(data[0]));
const canonicalContractPath = data[0];
this.coverage[canonicalContractPath].s[data[1].toNumber()] += 1;
}
}
return Object.assign({}, this.coverage);
}
};

@ -12,7 +12,7 @@
"author": "",
"license": "ISC",
"dependencies": {
"ethereumjs-testrpc": "^3.0.3",
"ethereumjs-testrpc": "https://github.com/ethereumjs/testrpc.git#5ba3c45b2ca306ab589f4a4c649d9afc39042680",
"istanbul": "^0.4.5",
"mkdirp": "^0.5.1",
"shelljs": "^0.7.4",
@ -21,11 +21,11 @@
},
"devDependencies": {
"crypto-js": "^3.1.9-1",
"ethereumjs-account": "^2.0.4",
"ethereumjs-tx": "^1.2.2",
"ethereumjs-util": "^5.0.1",
"merkle-patricia-tree": "^2.1.2",
"ethereumjs-account": "~2.0.4",
"ethereumjs-tx": "1.1.2",
"ethereumjs-util": "~4.5.0",
"merkle-patricia-tree": "~2.1.2",
"mocha": "^3.1.0",
"solc": "^0.4.6"
"solc": "0.4.6"
}
}

@ -18,7 +18,7 @@ if (!shell.test('-e','./node_modules/ethereumjs-vm/lib/opFns.js.orig')){
shell.exec('patch -b ./node_modules/ethereumjs-vm/lib/opFns.js ./hookIntoEvents.patch')
}
//Run the modified testrpc with large block limit
var testrpcProcess = childprocess.exec('./node_modules/ethereumjs-testrpc/bin/testrpc --gasLimit 0xfffffffffff')
var testrpcProcess = childprocess.exec('./node_modules/ethereumjs-testrpc/bin/testrpc --gasLimit 0xfffffffffffff --gasPrice 0x1')
if (shell.test('-d','../originalContracts')){
console.log("There is already an 'originalContracts' directory in your truffle directory.\nThis is probably due to a previous solcover failure.\nPlease make sure the ./contracts/ directory contains your contracts (perhaps by copying them from originalContracts), and then delete the originalContracts directory.")
@ -30,20 +30,20 @@ shell.mkdir('./../contracts/');
//For each contract in originalContracts, get the instrumented version
shell.ls('./../originalContracts/**/*.sol').forEach(function(file) {
if (file !== 'originalContracts/Migrations.sol') {
console.log("instrumenting ", file);
var contract = fs.readFileSync("./" + file).toString();
var fileName = path.basename(file);
var instrumentedContractInfo = getInstrumentedVersion(contract, file, true);
mkdirp.sync(path.dirname(file.replace('originalContracts', 'contracts')));
fs.writeFileSync(file.replace('originalContracts','contracts'), instrumentedContractInfo.contract);
var canonicalContractPath = path.resolve(file);
console.log("instrumenting ", canonicalContractPath);
var contract = fs.readFileSync(canonicalContractPath).toString();
var instrumentedContractInfo = getInstrumentedVersion(contract, canonicalContractPath, true);
mkdirp.sync(path.dirname(canonicalContractPath.replace('originalContracts', 'contracts')));
fs.writeFileSync(canonicalContractPath.replace('originalContracts','contracts'), instrumentedContractInfo.contract);
coverage.addContract(instrumentedContractInfo, canonicalContractPath);
}
});
shell.cp("./../originalContracts/Migrations.sol", "./../contracts/Migrations.sol");
shell.rm('./allFiredEvents'); //Delete previous results
shell.exec('truffle test --network coverage');
shell.exec('truffle test --network test');
events = fs.readFileSync('./allFiredEvents').toString().split('\n')
events.pop();

Loading…
Cancel
Save