Skip to content

Commit 4f3561f

Browse files
committed
wip
1 parent 07fba8a commit 4f3561f

File tree

1 file changed

+24
-29
lines changed

1 file changed

+24
-29
lines changed

yarn-project/pxe/src/tagging/sync_sender_tagging_indexes.test.ts

Lines changed: 24 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ describe('syncSenderTaggingIndexes', () => {
5656
const finalizedIndexStep1 = 3;
5757
const finalizedBlockNumberStep1 = 15;
5858

59-
let pendingTxHash: TxHash;
59+
const pendingTxHashStep2 = TxHash.random();
60+
const pendingIndexStep2 = 5;
6061

6162
beforeAll(async () => {
6263
await setUp();
@@ -95,17 +96,12 @@ describe('syncSenderTaggingIndexes', () => {
9596
});
9697

9798
it('step 2: pending log is synced', async () => {
98-
pendingTxHash = TxHash.random();
99-
100-
const pendingIndex = 5;
101-
102-
// Create a log with tag index 5
103-
const index5Tag = await computeSiloedTagForIndex(pendingIndex);
99+
const pendingTag = await computeSiloedTagForIndex(pendingIndexStep2);
104100

105101
aztecNode.getLogsByTags.mockImplementation((tags: Fr[]) => {
106-
// Return empty arrays for all tags except the one at index 5
102+
// Return empty arrays for all tags except the one at the pending index
107103
return Promise.resolve(
108-
tags.map((tag: Fr) => (tag.equals(index5Tag.value) ? [makeLog(pendingTxHash, index5Tag.value)] : [])),
104+
tags.map((tag: Fr) => (tag.equals(pendingTag.value) ? [makeLog(pendingTxHashStep2, pendingTag.value)] : [])),
109105
);
110106
});
111107

@@ -124,35 +120,34 @@ describe('syncSenderTaggingIndexes', () => {
124120
// Verify the highest finalized index was not updated
125121
expect(await taggingDataProvider.getHighestFinalizedIndex(secret)).toBe(finalizedIndexStep1);
126122
// Verify the highest used index was updated to the pending index
127-
expect(await taggingDataProvider.getHighestUsedIndexAsSender(secret)).toBe(pendingIndex);
123+
expect(await taggingDataProvider.getHighestUsedIndexAsSender(secret)).toBe(pendingIndexStep2);
128124
});
129125

130126
it('step 3: syncs logs across 2 windows', async () => {
131127
// Move finalized block into the future
132128
const newFinalizedBlockNumber = finalizedBlockNumberStep1 + 5;
133-
134-
const newHighestFinalizedIndex = 7;
129+
const newHighestFinalizedIndex = finalizedIndexStep1 + 4;
135130
const newHighestUsedIndex = newHighestFinalizedIndex + WINDOW_SIZE;
136131

137132
// Create tx hashes for new logs
138-
const index7TxHash = TxHash.random();
139-
const index36TxHash = TxHash.random();
133+
const newHighestFinalizedTxHash = TxHash.random();
134+
const newHighestUsedTxHash = TxHash.random();
140135

141136
// Create tags for multiple indices across 2 windows
142-
const index5Tag = await computeSiloedTagForIndex(5); // Previously pending, now finalized
143-
const index7Tag = await computeSiloedTagForIndex(newHighestFinalizedIndex); // New finalized log
144-
const index36Tag = await computeSiloedTagForIndex(newHighestUsedIndex); // New pending log
137+
const nowFinalizedTag = await computeSiloedTagForIndex(pendingIndexStep2); // Previously pending, now finalized
138+
const newHighestFinalizedTag = await computeSiloedTagForIndex(newHighestFinalizedIndex); // New finalized log
139+
const newHighestUsedTag = await computeSiloedTagForIndex(newHighestUsedIndex); // New pending log
145140

146141
// Mock getLogsByTags to return logs for multiple indices
147142
aztecNode.getLogsByTags.mockImplementation((tags: Fr[]) => {
148143
return Promise.resolve(
149144
tags.map((tag: Fr) => {
150-
if (tag.equals(index5Tag.value)) {
151-
return [makeLog(pendingTxHash, index5Tag.value)];
152-
} else if (tag.equals(index7Tag.value)) {
153-
return [makeLog(index7TxHash, index7Tag.value)];
154-
} else if (tag.equals(index36Tag.value)) {
155-
return [makeLog(index36TxHash, index36Tag.value)];
145+
if (tag.equals(nowFinalizedTag.value)) {
146+
return [makeLog(pendingTxHashStep2, nowFinalizedTag.value)];
147+
} else if (tag.equals(newHighestFinalizedTag.value)) {
148+
return [makeLog(newHighestFinalizedTxHash, newHighestFinalizedTag.value)];
149+
} else if (tag.equals(newHighestUsedTag.value)) {
150+
return [makeLog(newHighestUsedTxHash, newHighestUsedTag.value)];
156151
}
157152
return [];
158153
}),
@@ -161,20 +156,20 @@ describe('syncSenderTaggingIndexes', () => {
161156

162157
// Mock getTxReceipt to return appropriate statuses
163158
aztecNode.getTxReceipt.mockImplementation((hash: TxHash) => {
164-
if (hash.equals(pendingTxHash)) {
165-
// The previously pending tx (index 5) is now finalized
159+
if (hash.equals(pendingTxHashStep2)) {
160+
// The previously pending tx (index pendingIndexStep2) is now finalized
166161
return {
167162
status: TxStatus.SUCCESS,
168163
blockNumber: newFinalizedBlockNumber - 3,
169164
} as any;
170-
} else if (hash.equals(index7TxHash)) {
171-
// This tx (index 7) is finalized
165+
} else if (hash.equals(newHighestFinalizedTxHash)) {
166+
// This tx (index newHighestFinalizedIndex) is finalized
172167
return {
173168
status: TxStatus.SUCCESS,
174169
blockNumber: newFinalizedBlockNumber - 2,
175170
} as any;
176-
} else if (hash.equals(index36TxHash)) {
177-
// This tx (index 36) is pending
171+
} else if (hash.equals(newHighestUsedTxHash)) {
172+
// This tx (index newHighestUsedIndex) is pending
178173
return {
179174
status: TxStatus.SUCCESS,
180175
blockNumber: newFinalizedBlockNumber + 2,

0 commit comments

Comments
 (0)