Skip to content
Merged
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
24 changes: 24 additions & 0 deletions test/integration/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -445,4 +445,28 @@ describe('Hardhat Plugin: standard use cases', function() {

verify.branchCoverage(expected);
});

it('file-level function declarations', async function(){
mock.installFullProject('file-level-functions');
mock.hardhatSetupEnv(this);

await this.env.run("coverage");

const expected = [
{
file: mock.pathToContract(hardhatConfig, 'FunctionA.sol'),
pct: 25
},
{
file: mock.pathToContract(hardhatConfig, 'FunctionB.sol'),
pct: 25
},
{
file: mock.pathToContract(hardhatConfig, 'UsesFunctions.sol'),
pct: 100
},
];

verify.branchCoverage(expected);
});
})
5 changes: 5 additions & 0 deletions test/sources/projects/file-level-functions/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module.exports = {
silent: process.env.SILENT ? true : false,
skipFiles: [],
istanbulReporter: ['json-summary', 'text']
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma solidity >=0.8.0 <0.9.0;

function functionA(bool x) returns (bool) {
bool a = false;
if (a || x) return x;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma solidity >=0.8.0 <0.9.0;

function functionB(bool x) returns (bool) {
bool a = false;
if (a || x) return x;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
pragma solidity >=0.8.0 <0.9.0;

import "./FunctionA.sol";
import "./FunctionB.sol";

contract UsesFunctions {
bool a;

constructor() public {}

function useLocalFunction(bool x) public {
a = x;
}

function useImportedFunctions(bool x) public {
a = functionA(x);
a = functionB(x);
}
}
15 changes: 15 additions & 0 deletions test/sources/projects/file-level-functions/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../plugins/nomiclabs.plugin");

module.exports = {
solidity: {
version: "0.8.17",
settings: {
optimizer: {
enabled: true
},
viaIR: process.env.VIA_IR === "true"
}
},
logger: process.env.SILENT ? { log: () => {} } : console,
};
14 changes: 14 additions & 0 deletions test/sources/projects/file-level-functions/test/usesFunctions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
const UsesFunctions = artifacts.require("UsesFunctions");

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

before(async () => {
instance = await UsesFunctions.new();
});

it('when false', async function(){
await instance.useLocalFunction(false);
await instance.useImportedFunctions(false);
});
});