Skip to content

Commit

Permalink
Add tests for file-level function declarations (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
cgewecke committed Feb 9, 2024
1 parent 042a99e commit 44a999f
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 0 deletions.
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);
});
});

0 comments on commit 44a999f

Please sign in to comment.