From 0e5419eb17e87c20c56d6932f7a4704b1a8a88d7 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Fri, 29 Oct 2021 07:31:03 -0300 Subject: [PATCH 1/3] Throw error for old solc versions --- packages/hardhat-core/src/builtin-tasks/compile.ts | 14 ++++++++++++++ .../hardhat-core/src/internal/core/errors-list.ts | 10 ++++++++++ 2 files changed, 24 insertions(+) diff --git a/packages/hardhat-core/src/builtin-tasks/compile.ts b/packages/hardhat-core/src/builtin-tasks/compile.ts index 7d5f5e4df5..1d2b592ecd 100644 --- a/packages/hardhat-core/src/builtin-tasks/compile.ts +++ b/packages/hardhat-core/src/builtin-tasks/compile.ts @@ -99,6 +99,8 @@ function isConsoleLogError(error: any): boolean { const log = debug("hardhat:core:tasks:compile"); +const COMPILE_TASK_FIRST_SOLC_VERSION_SUPPORTED = "0.4.11"; + /** * Returns a list of absolute paths to all the solidity files in the project. * This list doesn't include dependencies, for example solidity files inside @@ -643,6 +645,18 @@ subtask(TASK_COMPILE_SOLIDITY_COMPILE_SOLC) }, { run } ): Promise<{ output: CompilerOutput; solcBuild: SolcBuild }> => { + // versions older than 0.4.11 don't work with hardhat + // see issue https://github.com/nomiclabs/hardhat/issues/2004 + if (semver.lt(solcVersion, COMPILE_TASK_FIRST_SOLC_VERSION_SUPPORTED)) { + throw new HardhatError( + ERRORS.BUILTIN_TASKS.COMPILE_TASK_UNSUPPORTED_SOLC_VERSION, + { + version: solcVersion, + firstSupportedVersion: COMPILE_TASK_FIRST_SOLC_VERSION_SUPPORTED, + } + ); + } + const solcBuild: SolcBuild = await run( TASK_COMPILE_SOLIDITY_GET_SOLC_BUILD, { diff --git a/packages/hardhat-core/src/internal/core/errors-list.ts b/packages/hardhat-core/src/internal/core/errors-list.ts index b4d3932668..93ce6b8c62 100644 --- a/packages/hardhat-core/src/internal/core/errors-list.ts +++ b/packages/hardhat-core/src/internal/core/errors-list.ts @@ -861,6 +861,16 @@ To start the JSON-RPC server, retry the command without the --network parameter. if the URL of the JSON-RPC wasn't set.`, shouldBeReported: false, }, + COMPILE_TASK_UNSUPPORTED_SOLC_VERSION: { + number: 608, + message: `Version %version% is not supported by Hardhat. + +The first supported version is %firstSupportedVersion%`, + title: "Unsupported solc version", + description: `This version of solidity is not supported by Hardhtat. +Please use a newer, supported version.`, + shouldBeReported: true, + }, }, ARTIFACTS: { NOT_FOUND: { From 692b91302d9661f69f6e0882cf998f0d9f336b4d Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Fri, 29 Oct 2021 07:32:02 -0300 Subject: [PATCH 2/3] Add changeset --- .changeset/early-pillows-bathe.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/early-pillows-bathe.md diff --git a/.changeset/early-pillows-bathe.md b/.changeset/early-pillows-bathe.md new file mode 100644 index 0000000000..4b0a7ca1ff --- /dev/null +++ b/.changeset/early-pillows-bathe.md @@ -0,0 +1,5 @@ +--- +"hardhat": patch +--- + +Throw an error for solc versions older than 0.4.11 From c099415c7c248899e0c8a40a893241347b998f11 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Fri, 29 Oct 2021 14:45:58 -0300 Subject: [PATCH 3/3] Add tests for old solc detection --- .../test/builtin-tasks/compile.ts | 36 +++++++++++++++++++ .../old-solidity-versions/contracts/Foo.sol | 3 ++ .../old-solidity-version-in-override.js | 12 +++++++ ...old-solidity-version-multiple-compilers.js | 12 +++++++ .../old-solidity-version.js | 3 ++ .../hardhat-core/test/helpers/environment.ts | 6 +++- 6 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 packages/hardhat-core/test/fixture-projects/old-solidity-versions/contracts/Foo.sol create mode 100644 packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version-in-override.js create mode 100644 packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version-multiple-compilers.js create mode 100644 packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version.js diff --git a/packages/hardhat-core/test/builtin-tasks/compile.ts b/packages/hardhat-core/test/builtin-tasks/compile.ts index 11e6d0dc09..0d7019e66a 100644 --- a/packages/hardhat-core/test/builtin-tasks/compile.ts +++ b/packages/hardhat-core/test/builtin-tasks/compile.ts @@ -4,9 +4,11 @@ import * as path from "path"; import { TASK_COMPILE_SOLIDITY_GET_COMPILATION_JOBS_FAILURE_REASONS } from "../../src/builtin-tasks/task-names"; import { SOLIDITY_FILES_CACHE_FILENAME } from "../../src/internal/constants"; +import { ERRORS } from "../../src/internal/core/errors-list"; import { globSync } from "../../src/internal/util/glob"; import { CompilationJobCreationErrorReason } from "../../src/types/builtin-tasks"; import { useEnvironment } from "../helpers/environment"; +import { expectHardhatErrorAsync } from "../helpers/errors"; import { useFixtureProject } from "../helpers/project"; import { mockFile } from "../utils/mock-file"; @@ -709,4 +711,38 @@ Read about compiler configuration at https://hardhat.org/config ); }); }); + + describe("old versions of solidity", function () { + useFixtureProject("old-solidity-versions"); + + describe("project with an old version of solidity", function () { + useEnvironment("old-solidity-version.js"); + + it("should throw an error", async function () { + await expectHardhatErrorAsync(async () => { + await this.env.run("compile"); + }, ERRORS.BUILTIN_TASKS.COMPILE_TASK_UNSUPPORTED_SOLC_VERSION); + }); + }); + + describe("project with an old version of solidity (multiple compilers)", function () { + useEnvironment("old-solidity-version-multiple-compilers.js"); + + it("should throw an error", async function () { + await expectHardhatErrorAsync(async () => { + await this.env.run("compile"); + }, ERRORS.BUILTIN_TASKS.COMPILE_TASK_UNSUPPORTED_SOLC_VERSION); + }); + }); + + describe("project with an old version of solidity in an override", function () { + useEnvironment("old-solidity-version-in-override.js"); + + it("should throw an error", async function () { + await expectHardhatErrorAsync(async () => { + await this.env.run("compile"); + }, ERRORS.BUILTIN_TASKS.COMPILE_TASK_UNSUPPORTED_SOLC_VERSION); + }); + }); + }); }); diff --git a/packages/hardhat-core/test/fixture-projects/old-solidity-versions/contracts/Foo.sol b/packages/hardhat-core/test/fixture-projects/old-solidity-versions/contracts/Foo.sol new file mode 100644 index 0000000000..4ad1f7fa3a --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/old-solidity-versions/contracts/Foo.sol @@ -0,0 +1,3 @@ +pragma solidity ^0.4.0; + +contract Foo {} diff --git a/packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version-in-override.js b/packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version-in-override.js new file mode 100644 index 0000000000..71b99b29e6 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version-in-override.js @@ -0,0 +1,12 @@ +module.exports = { + solidity: { + compilers: [ + { + version: "0.7.0", + }, + ], + overrides: { + "contracts/Foo.sol": { version: "0.4.8" }, + }, + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version-multiple-compilers.js b/packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version-multiple-compilers.js new file mode 100644 index 0000000000..e889c02a17 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version-multiple-compilers.js @@ -0,0 +1,12 @@ +module.exports = { + solidity: { + compilers: [ + { + version: "0.8.6", + }, + { + version: "0.4.9", + }, + ], + }, +}; diff --git a/packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version.js b/packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version.js new file mode 100644 index 0000000000..c95f52ced7 --- /dev/null +++ b/packages/hardhat-core/test/fixture-projects/old-solidity-versions/old-solidity-version.js @@ -0,0 +1,3 @@ +module.exports = { + solidity: "0.4.10", +}; diff --git a/packages/hardhat-core/test/helpers/environment.ts b/packages/hardhat-core/test/helpers/environment.ts index 3deb58ff4a..952af39250 100644 --- a/packages/hardhat-core/test/helpers/environment.ts +++ b/packages/hardhat-core/test/helpers/environment.ts @@ -7,12 +7,16 @@ declare module "mocha" { } } -export function useEnvironment() { +export function useEnvironment(configPath?: string) { beforeEach("Load environment", function () { + if (configPath !== undefined) { + process.env.HARDHAT_CONFIG = configPath; + } this.env = require("../../src/internal/lib/hardhat-lib"); }); afterEach("reset hardhat context", function () { + delete process.env.HARDHAT_CONFIG; resetHardhatContext(); }); }