-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix tests depending on removed logic
- Loading branch information
Showing
7 changed files
with
178 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
.../hardhat-core/test/fixture-projects/solidity-config-warnings/multiple-unsupported-solc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
packages/hardhat-core/test/fixture-projects/solidity-config-warnings/unsupported-new-solc.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...rdhat-core/test/fixture-projects/solidity-config-warnings/unsupported-solc-in-override.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")!; |