Skip to content

Commit

Permalink
Fix tests depending on removed logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fvictorio committed Dec 27, 2024
1 parent 8d07726 commit 2dad878
Show file tree
Hide file tree
Showing 7 changed files with 178 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class EdrProviderWrapper
_vm: MinimalEthereumJsVm;
},
// The common configuration for EthereumJS VM is not used by EDR, but tests expect it as part of the provider.
private readonly _common: Common,
private readonly _common: Common
) {
super();
}
Expand Down Expand Up @@ -290,7 +290,7 @@ export class EdrProviderWrapper
const wrapper = new EdrProviderWrapper(
provider,
minimalEthereumJsNode,
common,
common
);

// Pass through all events from the provider
Expand Down Expand Up @@ -334,7 +334,7 @@ export class EdrProviderWrapper

const needsTraces =
this._node._vm.evm.events.eventNames().length > 0 ||
this._node._vm.events.eventNames().length > 0
this._node._vm.events.eventNames().length > 0;

if (needsTraces) {
const rawTraces = responseObject.traces;
Expand Down Expand Up @@ -387,7 +387,7 @@ export class EdrProviderWrapper
if (isErrorResponse(response)) {
let error;

const stackTrace: SolidityStackTrace | null = responseObject.stackTrace();
const stackTrace: SolidityStackTrace | null = responseObject.stackTrace();

Check failure on line 390 in packages/hardhat-core/src/internal/hardhat-network/provider/provider.ts

View workflow job for this annotation

GitHub Actions / Lint

Property 'stackTrace' does not exist on type 'Response'.

if (stackTrace !== null) {
error = encodeSolidityStackTrace(response.error.message, stackTrace);
Expand Down
4 changes: 2 additions & 2 deletions packages/hardhat-core/test/builtin-tasks/compile.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { getLatestSupportedSolcVersion } from "@nomicfoundation/edr";
import { assert, expect } from "chai";
import ci from "ci-info";
import * as fsExtra from "fs-extra";
Expand All @@ -19,7 +20,6 @@ import {
getAllFilesMatchingSync,
getRealPathSync,
} from "../../src/internal/util/fs-utils";
import { getLatestSupportedVersion } from "../internal/hardhat-network/stack-traces/compilers-list";

function assertFileExists(pathToFile: string) {
assert.isTrue(
Expand Down Expand Up @@ -57,7 +57,7 @@ describe("compile task", function () {
// Test to check that the last version of solc is being tested
const userConfigSolcVersion = this.env.userConfig.solidity;

const lastSolcVersion = getLatestSupportedVersion();
const lastSolcVersion = getLatestSupportedSolcVersion();

assert.equal(
userConfigSolcVersion,
Expand Down
2 changes: 1 addition & 1 deletion packages/hardhat-core/test/builtin-tasks/flatten.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
import { getPackageJson } from "../../src/internal/util/packageInfo";
import { useEnvironment } from "../helpers/environment";
import { useFixtureProject } from "../helpers/project";
import { compileLiteral } from "../internal/hardhat-network/stack-traces/compilation";
import { compileLiteral } from "../helpers/compilation";

function getContractsOrder(flattenedFiles: string) {
const CONTRACT_REGEX = /\s*contract(\s+)(\w)/gm;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const {
getNextUnsupportedVersion,
getNextNextUnsupportedVersion,
} = require("../../internal/hardhat-network/stack-traces/compilers-list");
} = require("../../helpers/compilation");

module.exports = {
solidity: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {
getNextUnsupportedVersion,
} = require("../../internal/hardhat-network/stack-traces/compilers-list");
} = require("../../helpers/compilation");

module.exports = {
solidity: getNextUnsupportedVersion(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const {
getNextUnsupportedVersion,
} = require("../../internal/hardhat-network/stack-traces/compilers-list");
} = require("../../helpers/compilation");

module.exports = {
solidity: {
Expand Down
168 changes: 168 additions & 0 deletions packages/hardhat-core/test/helpers/compilation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
import { getLatestSupportedSolcVersion } from "@nomicfoundation/edr";
import semver from "semver";

import {
Compiler as SolcJsCompiler,
NativeCompiler,
} from "../../src/internal/solidity/compiler";
import {
Compiler,
CompilerDownloader,
CompilerPlatform,
} from "../../src/internal/solidity/compiler/downloader";
import { getCompilersDir } from "../../src/internal/util/global-dir";

import { CompilerInput, CompilerOutput } from "../../src/types";

interface SolcSourceFileToContents {
[filename: string]: { content: string };
}

export async function compileLiteral(
source: string,
solcVersion: string = "0.8.0",
filename: string = "literal.sol"
): Promise<[CompilerInput, CompilerOutput]> {
await downloadCompiler(solcVersion);
const compiler = await getCompilerForVersion(solcVersion);

return compile(getSolcInputForLiteral(source, filename), compiler);
}


function getSolcInput(sources: SolcSourceFileToContents): CompilerInput {
const optimizer = {
enabled: false,
};

const settings: CompilerInput["settings"] = {
optimizer,
outputSelection: {
"*": {
"*": [
"abi",
"evm.bytecode",
"evm.deployedBytecode",
"evm.methodIdentifiers",
],
"": ["id", "ast"],
},
},
};

return {
language: "Solidity",
sources,
settings,
};
}

function getSolcInputForLiteral(
source: string,
filename: string = "literal.sol"
): CompilerInput {
return getSolcInput({ [filename]: { content: source } });
}

async function compile(
input: CompilerInput,
compiler: Compiler
): Promise<[CompilerInput, CompilerOutput]> {
let runnableCompiler: any;
if (compiler.isSolcJs) {
runnableCompiler = new SolcJsCompiler(compiler.compilerPath);
} else {
runnableCompiler = new NativeCompiler(compiler.compilerPath);
}

const output = await runnableCompiler.compile(input);

if (output.errors !== undefined) {
for (const error of output.errors) {
if (error.severity === "error") {
throw new Error(`Failed to compile: ${error.message}`);
}
}
}

return [input, output];
}

async function getCompilerForVersion(
solidityVersion: string
): Promise<Compiler> {
const compilersCache = await getCompilersDir();
const downloader = CompilerDownloader.getConcurrencySafeDownloader(
CompilerDownloader.getCompilerPlatform(),
compilersCache
);

const compiler = await downloader.getCompiler(solidityVersion);
if (compiler !== undefined) {
return compiler;
}

const wasmDownloader = CompilerDownloader.getConcurrencySafeDownloader(
CompilerPlatform.WASM,
compilersCache
);

const wasmCompiler = await wasmDownloader.getCompiler(solidityVersion);

if (wasmCompiler === undefined) {
throw new Error("Expected compiler to be downloaded");
}

return wasmCompiler;
}

async function downloadCompiler(solidityVersion: string): Promise<void> {
const compilersCache = await getCompilersDir();
const downloader = CompilerDownloader.getConcurrencySafeDownloader(
CompilerDownloader.getCompilerPlatform(),
compilersCache
);

const isCompilerDownloaded = await downloader.isCompilerDownloaded(
solidityVersion
);

if (!isCompilerDownloaded) {
console.log("Downloading solc", solidityVersion);
await downloader.downloadCompiler(
solidityVersion,
async () => {},
async () => {}
);
}

const compiler = await downloader.getCompiler(solidityVersion);

if (compiler !== undefined) {
return;
}

const wasmDownloader = CompilerDownloader.getConcurrencySafeDownloader(
CompilerPlatform.WASM,
compilersCache
);

const isWasmCompilerDownloaded = await downloader.isCompilerDownloaded(
solidityVersion
);

if (!isWasmCompilerDownloaded) {
console.log("Downloading solcjs", solidityVersion);
await wasmDownloader.downloadCompiler(
solidityVersion,
async () => {},
async () => {}
);
}
}

export const getNextUnsupportedVersion = () =>
semver.inc(getLatestSupportedSolcVersion(), "patch")!;

export const getNextNextUnsupportedVersion = () =>
semver.inc(getNextUnsupportedVersion(), "patch")!;

0 comments on commit 2dad878

Please sign in to comment.