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 8fd6a5c commit 7b9f25d
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 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 @@ -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);
});
29 changes: 19 additions & 10 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 contract 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 contract detected, 1 passed, 0 failed)
SUCCESS␊
`

## validate - no upgradeable
Expand All @@ -277,3 +277,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 @@ -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

0 comments on commit 7b9f25d

Please sign in to comment.