Skip to content

Commit cd5d856

Browse files
committed
refactor(standard-contracts): collapse 3 reproducibility tests into one iterating file
Replaces three near-identical per-contract reproducibility.test.ts files with a single src/reproducibility.test.ts that iterates standardContracts[] from contract_data.ts. Pinned artifacts move from src/<slug>/pinned/ to a flat src/pinned/ directory. Adding a new standard contract is now strictly one row in standardContracts[] plus one pinned JSON; no test-file edits needed.
1 parent 0e02d31 commit cd5d856

7 files changed

Lines changed: 39 additions & 108 deletions

File tree

yarn-project/standard-contracts/src/auth-registry/reproducibility.test.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

yarn-project/standard-contracts/src/multi-call-entrypoint/reproducibility.test.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.

yarn-project/standard-contracts/src/auth-registry/pinned/AuthRegistry.artifact.json renamed to yarn-project/standard-contracts/src/pinned/AuthRegistry.artifact.json

File renamed without changes.

yarn-project/standard-contracts/src/multi-call-entrypoint/pinned/MultiCallEntrypoint.artifact.json renamed to yarn-project/standard-contracts/src/pinned/MultiCallEntrypoint.artifact.json

File renamed without changes.

yarn-project/standard-contracts/src/public-checks/pinned/PublicChecks.artifact.json renamed to yarn-project/standard-contracts/src/pinned/PublicChecks.artifact.json

File renamed without changes.

yarn-project/standard-contracts/src/public-checks/reproducibility.test.ts

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Release-branch reproducibility gate for the standard contracts.
2+
//
3+
// Sibling to the freshness gate in `standard_contract_data.test.ts`: that test asserts the
4+
// committed TS twin stays aligned with the freshly-built artifact. This test goes one level
5+
// further and pins the *full artifact JSON* so a release branch can detect any unintended
6+
// bytecode drift between the pinned release artifact and the current build output.
7+
//
8+
// TODO: enable on release branches by dropping the `.skip`. Run manually with:
9+
// yarn workspace @aztec/standard-contracts test src/reproducibility.test.ts
10+
import { createHash } from 'node:crypto';
11+
import { promises as fs } from 'node:fs';
12+
import path from 'node:path';
13+
import { fileURLToPath } from 'node:url';
14+
15+
import { standardContracts } from './contract_data.js';
16+
17+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
18+
const TARGET_DIR = path.join(__dirname, '../../../noir-projects/noir-contracts/target');
19+
const PINNED_DIR = path.join(__dirname, 'pinned');
20+
21+
describe.skip('standard contract artifact reproducibility', () => {
22+
it.each(standardContracts)(
23+
'$name pinned artifact matches the freshly-built artifact byte-for-byte',
24+
async ({ name, src }) => {
25+
const freshPath = path.join(TARGET_DIR, `${src}.json`);
26+
const pinnedPath = path.join(PINNED_DIR, `${name}.artifact.json`);
27+
const [pinned, fresh] = await Promise.all([fs.readFile(pinnedPath), fs.readFile(freshPath)]);
28+
const pinnedHash = createHash('sha256').update(pinned).digest('hex');
29+
const freshHash = createHash('sha256').update(fresh).digest('hex');
30+
if (pinnedHash !== freshHash) {
31+
throw new Error(
32+
`${name} pinned artifact is stale; if this drift is intentional on a release branch, copy ` +
33+
`${freshPath} over ${pinnedPath} and commit the result.\n` +
34+
` pinned sha256 = ${pinnedHash}\n fresh sha256 = ${freshHash}`,
35+
);
36+
}
37+
},
38+
);
39+
});

0 commit comments

Comments
 (0)