Skip to content

Commit

Permalink
fixed simulator test
Browse files Browse the repository at this point in the history
  • Loading branch information
benesjan committed Dec 13, 2024
1 parent 372889c commit 9754033
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions yarn-project/pxe/src/simulator_oracle/simulator_oracle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand Down Expand Up @@ -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 () => {
Expand All @@ -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();

Expand All @@ -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 () => {
Expand Down

0 comments on commit 9754033

Please sign in to comment.