// The copies must stay verbatim. Two guards, because they catch // different mistakes: // // * the recorded hashes catch an edit inside this repo, with no // platform checkout in sight (hermetic); // * the comparison against the platform repo catches a contract // that moved on without the copies, and skips when the checkout // is not there. import assert from 'node:assert/strict'; import { createHash } from 'node:crypto'; import { existsSync, readFileSync } from 'node:fs'; import { join, resolve } from 'node:path'; import { describe, it } from 'node:test'; import { protoDir, protoFiles } from '../src/proto.js'; function sha256(path: string): string { return createHash('sha256').update(readFileSync(path)).digest('hex'); } describe('the chain.v1 copies', () => { it('match their recorded hashes', () => { const recorded = new Map(); for (const line of readFileSync(join(protoDir, 'CHECKSUMS'), 'utf8').split('\n')) { const m = /^([0-9a-f]{64})\s+(\S+)$/.exec(line.trim()); if (m) recorded.set(m[2] as string, m[1] as string); } assert.equal(recorded.size, protoFiles.length, 'CHECKSUMS lists every file'); for (const file of protoFiles) { assert.equal(sha256(join(protoDir, file)), recorded.get(file), `${file} was edited`); } }); it('match the platform repo, when it is checked out here', (t) => { const platform = resolve( process.env.CHAIN_PLATFORM_REPO ?? join(protoDir, '..', '..', 'fai_chain'), ); if (!existsSync(join(platform, 'proto', 'chain', 'v1', 'hub.proto'))) { t.skip(`no platform checkout at ${platform}`); return; } for (const file of protoFiles) { assert.equal( sha256(join(protoDir, file)), sha256(join(platform, 'proto', file)), `${file} drifted from the platform repo: run scripts/sync-proto.mjs`, ); } }); });