Skip to content

Commit

Permalink
Add tests for old solc detection
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Oct 29, 2021
1 parent 692b913 commit c099415
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 1 deletion.
36 changes: 36 additions & 0 deletions packages/hardhat-core/test/builtin-tasks/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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);
});
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pragma solidity ^0.4.0;

contract Foo {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
solidity: {
compilers: [
{
version: "0.7.0",
},
],
overrides: {
"contracts/Foo.sol": { version: "0.4.8" },
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module.exports = {
solidity: {
compilers: [
{
version: "0.8.6",
},
{
version: "0.4.9",
},
],
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
solidity: "0.4.10",
};
6 changes: 5 additions & 1 deletion packages/hardhat-core/test/helpers/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}

0 comments on commit c099415

Please sign in to comment.