From 683ef22b40e5681b5ee37a36b97a8fcd99b4fdeb Mon Sep 17 00:00:00 2001 From: Eric Lau Date: Fri, 20 Oct 2023 12:03:11 -0400 Subject: [PATCH] CLI: Simplify summary message when using `--contract` (#905) --- packages/core/CHANGELOG.md | 1 + packages/core/src/cli/cli.test.ts | 9 +++++ packages/core/src/cli/cli.test.ts.md | 31 +++++++++++------- packages/core/src/cli/cli.test.ts.snap | Bin 2020 -> 2035 bytes .../src/cli/validate/project-report.test.ts | 2 +- .../cli/validate/project-report.test.ts.md | 2 +- .../cli/validate/project-report.test.ts.snap | Bin 557 -> 553 bytes .../core/src/cli/validate/project-report.ts | 26 ++++++++++----- .../cli/validate/validate-upgrade-safety.ts | 2 +- 9 files changed, 51 insertions(+), 22 deletions(-) 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 fa011da006e6fcca031c4d7731629e963ea2739f..a3a06768e68f262be5e69e689e267c434f8265b1 100644 GIT binary patch literal 2035 zcmV_z`uMa!jgZ|E&N@bU5GSUhq$MKL6G!k4(Y*qs)rU;{9M468$4+Qe5g#AL! z5axcSMxl2Tq9;Tm_y-<=1&KhUa6mRHm8Kj=Q^K`sR1mso6GGikQ^7GqA=VS5g^_c) z+IJH=nphJt_&WDk<){02O#|^Yg0vs`L5A@u_ zQq#aVTeIpsqwXFGghXFq=})jmp%lNh7{S^-kg>3FPej}Y)6$I_s1u->h-A8gA_ewg zG>Vi4Kw~@RK2^QuhI4180nv1=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AZVB}p9L+ma#|bLG`ZL4i?+b7K?%(dz z>y38%EST);MkU2*HN`1`r*TPmqF=D4X#Il>Lf7B0)?eE@i`j~E{e1K_-huV~Ot62* zfPGvL>}21r9RS`3yJGzI;7z$zjA3~us$=8~9OJK-hT}gO#44)PEdT%; CD9a@P 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 93598559339f08f3e5b7e66f19b60c5c663ba153..885aea7d7815dc8be0e1f72437574bb36dfd0acd 100644 GIT binary patch literal 553 zcmV+^0@nRORzVYP_igWf=$Q4ll$r4D2;DYYfw{yOQ zy`9zWoZ?Fd-;ja=AtgOOMZq7?vupco6CyzhI;NVtoq03!-n%Lmn)3Jl<2ABkjjKmX zWU!9jVb0*tl4BSFI!DfjBq!rZqw+>rUlRKdS5gWVZ+lP1ezDL9OrT7z zYl%PxBm9E61S)__^tglap$r#tyDV?Ld z!?-l4xK?{VD1|{=28E;Q;Az-uUZ~As)5#QGqtzlu3E3*m;9LcQGlxc0D6_a|P=Kmn zCAC(hvDoiFKbgIF_7nyw9FVx<-iO=5U5xSw#$bi_F-xHkVX7Rqc86Q-?y16U&+ks} r{`ke|-@AY3^vQp#{~N1E?_K_x|MV`7nd}@hX&v(u5xKr$Dg^)l9kmHt literal 557 zcmV+|0@D3KRzV|F6VsvnC800000000B+lCh2xF%X86AcT~TH<$(~kuJB%Rwxyx1EfeGA&wMu>#S$9 z2Cv7mXLZ@@;2ExejWiiM{9z5jTPtXSjf z(GnS~qj#7yIJD##Mu5(d^Wl(_@uX3CBdjlp{f8?l1&g=6ulG6+Ix)KUI}dwbdhqS@ zCxEK4g3IJ(b4rGt$oV*wPxqhwKCI(L!el&!S!Fd=Xjrf!1Ik0CyjNxk0&Km|Du=AL zOD810p@ERnq4&cK$Q}GYG4fPs-CiFp8pfDZ)FzLz+x9VLrbMS0=JQu)^G&^2Xapuu zCfBt@AcIkUL0keAz$JRzN%@cl4b?81v>9$M{)8-=3$zxsGD(}@NA0@Jbt{*z1`e2m^%*-4--h#xDQ;ix*e8n!zx)Ml{hWD2j*YLTOaY?Wqku7bgtLnA7bS$t^N z0964cwcbc$vEP4wGJEmtDGX9LFmdO-53_~2808U+!3yu=DTP9Wu5#Go4!7d&slsi| v@1%Es{6hNo?w^r9`H%X)K|Qi}dAI-RUBny!GuZ(%X@U6(DA!5oDFpxknw<<2 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(