Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAFrench committed Dec 17, 2024
1 parent 0882f76 commit 662601b
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
formatShellDiff,
formatShellDiffBrillig,
} from "./format/program";
import { computeProgramDiffs } from "./report";
import { computeProgramDiffs, parseReport } from "./report";
import { DiffBrillig, DiffCircuit, WorkspaceReport } from "./types";

const token = process.env.GITHUB_TOKEN || core.getInput("token");
Expand Down Expand Up @@ -102,11 +102,11 @@ function loadReports(referenceContent: string): [WorkspaceReport, WorkspaceRepor
const compareContent = fs.readFileSync(localReportPath, "utf8");

core.info(`Mapping compared gas reports`);
const compareReports: WorkspaceReport = JSON.parse(compareContent);
const compareReports = parseReport(compareContent);
core.info(`Got ${compareReports.programs.length} compare programs`);

core.info(`Mapping reference gas reports`);
const referenceReports: WorkspaceReport = JSON.parse(referenceContent);
const referenceReports = parseReport(referenceContent);
core.info(`Got ${compareReports.programs.length} reference programs`);
core.endGroup();

Expand Down
4 changes: 4 additions & 0 deletions src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ import {
DiffBrillig,
} from "./types";

export const parseReport = (content: string): WorkspaceReport => {
return JSON.parse(content);
};

export const variation = (current: number, previous: number) => {
const delta = current - previous;

Expand Down
6 changes: 3 additions & 3 deletions tests/contract_report.test.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import * as fs from "fs";

import { formatMarkdownDiff, formatShellDiff } from "../src/format/contract";
import { computeContractDiffs } from "../src/report";
import { computeContractDiffs, parseReport } from "../src/report";

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

const srcContractReports = JSON.parse(srcContent).contracts;
const cmpContractReports = JSON.parse(cmpContent).contracts;
const srcContractReports = parseReport(srcContent).contracts;
const cmpContractReports = parseReport(cmpContent).contracts;

describe("Markdown format", () => {
// shows how the runner will run a javascript action with env / stdout protocol
Expand Down
6 changes: 3 additions & 3 deletions tests/diff.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as fs from "fs";

import { computeProgramDiffs } from "../src/report";
import { computeProgramDiffs, parseReport } from "../src/report";
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");

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

it("should diff 1 and 2 successfully", () => {
const expectedDiffCircuits: DiffCircuit[] = [
Expand Down
6 changes: 4 additions & 2 deletions tests/loading.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import * as fs from "fs";

import { parseReport } from "../src/report";

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

describe("Report Loading", () => {
it("should load 1 successfully", () => {
console.log(JSON.parse(srcContent));
console.log(parseReport(srcContent));
});

it("should load 2 successfully", () => {
console.log(JSON.parse(cmpContent));
console.log(parseReport(cmpContent));
});
});
6 changes: 3 additions & 3 deletions tests/program_report.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import {
formatShellDiff,
formatShellDiffBrillig,
} from "../src/format/program";
import { computeProgramDiffs } from "../src/report";
import { computeProgramDiffs, parseReport } from "../src/report";
import { 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 srcContractReports: ProgramReport[] = JSON.parse(srcContent).programs;
const cmpContractReports: ProgramReport[] = JSON.parse(cmpContent).programs;
const srcContractReports: ProgramReport[] = parseReport(srcContent).programs;
const cmpContractReports: ProgramReport[] = parseReport(cmpContent).programs;

describe("Markdown format", () => {
// shows how the runner will run a javascript action with env / stdout protocol
Expand Down

0 comments on commit 662601b

Please sign in to comment.