From da0194fc07477adda975e2ca180e3c450870ed75 Mon Sep 17 00:00:00 2001 From: Christopher Dedominici <18092467+ChristopherDedominici@users.noreply.github.com> Date: Wed, 5 Jul 2023 15:32:36 +0200 Subject: [PATCH 01/12] Convert %d and %i into %s --- .../hardhat-network/stack-traces/consoleLogger.ts | 12 +++++++++++- .../test-files/0_8/console-logs/uint/uint/c.sol | 5 ++++- .../test-files/0_8/console-logs/uint/uint/test.json | 6 ++++-- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts index e5e9f92236..a3e5655ae4 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts @@ -134,7 +134,17 @@ export class ConsoleLogger { return; } - return this._decode(parameters, types); + const consoleLogs = this._decode(parameters, types); + + // Replace the occurrences of %d and %i with %s. This is necessary because if the arguments passed are numbers, + // they could be too large to be formatted as a Number or an Integer, so it is safer to use a String. + // %d and %i are replaced only if there is an odd number of % before the d or i. + // If there is an even number of % then it is assumed that the % is escaped and should not be replaced. + if (consoleLogs && consoleLogs.length > 0) { + consoleLogs[0] = String(consoleLogs[0]).replace(/((? Date: Thu, 6 Jul 2023 19:23:28 +0200 Subject: [PATCH 02/12] restore tests to original version --- .../test-files/0_8/console-logs/uint/uint/c.sol | 5 +---- .../test-files/0_8/console-logs/uint/uint/test.json | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/packages/hardhat-core/test/internal/hardhat-network/stack-traces/test-files/0_8/console-logs/uint/uint/c.sol b/packages/hardhat-core/test/internal/hardhat-network/stack-traces/test-files/0_8/console-logs/uint/uint/c.sol index cff64b761c..b972e036e3 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/stack-traces/test-files/0_8/console-logs/uint/uint/c.sol +++ b/packages/hardhat-core/test/internal/hardhat-network/stack-traces/test-files/0_8/console-logs/uint/uint/c.sol @@ -5,7 +5,7 @@ import "./../../../../../../../../console.sol"; contract C { function log( - uint p0, uint p1, uint p2, string memory p4, bool p8, address p12, uint p3, string memory p5, bool p9, address p13, string memory p6 + uint p0, uint p1, uint p2, string memory p4, bool p8, address p12, uint p3, string memory p5, bool p9, address p13 ) public { console.log(p0, p1); console.log(p0, p1, p2); @@ -28,8 +28,5 @@ contract C { console.log(p0, p1, p12, p4); console.log(p0, p1, p12, p8); console.log(p0, p1, p12, p13); - // In the variable p6, the occurrences of %d and %i will be converted to %s when the count of % characters preceding the d or i is odd. - // If the count is even, the % character is considered escaped and should not be replaced. - console.log(p6); } } diff --git a/packages/hardhat-core/test/internal/hardhat-network/stack-traces/test-files/0_8/console-logs/uint/uint/test.json b/packages/hardhat-core/test/internal/hardhat-network/stack-traces/test-files/0_8/console-logs/uint/uint/test.json index 1b84273b0f..9acbf9a04b 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/stack-traces/test-files/0_8/console-logs/uint/uint/test.json +++ b/packages/hardhat-core/test/internal/hardhat-network/stack-traces/test-files/0_8/console-logs/uint/uint/test.json @@ -19,8 +19,7 @@ 4, "string2", false, - "0x0000000000000000000000000000000000000002", - "%d %%d %%%d %%%%d %%%%%d %%%%%%d %i %%i %%%i %%%%i %%%%%i %%%%%%i %s %%s %%%s %%%%s %%%%%s %%%%%%s" + "0x0000000000000000000000000000000000000002" ], "consoleLogs": [ ["1", "2"], @@ -48,8 +47,7 @@ "2", "0x0000000000000000000000000000000000000001", "0x0000000000000000000000000000000000000002" - ], - ["%s %%d %%%s %%%%d %%%%%s %%%%%%d %s %%i %%%s %%%%i %%%%%s %%%%%%i %s %%s %%%s %%%%s %%%%%s %%%%%%s"] + ] ] } ] From 46fa616c826a4d518e58ba1d8c335b4270e7b165 Mon Sep 17 00:00:00 2001 From: Christopher Dedominici <18092467+ChristopherDedominici@users.noreply.github.com> Date: Thu, 6 Jul 2023 19:24:36 +0200 Subject: [PATCH 03/12] move logic to replace format specifiers into a function --- .../hardhat-network/stack-traces/consoleLogger.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts index a3e5655ae4..63ee50b39b 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts @@ -136,15 +136,22 @@ export class ConsoleLogger { const consoleLogs = this._decode(parameters, types); + this._replaceNumberFormatSpecifiers(consoleLogs); + + return consoleLogs; + } + + private _replaceNumberFormatSpecifiers(consoleLogs: ConsoleLogs) { // Replace the occurrences of %d and %i with %s. This is necessary because if the arguments passed are numbers, // they could be too large to be formatted as a Number or an Integer, so it is safer to use a String. // %d and %i are replaced only if there is an odd number of % before the d or i. // If there is an even number of % then it is assumed that the % is escaped and should not be replaced. - if (consoleLogs && consoleLogs.length > 0) { - consoleLogs[0] = String(consoleLogs[0]).replace(/((? 0) { + consoleLogs[0] = String(consoleLogs[0]).replace( + /((? Date: Thu, 6 Jul 2023 19:43:18 +0200 Subject: [PATCH 04/12] add new test file + its configuration --- .../fixture-projects/console-log/.gitignore | 2 + .../console-log/contracts/Test.sol | 16 +++++ .../console-log/hardhat.config.js | 3 + .../fixture-projects/console-log/package.json | 4 ++ .../hardhat-network/console-log/test.ts | 68 +++++++++++++++++++ 5 files changed, 93 insertions(+) create mode 100644 packages/hardhat-core/test/fixture-projects/console-log/.gitignore create mode 100644 packages/hardhat-core/test/fixture-projects/console-log/contracts/Test.sol create mode 100644 packages/hardhat-core/test/fixture-projects/console-log/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/console-log/package.json create mode 100644 packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts diff --git a/packages/hardhat-core/test/fixture-projects/console-log/.gitignore b/packages/hardhat-core/test/fixture-projects/console-log/.gitignore new file mode 100644 index 0000000000..e7f801166c --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/console-log/.gitignore @@ -0,0 +1,2 @@ +artifacts/ +cache/ diff --git a/packages/hardhat-core/test/fixture-projects/console-log/contracts/Test.sol b/packages/hardhat-core/test/fixture-projects/console-log/contracts/Test.sol new file mode 100644 index 0000000000..3621e2829f --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/console-log/contracts/Test.sol @@ -0,0 +1,16 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.7.0; + +import "hardhat/console.sol"; + +contract Test { + function test() public view { + console.log("%d", 123456789123456789123456789); + console.log("%i", 123456789123456789123456789); + console.log("%d%i%s", 12, 13, 14); + console.log("%d", 1, "%i", 1); + console.log("%d %%d %%%d %%%%d %%%%%d %%%%%%d", 1, 2, 3); + console.log("%i %%i %%%i %%%%i %%%%%i %%%%%%i", 1, 2, 3); + console.log("%s %%s %%%s %%%%s %%%%%s %%%%%%s", 1, 2, 3); + } +} diff --git a/packages/hardhat-core/test/fixture-projects/console-log/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/console-log/hardhat.config.js new file mode 100644 index 0000000000..38f2a55388 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/console-log/hardhat.config.js @@ -0,0 +1,3 @@ +module.exports = { + solidity: "0.7.3", +}; diff --git a/packages/hardhat-core/test/fixture-projects/console-log/package.json b/packages/hardhat-core/test/fixture-projects/console-log/package.json new file mode 100644 index 0000000000..103b68ed4b --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/console-log/package.json @@ -0,0 +1,4 @@ +{ + "name": "console-log", + "version": "1.0.0" +} diff --git a/packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts b/packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts new file mode 100644 index 0000000000..900c4e8bca --- /dev/null +++ b/packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts @@ -0,0 +1,68 @@ +import { assert } from "chai"; +import path from "path"; +import { Artifacts } from "../../../../src/internal/artifacts"; +import { useEnvironment } from "../../../helpers/environment"; +import { useFixtureProject } from "../../../helpers/project"; +import { TASK_COMPILE } from "../../../../src/builtin-tasks/task-names"; + +const ARTIFACTS_FOLDER_PATH = path.join( + __dirname, + "..", + "..", + "..", + "fixture-projects", + "console-log", + "artifacts", + "contracts", + "Test.sol" +); + +describe("Solidity console.log should print numbers without losing precision, occurrences of %d and %i should be correctly replaced with %s", function () { + // Set up the test environment + useFixtureProject("console-log"); + useEnvironment(); + + it("should print all the numbers without losing precision", async function () { + await this.env.run(TASK_COMPILE, { quiet: true }); + + // Retrieve the artifact of the solidity file compiled in the previous command + const artifacts = new Artifacts(ARTIFACTS_FOLDER_PATH); + const artifact = artifacts.readArtifactSync("Test"); + + // Deploy contract and get receipt + const [deployer] = await this.env.network.provider.send("eth_accounts"); + const tx = await this.env.network.provider.send("eth_sendTransaction", [ + { from: deployer, data: artifact.bytecode }, + ]); + const receipt = await this.env.network.provider.send( + "eth_getTransactionReceipt", + [tx] + ); + + // Modify console.log to store the messages that are gonna be printed when executing the smart contract function + const originalConsoleLog = console.log; + const capturedLogs: string[] = []; + console.log = (s: string) => { + capturedLogs.push(s); + }; + + // Call the contract function + await this.env.network.provider.send("eth_sendTransaction", [ + { from: deployer, to: receipt.contractAddress, data: "0xf8a8fd6d" }, + ]); + + // Restore the original console.log + console.log = originalConsoleLog; + + // Process the captured logs as needed + assert.equal("123456789123456789123456789", capturedLogs[0]); + assert.equal("123456789123456789123456789", capturedLogs[1]); + assert.equal("121314", capturedLogs[2]); + assert.equal("1 %i 1", capturedLogs[3]); + // When % are in even number it means that they are escaped so %d and %i are not transformed into %s. + // See util.format docs for more info. + assert.equal("1 %d %2 %%d %%3 %%%d", capturedLogs[4]); + assert.equal("1 %i %2 %%i %%3 %%%i", capturedLogs[5]); + assert.equal("1 %s %2 %%s %%3 %%%s", capturedLogs[6]); + }); +}); From b7d023a1ec171ec1d12642305aa5dcc7e1aa7136 Mon Sep 17 00:00:00 2001 From: Nick Barry Date: Sun, 9 Jul 2023 07:25:19 -0600 Subject: [PATCH 05/12] remove duplicate "Other helpers" section --- docs/src/content/hardhat-network-helpers/docs/reference.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/docs/src/content/hardhat-network-helpers/docs/reference.md b/docs/src/content/hardhat-network-helpers/docs/reference.md index 19562c8a5f..627ece392b 100644 --- a/docs/src/content/hardhat-network-helpers/docs/reference.md +++ b/docs/src/content/hardhat-network-helpers/docs/reference.md @@ -307,8 +307,6 @@ Parameters: - `prevRandao`: The new PREVRANDAO value to use. -## Other helpers - ### `reset([url], [blockNumber])` Resets the Hardhat Network. The result of calling this method depends on which arguments are provided: From 277e2bbd62db945af2da88337502d7df83a5cd21 Mon Sep 17 00:00:00 2001 From: Christopher Dedominici <18092467+ChristopherDedominici@users.noreply.github.com> Date: Mon, 10 Jul 2023 15:45:21 +0200 Subject: [PATCH 06/12] add more test: single sting passed to console.log --- .../test/fixture-projects/console-log/contracts/Test.sol | 5 +++++ .../test/internal/hardhat-network/console-log/test.ts | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/packages/hardhat-core/test/fixture-projects/console-log/contracts/Test.sol b/packages/hardhat-core/test/fixture-projects/console-log/contracts/Test.sol index 3621e2829f..cea384d9a1 100644 --- a/packages/hardhat-core/test/fixture-projects/console-log/contracts/Test.sol +++ b/packages/hardhat-core/test/fixture-projects/console-log/contracts/Test.sol @@ -12,5 +12,10 @@ contract Test { console.log("%d %%d %%%d %%%%d %%%%%d %%%%%%d", 1, 2, 3); console.log("%i %%i %%%i %%%%i %%%%%i %%%%%%i", 1, 2, 3); console.log("%s %%s %%%s %%%%s %%%%%s %%%%%%s", 1, 2, 3); + console.log("%d"); + console.log("%%d"); + console.log("%s"); + console.log("%d %i %s %%d"); + console.log("1"); } } diff --git a/packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts b/packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts index 900c4e8bca..a56a78ddf8 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts +++ b/packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts @@ -64,5 +64,10 @@ describe("Solidity console.log should print numbers without losing precision, oc assert.equal("1 %d %2 %%d %%3 %%%d", capturedLogs[4]); assert.equal("1 %i %2 %%i %%3 %%%i", capturedLogs[5]); assert.equal("1 %s %2 %%s %%3 %%%s", capturedLogs[6]); + assert.equal("%s", capturedLogs[7]); + assert.equal("%%d", capturedLogs[8]); + assert.equal("%s", capturedLogs[9]); + assert.equal("%s %s %s %%d", capturedLogs[10]); + assert.equal("1", capturedLogs[11]); }); }); From 37048f3981b758620efdadd3a1eede65f3c795b2 Mon Sep 17 00:00:00 2001 From: Christopher Dedominici <18092467+ChristopherDedominici@users.noreply.github.com> Date: Mon, 10 Jul 2023 20:56:00 +0200 Subject: [PATCH 07/12] fix PR comments --- .../stack-traces/consoleLogger.ts | 20 +++-- .../console-log/contracts/Test.sol | 19 +++-- .../internal/hardhat-network/console-log.ts | 77 +++++++++++++++++++ .../hardhat-network/console-log/test.ts | 73 ------------------ 4 files changed, 104 insertions(+), 85 deletions(-) create mode 100644 packages/hardhat-core/test/internal/hardhat-network/console-log.ts delete mode 100644 packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts diff --git a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts index 63ee50b39b..0826487bbb 100644 --- a/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts +++ b/packages/hardhat-core/src/internal/hardhat-network/stack-traces/consoleLogger.ts @@ -142,12 +142,20 @@ export class ConsoleLogger { } private _replaceNumberFormatSpecifiers(consoleLogs: ConsoleLogs) { - // Replace the occurrences of %d and %i with %s. This is necessary because if the arguments passed are numbers, - // they could be too large to be formatted as a Number or an Integer, so it is safer to use a String. - // %d and %i are replaced only if there is an odd number of % before the d or i. - // If there is an even number of % then it is assumed that the % is escaped and should not be replaced. - if (consoleLogs.length > 0) { - consoleLogs[0] = String(consoleLogs[0]).replace( + /** + * Replace the occurrences of %d and %i with %s. This is necessary because if the arguments passed are numbers, + * they could be too large to be formatted as a Number or an Integer, so it is safer to use a String. + * %d and %i are replaced only if there is an odd number of % before the d or i. + * If there is an even number of % then it is assumed that the % is escaped and should not be replaced. + * The regex matches a '%d' or an '%i' that has an even number of + * '%' behind it (including 0). This group of pairs of '%' is captured + * and preserved, while the '%[di]' is replaced with '%s'. + * Naively doing (%%)* is not enough; we also have to use the + * (? 0 && typeof consoleLogs[0] === "string") { + consoleLogs[0] = consoleLogs[0].replace( /((? { + capturedLogs.push(v); + }; + + // Call the contract function + await this.env.network.provider.send("eth_sendTransaction", [ + { + from: deployer, + to: receipt.contractAddress, + data: "0xf8a8fd6d", + }, + ]); + + // Restore the original console.log + console.log = originalConsoleLog; + + // Process the captured logs as needed + assert.strictEqual("123456789123456789123456789", capturedLogs[0]); + assert.strictEqual("123456789123456789123456789", capturedLogs[1]); + assert.strictEqual(`${n1}${n2}${n3}`, capturedLogs[2]); + assert.strictEqual(`${n1} %i ${n1}`, capturedLogs[3]); + // When % are in even number it means that they are escaped so %d and %i are not transformed into %s. + // See util.format docs for more info. + assert.strictEqual(`${n1} %d %2 %%d %%${n3} %%%d`, capturedLogs[4]); + assert.strictEqual(`${n1} %i %2 %%i %%${n3} %%%i`, capturedLogs[5]); + assert.strictEqual(`${n1} %s %2 %%s %%${n3} %%%s`, capturedLogs[6]); + assert.strictEqual("%s", capturedLogs[7]); + assert.strictEqual("%%d", capturedLogs[8]); + assert.strictEqual("%s", capturedLogs[9]); + assert.strictEqual("%s %s %s %%d", capturedLogs[10]); + assert.strictEqual( + "1111111111111111114444444444444444444455555555555555555555", + capturedLogs[11] + ); + assert.strictEqual("1", capturedLogs[12]); + assert.strictEqual("12", capturedLogs[13]); + assert.strictEqual("13", capturedLogs[14]); + + assert.strictEqual(capturedLogs.length, 15); + }); +}); diff --git a/packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts b/packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts deleted file mode 100644 index a56a78ddf8..0000000000 --- a/packages/hardhat-core/test/internal/hardhat-network/console-log/test.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { assert } from "chai"; -import path from "path"; -import { Artifacts } from "../../../../src/internal/artifacts"; -import { useEnvironment } from "../../../helpers/environment"; -import { useFixtureProject } from "../../../helpers/project"; -import { TASK_COMPILE } from "../../../../src/builtin-tasks/task-names"; - -const ARTIFACTS_FOLDER_PATH = path.join( - __dirname, - "..", - "..", - "..", - "fixture-projects", - "console-log", - "artifacts", - "contracts", - "Test.sol" -); - -describe("Solidity console.log should print numbers without losing precision, occurrences of %d and %i should be correctly replaced with %s", function () { - // Set up the test environment - useFixtureProject("console-log"); - useEnvironment(); - - it("should print all the numbers without losing precision", async function () { - await this.env.run(TASK_COMPILE, { quiet: true }); - - // Retrieve the artifact of the solidity file compiled in the previous command - const artifacts = new Artifacts(ARTIFACTS_FOLDER_PATH); - const artifact = artifacts.readArtifactSync("Test"); - - // Deploy contract and get receipt - const [deployer] = await this.env.network.provider.send("eth_accounts"); - const tx = await this.env.network.provider.send("eth_sendTransaction", [ - { from: deployer, data: artifact.bytecode }, - ]); - const receipt = await this.env.network.provider.send( - "eth_getTransactionReceipt", - [tx] - ); - - // Modify console.log to store the messages that are gonna be printed when executing the smart contract function - const originalConsoleLog = console.log; - const capturedLogs: string[] = []; - console.log = (s: string) => { - capturedLogs.push(s); - }; - - // Call the contract function - await this.env.network.provider.send("eth_sendTransaction", [ - { from: deployer, to: receipt.contractAddress, data: "0xf8a8fd6d" }, - ]); - - // Restore the original console.log - console.log = originalConsoleLog; - - // Process the captured logs as needed - assert.equal("123456789123456789123456789", capturedLogs[0]); - assert.equal("123456789123456789123456789", capturedLogs[1]); - assert.equal("121314", capturedLogs[2]); - assert.equal("1 %i 1", capturedLogs[3]); - // When % are in even number it means that they are escaped so %d and %i are not transformed into %s. - // See util.format docs for more info. - assert.equal("1 %d %2 %%d %%3 %%%d", capturedLogs[4]); - assert.equal("1 %i %2 %%i %%3 %%%i", capturedLogs[5]); - assert.equal("1 %s %2 %%s %%3 %%%s", capturedLogs[6]); - assert.equal("%s", capturedLogs[7]); - assert.equal("%%d", capturedLogs[8]); - assert.equal("%s", capturedLogs[9]); - assert.equal("%s %s %s %%d", capturedLogs[10]); - assert.equal("1", capturedLogs[11]); - }); -}); From 2b0ac92a33a3cae3c4acc00415c4a5821f5d7c5a Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Mon, 10 Jul 2023 19:54:20 -0300 Subject: [PATCH 08/12] Fix deletion of valid build-info file --- .changeset/seven-shrimps-tell.md | 5 + .../hardhat-core/src/internal/artifacts.ts | 10 +- .../test/builtin-tasks/compile.ts | 92 +++++++++++++++++++ .../compilation-contract-with-deps/.gitignore | 2 + .../contracts/A.sol | 6 ++ .../contracts/C.sol | 6 ++ .../contracts/E.sol | 6 ++ .../hardhat.config.js | 7 ++ .../dependency/contracts/console.sol | 6 ++ .../node_modules/dependency/package.json | 4 + 10 files changed, 135 insertions(+), 9 deletions(-) create mode 100644 .changeset/seven-shrimps-tell.md create mode 100644 packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/.gitignore create mode 100644 packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/A.sol create mode 100644 packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/C.sol create mode 100644 packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/E.sol create mode 100644 packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/hardhat.config.js create mode 100644 packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/node_modules/dependency/contracts/console.sol create mode 100644 packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/node_modules/dependency/package.json diff --git a/.changeset/seven-shrimps-tell.md b/.changeset/seven-shrimps-tell.md new file mode 100644 index 0000000000..e6500f9134 --- /dev/null +++ b/.changeset/seven-shrimps-tell.md @@ -0,0 +1,5 @@ +--- +"hardhat": patch +--- + +Fixed an issue in the compilation pipeline where a valid build-info file was mistakenly deleted diff --git a/packages/hardhat-core/src/internal/artifacts.ts b/packages/hardhat-core/src/internal/artifacts.ts index 95f156ee29..3311758a3e 100644 --- a/packages/hardhat-core/src/internal/artifacts.ts +++ b/packages/hardhat-core/src/internal/artifacts.ts @@ -444,8 +444,6 @@ export class Artifacts implements IArtifacts { const buildInfoFile = await this._getBuildInfoFromDebugFile(debugFile); if (buildInfoFile !== undefined) { return path.resolve(path.dirname(debugFile), buildInfoFile); - } else { - return undefined; } }) ); @@ -859,20 +857,14 @@ Please replace "${contractName}" for the correct contract name wherever you are } /** - * Remove the artifact file, its debug file and, if it exists, its build - * info file. + * Remove the artifact file and its debug file. */ private async _removeArtifactFiles(artifactPath: string) { await fsExtra.remove(artifactPath); const debugFilePath = this._getDebugFilePath(artifactPath); - const buildInfoPath = await this._getBuildInfoFromDebugFile(debugFilePath); await fsExtra.remove(debugFilePath); - - if (buildInfoPath !== undefined) { - await fsExtra.remove(buildInfoPath); - } } /** diff --git a/packages/hardhat-core/test/builtin-tasks/compile.ts b/packages/hardhat-core/test/builtin-tasks/compile.ts index 3be4a6ea0b..b49a6d035d 100644 --- a/packages/hardhat-core/test/builtin-tasks/compile.ts +++ b/packages/hardhat-core/test/builtin-tasks/compile.ts @@ -844,4 +844,96 @@ Read about compiler configuration at https://hardhat.org/config } }); }); + + describe("project with files importing dependencies", function () { + useFixtureProject("compilation-contract-with-deps"); + useEnvironment(); + + it("should not remove the build-info if it is still referenced by an external library", async function () { + await this.env.run("compile"); + + const pathContractA = path.join("contracts", "A.sol"); + let contractA = fsExtra.readFileSync(pathContractA, "utf-8"); + contractA = contractA.replace("contract A", "contract B"); + fsExtra.writeFileSync(pathContractA, contractA, "utf-8"); + + /** + * The _validArtifacts variable is not cleared when running the compile + * task twice in the same process, leading to an invalid output. This + * issue is not encountered when running the task from the CLI as each + * command operates as a separate process. To resolve this, the private + * variable should be cleared after each run of the compile task. + */ + // eslint-disable-next-line @typescript-eslint/dot-notation + (this.env.artifacts as any)["_validArtifacts"] = []; + + await this.env.run("compile"); + + // asserts + const buildInfoPathB = path.join( + "artifacts", + "contracts", + "A.sol", + "B.dbg.json" + ); + assertBuildInfoExists(buildInfoPathB); + const buildInfoPathConsole = path.join( + "artifacts", + "dependency", + "contracts", + "console.sol", + "console.dbg.json" + ); + assertBuildInfoExists(buildInfoPathConsole); + }); + + it("should not remove the build-info if it is still referenced by another local contract", async function () { + await this.env.run("compile"); + + const pathContractC = path.join("contracts", "C.sol"); + let contractC = fsExtra.readFileSync(pathContractC, "utf-8"); + contractC = contractC.replace("contract C", "contract D"); + fsExtra.writeFileSync(pathContractC, contractC, "utf-8"); + + /** + * The _validArtifacts variable is not cleared when running the compile + * task twice in the same process, leading to an invalid output. This + * issue is not encountered when running the task from the CLI as each + * command operates as a separate process. To resolve this, the private + * variable should be cleared after each run of the compile task. + */ + // eslint-disable-next-line @typescript-eslint/dot-notation + (this.env.artifacts as any)["_validArtifacts"] = []; + + await this.env.run("compile"); + + // asserts + const buildInfoPathC = path.join( + "artifacts", + "contracts", + "C.sol", + "D.dbg.json" + ); + assertBuildInfoExists(buildInfoPathC); + const buildInfoPathE = path.join( + "artifacts", + "contracts", + "E.sol", + "E.dbg.json" + ); + assertBuildInfoExists(buildInfoPathE); + }); + + afterEach(() => { + const pathContractA = path.join("contracts", "A.sol"); + let contractA = fsExtra.readFileSync(pathContractA, "utf-8"); + contractA = contractA.replace("contract B", "contract A"); + fsExtra.writeFileSync(pathContractA, contractA, "utf-8"); + + const pathContractC = path.join("contracts", "C.sol"); + let contractC = fsExtra.readFileSync(pathContractC, "utf-8"); + contractC = contractC.replace("contract D", "contract C"); + fsExtra.writeFileSync(pathContractC, contractC, "utf-8"); + }); + }); }); diff --git a/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/.gitignore b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/.gitignore new file mode 100644 index 0000000000..e7f801166c --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/.gitignore @@ -0,0 +1,2 @@ +artifacts/ +cache/ diff --git a/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/A.sol b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/A.sol new file mode 100644 index 0000000000..5b1504bdbd --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/A.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.19; + +import "dependency/contracts/console.sol"; + +contract A {} diff --git a/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/C.sol b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/C.sol new file mode 100644 index 0000000000..9bc8e3522d --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/C.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.19; + +import "./E.sol"; + +contract C {} diff --git a/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/E.sol b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/E.sol new file mode 100644 index 0000000000..55d440147e --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/E.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.19; + +import "dependency/contracts/console.sol"; + +contract E {} diff --git a/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/hardhat.config.js b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/hardhat.config.js new file mode 100644 index 0000000000..a764e2e07a --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/hardhat.config.js @@ -0,0 +1,7 @@ +// This project is compiled from scratch multiple times in the same test, which +// produces a lot of logs. We override this task to omit those logs. +subtask("compile:solidity:log:compilation-result", () => {}); + +module.exports = { + solidity: "0.8.19", +}; diff --git a/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/node_modules/dependency/contracts/console.sol b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/node_modules/dependency/contracts/console.sol new file mode 100644 index 0000000000..7e21bed415 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/node_modules/dependency/contracts/console.sol @@ -0,0 +1,6 @@ +// SPDX-License-Identifier: UNLICENSED +pragma solidity 0.8.19; + +contract console { + constructor() {} +} diff --git a/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/node_modules/dependency/package.json b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/node_modules/dependency/package.json new file mode 100644 index 0000000000..2c30dd0e49 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/node_modules/dependency/package.json @@ -0,0 +1,4 @@ +{ + "name": "dependency", + "version": "1.2.3" +} From a548cb9d0935b686ffcb4c8285d9b88f1839c643 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 11 Jul 2023 07:05:24 +0000 Subject: [PATCH 09/12] Bump semver from 5.7.1 to 5.7.2 in /docs Bumps [semver](https://github.com/npm/node-semver) from 5.7.1 to 5.7.2. - [Release notes](https://github.com/npm/node-semver/releases) - [Changelog](https://github.com/npm/node-semver/blob/v5.7.2/CHANGELOG.md) - [Commits](https://github.com/npm/node-semver/compare/v5.7.1...v5.7.2) --- updated-dependencies: - dependency-name: semver dependency-type: indirect ... Signed-off-by: dependabot[bot] --- docs/yarn.lock | 161 ++++++++++++++++++++++++++++++++++++------------- 1 file changed, 118 insertions(+), 43 deletions(-) diff --git a/docs/yarn.lock b/docs/yarn.lock index 862a255546..d9ce6d48ce 100644 --- a/docs/yarn.lock +++ b/docs/yarn.lock @@ -1400,6 +1400,18 @@ resolved "https://registry.npmjs.org/@emotion/weak-memoize/-/weak-memoize-0.2.5.tgz" integrity sha512-6U71C2Wp7r5XtFtQzYrW5iKFT67OixrSxjI4MptCHzdSVlgabczzqLe0ZSgnub/5Kp4hSbpDB1tMytZY9pwxxA== +"@eslint-community/eslint-utils@^4.2.0": + version "4.4.0" + resolved "https://registry.yarnpkg.com/@eslint-community/eslint-utils/-/eslint-utils-4.4.0.tgz#a23514e8fb9af1269d5f7788aa556798d61c6b59" + integrity sha512-1/sA4dwrzBAyeUoQ6oxahHKmrZvsnLCg4RfxW3ZFGGmQkSNQPFNLV9CUEFQP1x9EYXHTo5p6xdhZM1Ne9p/AfA== + dependencies: + eslint-visitor-keys "^3.3.0" + +"@eslint-community/regexpp@^4.4.0": + version "4.5.1" + resolved "https://registry.yarnpkg.com/@eslint-community/regexpp/-/regexpp-4.5.1.tgz#cdd35dce4fa1a89a4fd42b1599eb35b3af408884" + integrity sha512-Z5ba73P98O1KUYCCJTUeVpja9RcGoMdncZ6T49FCUl2lN38JtCJ+3WgIDBv0AuY4WChU5PmtJmOCTlN6FZTFKQ== + "@eslint/eslintrc@^1.2.0": version "1.2.0" resolved "https://registry.npmjs.org/@eslint/eslintrc/-/eslintrc-1.2.0.tgz" @@ -3009,6 +3021,11 @@ resolved "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz" integrity sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew== +"@types/semver@^7.3.12": + version "7.5.0" + resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.5.0.tgz#591c1ce3a702c45ee15f47a42ade72c2fd78978a" + integrity sha512-G8hZ6XJiHnuhQKR7ZmysCeJWE08o8T0AXtk5darsCaTVsYZhhgUrq53jizaR2FvsoeCwJhlmwTjkXBY5Pn/ZHw== + "@types/source-list-map@*": version "0.1.2" resolved "https://registry.npmjs.org/@types/source-list-map/-/source-list-map-0.1.2.tgz" @@ -3076,19 +3093,20 @@ dependencies: "@types/yargs-parser" "*" -"@typescript-eslint/eslint-plugin@^5.16.0": - version "5.16.0" - resolved "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.16.0.tgz" - integrity sha512-SJoba1edXvQRMmNI505Uo4XmGbxCK9ARQpkvOd00anxzri9RNQk0DDCxD+LIl+jYhkzOJiOMMKYEHnHEODjdCw== - dependencies: - "@typescript-eslint/scope-manager" "5.16.0" - "@typescript-eslint/type-utils" "5.16.0" - "@typescript-eslint/utils" "5.16.0" - debug "^4.3.2" - functional-red-black-tree "^1.0.1" - ignore "^5.1.8" - regexpp "^3.2.0" - semver "^7.3.5" +"@typescript-eslint/eslint-plugin@5.61.0": + version "5.61.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/eslint-plugin/-/eslint-plugin-5.61.0.tgz#a1a5290cf33863b4db3fb79350b3c5275a7b1223" + integrity sha512-A5l/eUAug103qtkwccSCxn8ZRwT+7RXWkFECdA4Cvl1dOlDUgTpAOfSEElZn2uSUxhdDpnCdetrf0jvU4qrL+g== + dependencies: + "@eslint-community/regexpp" "^4.4.0" + "@typescript-eslint/scope-manager" "5.61.0" + "@typescript-eslint/type-utils" "5.61.0" + "@typescript-eslint/utils" "5.61.0" + debug "^4.3.4" + graphemer "^1.4.0" + ignore "^5.2.0" + natural-compare-lite "^1.4.0" + semver "^7.3.7" tsutils "^3.21.0" "@typescript-eslint/experimental-utils@^5.3.0": @@ -3098,7 +3116,17 @@ dependencies: "@typescript-eslint/utils" "5.13.0" -"@typescript-eslint/parser@^5.0.0", "@typescript-eslint/parser@^5.16.0": +"@typescript-eslint/parser@5.61.0": + version "5.61.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/parser/-/parser-5.61.0.tgz#7fbe3e2951904bb843f8932ebedd6e0635bffb70" + integrity sha512-yGr4Sgyh8uO6fSi9hw3jAFXNBHbCtKKFMdX2IkT3ZqpKmtAq3lHS4ixB/COFuAIJpwl9/AqF7j72ZDWYKmIfvg== + dependencies: + "@typescript-eslint/scope-manager" "5.61.0" + "@typescript-eslint/types" "5.61.0" + "@typescript-eslint/typescript-estree" "5.61.0" + debug "^4.3.4" + +"@typescript-eslint/parser@^5.0.0": version "5.16.0" resolved "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-5.16.0.tgz" integrity sha512-fkDq86F0zl8FicnJtdXakFs4lnuebH6ZADDw6CYQv0UZeIjHvmEw87m9/29nk2Dv5Lmdp0zQ3zDQhiMWQf/GbA== @@ -3124,13 +3152,22 @@ "@typescript-eslint/types" "5.16.0" "@typescript-eslint/visitor-keys" "5.16.0" -"@typescript-eslint/type-utils@5.16.0": - version "5.16.0" - resolved "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-5.16.0.tgz" - integrity sha512-SKygICv54CCRl1Vq5ewwQUJV/8padIWvPgCxlWPGO/OgQLCijY9G7lDu6H+mqfQtbzDNlVjzVWQmeqbLMBLEwQ== +"@typescript-eslint/scope-manager@5.61.0": + version "5.61.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/scope-manager/-/scope-manager-5.61.0.tgz#b670006d069c9abe6415c41f754b1b5d949ef2b2" + integrity sha512-W8VoMjoSg7f7nqAROEmTt6LoBpn81AegP7uKhhW5KzYlehs8VV0ZW0fIDVbcZRcaP3aPSW+JZFua+ysQN+m/Nw== dependencies: - "@typescript-eslint/utils" "5.16.0" - debug "^4.3.2" + "@typescript-eslint/types" "5.61.0" + "@typescript-eslint/visitor-keys" "5.61.0" + +"@typescript-eslint/type-utils@5.61.0": + version "5.61.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/type-utils/-/type-utils-5.61.0.tgz#e90799eb2045c4435ea8378cb31cd8a9fddca47a" + integrity sha512-kk8u//r+oVK2Aj3ph/26XdH0pbAkC2RiSjUYhKD+PExemG4XSjpGFeyZ/QM8lBOa7O8aGOU+/yEbMJgQv/DnCg== + dependencies: + "@typescript-eslint/typescript-estree" "5.61.0" + "@typescript-eslint/utils" "5.61.0" + debug "^4.3.4" tsutils "^3.21.0" "@typescript-eslint/types@5.13.0": @@ -3143,6 +3180,11 @@ resolved "https://registry.npmjs.org/@typescript-eslint/types/-/types-5.16.0.tgz" integrity sha512-oUorOwLj/3/3p/HFwrp6m/J2VfbLC8gjW5X3awpQJ/bSG+YRGFS4dpsvtQ8T2VNveV+LflQHjlLvB6v0R87z4g== +"@typescript-eslint/types@5.61.0": + version "5.61.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/types/-/types-5.61.0.tgz#e99ff11b5792d791554abab0f0370936d8ca50c0" + integrity sha512-ldyueo58KjngXpzloHUog/h9REmHl59G1b3a5Sng1GfBo14BkS3ZbMEb3693gnP1k//97lh7bKsp6/V/0v1veQ== + "@typescript-eslint/typescript-estree@5.13.0": version "5.13.0" resolved "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-5.13.0.tgz" @@ -3169,6 +3211,19 @@ semver "^7.3.5" tsutils "^3.21.0" +"@typescript-eslint/typescript-estree@5.61.0": + version "5.61.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/typescript-estree/-/typescript-estree-5.61.0.tgz#4c7caca84ce95bb41aa585d46a764bcc050b92f3" + integrity sha512-Fud90PxONnnLZ36oR5ClJBLTLfU4pIWBmnvGwTbEa2cXIqj70AEDEmOmpkFComjBZ/037ueKrOdHuYmSFVD7Rw== + dependencies: + "@typescript-eslint/types" "5.61.0" + "@typescript-eslint/visitor-keys" "5.61.0" + debug "^4.3.4" + globby "^11.1.0" + is-glob "^4.0.3" + semver "^7.3.7" + tsutils "^3.21.0" + "@typescript-eslint/utils@5.13.0": version "5.13.0" resolved "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.13.0.tgz" @@ -3181,17 +3236,19 @@ eslint-scope "^5.1.1" eslint-utils "^3.0.0" -"@typescript-eslint/utils@5.16.0": - version "5.16.0" - resolved "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-5.16.0.tgz" - integrity sha512-iYej2ER6AwmejLWMWzJIHy3nPJeGDuCqf8Jnb+jAQVoPpmWzwQOfa9hWVB8GIQE5gsCv/rfN4T+AYb/V06WseQ== +"@typescript-eslint/utils@5.61.0": + version "5.61.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/utils/-/utils-5.61.0.tgz#5064838a53e91c754fffbddd306adcca3fe0af36" + integrity sha512-mV6O+6VgQmVE6+xzlA91xifndPW9ElFW8vbSF0xCT/czPXVhwDewKila1jOyRwa9AE19zKnrr7Cg5S3pJVrTWQ== dependencies: + "@eslint-community/eslint-utils" "^4.2.0" "@types/json-schema" "^7.0.9" - "@typescript-eslint/scope-manager" "5.16.0" - "@typescript-eslint/types" "5.16.0" - "@typescript-eslint/typescript-estree" "5.16.0" + "@types/semver" "^7.3.12" + "@typescript-eslint/scope-manager" "5.61.0" + "@typescript-eslint/types" "5.61.0" + "@typescript-eslint/typescript-estree" "5.61.0" eslint-scope "^5.1.1" - eslint-utils "^3.0.0" + semver "^7.3.7" "@typescript-eslint/visitor-keys@5.13.0": version "5.13.0" @@ -3209,6 +3266,14 @@ "@typescript-eslint/types" "5.16.0" eslint-visitor-keys "^3.0.0" +"@typescript-eslint/visitor-keys@5.61.0": + version "5.61.0" + resolved "https://registry.yarnpkg.com/@typescript-eslint/visitor-keys/-/visitor-keys-5.61.0.tgz#c79414fa42158fd23bd2bb70952dc5cdbb298140" + integrity sha512-50XQ5VdbWrX06mQXhy93WywSFZZGsv3EOjq+lqp6WC2t+j3mb6A9xYVdrRxafvK88vg9k9u+CT4l6D8PEatjKg== + dependencies: + "@typescript-eslint/types" "5.61.0" + eslint-visitor-keys "^3.3.0" + "@usulpro/react-json-view@^2.0.1": version "2.0.1" resolved "https://registry.npmjs.org/@usulpro/react-json-view/-/react-json-view-2.0.1.tgz" @@ -5159,7 +5224,7 @@ debug@2.6.9, debug@^2.2.0, debug@^2.3.3, debug@^2.6.0, debug@^2.6.9: dependencies: ms "2.0.0" -debug@4: +debug@4, debug@^4.3.4: version "4.3.4" resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865" integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ== @@ -6740,7 +6805,7 @@ globalthis@^1.0.0: dependencies: define-properties "^1.1.3" -globby@^11.0.2, globby@^11.0.4: +globby@^11.0.2, globby@^11.0.4, globby@^11.1.0: version "11.1.0" resolved "https://registry.npmjs.org/globby/-/globby-11.1.0.tgz" integrity sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g== @@ -6771,6 +6836,11 @@ graceful-fs@^4.1.11, graceful-fs@^4.1.15, graceful-fs@^4.1.2, graceful-fs@^4.1.6 resolved "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.9.tgz" integrity sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ== +graphemer@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/graphemer/-/graphemer-1.4.0.tgz#fb2f1d55e0e3a1849aeffc90c4fa0dd53a0e66c6" + integrity sha512-EtKwoO6kxCL9WO5xipiHTZlSzBm7WLT627TqC/uVRd0HKmq8NXyebnNYxDoBi7wt8eTWrUrKXCOVaFq9x1kgag== + gray-matter@^4.0.3: version "4.0.3" resolved "https://registry.yarnpkg.com/gray-matter/-/gray-matter-4.0.3.tgz#e893c064825de73ea1f5f7d88c7a9f7274288798" @@ -7203,7 +7273,7 @@ ignore@^4.0.3, ignore@^4.0.6: resolved "https://registry.npmjs.org/ignore/-/ignore-4.0.6.tgz" integrity sha512-cyFDKrqc/YdcWFniJhzI42+AzS+gNwmUzOSFcRCQYwySuBBBy/KjuxWLZ/FHEH6Moq1NizMOBWyTcv8O4OZIMg== -ignore@^5.1.8, ignore@^5.2.0: +ignore@^5.2.0: version "5.2.0" resolved "https://registry.npmjs.org/ignore/-/ignore-5.2.0.tgz" integrity sha512-CmxgYGiEPCLhfLnpPp1MoRmifwEIOgjcHXxOBjv7mY96c+eWScsOP9c112ZyLdWHi0FxHjI+4uVhKYp/gcdRmQ== @@ -9268,6 +9338,11 @@ nanomatch@^1.2.9: snapdragon "^0.8.1" to-regex "^3.0.1" +natural-compare-lite@^1.4.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/natural-compare-lite/-/natural-compare-lite-1.4.0.tgz#17b09581988979fddafe0201e931ba933c96cbb4" + integrity sha512-Tj+HTDSJJKaZnfiuw+iaF9skdPpTo2GtEly5JHnWV/hfv2Qj/9RKsGISQtLh2ox3l5EAGw487hnBee0sIJ6v2g== + natural-compare@^1.4.0: version "1.4.0" resolved "https://registry.npmjs.org/natural-compare/-/natural-compare-1.4.0.tgz" @@ -11218,24 +11293,24 @@ section-matter@^1.0.0: kind-of "^6.0.0" "semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0, semver@^5.6.0: - version "5.7.1" - resolved "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz" - integrity sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ== + version "5.7.2" + resolved "https://registry.yarnpkg.com/semver/-/semver-5.7.2.tgz#48d55db737c3287cd4835e17fa13feace1c41ef8" + integrity sha512-cBznnQ9KjJqU67B52RMC65CMarK2600WFnbkcaiwWq3xy/5haFJlshgnpjovMVJ+Hff49d8GEn0b87C5pDQ10g== semver@7.0.0: version "7.0.0" - resolved "https://registry.npmjs.org/semver/-/semver-7.0.0.tgz" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.0.0.tgz#5f3ca35761e47e05b206c6daff2cf814f0316b8e" integrity sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A== semver@^6.0.0, semver@^6.1.1, semver@^6.1.2, semver@^6.3.0: - version "6.3.0" - resolved "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz" - integrity sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw== - -semver@^7.3.2, semver@^7.3.4, semver@^7.3.5: - version "7.3.5" - resolved "https://registry.npmjs.org/semver/-/semver-7.3.5.tgz" - integrity sha512-PoeGJYh8HK4BTO/a9Tf6ZG3veo/A7ZVsYrSA6J8ny9nb3B1VrpkuN+z9OE5wfE5p6H4LchYZsegiQgbJD94ZFQ== + version "6.3.1" + resolved "https://registry.yarnpkg.com/semver/-/semver-6.3.1.tgz#556d2ef8689146e46dcea4bfdd095f3434dffcb4" + integrity sha512-BR7VvDCVHO+q2xBEWskxS6DJE1qRnb7DxzUrogb71CWoSficBxYsiAGd+Kl0mmq/MprG9yArRkyrQxTO6XjMzA== + +semver@^7.3.2, semver@^7.3.4, semver@^7.3.5, semver@^7.3.7: + version "7.5.4" + resolved "https://registry.yarnpkg.com/semver/-/semver-7.5.4.tgz#483986ec4ed38e1c6c48c34894a9182dbff68a6e" + integrity sha512-1bCSESV6Pv+i21Hvpxp3Dx+pSD8lIPt8uVjRrxAUt/nbswYc+tK6Y2btiULjd4+fnq15PX+nqQDC7Oft7WkwcA== dependencies: lru-cache "^6.0.0" From a0df3d2bdc5ad54781edac063a237371fbaa3f5a Mon Sep 17 00:00:00 2001 From: Christopher Dedominici <18092467+ChristopherDedominici@users.noreply.github.com> Date: Tue, 11 Jul 2023 11:25:38 +0200 Subject: [PATCH 10/12] add comment to explain byte hash in eth_sendTransaction --- .../hardhat-core/test/internal/hardhat-network/console-log.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/hardhat-core/test/internal/hardhat-network/console-log.ts b/packages/hardhat-core/test/internal/hardhat-network/console-log.ts index 9dc75e0315..d62ed9da54 100644 --- a/packages/hardhat-core/test/internal/hardhat-network/console-log.ts +++ b/packages/hardhat-core/test/internal/hardhat-network/console-log.ts @@ -43,7 +43,7 @@ describe("Solidity console.log should print numbers without losing precision, oc { from: deployer, to: receipt.contractAddress, - data: "0xf8a8fd6d", + data: "0xf8a8fd6d", // selector of 'test()' }, ]); From 3a753cca1ee11b8707497cf9fbf02ba55b83c4d6 Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Tue, 11 Jul 2023 09:04:53 -0300 Subject: [PATCH 11/12] Update variable names --- .../test/builtin-tasks/compile.ts | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/packages/hardhat-core/test/builtin-tasks/compile.ts b/packages/hardhat-core/test/builtin-tasks/compile.ts index b49a6d035d..48d5bb1a64 100644 --- a/packages/hardhat-core/test/builtin-tasks/compile.ts +++ b/packages/hardhat-core/test/builtin-tasks/compile.ts @@ -852,10 +852,10 @@ Read about compiler configuration at https://hardhat.org/config it("should not remove the build-info if it is still referenced by an external library", async function () { await this.env.run("compile"); - const pathContractA = path.join("contracts", "A.sol"); - let contractA = fsExtra.readFileSync(pathContractA, "utf-8"); + const pathToContractA = path.join("contracts", "A.sol"); + let contractA = fsExtra.readFileSync(pathToContractA, "utf-8"); contractA = contractA.replace("contract A", "contract B"); - fsExtra.writeFileSync(pathContractA, contractA, "utf-8"); + fsExtra.writeFileSync(pathToContractA, contractA, "utf-8"); /** * The _validArtifacts variable is not cleared when running the compile @@ -870,30 +870,30 @@ Read about compiler configuration at https://hardhat.org/config await this.env.run("compile"); // asserts - const buildInfoPathB = path.join( + const pathToBuildInfoB = path.join( "artifacts", "contracts", "A.sol", "B.dbg.json" ); - assertBuildInfoExists(buildInfoPathB); - const buildInfoPathConsole = path.join( + assertBuildInfoExists(pathToBuildInfoB); + const pathToBuildInfoConsole = path.join( "artifacts", "dependency", "contracts", "console.sol", "console.dbg.json" ); - assertBuildInfoExists(buildInfoPathConsole); + assertBuildInfoExists(pathToBuildInfoConsole); }); it("should not remove the build-info if it is still referenced by another local contract", async function () { await this.env.run("compile"); - const pathContractC = path.join("contracts", "C.sol"); - let contractC = fsExtra.readFileSync(pathContractC, "utf-8"); + const pathToContractC = path.join("contracts", "C.sol"); + let contractC = fsExtra.readFileSync(pathToContractC, "utf-8"); contractC = contractC.replace("contract C", "contract D"); - fsExtra.writeFileSync(pathContractC, contractC, "utf-8"); + fsExtra.writeFileSync(pathToContractC, contractC, "utf-8"); /** * The _validArtifacts variable is not cleared when running the compile @@ -908,32 +908,32 @@ Read about compiler configuration at https://hardhat.org/config await this.env.run("compile"); // asserts - const buildInfoPathC = path.join( + const pathToBuildInfoC = path.join( "artifacts", "contracts", "C.sol", "D.dbg.json" ); - assertBuildInfoExists(buildInfoPathC); - const buildInfoPathE = path.join( + assertBuildInfoExists(pathToBuildInfoC); + const pathToBuildInfoE = path.join( "artifacts", "contracts", "E.sol", "E.dbg.json" ); - assertBuildInfoExists(buildInfoPathE); + assertBuildInfoExists(pathToBuildInfoE); }); afterEach(() => { - const pathContractA = path.join("contracts", "A.sol"); - let contractA = fsExtra.readFileSync(pathContractA, "utf-8"); + const pathToContractA = path.join("contracts", "A.sol"); + let contractA = fsExtra.readFileSync(pathToContractA, "utf-8"); contractA = contractA.replace("contract B", "contract A"); - fsExtra.writeFileSync(pathContractA, contractA, "utf-8"); + fsExtra.writeFileSync(pathToContractA, contractA, "utf-8"); - const pathContractC = path.join("contracts", "C.sol"); - let contractC = fsExtra.readFileSync(pathContractC, "utf-8"); + const pathToContractC = path.join("contracts", "C.sol"); + let contractC = fsExtra.readFileSync(pathToContractC, "utf-8"); contractC = contractC.replace("contract D", "contract C"); - fsExtra.writeFileSync(pathContractC, contractC, "utf-8"); + fsExtra.writeFileSync(pathToContractC, contractC, "utf-8"); }); }); }); From a51451b4b5c4904b7dc1f65ee60065bfb5acfc55 Mon Sep 17 00:00:00 2001 From: Luis Schaab Date: Tue, 11 Jul 2023 09:14:44 -0300 Subject: [PATCH 12/12] Move cleanup to tests --- .../hardhat-core/test/builtin-tasks/compile.ts | 18 ++++++------------ .../contracts/E.sol | 2 -- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/packages/hardhat-core/test/builtin-tasks/compile.ts b/packages/hardhat-core/test/builtin-tasks/compile.ts index 48d5bb1a64..b0af00d529 100644 --- a/packages/hardhat-core/test/builtin-tasks/compile.ts +++ b/packages/hardhat-core/test/builtin-tasks/compile.ts @@ -869,6 +869,9 @@ Read about compiler configuration at https://hardhat.org/config await this.env.run("compile"); + contractA = contractA.replace("contract B", "contract A"); + fsExtra.writeFileSync(pathToContractA, contractA, "utf-8"); + // asserts const pathToBuildInfoB = path.join( "artifacts", @@ -907,6 +910,9 @@ Read about compiler configuration at https://hardhat.org/config await this.env.run("compile"); + contractC = contractC.replace("contract D", "contract C"); + fsExtra.writeFileSync(pathToContractC, contractC, "utf-8"); + // asserts const pathToBuildInfoC = path.join( "artifacts", @@ -923,17 +929,5 @@ Read about compiler configuration at https://hardhat.org/config ); assertBuildInfoExists(pathToBuildInfoE); }); - - afterEach(() => { - const pathToContractA = path.join("contracts", "A.sol"); - let contractA = fsExtra.readFileSync(pathToContractA, "utf-8"); - contractA = contractA.replace("contract B", "contract A"); - fsExtra.writeFileSync(pathToContractA, contractA, "utf-8"); - - const pathToContractC = path.join("contracts", "C.sol"); - let contractC = fsExtra.readFileSync(pathToContractC, "utf-8"); - contractC = contractC.replace("contract D", "contract C"); - fsExtra.writeFileSync(pathToContractC, contractC, "utf-8"); - }); }); }); diff --git a/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/E.sol b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/E.sol index 55d440147e..c804f1245e 100644 --- a/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/E.sol +++ b/packages/hardhat-core/test/fixture-projects/compilation-contract-with-deps/contracts/E.sol @@ -1,6 +1,4 @@ // SPDX-License-Identifier: UNLICENSED pragma solidity 0.8.19; -import "dependency/contracts/console.sol"; - contract E {}