From 587a1f3e9120e2f1ec0d9afb088439284b67d2e0 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Tue, 10 Nov 2020 13:25:03 -0800 Subject: [PATCH] Add complex compilation test case (#563) --- plugins/hardhat.plugin.js | 2 + plugins/resources/nomiclabs.ui.js | 3 ++ .../hardhat-compile-config/.solcover.js | 4 ++ .../contracts/ContractA1.sol | 17 +++++++++ .../contracts/ContractB1.sol | 17 +++++++++ .../contracts/ContractC1.sol | 17 +++++++++ .../hardhat-compile-config/hardhat.config.js | 37 +++++++++++++++++++ .../hardhat-compile-config/test/contracta1.js | 11 ++++++ .../hardhat-compile-config/test/contractb1.js | 15 ++++++++ .../hardhat-compile-config/test/contractc1.js | 20 ++++++++++ test/units/hardhat/standard.js | 26 +++++++++++++ 11 files changed, 169 insertions(+) create mode 100644 test/integration/projects/hardhat-compile-config/.solcover.js create mode 100644 test/integration/projects/hardhat-compile-config/contracts/ContractA1.sol create mode 100644 test/integration/projects/hardhat-compile-config/contracts/ContractB1.sol create mode 100644 test/integration/projects/hardhat-compile-config/contracts/ContractC1.sol create mode 100644 test/integration/projects/hardhat-compile-config/hardhat.config.js create mode 100644 test/integration/projects/hardhat-compile-config/test/contracta1.js create mode 100644 test/integration/projects/hardhat-compile-config/test/contractb1.js create mode 100644 test/integration/projects/hardhat-compile-config/test/contractc1.js diff --git a/plugins/hardhat.plugin.js b/plugins/hardhat.plugin.js index e50af4b..cb7cb51 100644 --- a/plugins/hardhat.plugin.js +++ b/plugins/hardhat.plugin.js @@ -117,6 +117,8 @@ async function plugin(args, env) { // ============== // Compilation // ============== + ui.report('compilation', []); + config.temp = args.temp; const { diff --git a/plugins/resources/nomiclabs.ui.js b/plugins/resources/nomiclabs.ui.js index 0adf3cf..d276efc 100644 --- a/plugins/resources/nomiclabs.ui.js +++ b/plugins/resources/nomiclabs.ui.js @@ -36,6 +36,9 @@ class PluginUI extends UI { 'instr-skip': `\n${c.bold('Coverage skipped for:')}` + `\n${c.bold('=====================')}\n`, + 'compilation': `\n${c.bold('Compilation:')}` + + `\n${c.bold('============')}\n`, + 'instr-skipped': `${ds} ${c.grey(args[0])}`, 'versions': `${ct} ${c.bold('ganache-core')}: ${args[0]}\n` + diff --git a/test/integration/projects/hardhat-compile-config/.solcover.js b/test/integration/projects/hardhat-compile-config/.solcover.js new file mode 100644 index 0000000..71b990c --- /dev/null +++ b/test/integration/projects/hardhat-compile-config/.solcover.js @@ -0,0 +1,4 @@ +module.exports = { + "silent": false, + "istanbulReporter": [ "json-summary", "text"] +} diff --git a/test/integration/projects/hardhat-compile-config/contracts/ContractA1.sol b/test/integration/projects/hardhat-compile-config/contracts/ContractA1.sol new file mode 100644 index 0000000..9d8d134 --- /dev/null +++ b/test/integration/projects/hardhat-compile-config/contracts/ContractA1.sol @@ -0,0 +1,17 @@ +pragma solidity ^0.5.0; + + +contract ContractA { + uint x; + constructor() public { + } + + function sendFn() public { + x = 5; + } + + function callFn() public pure returns (uint){ + uint y = 5; + return y; + } +} diff --git a/test/integration/projects/hardhat-compile-config/contracts/ContractB1.sol b/test/integration/projects/hardhat-compile-config/contracts/ContractB1.sol new file mode 100644 index 0000000..daa42f7 --- /dev/null +++ b/test/integration/projects/hardhat-compile-config/contracts/ContractB1.sol @@ -0,0 +1,17 @@ +pragma solidity ^0.5.0; + + +contract ContractB { + uint x; + constructor() public { + } + + function sendFn() public { + x = 5; + } + + function callFn() public pure returns (uint){ + uint y = 5; + return y; + } +} diff --git a/test/integration/projects/hardhat-compile-config/contracts/ContractC1.sol b/test/integration/projects/hardhat-compile-config/contracts/ContractC1.sol new file mode 100644 index 0000000..17ddf97 --- /dev/null +++ b/test/integration/projects/hardhat-compile-config/contracts/ContractC1.sol @@ -0,0 +1,17 @@ +pragma solidity ^0.6.0; + + +contract ContractC { + uint x; + constructor() public { + } + + function sendFn() public { + x = 5; + } + + function callFn() public pure returns (uint){ + uint y = 5; + return y; + } +} diff --git a/test/integration/projects/hardhat-compile-config/hardhat.config.js b/test/integration/projects/hardhat-compile-config/hardhat.config.js new file mode 100644 index 0000000..1461dbc --- /dev/null +++ b/test/integration/projects/hardhat-compile-config/hardhat.config.js @@ -0,0 +1,37 @@ +require("@nomiclabs/hardhat-truffle5"); +require(__dirname + "/../hardhat"); + +module.exports={ + solidity: { + compilers: [ + { + version: "0.5.5" + }, + { + version: "0.5.7" + }, + // Make sure optimizer gets disabled + { + version: "0.6.7", + settings: { + optimizer: { + enabled: true, + runs: 200 + } + } + } + ], + overrides: { + "contracts/ContractA.sol": { + version: "0.5.5", + settings: { + optimizer: { + enabled: true, + runs: 200 + } + } + } + } + }, + logger: process.env.SILENT ? { log: () => {} } : console, +}; diff --git a/test/integration/projects/hardhat-compile-config/test/contracta1.js b/test/integration/projects/hardhat-compile-config/test/contracta1.js new file mode 100644 index 0000000..4182d2b --- /dev/null +++ b/test/integration/projects/hardhat-compile-config/test/contracta1.js @@ -0,0 +1,11 @@ +const ContractA = artifacts.require("ContractA"); + +contract("contracta", function(accounts) { + let instance; + + before(async () => instance = await ContractA.new()) + + it('sends', async function(){ + await instance.sendFn(); + }); +}); diff --git a/test/integration/projects/hardhat-compile-config/test/contractb1.js b/test/integration/projects/hardhat-compile-config/test/contractb1.js new file mode 100644 index 0000000..42d8cb8 --- /dev/null +++ b/test/integration/projects/hardhat-compile-config/test/contractb1.js @@ -0,0 +1,15 @@ +const ContractB = artifacts.require("ContractB"); + +contract("contractB", function(accounts) { + let instance; + + before(async () => instance = await ContractB.new()) + + it('sends', async function(){ + await instance.sendFn(); + }); + + it('calls', async function(){ + await instance.callFn(); + }) +}); diff --git a/test/integration/projects/hardhat-compile-config/test/contractc1.js b/test/integration/projects/hardhat-compile-config/test/contractc1.js new file mode 100644 index 0000000..9b3d950 --- /dev/null +++ b/test/integration/projects/hardhat-compile-config/test/contractc1.js @@ -0,0 +1,20 @@ +const ContractC = artifacts.require("ContractC"); + +contract("contractc", function(accounts) { + let instance; + + before(async () => instance = await ContractC.new()) + + it('sends', async function(){ + await instance.sendFn(); + }); + + it('calls', async function(){ + await instance.callFn(); + }) + + it('sends', async function(){ + await instance.sendFn(); + }); + +}); diff --git a/test/units/hardhat/standard.js b/test/units/hardhat/standard.js index 8d88aeb..f0121ce 100644 --- a/test/units/hardhat/standard.js +++ b/test/units/hardhat/standard.js @@ -395,4 +395,30 @@ describe('Hardhat Plugin: standard use cases', function() { verify.lineCoverage(expected); }) + + it('complex compiler configs', async function(){ + mock.installFullProject('hardhat-compile-config'); + mock.hardhatSetupEnv(this); + + await this.env.run("coverage"); + + const expected = [ + { + file: mock.pathToContract(hardhatConfig, 'ContractA1.sol'), + pct: 33.33 + }, + { + file: mock.pathToContract(hardhatConfig, 'ContractB1.sol'), + pct: 100, + }, + { + file: mock.pathToContract(hardhatConfig, 'ContractC1.sol'), + pct: 100, + }, + + ]; + + verify.lineCoverage(expected); + }) + })