Initial import of verae-archive-aggregator from zapier monorepo
This commit is contained in:
commit
f77107ba99
5 changed files with 137 additions and 0 deletions
44
test/aggregate.test.js
Normal file
44
test/aggregate.test.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { WormArchive } from '../../verae-archive-worm/src/archive.js';
|
||||
import { aggregateAttached, mergeReceipts } from '../src/aggregate.js';
|
||||
|
||||
describe('aggregateAttached', () => {
|
||||
it('silent miss + one hit', () => {
|
||||
const a = new WormArchive('archive-a');
|
||||
const b = new WormArchive('archive-b');
|
||||
const sha = 'c'.repeat(64);
|
||||
b.put({ sha256: sha, kind: 'publicMeta', record: { publicMetadata: { k: 1 } } });
|
||||
const out = aggregateAttached({ sha256: sha, tenantId: 't1', archives: [a, b] });
|
||||
assert.equal(out.archiveReplies, 1);
|
||||
assert.deepEqual(out.silent, ['archive-a']);
|
||||
assert.equal(out.records[0].record.publicMetadata.k, 1);
|
||||
});
|
||||
|
||||
it('merges seal + attach receipts', () => {
|
||||
const seal = [{ kind: 'seal', timestamp: '2026-01-01T00:00:00Z', certificate: 'x' }];
|
||||
const recs = [
|
||||
{ kind: 'publicMeta', archiveId: 'archive-b', storedAt: '2026-01-02T00:00:00Z', record: { publicMetadata: { n: 2 } } },
|
||||
];
|
||||
const merged = mergeReceipts(seal, recs);
|
||||
assert.equal(merged.length, 2);
|
||||
assert.equal(merged[0].kind, 'seal');
|
||||
assert.equal(merged[1].kind, 'metadata-attach');
|
||||
});
|
||||
|
||||
it('merges tree-leaf receipts from bulk summaries', () => {
|
||||
const seal = [{ kind: 'seal', of: 'merkleRoot', sha256: 'aa'.repeat(32) }];
|
||||
const recs = [
|
||||
{
|
||||
kind: 'tree',
|
||||
archiveId: 'tree-node-east',
|
||||
storedAt: '2026-01-02T00:00:00Z',
|
||||
record: { merkleRoot: 'aa'.repeat(32), leafIndex: 1, proof: [] },
|
||||
},
|
||||
];
|
||||
const merged = mergeReceipts(seal, recs);
|
||||
assert.equal(merged[1].kind, 'tree-leaf');
|
||||
assert.equal(merged[1].itemizedOnMainChain, false);
|
||||
assert.equal(merged[1].archiveId, 'tree-node-east');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue