Skip to content

Commit

Permalink
integration tests working again
Browse files Browse the repository at this point in the history
  • Loading branch information
hojarasca committed May 29, 2024
1 parent c6a6fdd commit 2760b92
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 33 deletions.
17 changes: 9 additions & 8 deletions cli/src/lib/compare-current-state-with.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ export async function calculateDiffWithUpgrade(
env: EnvBuilder,
upgradeDirectory: string
): Promise<{ diff: ZkSyncEraDiff, state: ZkSyncEraState }> {
const changes = await withSpinner(async () => {
const importer = env.importer();
return importer.readFromFiles(upgradeDirectory, env.network);
}, 'Reading proposed upgrade...')

const state = await withSpinner(async () => {
const l1Client = env.l1Client();
const l1Abis = new AbiSet(l1Client);
Expand All @@ -22,19 +27,15 @@ export async function calculateDiffWithUpgrade(
);
}, "Gathering contract data");

const diff = await withSpinner(async () => {
return state.calculateDiff(changes, env.l1Client())
}, "Checking differences between versions");

await withSpinner(async () => {
const repo = await env.contractsRepo();
await repo.compile();
}, "Compiling system contracts");

const diff = await withSpinner(async () => {
const importer = env.importer();

const changes = await importer.readFromFiles(upgradeDirectory, env.network);

return state.calculateDiff(changes, env.l1Client())
}, "Checking differences between versions");

return {
diff,
state,
Expand Down
11 changes: 9 additions & 2 deletions cli/src/lib/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,23 @@ export class MalformedUpgrade extends Error {
export class MissingNetwork extends Error {
constructor(path: string, network: Network) {
super(
`Upgrade inside ${path} does not contain information for ${network}. Maybe you can try with a different network.`
`Upgrade inside ${path} does not contain information for "${network}". Maybe you can try with a different network.`
);
}
}

const KNOWN_ERRORS = [ContracNotVerified, NotAnUpgradeDir, NotADir, MalformedUpgrade];
const KNOWN_ERRORS = [
ContracNotVerified,
NotAnUpgradeDir,
NotADir,
MalformedUpgrade,
MissingNetwork
];

export function printError(e: Error): void {
const isKnown = KNOWN_ERRORS.some((kind) => e instanceof kind);

console.error(e)
if (isKnown) {
console.log("");
console.log(`> ${e.message}`);
Expand Down
4 changes: 2 additions & 2 deletions cli/src/lib/file-system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ export class FileSystem {
return targetDirStat.isDirectory();
}

async assertDirectoryExists(path: string, originalPath: string = path): Promise<void> {
async assertDirectoryExists (path: string): Promise<void> {
if (!(await this.directoryExists(path))) {
throw new NotADir(originalPath);
throw new NotADir(path);
}
}
}
7 changes: 3 additions & 4 deletions cli/src/lib/importer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ export class UpgradeImporter {

async readFromFiles(upgradeDirectory: string, network: Network): Promise<UpgradeChanges> {
const targetDir = upgradeDirectory;
await this.fs.assertDirectoryExists(targetDir);
const networkDir = await this.findNetworkDir(targetDir, network);

await this.fs.assertDirectoryExists(targetDir, upgradeDirectory);
await this.fs.assertDirectoryExists(targetDir, networkDir);
await this.fs.assertDirectoryExists(networkDir);

const common = await this.readMandatoryFile(
path.join(targetDir, "common.json"),
Expand Down Expand Up @@ -72,7 +71,7 @@ export class UpgradeImporter {
): Promise<z.infer<typeof parser>> {
const res = await this.readOptionalFile(filePath, parser);
if (res === undefined) {
return ifMissing;
throw ifMissing;
}
return res;
}
Expand Down
18 changes: 11 additions & 7 deletions test/__snapshots__/check.spec.ts.snap
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`validate check > 1699353977-boojum > should match snapshot 1`] = `
"- Gathering contract data: OK
"- Reading proposed upgrade...: OK
- Gathering contract data: OK
- Checking differences between versions: OK
- Compiling system contracts: OK
- Generating report: OK
Upgrade report:
===============
Expand Down Expand Up @@ -151,11 +155,11 @@ System contracts:
└─────────────────────┴────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────┘
Other contracts:
[90m┌─────────────────[39m[90m┬────────────────────────────────────────────────────────────────────[39m[90m┬────────────────────────────────────────────────────────────────────[39m[90m┬──────────────────────────────────┐[39m
[90m│[39m[31m Name [39m[90m│[39m[31m Current Bytecode hash [39m[90m│[39m[31m Proposed Bytecode Hash [39m[90m│[39m[31m BytecodeHash matches with github [39m[90m│[39m
[90m├─────────────────[39m[90m┼────────────────────────────────────────────────────────────────────[39m[90m┼────────────────────────────────────────────────────────────────────[39m[90m┼──────────────────────────────────┤[39m
[90m│[39m Default Account [90m│[39m 0x0100055b041eb28aff6e3a6e0f37c31fd053fc9ef142683b05e5f0aee6934066 [90m│[39m 0x01000651c5ae96f2aab07d720439e42491bb44c6384015e3a08e32620a4d582d [90m│[39m Yes [90m│[39m
[90m│[39m Bootloader [90m│[39m 0x010007ede999d096c84553fb514d3d6ca76fbf39789dda76bfeda9f3ae06236e [90m│[39m 0x01000983d4ac4f797cf5c077e022f72284969b13248c2a8e9846f574bdeb5b88 [90m│[39m Yes [90m│[39m
[90m└─────────────────[39m[90m┴────────────────────────────────────────────────────────────────────[39m[90m┴────────────────────────────────────────────────────────────────────[39m[90m┴──────────────────────────────────┘[39m
[90m┌─────────────────[39m[90m┬────────────────────────────────────────────────────────────────────[39m[90m┬────────────────────────────────────────────────────────────────────[39m[90m┬────────────────────────────────────────────┐[39m
[90m│[39m[31m Name [39m[90m│[39m[31m Current Bytecode hash [39m[90m│[39m[31m Proposed Bytecode Hash [39m[90m│[39m[31m BytecodeHash matches with locally compiled [39m[90m│[39m
[90m├─────────────────[39m[90m┼────────────────────────────────────────────────────────────────────[39m[90m┼────────────────────────────────────────────────────────────────────[39m[90m┼────────────────────────────────────────────┤[39m
[90m│[39m Default Account [90m│[39m 0x0100055b041eb28aff6e3a6e0f37c31fd053fc9ef142683b05e5f0aee6934066 [90m│[39m 0x01000651c5ae96f2aab07d720439e42491bb44c6384015e3a08e32620a4d582d [90m│[39m Yes [90m│[39m
[90m│[39m Bootloader [90m│[39m 0x010007ede999d096c84553fb514d3d6ca76fbf39789dda76bfeda9f3ae06236e [90m│[39m 0x01000983d4ac4f797cf5c077e022f72284969b13248c2a8e9846f574bdeb5b88 [90m│[39m Yes [90m│[39m
[90m└─────────────────[39m[90m┴────────────────────────────────────────────────────────────────────[39m[90m┴────────────────────────────────────────────────────────────────────[39m[90m┴────────────────────────────────────────────┘[39m
"
`;
26 changes: 16 additions & 10 deletions test/check.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,21 +239,27 @@ describe("validate check", () => {

describe("when the directory is not a valid upgrade", () => {
it("fails", async () => {
expect(
async () => await execAsync("pnpm validate check reference/not_an_upgrade")
).rejects.toSatisfy((e) => {
const err = e as any;
expect(err.stdout).to.contain(
'Expected "reference/not_an_upgrade" to be an upgrade directory but it\'s not. Upgrade directories contain a "common.json" file inside'
);
return true;
});
const { stdout, stderr } = await expectToFailAsync(() =>
execAsync("pnpm validate check reference/not_an_upgrade")
);
expect(stdout).to.contain(
'Expected "reference/not_an_upgrade" to be an upgrade directory but it\'s not. Upgrade directories contain a "common.json" file inside'
);
// expect(
// async () => await execAsync("pnpm validate check reference/not_an_upgrade")
// ).rejects.toSatisfy((e) => {
// const err = e as any;
// expect(err.stdout).to.contain(
// 'Expected "reference/not_an_upgrade" to be an upgrade directory but it\'s not. Upgrade directories contain a "common.json" file inside'
// );
// return true;
// });
});
});

describe("when directory does not exists", () => {
it("fails", async () => {
const { stdout } = await expectToFailAsync(() =>
const { stdout, stderr } = await expectToFailAsync(() =>
execAsync("pnpm validate check reference/not_a_directory")
);
expect(stdout).toContain(
Expand Down
File renamed without changes.
Empty file.

1 comment on commit 2760b92

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

44.29%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
bin
   validate.js0%0%0%0%1, 1–3
src
   entrypoint.ts0%0%0%0%1, 1–4
src/commands
   check-command.ts25%100%0%26.67%10–15, 5–9
   contract-diff-command.ts17.14%100%0%17.65%10–34, 7–9
   download-code-command.ts23.08%100%0%24%10–25, 7–9
   index.ts100%100%100%100%
src/lib
   abi-set.ts8.51%0%0%8.89%10–39, 4, 40–45, 5–9
   block-explorer-client.ts29.31%100%37.50%27.61%100–140, 143–152, 160–162, 32–52, 55–79, 82–99
   cli.ts5.99%100%0%6.02%100–109, 11, 110–119, 12, 120–129, 13, 130–139, 14, 140–149, 15, 150–159, 16, 160–166, 17–99
   compare-current-state-with.ts18.18%100%0%18.60%10–43, 9
   constants.ts100%100%100%100%
   contract-data.ts81.82%100%75%80.56%17–23
   env-builder.ts83.33%81.25%71.43%85.42%33–34, 53–55, 62–64, 74–75, 78–79, 82–83, 92–94
   era-contracts-repo.ts95.36%90.63%100%95.92%105–107, 72–74, 97–99
   errors.ts64.62%100%33.33%66.67%12–13, 32–35, 47–57, 6–7
   file-system.ts58.33%66.67%50%58.62%11–12, 15–22, 25–27
   fs-utils.ts77.50%100%66.67%74.19%17–24
   importer.ts94.07%85.71%100%95.28%37–38, 73–75, 96–98
   index.ts100%100%100%100%
   rpc-client.ts58.51%100%50%57.32%37–39, 46–56, 59–60, 63–81
   system-contract-change.ts16.67%0%0%17.50%10–40, 7–9
   upgrade-changes.ts89.80%78.57%71.43%92.06%100–101, 104–106, 108–111, 47–48, 63–64
   verifier.ts90%100%66.67%92%23–24
   with-spinner.ts18.75%100%0%20%10–15, 4–9
   zk-sync-era-diff.ts3.04%0%0%3.05%100–129, 13, 130–139, 14, 140–149, 15, 150–159, 16, 160–169, 17, 170–179, 18, 180–189, 19, 190–199, 20, 200–209, 21, 210–219, 22, 220–229, 23, 230–239, 24, 240–249, 25, 250–259, 26, 260–269, 27, 270–279, 28, 280–289, 29, 290–299, 30, 300–309, 31, 310–319, 32, 320–329, 33, 330–339, 34, 340–349, 35, 350–359, 36, 360–369, 37, 370–379, 38, 380–389, 39, 390–399, 40, 400–409, 41, 410–419, 42, 420–426, 43–99
   zk-sync-era-state.ts13.41%0%0%13.51%100–259, 35–99
src/schema
   common.ts100%100%100%100%
   compiled.ts100%100%100%100%
   etherscan.ts100%100%100%100%
   facetCuts.ts100%100%100%100%
   facets.ts100%100%100%100%
   github-schemas.ts100%100%100%100%
   index.ts100%100%100%100%
   l2Upgrade.ts100%100%100%100%
   manifest.ts100%100%100%100%
   new-facets.ts100%100%100%100%
   transactions.ts100%100%100%100%

Please sign in to comment.