testNamespaceAndCausalHashesArePinned
Namespace and causal hashes are pinned.
import { causalHash, EMPTY_NAMESPACE, ROOT_CAUSAL } from "#codebase/tcmts/store"; import { a, b, open } from "#codebase/tcmts/store/test/history"; import assert from "node:assert/strict"; export const testNamespaceAndCausalHashesArePinned = () => { const s = open(); assert.equal(EMPTY_NAMESPACE, "a7d65ecy52g7uixil4g4q7neogcjcfdiaq7grajdkbpfaun33rha"); assert.equal(ROOT_CAUSAL, "dc4c7qxqiu7x2ujh2nqrvt4wcd4tpb7ox53hcehj2tobqdouoglq"); const ns = s.namespaceOf([ { path: "lib.square", hash: a }, { path: "lib.util.Point", hash: b }, { path: "lib.util.Point", hash: a }, { path: "main", hash: b }, ]); assert.equal(ns, "tpg34pl2raqwlq5gkg6xx7qqrm35xouibjsqycioi6rb3v7uevfa"); assert.equal(causalHash(ns, [ROOT_CAUSAL]), "mjb26ej3yt4v77nqypef7sfsz2vzjxcu5dbhyoks2y4w4cqwulaa"); // order doesn't matter: of names, or of a merge's parents assert.equal(s.namespaceOf([{ path: "main", hash: b }, { path: "lib.util.Point", hash: a }, { path: "lib.square", hash: a }, { path: "lib.util.Point", hash: b }]), ns); assert.equal(causalHash(ns, [a, b]), causalHash(ns, [b, a])); // and a namespace reads back as the names it was made from assert.deepEqual( s.namespaceRows(ns).map((r) => `${r.path} ${r.hash[0]}`), ["lib.square a", "lib.util.Point a", "lib.util.Point b", "main b"], ); }