Skip to content

Commit

Permalink
Check solc output is complete before validations (#253)
Browse files Browse the repository at this point in the history
  • Loading branch information
frangio authored Dec 4, 2020
1 parent 36e50aa commit a4ae92b
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
4 changes: 4 additions & 0 deletions packages/plugin-hardhat/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## 1.4.2 (2020-12-04)

- Fix a bug that prevented some solc errors from reaching the console. ([#253](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/253))

## 1.4.1 (2020-11-30)

- Add `admin` to the TypeScript type for `hre.upgrades`.
Expand Down
11 changes: 8 additions & 3 deletions packages/plugin-hardhat/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,14 @@ interface RunCompilerArgs {
subtask(TASK_COMPILE_SOLIDITY_COMPILE, async (args: RunCompilerArgs, hre, runSuper) => {
// TODO: patch input
const { output, solcBuild } = await runSuper();
const decodeSrc = solcInputOutputDecoder(args.input, output);
const validations = validate(output, decodeSrc);
await writeValidations(hre, validations);

const { isFullSolcOutput } = await import('./utils/is-full-solc-output');
if (isFullSolcOutput(output)) {
const decodeSrc = solcInputOutputDecoder(args.input, output);
const validations = validate(output, decodeSrc);
await writeValidations(hre, validations);
}

return { output, solcBuild };
});

Expand Down
30 changes: 30 additions & 0 deletions packages/plugin-hardhat/src/utils/is-full-solc-output.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { SolcOutput } from '@openzeppelin/upgrades-core';

type RecursivePartial<T> = { [k in keyof T]?: RecursivePartial<T[k]> };

type MaybeSolcOutput = RecursivePartial<SolcOutput>;

export function isFullSolcOutput(output: MaybeSolcOutput | undefined): boolean {
if (output?.contracts == undefined || output?.sources == undefined) {
return false;
}

for (const file of Object.values(output.contracts)) {
if (file == undefined) {
return false;
}
for (const contract of Object.values(file)) {
if (contract?.evm?.bytecode == undefined) {
return false;
}
}
}

for (const file of Object.values(output.sources)) {
if (file?.ast == undefined || file?.id == undefined) {
return false;
}
}

return true;
}

0 comments on commit a4ae92b

Please sign in to comment.