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
3 changes: 2 additions & 1 deletion HARDHAT_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Solidity code coverage plugin for [Hardhat](http://hardhat.org).
$ npm install --save-dev solidity-coverage
```

And add the following to your `.config.js`:
And add the following to your `hardhat.config.js`:

```js
require("solidity-coverage");
Expand Down Expand Up @@ -73,6 +73,7 @@ module.exports = {
| onCompileComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* compilation completes, *before* tests are run. Useful if you have secondary compilation steps or need to modify built artifacts. [More...][23]|
| onTestsComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* the tests complete, *before* Istanbul reports are generated. [More...][23]|
| onIstanbulComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* the Istanbul reports are generated, *before* the ganache server is shut down. Useful if you need to clean resources up. [More...][23]|
| configureYulOptimizer | *Boolean* | false | (Experimental) Setting to `true` should resolve "stack too deep" compiler errrors in large projects using ABIEncoderV2 |

[<sup>*</sup> Advanced use][14]

Expand Down
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ A working example can be found at [openzeppelin-contracts, here.][35]
## Command Options
| Option <img width=200/> | Example <img width=750/>| Description <img width=1000/> |
|--------------|------------------------------------|--------------------------------|
| file | `--file="test/registry/*.js"` | (Truffle) Filename or glob describing a subset of tests to run. (Globs must be enclosed by quotes.)|
| testfiles | `--testfiles "test/registry/*.ts"` | (Buidler) Test file(s) to run. (Globs must be enclosed by quotes.)|
| file | `--file="test/registry/*.js"` | (Truffle) Filename or glob describing a subset of tests to run. (Globs must be enclosed by quotes and use [globby matching patterns][38])|
| testfiles | `--testfiles "test/registry/*.ts"` | (Buidler) Test file(s) to run. (Globs must be enclosed by quotes and use [globby matching patterns][38])|
| solcoverjs | `--solcoverjs ./../.solcover.js` | Relative path from working directory to config. Useful for monorepo packages that share settings. (Path must be "./" prefixed) |
| network | `--network development` | Use network settings defined in the Truffle or Buidler config |
| temp[<sup>*</sup>][14] | `--temp build` | :warning: **Caution** :warning: Path to a *disposable* folder to store compilation artifacts in. Useful when your test setup scripts include hard-coded paths to a build directory. [More...][14] |
Expand Down Expand Up @@ -129,6 +129,7 @@ module.exports = {
| onCompileComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* compilation completes, *before* tests are run. Useful if you have secondary compilation steps or need to modify built artifacts. [More...][23]|
| onTestsComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* the tests complete, *before* Istanbul reports are generated. [More...][23]|
| onIstanbulComplete[<sup>*</sup>][14] | *Function* | | Hook run *after* the Istanbul reports are generated, *before* the ganache server is shut down. Useful if you need to clean resources up. [More...][23]|
| configureYulOptimizer | *Boolean* | false | (Experimental) Setting to `true` should resolve "stack too deep" compiler errrors in large projects using ABIEncoderV2 |

[<sup>*</sup> Advanced use][14]

Expand Down Expand Up @@ -193,6 +194,10 @@ $ yarn
+ [@yxliang01](https://github.com/yxliang01)
+ [@maxsam4](https://github.com/maxsam4)
+ [@justinjmoses](https://github.com/justinjmoses)
+ [@JasoonS](https://github.com/https://github.com/JasoonS)
+ [@feuGeneA](https://github.com/https://github.com/feuGeneA)
+ [@Dylan-Kerler](https://github.com/Dylan-Kerler)
+ [@paulrberg](https://github.com/paulrberg)

[1]: https://github.com/trufflesuite/ganache-core#options
[2]: https://istanbul.js.org/docs/advanced/alternative-reporters/
Expand Down Expand Up @@ -231,4 +236,5 @@ $ yarn
[35]: https://github.com/OpenZeppelin/openzeppelin-contracts/blob/e5fbbda9bac49039847a7ed20c1d966766ecc64a/scripts/coverage.js
[36]: https://hardhat.org/
[37]: https://github.com/sc-forks/solidity-coverage/blob/master/HARDHAT_README.md
[38]: https://github.com/sindresorhus/globby#globbing-patterns

2 changes: 1 addition & 1 deletion lib/injector.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Injector {
_getHashMethodDefinition(id, contract){
const hash = web3Utils.keccak256(id).slice(0,10);
const method = this._getMethodIdentifier(id);
return `\nfunction ${method}(bytes32 c__${hash}) public pure {}\n`;
return `\nfunction ${method}(bytes32 c__${hash}) internal pure {}\n`;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "solidity-coverage",
"version": "0.7.16",
"version": "0.7.17",
"description": "",
"main": "plugins/nomiclabs.plugin.js",
"bin": {
Expand All @@ -24,13 +24,13 @@
"author": "",
"license": "ISC",
"dependencies": {
"@solidity-parser/parser": "^0.12.0",
"@solidity-parser/parser": "^0.13.2",
"@truffle/provider": "^0.2.24",
"chalk": "^2.4.2",
"death": "^1.1.0",
"detect-port": "^1.3.0",
"fs-extra": "^8.1.0",
"ganache-cli": "^6.11.0",
"ganache-cli": "^6.12.2",
"ghost-testrpc": "^0.0.2",
"global-modules": "^2.0.0",
"globby": "^10.0.1",
Expand All @@ -53,7 +53,7 @@
"@truffle/contract": "^4.0.36",
"buidler-gas-reporter": "^0.1.3",
"decache": "^4.5.1",
"hardhat": "^2.0.7",
"hardhat": "^2.5.0",
"hardhat-gas-reporter": "^1.0.1",
"mocha": "5.2.0",
"nyc": "^14.1.1",
Expand Down
17 changes: 15 additions & 2 deletions plugins/hardhat.plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ const {

// Toggled true for `coverage` task only.
let measureCoverage = false;
let configureYulOptimizer = false;
let instrumentedSources

// UI for the task flags...
const ui = new PluginUI();

task(TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT).setAction(async (_, { config }, runSuper) => {
subtask(TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT).setAction(async (_, { config }, runSuper) => {
const solcInput = await runSuper();
if (measureCoverage) {
// The source name here is actually the global name in the solc input,
Expand All @@ -40,7 +41,7 @@ task(TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT).setAction(async (_, { config }, r
});

// Solidity settings are best set here instead of the TASK_COMPILE_SOLIDITY_GET_COMPILER_INPUT task.
task(TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE).setAction(async (_, __, runSuper) => {
subtask(TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE).setAction(async (_, __, runSuper) => {
const compilationJob = await runSuper();
if (measureCoverage && typeof compilationJob === "object") {
if (compilationJob.solidityConfig.settings === undefined) {
Expand All @@ -58,6 +59,17 @@ task(TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOB_FOR_FILE).setAction(async (_, __,
settings.metadata.useLiteralContent = false;
// Override optimizer settings for all compilers
settings.optimizer.enabled = false;

// This is fixes a stack too deep bug in ABIEncoderV2
// Experimental because not sure this works as expected across versions....
if (configureYulOptimizer) {
settings.optimizer.details = {
yul: true,
yulDetails: {
stackAllocation: true,
},
}
}
}
return compilationJob;
});
Expand Down Expand Up @@ -127,6 +139,7 @@ task("coverage", "Generates a code coverage report for tests")
ui.report('compilation', []);

config.temp = args.temp;
configureYulOptimizer = api.config.configureYulOptimizer;

// With Hardhat >= 2.0.4, everything should automatically recompile
// after solidity-coverage corrupts the artifacts.
Expand Down
5 changes: 3 additions & 2 deletions plugins/resources/nomiclabs.utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,18 +127,19 @@ function configureHardhatEVMGas(networkConfig, api){
networkConfig.blockGasLimit = api.gasLimitNumber;
networkConfig.gas = api.gasLimit;
networkConfig.gasPrice = api.gasPrice;
networkConfig.initialBaseFeePerGas = 0;
}

function configureNetworkEnv(env, networkName, networkConfig, provider, isHardhatEVM){
env.config.networks[networkName] = networkConfig;
env.config.defaultNetwork = networkName;

env.network = {
env.network = Object.assign(env.network, {
name: networkName,
config: networkConfig,
provider: provider,
isHardhatEVM: isHardhatEVM
}
});

env.ethereum = provider;

Expand Down
19 changes: 0 additions & 19 deletions scripts/run-nomiclabs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,6 @@ fi

echo "PR_PATH >>>>> $PR_PATH"

echo ""
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Simple buidler/buidler-trufflev5 "
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo ""

# Install buidler-e2e
git clone https://github.com/sc-forks/buidler-e2e.git
cd buidler-e2e
npm install --silent

# Install and run solidity-coverage @ PR
npm install --save-dev --silent $PR_PATH
cat package.json

npx buidler coverage

verifyCoverageExists

echo ""
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
echo "Simple hardhat/hardhat-trufflev5 "
Expand Down
3 changes: 2 additions & 1 deletion test/integration/projects/solc-7/.solcover.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module.exports = {
silent: process.env.SILENT ? true : false,
skipFiles: ['skipped-folder'],
istanbulReporter: ['json-summary', 'text']
istanbulReporter: ['json-summary', 'text'],
configureYulOptimizer: true
}
6 changes: 6 additions & 0 deletions test/integration/projects/solc-8/.solcover.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
silent: process.env.SILENT ? true : false,
skipFiles: ['skipped-folder'],
istanbulReporter: ['json-summary', 'text'],
configureYulOptimizer: true
}
20 changes: 20 additions & 0 deletions test/integration/projects/solc-8/contracts/Contract_solc8.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: MIT
pragma solidity >=0.8.0 <0.9.0;
pragma abicoder v2;

error InvalidSomeAddress(address someAddress);

contract ContractA {

address public someAddress;

function throwError(address _add) external {
this;

if (_add == address(0)) {
revert InvalidSomeAddress(_add);
}

someAddress = _add;
}
}
9 changes: 9 additions & 0 deletions test/integration/projects/solc-8/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require("@nomiclabs/hardhat-truffle5");
require(__dirname + "/../plugins/nomiclabs.plugin");

module.exports = {
solidity: {
version: "0.8.5"
},
logger: process.env.SILENT ? { log: () => {} } : console,
};
13 changes: 13 additions & 0 deletions test/integration/projects/solc-8/test/test_solc8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const ContractA = artifacts.require("ContractA");

contract("contracta", function(accounts) {
let a,b;

before(async () => {
a = await ContractA.new();
})

it('a:throwError', async function(){
await a.throwError(a.address);
});
});
12 changes: 6 additions & 6 deletions test/units/assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ describe('asserts and requires', () => {
const mapping = coverage.generate(contract.data, util.pathPrefix);

assert.deepEqual(mapping[util.filePath].l, {
5: 1,
5: 2,
});
assert.deepEqual(mapping[util.filePath].b, {});
assert.deepEqual(mapping[util.filePath].s, {
1: 1,
1: 2,
});
assert.deepEqual(mapping[util.filePath].f, {
1: 1,
1: 2,
});
});

Expand All @@ -47,14 +47,14 @@ describe('asserts and requires', () => {

const mapping = coverage.generate(contract.data, util.pathPrefix);
assert.deepEqual(mapping[util.filePath].l, {
5: 2,
5: 4,
});
assert.deepEqual(mapping[util.filePath].b, {});
assert.deepEqual(mapping[util.filePath].s, {
1: 2,
1: 4,
});
assert.deepEqual(mapping[util.filePath].f, {
1: 2,
1: 4,
});
});

Expand Down
6 changes: 3 additions & 3 deletions test/units/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ describe('function declarations', () => {
const mapping = coverage.generate(contract.data, util.pathPrefix);

assert.deepEqual(mapping[util.filePath].l, {
6: 1, 11: 1
6: 2, 11: 1 // Doubled line-hit
});
assert.deepEqual(mapping[util.filePath].b, {});
assert.deepEqual(mapping[util.filePath].s, {
1: 1, 2: 1
1: 2, 2: 1
});
assert.deepEqual(mapping[util.filePath].f, {
1: 1,
1: 2,
2: 1,
});
});
Expand Down
20 changes: 19 additions & 1 deletion test/units/hardhat/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ describe('Hardhat Plugin: standard use cases', function() {
);
});

it('with relative path solidity imports', async function() {
// Test fixture is not compatible with HH 2.5.0. Throws mysterious error (though fixture has no libs?)
// HH11: Internal invariant was violated: Libraries should have both name and version, or neither one
it.skip('with relative path solidity imports', async function() {
mock.installFullProject('import-paths');
mock.hardhatSetupEnv(this);

Expand Down Expand Up @@ -324,6 +326,22 @@ describe('Hardhat Plugin: standard use cases', function() {
verify.lineCoverage(expected);
})

it('solc 0.8.x', async function(){
mock.installFullProject('solc-8');
mock.hardhatSetupEnv(this);

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

const expectedLine = [
{
file: mock.pathToContract(hardhatConfig, 'Contract_solc8.sol'),
pct: 75
},
];

verify.lineCoverage(expectedLine);
});

// This test freezes when gas-reporter is not disabled
it('disables hardhat-gas-reporter', async function() {
mock.installFullProject('hardhat-gas-reporter');
Expand Down
2 changes: 1 addition & 1 deletion test/units/truffle/standard.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ describe('Truffle Plugin: standard use cases', function() {
truffleConfig.logger = mock.testLogger;
truffleConfig.version = true;

const configClientVersion = "v2.12.1";
const configClientVersion = "v2.13.2";

// Config client
mock.installFullProject('ganache-solcoverjs');
Expand Down
Loading