From c099415c7c248899e0c8a40a893241347b998f11 Mon Sep 17 00:00:00 2001 From: Franco Victorio Date: Fri, 29 Oct 2021 14:45:58 -0300 Subject: [PATCH] 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(); }); }