From b1ee826ae5201126dcb4a37ce8df3f3c72ff3b16 Mon Sep 17 00:00:00 2001 From: cgewecke Date: Fri, 2 Feb 2024 16:49:19 -0800 Subject: [PATCH] Add test for transaction price errors with hardhat_mine (#845) --- test/integration/standard.js | 16 ++++++++++++++ .../projects/hardhat-mine/.solcover.js | 7 ++++++ .../hardhat-mine/contracts/Setter.sol | 12 ++++++++++ .../projects/hardhat-mine/hardhat.config.js | 10 +++++++++ .../projects/hardhat-mine/test/testMine.js | 22 +++++++++++++++++++ 5 files changed, 67 insertions(+) create mode 100644 test/sources/projects/hardhat-mine/.solcover.js create mode 100644 test/sources/projects/hardhat-mine/contracts/Setter.sol create mode 100644 test/sources/projects/hardhat-mine/hardhat.config.js create mode 100644 test/sources/projects/hardhat-mine/test/testMine.js diff --git a/test/integration/standard.js b/test/integration/standard.js index 9f700d7..3f9d568 100644 --- a/test/integration/standard.js +++ b/test/integration/standard.js @@ -304,6 +304,22 @@ describe('Hardhat Plugin: standard use cases', function() { verify.lineCoverage(expected); }) + it('can use hardhat_mine without erroring', async function(){ + mock.installFullProject('hardhat-mine'); + mock.hardhatSetupEnv(this); + + await this.env.run("coverage"); + + const expected = [ + { + file: mock.pathToContract(hardhatConfig, 'Setter.sol'), + pct: 100 + } + ]; + + verify.lineCoverage(expected); + }) + // This test freezes when gas-reporter is not disabled it('disables hardhat-gas-reporter', async function() { mock.installFullProject('hardhat-gas-reporter'); diff --git a/test/sources/projects/hardhat-mine/.solcover.js b/test/sources/projects/hardhat-mine/.solcover.js new file mode 100644 index 0000000..d9d3f31 --- /dev/null +++ b/test/sources/projects/hardhat-mine/.solcover.js @@ -0,0 +1,7 @@ +// Testing hooks +const fn = (msg, config) => config.logger.log(msg); + +module.exports = { + silent: process.env.SILENT ? true : false, + istanbulReporter: ['json-summary', 'text'], +} diff --git a/test/sources/projects/hardhat-mine/contracts/Setter.sol b/test/sources/projects/hardhat-mine/contracts/Setter.sol new file mode 100644 index 0000000..4ab3f6c --- /dev/null +++ b/test/sources/projects/hardhat-mine/contracts/Setter.sol @@ -0,0 +1,12 @@ +pragma solidity >=0.8.0 <0.9.0; + + +contract Setter { + uint x; + constructor() public { + } + + function set() public { + x = 1; + } +} diff --git a/test/sources/projects/hardhat-mine/hardhat.config.js b/test/sources/projects/hardhat-mine/hardhat.config.js new file mode 100644 index 0000000..803b099 --- /dev/null +++ b/test/sources/projects/hardhat-mine/hardhat.config.js @@ -0,0 +1,10 @@ +require("@nomiclabs/hardhat-waffle"); +require("@nomiclabs/hardhat-ethers"); +require(__dirname + "/../plugins/nomiclabs.plugin"); + +module.exports = { + solidity: { + version: "0.8.17" + }, + logger: process.env.SILENT ? { log: () => {} } : console, +}; diff --git a/test/sources/projects/hardhat-mine/test/testMine.js b/test/sources/projects/hardhat-mine/test/testMine.js new file mode 100644 index 0000000..e21fe9d --- /dev/null +++ b/test/sources/projects/hardhat-mine/test/testMine.js @@ -0,0 +1,22 @@ +const { expect } = require("chai"); +const { ethers } = require("hardhat"); + +describe("Setter", function() { + let instance; + + before(async () => { + const factory = await ethers.getContractFactory("Setter"); + instance = await factory.deploy(); + }); + + it('sets at the beginning', async function(){ + await instance.set(); + }); + + it('sets at the end', async function(){ + // Mine about 50K blocks + await hre.network.provider.send('hardhat_mine', ['0xCCCC']) + await instance.set(); + }); +}); +