|
4 | 4 |
|
5 | 5 | import { readFileSync, existsSync } from "fs"; |
6 | 6 | import { execSync } from "child_process"; |
7 | | -import { createHash } from "crypto"; |
8 | 7 | import { join } from "path"; |
9 | 8 |
|
10 | 9 | const [mainDir, prDir] = process.argv.slice(2); |
@@ -32,10 +31,14 @@ function extractVersions(filePath: string) { |
32 | 31 |
|
33 | 32 | function forgeInspect(contract: string, root: string): string | null { |
34 | 33 | try { |
35 | | - return execSync(`forge inspect "contracts/${contract}.sol:${contract}" --root "${root}" deployedBytecode`, { |
| 34 | + const raw = execSync(`forge inspect "contracts/${contract}.sol:${contract}" --root "${root}" deployedBytecode`, { |
36 | 35 | encoding: "utf-8", |
37 | 36 | stdio: ["pipe", "pipe", "pipe"], |
38 | | - }).trim(); |
| 37 | + env: { ...process.env, NO_COLOR: "1" }, |
| 38 | + }); |
| 39 | + // Extract hex bytecode — forge may prepend ANSI codes or compilation progress to stdout |
| 40 | + const match = raw.match(/0x[0-9a-fA-F]+/); |
| 41 | + return match ? match[0] : null; |
39 | 42 | } catch (e: any) { |
40 | 43 | if (e.stderr) console.error(String(e.stderr)); |
41 | 44 | return null; |
@@ -90,31 +93,6 @@ for (const name of contracts) { |
90 | 93 | } |
91 | 94 |
|
92 | 95 | const bytecodeChanged = mainBytecode !== prBytecode; |
93 | | - |
94 | | - if (bytecodeChanged) { |
95 | | - const sha = (s: string) => createHash("sha256").update(s).digest("hex").slice(0, 12); |
96 | | - console.log(` main bytecode: len=${mainBytecode.length} sha=${sha(mainBytecode)}`); |
97 | | - console.log(` PR bytecode: len=${prBytecode.length} sha=${sha(prBytecode)}`); |
98 | | - // Find first divergence point |
99 | | - for (let i = 0; i < Math.min(mainBytecode.length, prBytecode.length); i++) { |
100 | | - if (mainBytecode[i] !== prBytecode[i]) { |
101 | | - console.log(` first diff at offset ${i}: main=...${mainBytecode.slice(Math.max(0, i - 10), i + 10)}... pr=...${prBytecode.slice(Math.max(0, i - 10), i + 10)}...`); |
102 | | - break; |
103 | | - } |
104 | | - } |
105 | | - // Check key files match |
106 | | - for (const f of ["foundry.toml", "addresses/GatewayAddresses.sol"]) { |
107 | | - const mp = join(mainDir, f), pp = join(prDir, f); |
108 | | - const mh = existsSync(mp) ? sha(readFileSync(mp, "utf-8")) : "MISSING"; |
109 | | - const ph = existsSync(pp) ? sha(readFileSync(pp, "utf-8")) : "MISSING"; |
110 | | - console.log(` ${f}: main=${mh} pr=${ph} ${mh === ph ? "MATCH" : "MISMATCH"}`); |
111 | | - } |
112 | | - // Check source files match |
113 | | - const mSrcHash = sha(readFileSync(mainSol, "utf-8")); |
114 | | - const pSrcHash = sha(readFileSync(prSol, "utf-8")); |
115 | | - console.log(` ${name}.sol: main=${mSrcHash} pr=${pSrcHash} ${mSrcHash === pSrcHash ? "MATCH" : "MISMATCH"}`); |
116 | | - } |
117 | | - |
118 | 96 | const reinitChanged = mainV.REINITIALIZER_VERSION !== prV.REINITIALIZER_VERSION; |
119 | 97 | const versionChanged = |
120 | 98 | mainV.MAJOR_VERSION !== prV.MAJOR_VERSION || |
|
0 commit comments