diff --git a/test/integration/standard.js b/test/integration/standard.js index d53ff483..a52a89fd 100644 --- a/test/integration/standard.js +++ b/test/integration/standard.js @@ -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); + }); }) diff --git a/test/sources/projects/file-level-functions/.solcover.js b/test/sources/projects/file-level-functions/.solcover.js new file mode 100644 index 00000000..2bcb9670 --- /dev/null +++ b/test/sources/projects/file-level-functions/.solcover.js @@ -0,0 +1,5 @@ +module.exports = { + silent: process.env.SILENT ? true : false, + skipFiles: [], + istanbulReporter: ['json-summary', 'text'] +} diff --git a/test/sources/projects/file-level-functions/contracts/FunctionA.sol b/test/sources/projects/file-level-functions/contracts/FunctionA.sol new file mode 100644 index 00000000..2a47e9c7 --- /dev/null +++ b/test/sources/projects/file-level-functions/contracts/FunctionA.sol @@ -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; +} diff --git a/test/sources/projects/file-level-functions/contracts/FunctionB.sol b/test/sources/projects/file-level-functions/contracts/FunctionB.sol new file mode 100644 index 00000000..a9a08b80 --- /dev/null +++ b/test/sources/projects/file-level-functions/contracts/FunctionB.sol @@ -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; +} diff --git a/test/sources/projects/file-level-functions/contracts/UsesFunctions.sol b/test/sources/projects/file-level-functions/contracts/UsesFunctions.sol new file mode 100644 index 00000000..9f7e5b70 --- /dev/null +++ b/test/sources/projects/file-level-functions/contracts/UsesFunctions.sol @@ -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); + } +} diff --git a/test/sources/projects/file-level-functions/hardhat.config.js b/test/sources/projects/file-level-functions/hardhat.config.js new file mode 100644 index 00000000..cfc8f8ee --- /dev/null +++ b/test/sources/projects/file-level-functions/hardhat.config.js @@ -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, +}; diff --git a/test/sources/projects/file-level-functions/test/usesFunctions.js b/test/sources/projects/file-level-functions/test/usesFunctions.js new file mode 100644 index 00000000..0ab015ac --- /dev/null +++ b/test/sources/projects/file-level-functions/test/usesFunctions.js @@ -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); + }); +});