Skip to content

Commit a4ae92b

Browse files
authored
Check solc output is complete before validations (#253)
1 parent 36e50aa commit a4ae92b

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

packages/plugin-hardhat/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
## 1.4.2 (2020-12-04)
4+
5+
- Fix a bug that prevented some solc errors from reaching the console. ([#253](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/253))
6+
37
## 1.4.1 (2020-11-30)
48

59
- Add `admin` to the TypeScript type for `hre.upgrades`.

packages/plugin-hardhat/src/index.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,14 @@ interface RunCompilerArgs {
3131
subtask(TASK_COMPILE_SOLIDITY_COMPILE, async (args: RunCompilerArgs, hre, runSuper) => {
3232
// TODO: patch input
3333
const { output, solcBuild } = await runSuper();
34-
const decodeSrc = solcInputOutputDecoder(args.input, output);
35-
const validations = validate(output, decodeSrc);
36-
await writeValidations(hre, validations);
34+
35+
const { isFullSolcOutput } = await import('./utils/is-full-solc-output');
36+
if (isFullSolcOutput(output)) {
37+
const decodeSrc = solcInputOutputDecoder(args.input, output);
38+
const validations = validate(output, decodeSrc);
39+
await writeValidations(hre, validations);
40+
}
41+
3742
return { output, solcBuild };
3843
});
3944

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import type { SolcOutput } from '@openzeppelin/upgrades-core';
2+
3+
type RecursivePartial<T> = { [k in keyof T]?: RecursivePartial<T[k]> };
4+
5+
type MaybeSolcOutput = RecursivePartial<SolcOutput>;
6+
7+
export function isFullSolcOutput(output: MaybeSolcOutput | undefined): boolean {
8+
if (output?.contracts == undefined || output?.sources == undefined) {
9+
return false;
10+
}
11+
12+
for (const file of Object.values(output.contracts)) {
13+
if (file == undefined) {
14+
return false;
15+
}
16+
for (const contract of Object.values(file)) {
17+
if (contract?.evm?.bytecode == undefined) {
18+
return false;
19+
}
20+
}
21+
}
22+
23+
for (const file of Object.values(output.sources)) {
24+
if (file?.ast == undefined || file?.id == undefined) {
25+
return false;
26+
}
27+
}
28+
29+
return true;
30+
}

0 commit comments

Comments
 (0)