Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Support solc v0.4.x
  • Loading branch information
cgewecke committed Apr 3, 2024
commit 298eee321df428183f06d3549bba7e0b5026e2e6
4 changes: 3 additions & 1 deletion lib/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class API {
this.istanbulReporter = config.istanbulReporter || ['html', 'lcov', 'text', 'json'];

this.viaIR = config.viaIR;
this.usingSolcV4 = config.usingSolcV4;
this.solcOptimizerDetails = config.solcOptimizerDetails;

this.setLoggingLevel(config.silent);
Expand Down Expand Up @@ -177,7 +178,8 @@ class API {
// Hardhat
async attachToHardhatVM(provider){
const self = this;
this.collector = new DataCollector(this.instrumenter.instrumentationData, this.viaIR);
const useExpandedOpcodeDictionary = this.viaIR || this.usingSolcV4;
this.collector = new DataCollector(this.instrumenter.instrumentationData, useExpandedOpcodeDictionary);

if ('init' in provider) {
// Newer versions of Hardhat initialize the provider lazily, so we need to
Expand Down
18 changes: 17 additions & 1 deletion plugins/resources/nomiclabs.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ function normalizeConfig(config, args={}){

if (config.solidity && config.solidity.compilers.length) {
config.viaIR = isUsingViaIR(config.solidity);
config.usingSolcV4 = isUsingSolcV4(config.solidity);
}

config.workingDir = config.paths.root;
Expand All @@ -63,8 +64,23 @@ function normalizeConfig(config, args={}){
return config;
}

function isUsingViaIR(solidity) {
function isUsingSolcV4(solidity) {
for (compiler of solidity.compilers) {
if (compiler.version && semver.lt(compiler.version, '0.5.0')) {
return true;
}
}
if (solidity.overrides) {
for (key of Object.keys(solidity.overrides)){
if (solidity.overrides[key].version && semver.lt(solidity.overrides[key].version, '0.5.0')) {
return true;
}
}
}
return false;
}

function isUsingViaIR(solidity) {
for (compiler of solidity.compilers) {
if (compiler.settings && compiler.settings.viaIR) {
return true;
Expand Down
3 changes: 2 additions & 1 deletion plugins/resources/plugin.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,9 @@ function loadSolcoverJS(config={}){
coverageConfig = {};
}

// viaIR is eval'd in `nomiclab.utils.normalizeConfig`
// viaIR and solc versions are eval'd in `nomiclab.utils.normalizeConfig`
coverageConfig.viaIR = config.viaIR;
coverageConfig.usingSolcV4 = config.usingSolcV4;

coverageConfig.log = log;
coverageConfig.cwd = config.workingDir;
Expand Down
5 changes: 4 additions & 1 deletion test/integration/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@ describe('Hardhat Plugin: standard use cases', function() {
file: mock.pathToContract(hardhatConfig, 'ContractC1.sol'),
pct: 100,
},

{
file: mock.pathToContract(hardhatConfig, 'ContractD1.sol'),
pct: 100,
},
];

verify.lineCoverage(expected);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
pragma solidity 0.4.21;


contract ContractD {
uint x;

function sendFn() public {
x = 5;
}

function callFn() public pure returns (uint){
uint y = 5;
return y;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ require(__dirname + "/../plugins/nomiclabs.plugin");
module.exports={
solidity: {
compilers: [
{
version: "0.4.21",
settings: {
optimizer: {
enabled: true
}
},
},
{
version: "0.8.17",
settings: {
Expand Down
20 changes: 20 additions & 0 deletions test/sources/projects/hardhat-compile-config/test/contractd1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const ContractD = artifacts.require("ContractD");

contract("contractd", function(accounts) {
let instance;

before(async () => instance = await ContractD.new())

it('sends', async function(){
await instance.sendFn();
});

it('calls', async function(){
await instance.callFn();
})

it('sends', async function(){
await instance.sendFn();
});

});