Skip to content

Commit 44a999f

Browse files
authored
Add tests for file-level function declarations (#858)
1 parent 042a99e commit 44a999f

File tree

7 files changed

+89
-0
lines changed

7 files changed

+89
-0
lines changed

test/integration/standard.js

+24
Original file line numberDiff line numberDiff line change
@@ -445,4 +445,28 @@ describe('Hardhat Plugin: standard use cases', function() {
445445

446446
verify.branchCoverage(expected);
447447
});
448+
449+
it('file-level function declarations', async function(){
450+
mock.installFullProject('file-level-functions');
451+
mock.hardhatSetupEnv(this);
452+
453+
await this.env.run("coverage");
454+
455+
const expected = [
456+
{
457+
file: mock.pathToContract(hardhatConfig, 'FunctionA.sol'),
458+
pct: 25
459+
},
460+
{
461+
file: mock.pathToContract(hardhatConfig, 'FunctionB.sol'),
462+
pct: 25
463+
},
464+
{
465+
file: mock.pathToContract(hardhatConfig, 'UsesFunctions.sol'),
466+
pct: 100
467+
},
468+
];
469+
470+
verify.branchCoverage(expected);
471+
});
448472
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module.exports = {
2+
silent: process.env.SILENT ? true : false,
3+
skipFiles: [],
4+
istanbulReporter: ['json-summary', 'text']
5+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pragma solidity >=0.8.0 <0.9.0;
2+
3+
function functionA(bool x) returns (bool) {
4+
bool a = false;
5+
if (a || x) return x;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pragma solidity >=0.8.0 <0.9.0;
2+
3+
function functionB(bool x) returns (bool) {
4+
bool a = false;
5+
if (a || x) return x;
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pragma solidity >=0.8.0 <0.9.0;
2+
3+
import "./FunctionA.sol";
4+
import "./FunctionB.sol";
5+
6+
contract UsesFunctions {
7+
bool a;
8+
9+
constructor() public {}
10+
11+
function useLocalFunction(bool x) public {
12+
a = x;
13+
}
14+
15+
function useImportedFunctions(bool x) public {
16+
a = functionA(x);
17+
a = functionB(x);
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
require("@nomiclabs/hardhat-truffle5");
2+
require(__dirname + "/../plugins/nomiclabs.plugin");
3+
4+
module.exports = {
5+
solidity: {
6+
version: "0.8.17",
7+
settings: {
8+
optimizer: {
9+
enabled: true
10+
},
11+
viaIR: process.env.VIA_IR === "true"
12+
}
13+
},
14+
logger: process.env.SILENT ? { log: () => {} } : console,
15+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const UsesFunctions = artifacts.require("UsesFunctions");
2+
3+
contract("contracts", function(accounts) {
4+
let instance;
5+
6+
before(async () => {
7+
instance = await UsesFunctions.new();
8+
});
9+
10+
it('when false', async function(){
11+
await instance.useLocalFunction(false);
12+
await instance.useImportedFunctions(false);
13+
});
14+
});

0 commit comments

Comments
 (0)