|
|
|
@ -3,7 +3,6 @@ |
|
|
|
|
This file contains utilities for generating a mock truffle project to test solcover's |
|
|
|
|
run script against. |
|
|
|
|
*/ |
|
|
|
|
const assert = require('assert'); |
|
|
|
|
const fs = require('fs'); |
|
|
|
|
const shell = require('shelljs'); |
|
|
|
|
|
|
|
|
@ -11,7 +10,7 @@ const shell = require('shelljs'); |
|
|
|
|
* Moves existing coverage reports into a safe place while testing run script which |
|
|
|
|
* would overwrite them. Silences shell complaints about non-existent files. |
|
|
|
|
*/ |
|
|
|
|
module.exports.protectCoverage = function () { |
|
|
|
|
module.exports.protectCoverage = function protectCoverage() { |
|
|
|
|
shell.config.silent = true; |
|
|
|
|
shell.rm('-Rf', './safe'); |
|
|
|
|
shell.mkdir('./safe'); |
|
|
|
@ -24,7 +23,7 @@ module.exports.protectCoverage = function () { |
|
|
|
|
* Restores pre-existing coverage reports after testing run script. |
|
|
|
|
* Silences shell complaints about non-existent files. |
|
|
|
|
*/ |
|
|
|
|
module.exports.restoreCoverage = function () { |
|
|
|
|
module.exports.restoreCoverage = function restoreCoverage() { |
|
|
|
|
shell.config.silent = true; |
|
|
|
|
shell.mv('./safe/coverage', './coverage'); |
|
|
|
|
shell.mv('./safe/coverage.json', './coverage.json'); |
|
|
|
@ -38,7 +37,7 @@ module.exports.restoreCoverage = function () { |
|
|
|
|
* @param {String} contract <contractName.sol> located in /test/sources/run/ |
|
|
|
|
* @param {[type]} test <testName.js> located in /test/run/ |
|
|
|
|
*/ |
|
|
|
|
module.exports.install = function (contract, test, config) { |
|
|
|
|
module.exports.install = function install(contract, test, config) { |
|
|
|
|
shell.mkdir('./mock'); |
|
|
|
|
shell.mkdir('./mock/contracts'); |
|
|
|
|
shell.mkdir('./mock/migrations'); |
|
|
|
@ -48,7 +47,7 @@ module.exports.install = function (contract, test, config) { |
|
|
|
|
if (Array.isArray(contract)) { |
|
|
|
|
contract.forEach(item => { |
|
|
|
|
shell.cp(`./test/sources/run/${item}`, `./mock/contracts/${item}`); |
|
|
|
|
}) |
|
|
|
|
}); |
|
|
|
|
} else { |
|
|
|
|
shell.cp(`./test/sources/run/${contract}`, `./mock/contracts/${contract}`); |
|
|
|
|
} |
|
|
|
@ -62,7 +61,7 @@ module.exports.install = function (contract, test, config) { |
|
|
|
|
deployer.deploy(Migrations); |
|
|
|
|
};`;
|
|
|
|
|
|
|
|
|
|
const contractLocation = './' + contract; |
|
|
|
|
const contractLocation = `./${contract}`; |
|
|
|
|
const deployContracts = ` |
|
|
|
|
var contract = artifacts.require('${contractLocation}'); |
|
|
|
|
module.exports = function(deployer) { |
|
|
|
@ -97,15 +96,15 @@ module.exports.install = function (contract, test, config) { |
|
|
|
|
* @param {String} contract <contractName.sol> located in /test/sources/run/ |
|
|
|
|
* @param {[type]} test <testName.js> located in /test/run/ |
|
|
|
|
*/ |
|
|
|
|
module.exports.installInheritanceTest = function (config) { |
|
|
|
|
module.exports.installInheritanceTest = function installInheritanceTest(config) { |
|
|
|
|
shell.mkdir('./mock'); |
|
|
|
|
shell.mkdir('./mock/contracts'); |
|
|
|
|
shell.mkdir('./mock/migrations'); |
|
|
|
|
shell.mkdir('./mock/test'); |
|
|
|
|
|
|
|
|
|
// Mock contracts
|
|
|
|
|
shell.cp(`./test/sources/run/Proxy.sol`, `./mock/contracts/Proxy.sol`); |
|
|
|
|
shell.cp(`./test/sources/run/Owned.sol`, `./mock/contracts/Owned.sol`); |
|
|
|
|
shell.cp('./test/sources/run/Proxy.sol', './mock/contracts/Proxy.sol'); |
|
|
|
|
shell.cp('./test/sources/run/Owned.sol', './mock/contracts/Owned.sol'); |
|
|
|
|
shell.cp('./test/sources/run/Migrations.sol', './mock/contracts/Migrations.sol'); |
|
|
|
|
|
|
|
|
|
// Mock migrations
|
|
|
|
@ -128,7 +127,7 @@ module.exports.installInheritanceTest = function (config) { |
|
|
|
|
fs.writeFileSync('./mock/migrations/2_deploy_contracts.js', deployContracts); |
|
|
|
|
|
|
|
|
|
// Mock test
|
|
|
|
|
shell.cp(`./test/run/inheritance.js`, `./mock/test/inheritance.js`); |
|
|
|
|
shell.cp('./test/run/inheritance.js', './mock/test/inheritance.js'); |
|
|
|
|
|
|
|
|
|
// Mock truffle.js
|
|
|
|
|
const trufflejs = `module.exports = {
|
|
|
|
@ -149,7 +148,7 @@ module.exports.installInheritanceTest = function (config) { |
|
|
|
|
/** |
|
|
|
|
* Removes mock truffle project and coverage reports generated by runCovered tests |
|
|
|
|
*/ |
|
|
|
|
module.exports.remove = function () { |
|
|
|
|
module.exports.remove = function remove() { |
|
|
|
|
shell.config.silent = true; |
|
|
|
|
shell.rm('./.solcover.js'); |
|
|
|
|
shell.rm('-Rf', 'mock'); |
|
|
|
|