Skip to content

Commit fc54bb0

Browse files
committed
wip
1 parent da009d4 commit fc54bb0

File tree

1 file changed

+46
-77
lines changed

1 file changed

+46
-77
lines changed

yarn-project/pxe/src/tagging/recipient_sync/utils/load_logs_for_range.test.ts

Lines changed: 46 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -60,38 +60,7 @@ describe('loadLogsForRange', () => {
6060
expect(await loadLogsForRange(secret, app, aztecNode, 0, 10, NON_INTERFERING_ANCHOR_BLOCK_NUMBER)).toHaveLength(0);
6161
});
6262

63-
it('returns logs with block timestamps and tagging indexes for a single log', async () => {
64-
const txHash = TxHash.random();
65-
const blockNumber = 5;
66-
const index = 3;
67-
const timestamp = 1000n;
68-
const tag = await computeSiloedTagForIndex(index);
69-
const blockHeader = makeBlockHeader(0, { timestamp });
70-
71-
aztecNode.getLogsByTags.mockImplementation((tags: Fr[]) => {
72-
return Promise.all(
73-
tags.map(async (t: Fr) =>
74-
t.equals(tag.value) ? [makeLog(txHash, await blockHeader.hash(), blockNumber, tag)] : [],
75-
),
76-
);
77-
});
78-
79-
aztecNode.getBlockHeaderByHash.mockImplementation(async (hash: Fr) => {
80-
if (hash.equals(await blockHeader.hash())) {
81-
return blockHeader;
82-
}
83-
return undefined;
84-
});
85-
86-
const result = await loadLogsForRange(secret, app, aztecNode, 0, 10, NON_INTERFERING_ANCHOR_BLOCK_NUMBER);
87-
88-
expect(result).toHaveLength(1);
89-
expect(result[0].log.txHash.equals(txHash)).toBe(true);
90-
expect(result[0].blockTimestamp).toBe(timestamp);
91-
expect(result[0].taggingIndex).toBe(index);
92-
});
93-
94-
it('filters out public logs and only returns private logs', async () => {
63+
it('only returns private logs', async () => {
9564
const txHash = TxHash.random();
9665
const blockNumber = 5;
9766
const index = 3;
@@ -175,6 +144,50 @@ describe('loadLogsForRange', () => {
175144
expect(resultByIndex[1].log.txHash.equals(txHash2)).toBe(true);
176145
});
177146

147+
it('handles multiple logs at the same index', async () => {
148+
const txHash1 = TxHash.random();
149+
const txHash2 = TxHash.random();
150+
const blockNumber1 = 5;
151+
const blockNumber2 = 6;
152+
const index = 4;
153+
const timestamp1 = 1000n;
154+
const timestamp2 = 2000n;
155+
const tag = await computeSiloedTagForIndex(index);
156+
const blockHeader1 = makeBlockHeader(0, { timestamp: timestamp1 });
157+
const blockHeader2 = makeBlockHeader(1, { timestamp: timestamp2 });
158+
159+
aztecNode.getLogsByTags.mockImplementation((tags: Fr[]) => {
160+
return Promise.all(
161+
tags.map(async (t: Fr) =>
162+
t.equals(tag.value)
163+
? [
164+
makeLog(txHash1, await blockHeader1.hash(), blockNumber1, tag),
165+
makeLog(txHash2, await blockHeader2.hash(), blockNumber2, tag),
166+
]
167+
: [],
168+
),
169+
);
170+
});
171+
172+
aztecNode.getBlockHeaderByHash.mockImplementation(async (hash: Fr) => {
173+
if (hash.equals(await blockHeader1.hash())) {
174+
return blockHeader1;
175+
} else if (hash.equals(await blockHeader2.hash())) {
176+
return blockHeader2;
177+
}
178+
return undefined;
179+
});
180+
181+
const result = await loadLogsForRange(secret, app, aztecNode, 0, 10, NON_INTERFERING_ANCHOR_BLOCK_NUMBER);
182+
183+
expect(result).toHaveLength(2);
184+
expect(result[0].taggingIndex).toBe(index);
185+
expect(result[1].taggingIndex).toBe(index);
186+
const txHashes = result.map(r => r.log.txHash.toString());
187+
expect(txHashes).toContain(txHash1.toString());
188+
expect(txHashes).toContain(txHash2.toString());
189+
});
190+
178191
it('handles multiple logs in the same block', async () => {
179192
const txHash1 = TxHash.random();
180193
const txHash2 = TxHash.random();
@@ -299,51 +312,7 @@ describe('loadLogsForRange', () => {
299312
expect(result[0].taggingIndex).toBe(index2);
300313
});
301314

302-
it('handles multiple logs at the same index', async () => {
303-
const txHash1 = TxHash.random();
304-
const txHash2 = TxHash.random();
305-
const blockNumber1 = 5;
306-
const blockNumber2 = 6;
307-
const index = 4;
308-
const timestamp1 = 1000n;
309-
const timestamp2 = 2000n;
310-
const tag = await computeSiloedTagForIndex(index);
311-
const blockHeader1 = makeBlockHeader(0, { timestamp: timestamp1 });
312-
const blockHeader2 = makeBlockHeader(1, { timestamp: timestamp2 });
313-
314-
aztecNode.getLogsByTags.mockImplementation((tags: Fr[]) => {
315-
return Promise.all(
316-
tags.map(async (t: Fr) =>
317-
t.equals(tag.value)
318-
? [
319-
makeLog(txHash1, await blockHeader1.hash(), blockNumber1, tag),
320-
makeLog(txHash2, await blockHeader2.hash(), blockNumber2, tag),
321-
]
322-
: [],
323-
),
324-
);
325-
});
326-
327-
aztecNode.getBlockHeaderByHash.mockImplementation(async (hash: Fr) => {
328-
if (hash.equals(await blockHeader1.hash())) {
329-
return blockHeader1;
330-
} else if (hash.equals(await blockHeader2.hash())) {
331-
return blockHeader2;
332-
}
333-
return undefined;
334-
});
335-
336-
const result = await loadLogsForRange(secret, app, aztecNode, 0, 10, NON_INTERFERING_ANCHOR_BLOCK_NUMBER);
337-
338-
expect(result).toHaveLength(2);
339-
expect(result[0].taggingIndex).toBe(index);
340-
expect(result[1].taggingIndex).toBe(index);
341-
const txHashes = result.map(r => r.log.txHash.toString());
342-
expect(txHashes).toContain(txHash1.toString());
343-
expect(txHashes).toContain(txHash2.toString());
344-
});
345-
346-
it('filters out logs from blocks after anchor block number', async () => {
315+
it('filters out logs from blocks after anchor block', async () => {
347316
const anchorBlockNumber = 10;
348317

349318
const index = 3;

0 commit comments

Comments
 (0)