Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI: Simplify summary message when using --contract #905

Merged
merged 3 commits into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- CLI: Add `--requireReference` option. ([#900](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/900))
- CLI: Simplify summary message when using `--contract`. ([#905](https://github.com/OpenZeppelin/openzeppelin-upgrades/pull/905))

## 1.30.1 (2023-10-11)

Expand Down
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 @@ -251,3 +251,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);
});
31 changes: 20 additions & 11 deletions packages/core/src/cli/cli.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,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 @@ -153,7 +153,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 @@ -166,7 +166,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 @@ -181,7 +181,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 @@ -197,7 +197,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 @@ -213,7 +213,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 @@ -223,7 +223,7 @@ Generated by [AVA](https://avajs.dev).

` ✔ contracts/test/cli/Validate.sol:BecomesSafe (upgrades from contracts/test/cli/Validate.sol:MultipleUnsafe)␊
SUCCESS (1 upgradeable contracts detected, 1 passed, 0 failed)
SUCCESS␊
`

## validate - requireReference - no reference, has upgradesFrom - unsafe
Expand All @@ -235,7 +235,7 @@ Generated by [AVA](https://avajs.dev).
BecomesSafe: Deleted \`x\`␊
> Keep the variable even if unused␊
FAILED (1 upgradeable contract detected, 0 passed, 1 failed)
FAILED␊
Stderr: `

Expand All @@ -249,7 +249,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 @@ -259,7 +259,7 @@ Generated by [AVA](https://avajs.dev).

` ✔ contracts/test/cli/Validate.sol:StorageV2_Ok_NoAnnotation (upgrades from contracts/test/cli/Validate.sol:StorageV1)␊
SUCCESS (1 upgradeable contracts detected, 1 passed, 0 failed)
SUCCESS␊
`

## validate - no upgradeable
Expand All @@ -275,5 +275,14 @@ Generated by [AVA](https://avajs.dev).

` ✔ contracts/test/cli/Annotation.sol:Annotation␊
SUCCESS (1 upgradeable contracts detected, 1 passed, 0 failed)␊
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.
2 changes: 1 addition & 1 deletion packages/core/src/cli/validate/project-report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test('get project report - ok - console', async t => {
t.true(report.ok);
t.is(report.numPassed, 1);
t.is(report.numTotal, 1);
t.regex(report.explain(), /SUCCESS \(1 upgradeable contracts detected, 1 passed, 0 failed\)/);
t.regex(report.explain(), /SUCCESS \(1 upgradeable contract detected, 1 passed, 0 failed\)/);
});

test('get project report - errors - console', async t => {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/cli/validate/project-report.test.ts.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,4 @@ Generated by [AVA](https://avajs.dev).
✔ mypath/MyContract.sol:MyContract2␊
FAILED (2 upgradeable contract detected, 1 passed, 1 failed)`
FAILED (2 upgradeable contracts detected, 1 passed, 1 failed)`
Binary file modified packages/core/src/cli/validate/project-report.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 = numFailed === 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 @@ -42,7 +42,7 @@ export async function validateUpgradeSafety(
const specifiedContracts = findSpecifiedContracts(sourceContracts, allOpts, contract, reference);

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

export function findSpecifiedContracts(
Expand Down