diff --git a/packages/core/CHANGELOG.md b/packages/core/CHANGELOG.md index 7b1ad7285..fa237d283 100644 --- a/packages/core/CHANGELOG.md +++ b/packages/core/CHANGELOG.md @@ -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) diff --git a/packages/core/src/cli/cli.test.ts b/packages/core/src/cli/cli.test.ts index 303bab822..8e562a5f4 100644 --- a/packages/core/src/cli/cli.test.ts +++ b/packages/core/src/cli/cli.test.ts @@ -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); +}); diff --git a/packages/core/src/cli/cli.test.ts.md b/packages/core/src/cli/cli.test.ts.md index 5281d45ae..746bef95d 100644 --- a/packages/core/src/cli/cli.test.ts.md +++ b/packages/core/src/cli/cli.test.ts.md @@ -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: ` @@ -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: ` @@ -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: ` @@ -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: ` @@ -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: ` @@ -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: ` @@ -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 @@ -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: ` @@ -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: ` @@ -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 @@ -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␊ ` diff --git a/packages/core/src/cli/cli.test.ts.snap b/packages/core/src/cli/cli.test.ts.snap index fa011da00..a3a06768e 100644 Binary files a/packages/core/src/cli/cli.test.ts.snap and b/packages/core/src/cli/cli.test.ts.snap differ diff --git a/packages/core/src/cli/validate/project-report.test.ts b/packages/core/src/cli/validate/project-report.test.ts index 72ec286e6..c3ad5bfdb 100644 --- a/packages/core/src/cli/validate/project-report.test.ts +++ b/packages/core/src/cli/validate/project-report.test.ts @@ -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 => { diff --git a/packages/core/src/cli/validate/project-report.test.ts.md b/packages/core/src/cli/validate/project-report.test.ts.md index 05801d215..515107d03 100644 --- a/packages/core/src/cli/validate/project-report.test.ts.md +++ b/packages/core/src/cli/validate/project-report.test.ts.md @@ -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)` diff --git a/packages/core/src/cli/validate/project-report.test.ts.snap b/packages/core/src/cli/validate/project-report.test.ts.snap index 935985593..885aea7d7 100644 Binary files a/packages/core/src/cli/validate/project-report.test.ts.snap and b/packages/core/src/cli/validate/project-report.test.ts.snap differ diff --git a/packages/core/src/cli/validate/project-report.ts b/packages/core/src/cli/validate/project-report.ts index 69c1bab7f..4b415a204 100644 --- a/packages/core/src/cli/validate/project-report.ts +++ b/packages/core/src/cli/validate/project-report.ts @@ -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); @@ -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'); } } @@ -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); } diff --git a/packages/core/src/cli/validate/validate-upgrade-safety.ts b/packages/core/src/cli/validate/validate-upgrade-safety.ts index afcdb28f9..78174ebdd 100644 --- a/packages/core/src/cli/validate/validate-upgrade-safety.ts +++ b/packages/core/src/cli/validate/validate-upgrade-safety.ts @@ -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(