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

fix: correctly handle packages with zero functions #13

Merged
merged 2 commits into from
Dec 20, 2024
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
17 changes: 17 additions & 0 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,23 @@ const computeProgramDiffs = (sourceReports, compareReports) => {
const srcReport = sourceReports.find((report) => report.package_name == reportName);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const cmpReport = compareReports.find((report) => report.package_name == reportName);
if (srcReport.functions.length === 0 || cmpReport.functions.length === 0) {
return {
name: "",
opcodes: {
previous: 0,
current: 0,
delta: 0,
percentage: 0,
},
circuit_size: {
previous: 0,
current: 0,
delta: 0,
percentage: 0,
},
};
}
// For now we fetch just the main of each program
return computeCircuitDiff(srcReport.functions[0], cmpReport.functions[0], reportName);
})
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ export const computeProgramDiffs = (
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const cmpReport = compareReports.find((report) => report.package_name == reportName)!;

if (srcReport.functions.length === 0 || cmpReport.functions.length === 0) {
return {
name: "",
opcodes: {
previous: 0,
current: 0,
delta: 0,
percentage: 0,
},
circuit_size: {
previous: 0,
current: 0,
delta: 0,
percentage: 0,
},
};
}

// For now we fetch just the main of each program
return computeCircuitDiff(srcReport.functions[0], cmpReport.functions[0], reportName);
})
Expand Down
9 changes: 9 additions & 0 deletions tests/diff.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import { DiffBrillig, DiffCircuit, ProgramReport } from "../src/types";

const srcContent = fs.readFileSync("tests/mocks/gas_report.2.json", "utf8");
const cmpContent = fs.readFileSync("tests/mocks/gas_report.1.json", "utf8");
const brilligContent = fs.readFileSync("tests/mocks/brillig_report.json", "utf8");

describe("Program diffs", () => {
const srcProgramReports: ProgramReport[] = parseReport(srcContent).programs;
const cmpProgramReports: ProgramReport[] = parseReport(cmpContent).programs;
const brilligProgramReports: ProgramReport[] = parseReport(brilligContent).programs;

it("should diff 1 and 2 successfully", () => {
const expectedDiffCircuits: DiffCircuit[] = [
Expand Down Expand Up @@ -52,4 +54,11 @@ describe("Program diffs", () => {
it("should return zero diff for identical reports", () => {
expect(computeProgramDiffs(srcProgramReports, srcProgramReports)).toStrictEqual([[], []]);
});

it("should return zero diff for brillig reports", () => {
expect(computeProgramDiffs(brilligProgramReports, brilligProgramReports)).toStrictEqual([
[],
[],
]);
});
});
Loading
Loading