Skip to content

Commit

Permalink
Simplify summary message if specified contract
Browse files Browse the repository at this point in the history
  • Loading branch information
ericglau committed Oct 20, 2023
1 parent 61fd1cd commit 7294b50
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
9 changes: 9 additions & 0 deletions packages/core/src/cli/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,3 +184,12 @@ test('validate - ok', async t => {
const output = (await execAsync(`${CLI} validate ${temp}`)).stdout;
t.snapshot(output);
});

test('validate - single contract - ok', async t => {
const temp = await getTempDir(t);
const buildInfo = await artifacts.getBuildInfo(`contracts/test/cli/Annotation.sol:Annotation`);
await fs.writeFile(path.join(temp, 'validate.json'), JSON.stringify(buildInfo));

const output = (await execAsync(`${CLI} validate ${temp} --contract Annotation`)).stdout;
t.snapshot(output);
});
21 changes: 15 additions & 6 deletions packages/core/src/cli/cli.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ Generated by [AVA](https://avajs.dev).
contracts/test/cli/Validate.sol:14: Use of selfdestruct is not allowed␊
https://zpl.in/upgrades/error-003␊
FAILED (1 upgradeable contract detected, 0 passed, 1 failed)
FAILED␊
Stderr: `

Expand All @@ -151,7 +151,7 @@ Generated by [AVA](https://avajs.dev).
- Slot changed from 1 to 2␊
> Set __gap array to size 48␊
FAILED (1 upgradeable contract detected, 0 passed, 1 failed)
FAILED␊
Stderr: `

Expand All @@ -164,7 +164,7 @@ Generated by [AVA](https://avajs.dev).
contracts/test/cli/Validate.sol:97: Use of selfdestruct is not allowed␊
https://zpl.in/upgrades/error-003␊
FAILED (1 upgradeable contract detected, 0 passed, 1 failed)
FAILED␊
Stderr: `

Expand All @@ -179,7 +179,7 @@ Generated by [AVA](https://avajs.dev).
@openzeppelin/contracts-upgradeable/proxy/utils/UUPSUpgradeable.sol␊
https://zpl.in/upgrades/error-008␊
FAILED (1 upgradeable contract detected, 0 passed, 1 failed)
FAILED␊
Stderr: `

Expand All @@ -195,7 +195,7 @@ Generated by [AVA](https://avajs.dev).
StorageV1: Deleted \`__gap\`␊
> Keep the variable even if unused␊
FAILED (1 upgradeable contract detected, 0 passed, 1 failed)
FAILED␊
Stderr: `

Expand All @@ -211,7 +211,7 @@ Generated by [AVA](https://avajs.dev).
StorageV1: Deleted \`__gap\`␊
> Keep the variable even if unused␊
FAILED (1 upgradeable contract detected, 0 passed, 1 failed)
FAILED␊
Stderr: `

Expand All @@ -230,3 +230,12 @@ Generated by [AVA](https://avajs.dev).
SUCCESS (1 upgradeable contract detected, 1 passed, 0 failed)␊
`

## validate - single contract - ok

> Snapshot 1
` ✔ contracts/test/cli/Annotation.sol:Annotation␊
SUCCESS␊
`
Binary file modified packages/core/src/cli/cli.test.ts.snap
Binary file not shown.
26 changes: 18 additions & 8 deletions packages/core/src/cli/validate/project-report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { UpgradeableContractReport } from './contract-report';
import { Report } from '../../standalone';

export class ProjectReport implements Report {
constructor(readonly upgradeableContractReports: UpgradeableContractReport[]) {}
constructor(
readonly upgradeableContractReports: UpgradeableContractReport[],
readonly specifiedContract?: boolean,
) {}

get ok(): boolean {
return this.upgradeableContractReports.every(r => r.ok);
Expand All @@ -13,13 +16,17 @@ export class ProjectReport implements Report {
return 'No upgradeable contracts detected.';
} else {
const lines = this.upgradeableContractReports.map(r => r.explain(color));
const numFailed = this.numTotal - this.numPassed;
const plural = this.numTotal === 1 ? '' : 's';
const status = this.ok ? 'SUCCESS' : 'FAILED';

lines.push(
`${status} (${this.numTotal} upgradeable contract${plural} detected, ${this.numPassed} passed, ${numFailed} failed)`,
);
if (this.specifiedContract) {
lines.push(`${status}`);
} else {
const numFailed = this.numTotal - this.numPassed;
const plural = this.numTotal === 1 ? '' : 's';
lines.push(
`${status} (${this.numTotal} upgradeable contract${plural} detected, ${this.numPassed} passed, ${numFailed} failed)`,
);
}
return lines.join('\n\n');
}
}
Expand All @@ -39,6 +46,9 @@ export class ProjectReport implements Report {
}
}

export function getProjectReport(upgradeableContractReports: UpgradeableContractReport[]): ProjectReport {
return new ProjectReport(upgradeableContractReports);
export function getProjectReport(
upgradeableContractReports: UpgradeableContractReport[],
specifiedContract?: boolean,
): ProjectReport {
return new ProjectReport(upgradeableContractReports, specifiedContract);
}
2 changes: 1 addition & 1 deletion packages/core/src/cli/validate/validate-upgrade-safety.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export async function validateUpgradeSafety(
const specifiedContracts = findSpecifiedContracts(sourceContracts, contract, reference);

const contractReports = getContractReports(sourceContracts, opts, specifiedContracts);
return getProjectReport(contractReports);
return getProjectReport(contractReports, specifiedContracts !== undefined);
}

function findSpecifiedContracts(
Expand Down

0 comments on commit 7294b50

Please sign in to comment.