Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #636 - add solidity compiler flags to use to allow compilation of all valid contracts without optimization #642

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solidity-coverage",
"version": "0.7.16",
"version": "0.7.17",
"description": "",
"main": "plugins/nomiclabs.plugin.js",
"bin": {
Expand Down
28 changes: 17 additions & 11 deletions plugins/buidler.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ function plugin() {

task("coverage", "Generates a code coverage report for tests")

.addOptionalParam("testfiles", ui.flags.file, "", types.string)
.addOptionalParam("testfiles", ui.flags.file, "", types.string)
.addOptionalParam("solcoverjs", ui.flags.solcoverjs, "", types.string)
.addOptionalParam('temp', ui.flags.temp, "", types.string)
.addOptionalParam('temp', ui.flags.temp, "", types.string)

.setAction(async function(args, env){
.setAction(async function (args, env) {
let error;
let ui;
let api;
Expand Down Expand Up @@ -109,6 +109,12 @@ function plugin() {
config.paths.artifacts = tempArtifactsDir;
config.paths.cache = buidlerUtils.tempCacheDir(config);
config.solc.optimizer.enabled = false;
config.solc.optimizer.details = {
yul: true,
yulDetails: {
stackAllocation: true,
},
};

await env.run(TASK_COMPILE);

Expand All @@ -122,7 +128,7 @@ function plugin() {
: [];

try {
await env.run(TASK_TEST, {testFiles: testfiles})
await env.run(TASK_TEST, { testFiles: testfiles })
} catch (e) {
error = e;
}
Expand All @@ -134,15 +140,15 @@ function plugin() {
await api.report();
await api.onIstanbulComplete(config);

} catch(e) {
error = e;
}
} catch (e) {
error = e;
}

await buidlerUtils.finish(config, api);
await buidlerUtils.finish(config, api);

if (error !== undefined ) throw error;
if (process.exitCode > 0) throw new Error(ui.generate('tests-fail', [process.exitCode]));
})
if (error !== undefined) throw error;
if (process.exitCode > 0) throw new Error(ui.generate('tests-fail', [process.exitCode]));
})
}

module.exports = plugin;
250 changes: 128 additions & 122 deletions plugins/hardhat.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ task(TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE).setAction(async (_, __,
settings.metadata.useLiteralContent = false;
// Override optimizer settings for all compilers
settings.optimizer.enabled = false;
settings.optimizer.details = {
yul: true,
yulDetails: {
stackAllocation: true,
},
};
}
return compilationJob;
});
Expand All @@ -68,148 +74,148 @@ task(TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE).setAction(async (_, __,
* @param {HardhatEnv} env
*/
task("coverage", "Generates a code coverage report for tests")
.addOptionalParam("testfiles", ui.flags.file, "", types.string)
.addOptionalParam("testfiles", ui.flags.file, "", types.string)
.addOptionalParam("solcoverjs", ui.flags.solcoverjs, "", types.string)
.addOptionalParam('temp', ui.flags.temp, "", types.string)
.setAction(async function(args, env){

let error;
let ui;
let api;
let config;
let client;
let address;
let failedTests = 0;

instrumentedSources = {};
measureCoverage = true;

try {
config = nomiclabsUtils.normalizeConfig(env.config, args);
ui = new PluginUI(config.logger.log);
api = new API(utils.loadSolcoverJS(config));

// Catch interrupt signals
process.on("SIGINT", nomiclabsUtils.finish.bind(null, config, api, true));

// Version Info
ui.report('hardhat-versions', [pkg.version]);

// Merge non-null flags into hardhatArguments
const flags = {};
for (const key of Object.keys(args)){
if (args[key] && args[key].length){
flags[key] = args[key]
.addOptionalParam('temp', ui.flags.temp, "", types.string)
.setAction(async function (args, env) {

let error;
let ui;
let api;
let config;
let client;
let address;
let failedTests = 0;

instrumentedSources = {};
measureCoverage = true;

try {
config = nomiclabsUtils.normalizeConfig(env.config, args);
ui = new PluginUI(config.logger.log);
api = new API(utils.loadSolcoverJS(config));

// Catch interrupt signals
process.on("SIGINT", nomiclabsUtils.finish.bind(null, config, api, true));

// Version Info
ui.report('hardhat-versions', [pkg.version]);

// Merge non-null flags into hardhatArguments
const flags = {};
for (const key of Object.keys(args)) {
if (args[key] && args[key].length) {
flags[key] = args[key]
}
}
}
env.hardhatArguments = Object.assign(env.hardhatArguments, flags)
env.hardhatArguments = Object.assign(env.hardhatArguments, flags)

// ================
// Instrumentation
// ================
// ================
// Instrumentation
// ================

const skipFiles = api.skipFiles || [];
const skipFiles = api.skipFiles || [];

let {
targets,
skipped
} = utils.assembleFiles(config, skipFiles);
let {
targets,
skipped
} = utils.assembleFiles(config, skipFiles);

targets = api.instrument(targets);
for (const target of targets) {
instrumentedSources[target.canonicalPath] = target.source;
}
utils.reportSkipped(config, skipped);

// ==============
// Compilation
// ==============
ui.report('compilation', []);

config.temp = args.temp;

// With Hardhat >= 2.0.4, everything should automatically recompile
// after solidity-coverage corrupts the artifacts.
// Prior to that version, we (try to) save artifacts to a temp folder.
if (!config.useHardhatDefaultPaths){
const {
tempArtifactsDir,
tempContractsDir
} = utils.getTempLocations(config);

utils.setupTempFolders(config, tempContractsDir, tempArtifactsDir)
config.paths.artifacts = tempArtifactsDir;
config.paths.cache = nomiclabsUtils.tempCacheDir(config);
}
targets = api.instrument(targets);
for (const target of targets) {
instrumentedSources[target.canonicalPath] = target.source;
}
utils.reportSkipped(config, skipped);

// ==============
// Compilation
// ==============
ui.report('compilation', []);

config.temp = args.temp;

// With Hardhat >= 2.0.4, everything should automatically recompile
// after solidity-coverage corrupts the artifacts.
// Prior to that version, we (try to) save artifacts to a temp folder.
if (!config.useHardhatDefaultPaths) {
const {
tempArtifactsDir,
tempContractsDir
} = utils.getTempLocations(config);

utils.setupTempFolders(config, tempContractsDir, tempArtifactsDir)
config.paths.artifacts = tempArtifactsDir;
config.paths.cache = nomiclabsUtils.tempCacheDir(config);
}

await env.run(TASK_COMPILE);
await env.run(TASK_COMPILE);

await api.onCompileComplete(config);
await api.onCompileComplete(config);

// ==============
// Server launch
// ==============
const network = nomiclabsUtils.setupHardhatNetwork(env, api, ui);
// ==============
// Server launch
// ==============
const network = nomiclabsUtils.setupHardhatNetwork(env, api, ui);

if (network.isHardhatEVM){
accounts = await utils.getAccountsHardhat(network.provider);
nodeInfo = await utils.getNodeInfoHardhat(network.provider);
if (network.isHardhatEVM) {
accounts = await utils.getAccountsHardhat(network.provider);
nodeInfo = await utils.getNodeInfoHardhat(network.provider);

api.attachToHardhatVM(network.provider);
api.attachToHardhatVM(network.provider);

ui.report('hardhat-network', [
nodeInfo.split('/')[1],
env.network.name,
]);
} else {
client = api.client || require('ganache-cli');
address = await api.ganache(client);
const accountsRequest = await utils.getAccountsGanache(api.server.provider);
const nodeInfoRequest = await utils.getNodeInfoGanache(api.server.provider);
ui.report('hardhat-network', [
nodeInfo.split('/')[1],
env.network.name,
]);
} else {
client = api.client || require('ganache-cli');
address = await api.ganache(client);
const accountsRequest = await utils.getAccountsGanache(api.server.provider);
const nodeInfoRequest = await utils.getNodeInfoGanache(api.server.provider);

ui.report('ganache-network', [
nodeInfoRequest.result.split('/')[1],
env.network.name,
api.port
]);
ui.report('ganache-network', [
nodeInfoRequest.result.split('/')[1],
env.network.name,
api.port
]);

accounts = accountsRequest.result;
}
accounts = accountsRequest.result;
}

// Set default account (if not already configured)
nomiclabsUtils.setNetworkFrom(network.config, accounts);
// Set default account (if not already configured)
nomiclabsUtils.setNetworkFrom(network.config, accounts);

// Run post-launch server hook;
await api.onServerReady(config);
// Run post-launch server hook;
await api.onServerReady(config);

// ======
// Tests
// ======
const testfiles = args.testfiles
? nomiclabsUtils.getTestFilePaths(args.testfiles)
: [];
// ======
// Tests
// ======
const testfiles = args.testfiles
? nomiclabsUtils.getTestFilePaths(args.testfiles)
: [];

try {
failedTests = await env.run(TASK_TEST, { testFiles: testfiles })
} catch (e) {
error = e;
}
await api.onTestsComplete(config);

// ========
// Istanbul
// ========
await api.report();
await api.onIstanbulComplete(config);

try {
failedTests = await env.run(TASK_TEST, {testFiles: testfiles})
} catch (e) {
error = e;
} finally {
measureCoverage = false;
}
await api.onTestsComplete(config);

// ========
// Istanbul
// ========
await api.report();
await api.onIstanbulComplete(config);

} catch(e) {
error = e;
} finally {
measureCoverage = false;
}

await nomiclabsUtils.finish(config, api);
await nomiclabsUtils.finish(config, api);

if (error !== undefined ) throw new HardhatPluginError(error);
if (failedTests > 0) throw new HardhatPluginError(ui.generate('tests-fail', [failedTests]));
})
if (error !== undefined) throw new HardhatPluginError(error);
if (failedTests > 0) throw new HardhatPluginError(ui.generate('tests-fail', [failedTests]));
})
12 changes: 9 additions & 3 deletions plugins/truffle.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const path = require('path');
* @param {Object} config @truffle/config config
* @return {Promise}
*/
async function plugin(config){
async function plugin(config) {
let ui;
let api;
let error;
Expand All @@ -25,7 +25,7 @@ async function plugin(config){

ui = new PluginUI(config.logger.log);

if(config.help) return ui.report('help'); // Exit if --help
if (config.help) return ui.report('help'); // Exit if --help

truffle = truffleUtils.loadLibrary(config);
api = new API(utils.loadSolcoverJS(config));
Expand Down Expand Up @@ -92,6 +92,12 @@ async function plugin(config){

config.all = true;
config.compilers.solc.settings.optimizer.enabled = false;
config.compilers.solc.settings.optimizer.details = {
yul: true,
yulDetails: {
stackAllocation: true,
},
};

// Compile Instrumented Contracts
await truffle.contracts.compile(config);
Expand All @@ -110,7 +116,7 @@ async function plugin(config){
await api.report();
await api.onIstanbulComplete(config);

} catch(e){
} catch (e) {
error = e;
}

Expand Down