mirror of
https://github.com/datahaven-xyz/datahaven
synced 2026-05-24 01:38:32 +00:00
## Summary This PR improve the generating state workflow. It will also check for outdated state-diff.json and add a practical script to easily generate a new one. The way we generate state has also been changed to make it work with macOS M1 system. We don't run the tool in the container anymore but instead directly on the machine. ## What changes * A check-generated-state.js script was added to quickly look for outdated test * The check was added in the CI * A generate-contracts.ts script was added to easily generate the new state with the new instructions to run on MacOS --------- Co-authored-by: Gonza Montiel <gon.montiel@gmail.com> Co-authored-by: Ahmad Kaouk <56095276+ahmadkaouk@users.noreply.github.com> Co-authored-by: Steve Degosserie <723552+stiiifff@users.noreply.github.com> Co-authored-by: Gonza Montiel <gonzamontiel@users.noreply.github.com>
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
// @ts-nocheck
|
|
|
|
import { createHash } from "node:crypto";
|
|
import type { Dirent } from "node:fs";
|
|
import { readdirSync, readFileSync } from "node:fs";
|
|
import path from "node:path";
|
|
|
|
/**
|
|
* Recursively walks a directory and feeds all file contents into a SHA1 hash.
|
|
* This ensures that any change in nested contract files is reflected
|
|
* in the resulting checksum.
|
|
*/
|
|
export function generateContractsChecksum(contractsPath: string): string {
|
|
const root = path.resolve(contractsPath);
|
|
const hash = createHash("sha1");
|
|
|
|
const visit = (dir: string) => {
|
|
const entries: Dirent[] = readdirSync(dir, { withFileTypes: true });
|
|
|
|
// Ensure deterministic ordering across platforms
|
|
entries
|
|
.slice()
|
|
.sort((a: Dirent, b: Dirent) => a.name.localeCompare(b.name))
|
|
.forEach((entry: Dirent) => {
|
|
const fullPath = path.join(dir, entry.name);
|
|
|
|
if (entry.isDirectory()) {
|
|
visit(fullPath);
|
|
} else if (entry.isFile()) {
|
|
const data = readFileSync(fullPath);
|
|
hash.update(data);
|
|
}
|
|
});
|
|
};
|
|
|
|
visit(root);
|
|
|
|
return hash.digest("hex");
|
|
}
|