From 9754033f4e9ffb7118b32bc1dc7ffd74405085c7 Mon Sep 17 00:00:00 2001 From: benesjan Date: Fri, 13 Dec 2024 21:55:49 +0000 Subject: [PATCH] fixed simulator test --- .../simulator_oracle/simulator_oracle.test.ts | 41 ++++++++++--------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts index 1e88eaab363..b5bfdd0adb5 100644 --- a/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts +++ b/yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts @@ -233,7 +233,8 @@ describe('Simulator oracle', () => { const senderOffset = 0; generateMockLogs(senderOffset); const syncedLogs = await simulatorOracle.syncTaggedLogs(contractAddress, 3); - // We expect to have all logs intended for the recipient, one per sender + 1 with a duplicated tag for the first one + half of the logs for the second index + // We expect to have all logs intended for the recipient, one per sender + 1 with a duplicated tag for the first + // one + half of the logs for the second index expect(syncedLogs.get(recipient.address.toString())).toHaveLength(NUM_SENDERS + 1 + NUM_SENDERS / 2); // Recompute the secrets (as recipient) to ensure indexes are updated @@ -252,9 +253,9 @@ describe('Simulator oracle', () => { expect(indexes).toHaveLength(NUM_SENDERS); expect(indexes).toEqual([1, 1, 1, 1, 1, 2, 2, 2, 2, 2]); - // We should have called the node 12 times: - // 2 times with logs (sliding the window) + 10 times with no results (window size) - expect(aztecNode.getLogsByTags.mock.calls.length).toBe(2 + SENDER_OFFSET_WINDOW_SIZE); + // We should have called the node 2 times: + // 2 times: first time during initial request, second time after pushing the edge of the window once + expect(aztecNode.getLogsByTags.mock.calls.length).toBe(2); }); it('should sync tagged logs as senders', async () => { @@ -332,9 +333,9 @@ describe('Simulator oracle', () => { expect(indexes).toHaveLength(NUM_SENDERS); expect(indexes).toEqual([6, 6, 6, 6, 6, 7, 7, 7, 7, 7]); - // We should have called the node 17 times: - // 5 times with no results (sender offset) + 2 times with logs (sliding the window) + 10 times with no results (window size) - expect(aztecNode.getLogsByTags.mock.calls.length).toBe(5 + 2 + SENDER_OFFSET_WINDOW_SIZE); + // We should have called the node 2 times: + // 2 times: first time during initial request, second time after pushing the edge of the window once + expect(aztecNode.getLogsByTags.mock.calls.length).toBe(2); }); it("should sync tagged logs for which indexes are not updated if they're inside the window", async () => { @@ -358,16 +359,16 @@ describe('Simulator oracle', () => { expect(syncedLogs.get(recipient.address.toString())).toHaveLength(NUM_SENDERS + 1 + NUM_SENDERS / 2); // First sender should have 2 logs, but keep index 2 since they were built using the same tag - // Next 4 senders hould also have index 2 = offset + 1 + // Next 4 senders should also have index 2 = offset + 1 // Last 5 senders should have index 3 = offset + 2 const indexes = await database.getTaggingSecretsIndexesAsRecipient(secrets); expect(indexes).toHaveLength(NUM_SENDERS); expect(indexes).toEqual([2, 2, 2, 2, 2, 3, 3, 3, 3, 3]); - // We should have called the node 13 times: - // 1 time without logs + 2 times with logs (sliding the window) + 10 times with no results (window size) - expect(aztecNode.getLogsByTags.mock.calls.length).toBe(3 + SENDER_OFFSET_WINDOW_SIZE); + // We should have called the node 2 times: + // first time during initial request, second time after pushing the edge of the window once + expect(aztecNode.getLogsByTags.mock.calls.length).toBe(2); }); it("should not sync tagged logs for which indexes are not updated if they're outside the window", async () => { @@ -396,9 +397,8 @@ describe('Simulator oracle', () => { expect(indexes).toHaveLength(NUM_SENDERS); expect(indexes).toEqual([11, 11, 11, 11, 11, 11, 11, 11, 11, 11]); - // We should have called the node SENDER_OFFSET_WINDOW_SIZE + 1 (with logs) + SENDER_OFFSET_WINDOW_SIZE: - // Once for index 1 (NUM_SENDERS/2 logs) + 2 times the sliding window (no logs each time) - expect(aztecNode.getLogsByTags.mock.calls.length).toBe(1 + 2 * SENDER_OFFSET_WINDOW_SIZE); + // We should have called the node once and that is only for the first window + expect(aztecNode.getLogsByTags.mock.calls.length).toBe(1); }); it('should sync tagged logs from scratch after a DB wipe', async () => { @@ -420,8 +420,9 @@ describe('Simulator oracle', () => { // No logs should be synced since we start from index 2 = 12 - window_size expect(syncedLogs.get(recipient.address.toString())).toHaveLength(0); - // We should have called the node 21 times (window size + current_index + window size) - expect(aztecNode.getLogsByTags.mock.calls.length).toBe(2 * SENDER_OFFSET_WINDOW_SIZE + 1); + // Since no logs were synced, window edge hash not been pushed and for this reason we should have called + // the node only once for the initial window + expect(aztecNode.getLogsByTags.mock.calls.length).toBe(1); aztecNode.getLogsByTags.mockClear(); @@ -431,16 +432,16 @@ describe('Simulator oracle', () => { syncedLogs = await simulatorOracle.syncTaggedLogs(contractAddress, 3); // First sender should have 2 logs, but keep index 1 since they were built using the same tag - // Next 4 senders hould also have index 1 = offset + 1 + // Next 4 senders should also have index 1 = offset + 1 // Last 5 senders should have index 2 = offset + 2 const indexes = await database.getTaggingSecretsIndexesAsRecipient(secrets); expect(indexes).toHaveLength(NUM_SENDERS); expect(indexes).toEqual([1, 1, 1, 1, 1, 2, 2, 2, 2, 2]); - // We should have called the node 12 times: - // 2 times with logs (sliding the window) + 10 times with no results (window size) - expect(aztecNode.getLogsByTags.mock.calls.length).toBe(2 + SENDER_OFFSET_WINDOW_SIZE); + // We should have called the node 2 times: + // first time during initial request, second time after pushing the edge of the window once + expect(aztecNode.getLogsByTags.mock.calls.length).toBe(2); }); it('should not sync tagged logs with a blockNumber > maxBlockNumber', async () => {