@aztec/archiver 0.0.0-test.0 → 0.0.1-commit.023c3e5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (225) hide show
  1. package/README.md +164 -9
  2. package/dest/archiver.d.ts +136 -0
  3. package/dest/archiver.d.ts.map +1 -0
  4. package/dest/archiver.js +781 -0
  5. package/dest/config.d.ts +30 -0
  6. package/dest/config.d.ts.map +1 -0
  7. package/dest/config.js +71 -0
  8. package/dest/errors.d.ts +41 -0
  9. package/dest/errors.d.ts.map +1 -0
  10. package/dest/errors.js +62 -0
  11. package/dest/factory.d.ts +13 -16
  12. package/dest/factory.d.ts.map +1 -1
  13. package/dest/factory.js +103 -55
  14. package/dest/index.d.ts +10 -4
  15. package/dest/index.d.ts.map +1 -1
  16. package/dest/index.js +8 -3
  17. package/dest/interfaces.d.ts +9 -0
  18. package/dest/interfaces.d.ts.map +1 -0
  19. package/dest/interfaces.js +3 -0
  20. package/dest/l1/bin/retrieve-calldata.d.ts +3 -0
  21. package/dest/l1/bin/retrieve-calldata.d.ts.map +1 -0
  22. package/dest/l1/bin/retrieve-calldata.js +149 -0
  23. package/dest/l1/calldata_retriever.d.ts +112 -0
  24. package/dest/l1/calldata_retriever.d.ts.map +1 -0
  25. package/dest/l1/calldata_retriever.js +471 -0
  26. package/dest/l1/data_retrieval.d.ts +88 -0
  27. package/dest/l1/data_retrieval.d.ts.map +1 -0
  28. package/dest/l1/data_retrieval.js +312 -0
  29. package/dest/l1/debug_tx.d.ts +19 -0
  30. package/dest/l1/debug_tx.d.ts.map +1 -0
  31. package/dest/l1/debug_tx.js +73 -0
  32. package/dest/l1/spire_proposer.d.ts +70 -0
  33. package/dest/l1/spire_proposer.d.ts.map +1 -0
  34. package/dest/l1/spire_proposer.js +157 -0
  35. package/dest/l1/trace_tx.d.ts +97 -0
  36. package/dest/l1/trace_tx.d.ts.map +1 -0
  37. package/dest/l1/trace_tx.js +91 -0
  38. package/dest/l1/types.d.ts +12 -0
  39. package/dest/l1/types.d.ts.map +1 -0
  40. package/dest/l1/types.js +3 -0
  41. package/dest/l1/validate_trace.d.ts +32 -0
  42. package/dest/l1/validate_trace.d.ts.map +1 -0
  43. package/dest/l1/validate_trace.js +154 -0
  44. package/dest/modules/data_source_base.d.ts +84 -0
  45. package/dest/modules/data_source_base.d.ts.map +1 -0
  46. package/dest/modules/data_source_base.js +260 -0
  47. package/dest/modules/data_store_updater.d.ts +73 -0
  48. package/dest/modules/data_store_updater.d.ts.map +1 -0
  49. package/dest/modules/data_store_updater.js +302 -0
  50. package/dest/modules/instrumentation.d.ts +37 -0
  51. package/dest/modules/instrumentation.d.ts.map +1 -0
  52. package/dest/modules/instrumentation.js +110 -0
  53. package/dest/modules/l1_synchronizer.d.ts +75 -0
  54. package/dest/modules/l1_synchronizer.d.ts.map +1 -0
  55. package/dest/modules/l1_synchronizer.js +1112 -0
  56. package/dest/modules/validation.d.ts +17 -0
  57. package/dest/modules/validation.d.ts.map +1 -0
  58. package/dest/modules/validation.js +104 -0
  59. package/dest/store/block_store.d.ts +192 -0
  60. package/dest/store/block_store.d.ts.map +1 -0
  61. package/dest/store/block_store.js +721 -0
  62. package/dest/store/contract_class_store.d.ts +18 -0
  63. package/dest/store/contract_class_store.d.ts.map +1 -0
  64. package/dest/{archiver/kv_archiver_store → store}/contract_class_store.js +25 -27
  65. package/dest/store/contract_instance_store.d.ts +24 -0
  66. package/dest/store/contract_instance_store.d.ts.map +1 -0
  67. package/dest/store/contract_instance_store.js +77 -0
  68. package/dest/store/kv_archiver_store.d.ts +340 -0
  69. package/dest/store/kv_archiver_store.d.ts.map +1 -0
  70. package/dest/store/kv_archiver_store.js +446 -0
  71. package/dest/store/log_store.d.ts +54 -0
  72. package/dest/store/log_store.d.ts.map +1 -0
  73. package/dest/store/log_store.js +436 -0
  74. package/dest/store/message_store.d.ts +40 -0
  75. package/dest/store/message_store.d.ts.map +1 -0
  76. package/dest/store/message_store.js +188 -0
  77. package/dest/structs/data_retrieval.d.ts +27 -0
  78. package/dest/structs/data_retrieval.d.ts.map +1 -0
  79. package/dest/structs/inbox_message.d.ts +15 -0
  80. package/dest/structs/inbox_message.d.ts.map +1 -0
  81. package/dest/structs/inbox_message.js +39 -0
  82. package/dest/structs/published.d.ts +2 -0
  83. package/dest/structs/published.d.ts.map +1 -0
  84. package/dest/structs/published.js +1 -0
  85. package/dest/test/fake_l1_state.d.ts +190 -0
  86. package/dest/test/fake_l1_state.d.ts.map +1 -0
  87. package/dest/test/fake_l1_state.js +383 -0
  88. package/dest/test/index.d.ts +2 -1
  89. package/dest/test/index.d.ts.map +1 -1
  90. package/dest/test/index.js +4 -1
  91. package/dest/test/mock_archiver.d.ts +16 -8
  92. package/dest/test/mock_archiver.d.ts.map +1 -1
  93. package/dest/test/mock_archiver.js +18 -14
  94. package/dest/test/mock_l1_to_l2_message_source.d.ts +9 -6
  95. package/dest/test/mock_l1_to_l2_message_source.d.ts.map +1 -1
  96. package/dest/test/mock_l1_to_l2_message_source.js +30 -7
  97. package/dest/test/mock_l2_block_source.d.ts +62 -16
  98. package/dest/test/mock_l2_block_source.d.ts.map +1 -1
  99. package/dest/test/mock_l2_block_source.js +263 -32
  100. package/dest/test/mock_structs.d.ts +85 -0
  101. package/dest/test/mock_structs.d.ts.map +1 -0
  102. package/dest/test/mock_structs.js +171 -0
  103. package/dest/test/noop_l1_archiver.d.ts +23 -0
  104. package/dest/test/noop_l1_archiver.d.ts.map +1 -0
  105. package/dest/test/noop_l1_archiver.js +68 -0
  106. package/package.json +31 -33
  107. package/src/archiver.ts +543 -0
  108. package/src/config.ts +95 -0
  109. package/src/errors.ts +102 -0
  110. package/src/factory.ts +144 -71
  111. package/src/index.ts +10 -3
  112. package/src/interfaces.ts +9 -0
  113. package/src/l1/README.md +98 -0
  114. package/src/l1/bin/retrieve-calldata.ts +187 -0
  115. package/src/l1/calldata_retriever.ts +641 -0
  116. package/src/l1/data_retrieval.ts +495 -0
  117. package/src/l1/debug_tx.ts +99 -0
  118. package/src/l1/spire_proposer.ts +160 -0
  119. package/src/l1/trace_tx.ts +128 -0
  120. package/src/l1/types.ts +13 -0
  121. package/src/l1/validate_trace.ts +229 -0
  122. package/src/modules/data_source_base.ts +367 -0
  123. package/src/modules/data_store_updater.ts +423 -0
  124. package/src/modules/instrumentation.ts +157 -0
  125. package/src/modules/l1_synchronizer.ts +930 -0
  126. package/src/modules/validation.ts +129 -0
  127. package/src/store/block_store.ts +966 -0
  128. package/src/{archiver/kv_archiver_store → store}/contract_class_store.ts +26 -32
  129. package/src/{archiver/kv_archiver_store → store}/contract_instance_store.ts +37 -29
  130. package/src/store/kv_archiver_store.ts +639 -0
  131. package/src/store/log_store.ts +575 -0
  132. package/src/store/message_store.ts +261 -0
  133. package/src/structs/inbox_message.ts +41 -0
  134. package/src/structs/published.ts +1 -0
  135. package/src/test/fake_l1_state.ts +599 -0
  136. package/src/test/fixtures/debug_traceTransaction-multicall3.json +88 -0
  137. package/src/test/fixtures/debug_traceTransaction-multiplePropose.json +153 -0
  138. package/src/test/fixtures/debug_traceTransaction-proxied.json +122 -0
  139. package/src/test/fixtures/trace_transaction-multicall3.json +65 -0
  140. package/src/test/fixtures/trace_transaction-multiplePropose.json +319 -0
  141. package/src/test/fixtures/trace_transaction-proxied.json +128 -0
  142. package/src/test/fixtures/trace_transaction-randomRevert.json +216 -0
  143. package/src/test/index.ts +4 -0
  144. package/src/test/mock_archiver.ts +22 -16
  145. package/src/test/mock_l1_to_l2_message_source.ts +26 -8
  146. package/src/test/mock_l2_block_source.ts +313 -42
  147. package/src/test/mock_structs.ts +311 -0
  148. package/src/test/noop_l1_archiver.ts +109 -0
  149. package/dest/archiver/archiver.d.ts +0 -197
  150. package/dest/archiver/archiver.d.ts.map +0 -1
  151. package/dest/archiver/archiver.js +0 -900
  152. package/dest/archiver/archiver_store.d.ts +0 -220
  153. package/dest/archiver/archiver_store.d.ts.map +0 -1
  154. package/dest/archiver/archiver_store.js +0 -4
  155. package/dest/archiver/archiver_store_test_suite.d.ts +0 -8
  156. package/dest/archiver/archiver_store_test_suite.d.ts.map +0 -1
  157. package/dest/archiver/archiver_store_test_suite.js +0 -794
  158. package/dest/archiver/config.d.ts +0 -37
  159. package/dest/archiver/config.d.ts.map +0 -1
  160. package/dest/archiver/config.js +0 -46
  161. package/dest/archiver/data_retrieval.d.ts +0 -74
  162. package/dest/archiver/data_retrieval.d.ts.map +0 -1
  163. package/dest/archiver/data_retrieval.js +0 -283
  164. package/dest/archiver/errors.d.ts +0 -4
  165. package/dest/archiver/errors.d.ts.map +0 -1
  166. package/dest/archiver/errors.js +0 -5
  167. package/dest/archiver/index.d.ts +0 -8
  168. package/dest/archiver/index.d.ts.map +0 -1
  169. package/dest/archiver/index.js +0 -5
  170. package/dest/archiver/instrumentation.d.ts +0 -29
  171. package/dest/archiver/instrumentation.d.ts.map +0 -1
  172. package/dest/archiver/instrumentation.js +0 -99
  173. package/dest/archiver/kv_archiver_store/block_store.d.ts +0 -87
  174. package/dest/archiver/kv_archiver_store/block_store.d.ts.map +0 -1
  175. package/dest/archiver/kv_archiver_store/block_store.js +0 -217
  176. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts +0 -18
  177. package/dest/archiver/kv_archiver_store/contract_class_store.d.ts.map +0 -1
  178. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts +0 -21
  179. package/dest/archiver/kv_archiver_store/contract_instance_store.d.ts.map +0 -1
  180. package/dest/archiver/kv_archiver_store/contract_instance_store.js +0 -63
  181. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts +0 -153
  182. package/dest/archiver/kv_archiver_store/kv_archiver_store.d.ts.map +0 -1
  183. package/dest/archiver/kv_archiver_store/kv_archiver_store.js +0 -254
  184. package/dest/archiver/kv_archiver_store/log_store.d.ts +0 -49
  185. package/dest/archiver/kv_archiver_store/log_store.d.ts.map +0 -1
  186. package/dest/archiver/kv_archiver_store/log_store.js +0 -364
  187. package/dest/archiver/kv_archiver_store/message_store.d.ts +0 -33
  188. package/dest/archiver/kv_archiver_store/message_store.d.ts.map +0 -1
  189. package/dest/archiver/kv_archiver_store/message_store.js +0 -85
  190. package/dest/archiver/kv_archiver_store/nullifier_store.d.ts +0 -12
  191. package/dest/archiver/kv_archiver_store/nullifier_store.d.ts.map +0 -1
  192. package/dest/archiver/kv_archiver_store/nullifier_store.js +0 -73
  193. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts +0 -23
  194. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.d.ts.map +0 -1
  195. package/dest/archiver/memory_archiver_store/l1_to_l2_message_store.js +0 -49
  196. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts +0 -175
  197. package/dest/archiver/memory_archiver_store/memory_archiver_store.d.ts.map +0 -1
  198. package/dest/archiver/memory_archiver_store/memory_archiver_store.js +0 -636
  199. package/dest/archiver/structs/data_retrieval.d.ts +0 -27
  200. package/dest/archiver/structs/data_retrieval.d.ts.map +0 -1
  201. package/dest/archiver/structs/published.d.ts +0 -11
  202. package/dest/archiver/structs/published.d.ts.map +0 -1
  203. package/dest/archiver/structs/published.js +0 -1
  204. package/dest/rpc/index.d.ts +0 -10
  205. package/dest/rpc/index.d.ts.map +0 -1
  206. package/dest/rpc/index.js +0 -18
  207. package/src/archiver/archiver.ts +0 -1181
  208. package/src/archiver/archiver_store.ts +0 -263
  209. package/src/archiver/archiver_store_test_suite.ts +0 -810
  210. package/src/archiver/config.ts +0 -92
  211. package/src/archiver/data_retrieval.ts +0 -422
  212. package/src/archiver/errors.ts +0 -5
  213. package/src/archiver/index.ts +0 -7
  214. package/src/archiver/instrumentation.ts +0 -132
  215. package/src/archiver/kv_archiver_store/block_store.ts +0 -283
  216. package/src/archiver/kv_archiver_store/kv_archiver_store.ts +0 -358
  217. package/src/archiver/kv_archiver_store/log_store.ts +0 -444
  218. package/src/archiver/kv_archiver_store/message_store.ts +0 -102
  219. package/src/archiver/kv_archiver_store/nullifier_store.ts +0 -97
  220. package/src/archiver/memory_archiver_store/l1_to_l2_message_store.ts +0 -61
  221. package/src/archiver/memory_archiver_store/memory_archiver_store.ts +0 -801
  222. package/src/archiver/structs/published.ts +0 -11
  223. package/src/rpc/index.ts +0 -20
  224. /package/dest/{archiver/structs → structs}/data_retrieval.js +0 -0
  225. /package/src/{archiver/structs → structs}/data_retrieval.ts +0 -0
@@ -1,794 +0,0 @@
1
- import { INITIAL_L2_BLOCK_NUM, L1_TO_L2_MSG_SUBTREE_HEIGHT, MAX_NULLIFIERS_PER_TX, PRIVATE_LOG_SIZE_IN_FIELDS, PUBLIC_LOG_DATA_SIZE_IN_FIELDS } from '@aztec/constants';
2
- import { times, timesParallel } from '@aztec/foundation/collection';
3
- import { randomInt } from '@aztec/foundation/crypto';
4
- import { Fr } from '@aztec/foundation/fields';
5
- import { AztecAddress } from '@aztec/stdlib/aztec-address';
6
- import { L2Block, wrapInBlock } from '@aztec/stdlib/block';
7
- import { SerializableContractInstance, computePublicBytecodeCommitment } from '@aztec/stdlib/contract';
8
- import { LogId, PrivateLog, PublicLog } from '@aztec/stdlib/logs';
9
- import { InboxLeaf } from '@aztec/stdlib/messaging';
10
- import { makeContractClassPublic, makeExecutablePrivateFunctionWithMembershipProof, makeUnconstrainedFunctionWithMembershipProof } from '@aztec/stdlib/testing';
11
- import '@aztec/stdlib/testing/jest';
12
- import { TxEffect, TxHash } from '@aztec/stdlib/tx';
13
- /**
14
- * @param testName - The name of the test suite.
15
- * @param getStore - Returns an instance of a store that's already been initialized.
16
- */ export function describeArchiverDataStore(testName, getStore) {
17
- describe(testName, ()=>{
18
- let store;
19
- let blocks;
20
- const blockTests = [
21
- [
22
- 1,
23
- 1,
24
- ()=>blocks.slice(0, 1)
25
- ],
26
- [
27
- 10,
28
- 1,
29
- ()=>blocks.slice(9, 10)
30
- ],
31
- [
32
- 1,
33
- 10,
34
- ()=>blocks.slice(0, 10)
35
- ],
36
- [
37
- 2,
38
- 5,
39
- ()=>blocks.slice(1, 6)
40
- ],
41
- [
42
- 5,
43
- 2,
44
- ()=>blocks.slice(4, 6)
45
- ]
46
- ];
47
- const makeL1Published = (block, l1BlockNumber)=>({
48
- data: block,
49
- l1: {
50
- blockNumber: BigInt(l1BlockNumber),
51
- blockHash: `0x${l1BlockNumber}`,
52
- timestamp: BigInt(l1BlockNumber * 1000)
53
- }
54
- });
55
- beforeEach(async ()=>{
56
- store = await getStore();
57
- blocks = await timesParallel(10, async (i)=>makeL1Published(await L2Block.random(i + 1), i + 10));
58
- });
59
- describe('addBlocks', ()=>{
60
- it('returns success when adding blocks', async ()=>{
61
- await expect(store.addBlocks(blocks)).resolves.toBe(true);
62
- });
63
- it('allows duplicate blocks', async ()=>{
64
- await store.addBlocks(blocks);
65
- await expect(store.addBlocks(blocks)).resolves.toBe(true);
66
- });
67
- });
68
- describe('unwindBlocks', ()=>{
69
- it('unwinding blocks will remove blocks from the chain', async ()=>{
70
- await store.addBlocks(blocks);
71
- const blockNumber = await store.getSynchedL2BlockNumber();
72
- expect(await store.getBlocks(blockNumber, 1)).toEqual([
73
- blocks[blocks.length - 1]
74
- ]);
75
- await store.unwindBlocks(blockNumber, 1);
76
- expect(await store.getSynchedL2BlockNumber()).toBe(blockNumber - 1);
77
- expect(await store.getBlocks(blockNumber, 1)).toEqual([]);
78
- });
79
- it('can unwind multiple empty blocks', async ()=>{
80
- const emptyBlocks = await timesParallel(10, async (i)=>makeL1Published(await L2Block.random(i + 1, 0), i + 10));
81
- await store.addBlocks(emptyBlocks);
82
- expect(await store.getSynchedL2BlockNumber()).toBe(10);
83
- await store.unwindBlocks(10, 3);
84
- expect(await store.getSynchedL2BlockNumber()).toBe(7);
85
- expect((await store.getBlocks(1, 10)).map((b)=>b.data.number)).toEqual([
86
- 1,
87
- 2,
88
- 3,
89
- 4,
90
- 5,
91
- 6,
92
- 7
93
- ]);
94
- });
95
- it('refuses to unwind blocks if the tip is not the last block', async ()=>{
96
- await store.addBlocks(blocks);
97
- await expect(store.unwindBlocks(5, 1)).rejects.toThrow(/can only unwind blocks from the tip/i);
98
- });
99
- });
100
- describe('getBlocks', ()=>{
101
- beforeEach(async ()=>{
102
- await store.addBlocks(blocks);
103
- });
104
- it.each(blockTests)('retrieves previously stored blocks', async (start, limit, getExpectedBlocks)=>{
105
- await expect(store.getBlocks(start, limit)).resolves.toEqual(getExpectedBlocks());
106
- });
107
- it('returns an empty array if no blocks are found', async ()=>{
108
- await expect(store.getBlocks(12, 1)).resolves.toEqual([]);
109
- });
110
- it('throws an error if limit is invalid', async ()=>{
111
- await expect(store.getBlocks(1, 0)).rejects.toThrow('Invalid limit: 0');
112
- });
113
- it('throws an error if `from` it is out of range', async ()=>{
114
- await expect(store.getBlocks(INITIAL_L2_BLOCK_NUM - 100, 1)).rejects.toThrow('Invalid start: -99');
115
- });
116
- });
117
- describe('getSyncedL2BlockNumber', ()=>{
118
- it('returns the block number before INITIAL_L2_BLOCK_NUM if no blocks have been added', async ()=>{
119
- await expect(store.getSynchedL2BlockNumber()).resolves.toEqual(INITIAL_L2_BLOCK_NUM - 1);
120
- });
121
- it("returns the most recently added block's number", async ()=>{
122
- await store.addBlocks(blocks);
123
- await expect(store.getSynchedL2BlockNumber()).resolves.toEqual(blocks.at(-1).data.number);
124
- });
125
- });
126
- describe('getSynchPoint', ()=>{
127
- it('returns undefined if no blocks have been added', async ()=>{
128
- await expect(store.getSynchPoint()).resolves.toEqual({
129
- blocksSynchedTo: undefined,
130
- messagesSynchedTo: undefined
131
- });
132
- });
133
- it('returns the L1 block number in which the most recent L2 block was published', async ()=>{
134
- await store.addBlocks(blocks);
135
- await expect(store.getSynchPoint()).resolves.toEqual({
136
- blocksSynchedTo: 19n,
137
- messagesSynchedTo: undefined
138
- });
139
- });
140
- it('returns the L1 block number that most recently added messages from inbox', async ()=>{
141
- await store.addL1ToL2Messages({
142
- lastProcessedL1BlockNumber: 1n,
143
- retrievedData: [
144
- new InboxLeaf(1n, Fr.ZERO)
145
- ]
146
- });
147
- await expect(store.getSynchPoint()).resolves.toEqual({
148
- blocksSynchedTo: undefined,
149
- messagesSynchedTo: 1n
150
- });
151
- });
152
- });
153
- describe('addLogs', ()=>{
154
- it('adds private & public logs', async ()=>{
155
- const block = blocks[0].data;
156
- await expect(store.addLogs([
157
- block
158
- ])).resolves.toEqual(true);
159
- });
160
- });
161
- describe('deleteLogs', ()=>{
162
- it('deletes private & public logs', async ()=>{
163
- const block = blocks[0].data;
164
- await store.addBlocks([
165
- blocks[0]
166
- ]);
167
- await expect(store.addLogs([
168
- block
169
- ])).resolves.toEqual(true);
170
- expect((await store.getPrivateLogs(1, 1)).length).toEqual(block.body.txEffects.map((txEffect)=>txEffect.privateLogs).flat().length);
171
- expect((await store.getPublicLogs({
172
- fromBlock: 1
173
- })).logs.length).toEqual(block.body.txEffects.map((txEffect)=>txEffect.publicLogs).flat().length);
174
- // This one is a pain for memory as we would never want to just delete memory in the middle.
175
- await store.deleteLogs([
176
- block
177
- ]);
178
- expect((await store.getPrivateLogs(1, 1)).length).toEqual(0);
179
- expect((await store.getPublicLogs({
180
- fromBlock: 1
181
- })).logs.length).toEqual(0);
182
- });
183
- });
184
- describe('getPrivateLogs', ()=>{
185
- it('gets added private logs', async ()=>{
186
- const block = blocks[0].data;
187
- await store.addBlocks([
188
- blocks[0]
189
- ]);
190
- await store.addLogs([
191
- block
192
- ]);
193
- const privateLogs = await store.getPrivateLogs(1, 1);
194
- expect(privateLogs).toEqual(block.body.txEffects.map((txEffect)=>txEffect.privateLogs).flat());
195
- });
196
- });
197
- describe('getTxEffect', ()=>{
198
- beforeEach(async ()=>{
199
- await store.addLogs(blocks.map((b)=>b.data));
200
- await store.addBlocks(blocks);
201
- });
202
- it.each([
203
- ()=>wrapInBlock(blocks[0].data.body.txEffects[0], blocks[0].data),
204
- ()=>wrapInBlock(blocks[9].data.body.txEffects[3], blocks[9].data),
205
- ()=>wrapInBlock(blocks[3].data.body.txEffects[1], blocks[3].data),
206
- ()=>wrapInBlock(blocks[5].data.body.txEffects[2], blocks[5].data),
207
- ()=>wrapInBlock(blocks[1].data.body.txEffects[0], blocks[1].data)
208
- ])('retrieves a previously stored transaction', async (getExpectedTx)=>{
209
- const expectedTx = await getExpectedTx();
210
- const actualTx = await store.getTxEffect(expectedTx.data.txHash);
211
- expect(actualTx).toEqual(expectedTx);
212
- });
213
- it('returns undefined if tx is not found', async ()=>{
214
- await expect(store.getTxEffect(TxHash.random())).resolves.toBeUndefined();
215
- });
216
- it.each([
217
- ()=>wrapInBlock(blocks[0].data.body.txEffects[0], blocks[0].data),
218
- ()=>wrapInBlock(blocks[9].data.body.txEffects[3], blocks[9].data),
219
- ()=>wrapInBlock(blocks[3].data.body.txEffects[1], blocks[3].data),
220
- ()=>wrapInBlock(blocks[5].data.body.txEffects[2], blocks[5].data),
221
- ()=>wrapInBlock(blocks[1].data.body.txEffects[0], blocks[1].data)
222
- ])('tries to retrieves a previously stored transaction after deleted', async (getExpectedTx)=>{
223
- await store.unwindBlocks(blocks.length, blocks.length);
224
- const expectedTx = await getExpectedTx();
225
- const actualTx = await store.getTxEffect(expectedTx.data.txHash);
226
- expect(actualTx).toEqual(undefined);
227
- });
228
- it('returns undefined if tx is not found', async ()=>{
229
- await expect(store.getTxEffect(TxHash.random())).resolves.toBeUndefined();
230
- });
231
- });
232
- describe('L1 to L2 Messages', ()=>{
233
- const l2BlockNumber = 13n;
234
- const l1ToL2MessageSubtreeSize = 2 ** L1_TO_L2_MSG_SUBTREE_HEIGHT;
235
- const generateBlockMessages = (blockNumber, numMessages)=>Array.from({
236
- length: numMessages
237
- }, (_, i)=>new InboxLeaf(InboxLeaf.smallestIndexFromL2Block(blockNumber) + BigInt(i), Fr.random()));
238
- it('returns messages in correct order', async ()=>{
239
- const msgs = generateBlockMessages(l2BlockNumber, l1ToL2MessageSubtreeSize);
240
- const shuffledMessages = msgs.slice().sort(()=>randomInt(1) - 0.5);
241
- await store.addL1ToL2Messages({
242
- lastProcessedL1BlockNumber: 100n,
243
- retrievedData: shuffledMessages
244
- });
245
- const retrievedMessages = await store.getL1ToL2Messages(l2BlockNumber);
246
- const expectedLeavesOrder = msgs.map((msg)=>msg.leaf);
247
- expect(expectedLeavesOrder).toEqual(retrievedMessages);
248
- });
249
- it('throws if it is impossible to sequence messages correctly', async ()=>{
250
- const msgs = generateBlockMessages(l2BlockNumber, l1ToL2MessageSubtreeSize - 1);
251
- // We replace a message with index 4 with a message with index at the end of the tree
252
- // --> with that there will be a gap and it will be impossible to sequence the
253
- // end of tree = start of next tree/block - 1
254
- msgs[4] = new InboxLeaf(InboxLeaf.smallestIndexFromL2Block(l2BlockNumber + 1n) - 1n, Fr.random());
255
- await store.addL1ToL2Messages({
256
- lastProcessedL1BlockNumber: 100n,
257
- retrievedData: msgs
258
- });
259
- await expect(async ()=>{
260
- await store.getL1ToL2Messages(l2BlockNumber);
261
- }).rejects.toThrow(`L1 to L2 message gap found in block ${l2BlockNumber}`);
262
- });
263
- });
264
- describe('contractInstances', ()=>{
265
- let contractInstance;
266
- const blockNum = 10;
267
- beforeEach(async ()=>{
268
- const classId = Fr.random();
269
- const randomInstance = await SerializableContractInstance.random({
270
- currentContractClassId: classId,
271
- originalContractClassId: classId
272
- });
273
- contractInstance = {
274
- ...randomInstance,
275
- address: await AztecAddress.random()
276
- };
277
- await store.addContractInstances([
278
- contractInstance
279
- ], blockNum);
280
- });
281
- it('returns previously stored contract instances', async ()=>{
282
- await expect(store.getContractInstance(contractInstance.address)).resolves.toMatchObject(contractInstance);
283
- });
284
- it('returns undefined if contract instance is not found', async ()=>{
285
- await expect(store.getContractInstance(await AztecAddress.random())).resolves.toBeUndefined();
286
- });
287
- it('returns undefined if previously stored contract instances was deleted', async ()=>{
288
- await store.deleteContractInstances([
289
- contractInstance
290
- ], blockNum);
291
- await expect(store.getContractInstance(contractInstance.address)).resolves.toBeUndefined();
292
- });
293
- });
294
- describe('contractClasses', ()=>{
295
- let contractClass;
296
- const blockNum = 10;
297
- beforeEach(async ()=>{
298
- contractClass = await makeContractClassPublic();
299
- await store.addContractClasses([
300
- contractClass
301
- ], [
302
- await computePublicBytecodeCommitment(contractClass.packedBytecode)
303
- ], blockNum);
304
- });
305
- it('returns previously stored contract class', async ()=>{
306
- await expect(store.getContractClass(contractClass.id)).resolves.toMatchObject(contractClass);
307
- });
308
- it('returns undefined if the initial deployed contract class was deleted', async ()=>{
309
- await store.deleteContractClasses([
310
- contractClass
311
- ], blockNum);
312
- await expect(store.getContractClass(contractClass.id)).resolves.toBeUndefined();
313
- });
314
- it('returns contract class if later "deployment" class was deleted', async ()=>{
315
- await store.addContractClasses([
316
- contractClass
317
- ], [
318
- await computePublicBytecodeCommitment(contractClass.packedBytecode)
319
- ], blockNum + 1);
320
- await store.deleteContractClasses([
321
- contractClass
322
- ], blockNum + 1);
323
- await expect(store.getContractClass(contractClass.id)).resolves.toMatchObject(contractClass);
324
- });
325
- it('returns undefined if contract class is not found', async ()=>{
326
- await expect(store.getContractClass(Fr.random())).resolves.toBeUndefined();
327
- });
328
- it('adds new private functions', async ()=>{
329
- const fns = times(3, makeExecutablePrivateFunctionWithMembershipProof);
330
- await store.addFunctions(contractClass.id, fns, []);
331
- const stored = await store.getContractClass(contractClass.id);
332
- expect(stored?.privateFunctions).toEqual(fns);
333
- });
334
- it('does not duplicate private functions', async ()=>{
335
- const fns = times(3, makeExecutablePrivateFunctionWithMembershipProof);
336
- await store.addFunctions(contractClass.id, fns.slice(0, 1), []);
337
- await store.addFunctions(contractClass.id, fns, []);
338
- const stored = await store.getContractClass(contractClass.id);
339
- expect(stored?.privateFunctions).toEqual(fns);
340
- });
341
- it('adds new unconstrained functions', async ()=>{
342
- const fns = times(3, makeUnconstrainedFunctionWithMembershipProof);
343
- await store.addFunctions(contractClass.id, [], fns);
344
- const stored = await store.getContractClass(contractClass.id);
345
- expect(stored?.unconstrainedFunctions).toEqual(fns);
346
- });
347
- it('does not duplicate unconstrained functions', async ()=>{
348
- const fns = times(3, makeUnconstrainedFunctionWithMembershipProof);
349
- await store.addFunctions(contractClass.id, [], fns.slice(0, 1));
350
- await store.addFunctions(contractClass.id, [], fns);
351
- const stored = await store.getContractClass(contractClass.id);
352
- expect(stored?.unconstrainedFunctions).toEqual(fns);
353
- });
354
- });
355
- describe('getLogsByTags', ()=>{
356
- const numBlocks = 3;
357
- const numTxsPerBlock = 4;
358
- const numPrivateLogsPerTx = 3;
359
- const numPublicLogsPerTx = 2;
360
- let blocks;
361
- const makeTag = (blockNumber, txIndex, logIndex, isPublic = false)=>new Fr((blockNumber * 100 + txIndex * 10 + logIndex) * (isPublic ? 123 : 1));
362
- // See parseLogFromPublic
363
- // Search the codebase for "disgusting encoding" to see other hardcoded instances of this encoding, that you might need to change if you ever find yourself here.
364
- const makeLengthsField = (publicValuesLen, privateValuesLen)=>{
365
- const buf = Buffer.alloc(32);
366
- buf.writeUint16BE(publicValuesLen, 27);
367
- buf.writeUint16BE(privateValuesLen, 30);
368
- return Fr.fromBuffer(buf);
369
- };
370
- const makePrivateLog = (tag)=>PrivateLog.fromFields([
371
- tag,
372
- ...times(PRIVATE_LOG_SIZE_IN_FIELDS - 1, (i)=>new Fr(tag.toNumber() + i))
373
- ]);
374
- // The tag lives in field 1, not 0, of a public log
375
- // See extractTaggedLogsFromPublic and noir-projects/aztec-nr/aztec/src/macros/notes/mod.nr -> emit_log
376
- const makePublicLog = (tag)=>PublicLog.fromFields([
377
- AztecAddress.fromNumber(1).toField(),
378
- makeLengthsField(2, PUBLIC_LOG_DATA_SIZE_IN_FIELDS - 3),
379
- tag,
380
- ...times(PUBLIC_LOG_DATA_SIZE_IN_FIELDS - 1, (i)=>new Fr(tag.toNumber() + i))
381
- ]);
382
- const mockPrivateLogs = (blockNumber, txIndex)=>{
383
- return times(numPrivateLogsPerTx, (logIndex)=>{
384
- const tag = makeTag(blockNumber, txIndex, logIndex);
385
- return makePrivateLog(tag);
386
- });
387
- };
388
- const mockPublicLogs = (blockNumber, txIndex)=>{
389
- return times(numPublicLogsPerTx, (logIndex)=>{
390
- const tag = makeTag(blockNumber, txIndex, logIndex, /* isPublic */ true);
391
- return makePublicLog(tag);
392
- });
393
- };
394
- const mockBlockWithLogs = async (blockNumber)=>{
395
- const block = await L2Block.random(blockNumber);
396
- block.header.globalVariables.blockNumber = new Fr(blockNumber);
397
- block.body.txEffects = await timesParallel(numTxsPerBlock, async (txIndex)=>{
398
- const txEffect = await TxEffect.random();
399
- txEffect.privateLogs = mockPrivateLogs(blockNumber, txIndex);
400
- txEffect.publicLogs = mockPublicLogs(blockNumber, txIndex);
401
- return txEffect;
402
- });
403
- return {
404
- data: block,
405
- l1: {
406
- blockNumber: BigInt(blockNumber),
407
- blockHash: `0x${blockNumber}`,
408
- timestamp: BigInt(blockNumber)
409
- }
410
- };
411
- };
412
- beforeEach(async ()=>{
413
- blocks = await timesParallel(numBlocks, (index)=>mockBlockWithLogs(index));
414
- await store.addBlocks(blocks);
415
- await store.addLogs(blocks.map((b)=>b.data));
416
- });
417
- it('is possible to batch request private logs via tags', async ()=>{
418
- const tags = [
419
- makeTag(1, 1, 2),
420
- makeTag(0, 2, 0)
421
- ];
422
- const logsByTags = await store.getLogsByTags(tags);
423
- expect(logsByTags).toEqual([
424
- [
425
- expect.objectContaining({
426
- blockNumber: 1,
427
- logData: makePrivateLog(tags[0]).toBuffer(),
428
- isFromPublic: false
429
- })
430
- ],
431
- [
432
- expect.objectContaining({
433
- blockNumber: 0,
434
- logData: makePrivateLog(tags[1]).toBuffer(),
435
- isFromPublic: false
436
- })
437
- ]
438
- ]);
439
- });
440
- it('is possible to batch request all logs (private and public) via tags', async ()=>{
441
- // Tag(0, 0, 0) is shared with the first private log and the first public log.
442
- const tags = [
443
- makeTag(0, 0, 0)
444
- ];
445
- const logsByTags = await store.getLogsByTags(tags);
446
- expect(logsByTags).toEqual([
447
- [
448
- expect.objectContaining({
449
- blockNumber: 0,
450
- logData: makePrivateLog(tags[0]).toBuffer(),
451
- isFromPublic: false
452
- }),
453
- expect.objectContaining({
454
- blockNumber: 0,
455
- logData: makePublicLog(tags[0]).toBuffer(),
456
- isFromPublic: true
457
- })
458
- ]
459
- ]);
460
- });
461
- it('is possible to batch request logs that have the same tag but different content', async ()=>{
462
- const tags = [
463
- makeTag(1, 2, 1)
464
- ];
465
- // Create a block containing logs that have the same tag as the blocks before.
466
- const newBlockNumber = numBlocks;
467
- const newBlock = await mockBlockWithLogs(newBlockNumber);
468
- const newLog = newBlock.data.body.txEffects[1].privateLogs[1];
469
- newLog.fields[0] = tags[0];
470
- newBlock.data.body.txEffects[1].privateLogs[1] = newLog;
471
- await store.addBlocks([
472
- newBlock
473
- ]);
474
- await store.addLogs([
475
- newBlock.data
476
- ]);
477
- const logsByTags = await store.getLogsByTags(tags);
478
- expect(logsByTags).toEqual([
479
- [
480
- expect.objectContaining({
481
- blockNumber: 1,
482
- logData: makePrivateLog(tags[0]).toBuffer(),
483
- isFromPublic: false
484
- }),
485
- expect.objectContaining({
486
- blockNumber: newBlockNumber,
487
- logData: newLog.toBuffer(),
488
- isFromPublic: false
489
- })
490
- ]
491
- ]);
492
- });
493
- it('is possible to request logs for non-existing tags and determine their position', async ()=>{
494
- const tags = [
495
- makeTag(99, 88, 77),
496
- makeTag(1, 1, 1)
497
- ];
498
- const logsByTags = await store.getLogsByTags(tags);
499
- expect(logsByTags).toEqual([
500
- [],
501
- [
502
- expect.objectContaining({
503
- blockNumber: 1,
504
- logData: makePrivateLog(tags[1]).toBuffer(),
505
- isFromPublic: false
506
- })
507
- ]
508
- ]);
509
- });
510
- it('is not possible to add public logs by tag if they are invalid', async ()=>{
511
- const tag = makeTag(99, 88, 77);
512
- const invalidLogs = [
513
- PublicLog.fromFields([
514
- AztecAddress.fromNumber(1).toField(),
515
- makeLengthsField(2, 3),
516
- tag,
517
- ...times(PUBLIC_LOG_DATA_SIZE_IN_FIELDS - 1, (i)=>new Fr(tag.toNumber() + i))
518
- ]),
519
- PublicLog.fromFields([
520
- AztecAddress.fromNumber(1).toField(),
521
- makeLengthsField(2, PUBLIC_LOG_DATA_SIZE_IN_FIELDS),
522
- tag,
523
- ...times(PUBLIC_LOG_DATA_SIZE_IN_FIELDS - 1, (i)=>new Fr(tag.toNumber() + i))
524
- ])
525
- ];
526
- // Create a block containing these invalid logs
527
- const newBlockNumber = numBlocks;
528
- const newBlock = await mockBlockWithLogs(newBlockNumber);
529
- newBlock.data.body.txEffects[0].publicLogs = invalidLogs;
530
- await store.addBlocks([
531
- newBlock
532
- ]);
533
- await store.addLogs([
534
- newBlock.data
535
- ]);
536
- const logsByTags = await store.getLogsByTags([
537
- tag
538
- ]);
539
- // Neither of the logs should have been added:
540
- expect(logsByTags).toEqual([
541
- []
542
- ]);
543
- });
544
- });
545
- describe('getPublicLogs', ()=>{
546
- const txsPerBlock = 4;
547
- const numPublicFunctionCalls = 3;
548
- const numPublicLogs = 2;
549
- const numBlocks = 10;
550
- let blocks;
551
- beforeEach(async ()=>{
552
- blocks = await timesParallel(numBlocks, async (index)=>({
553
- data: await L2Block.random(index + 1, txsPerBlock, numPublicFunctionCalls, numPublicLogs),
554
- l1: {
555
- blockNumber: BigInt(index),
556
- blockHash: `0x${index}`,
557
- timestamp: BigInt(index)
558
- }
559
- }));
560
- await store.addBlocks(blocks);
561
- await store.addLogs(blocks.map((b)=>b.data));
562
- });
563
- it('no logs returned if deleted ("txHash" filter param is respected variant)', async ()=>{
564
- // get random tx
565
- const targetBlockIndex = randomInt(numBlocks);
566
- const targetTxIndex = randomInt(txsPerBlock);
567
- const targetTxHash = blocks[targetBlockIndex].data.body.txEffects[targetTxIndex].txHash;
568
- await Promise.all([
569
- store.unwindBlocks(blocks.length, blocks.length),
570
- store.deleteLogs(blocks.map((b)=>b.data))
571
- ]);
572
- const response = await store.getPublicLogs({
573
- txHash: targetTxHash
574
- });
575
- const logs = response.logs;
576
- expect(response.maxLogsHit).toBeFalsy();
577
- expect(logs.length).toEqual(0);
578
- });
579
- it('"txHash" filter param is respected', async ()=>{
580
- // get random tx
581
- const targetBlockIndex = randomInt(numBlocks);
582
- const targetTxIndex = randomInt(txsPerBlock);
583
- const targetTxHash = blocks[targetBlockIndex].data.body.txEffects[targetTxIndex].txHash;
584
- const response = await store.getPublicLogs({
585
- txHash: targetTxHash
586
- });
587
- const logs = response.logs;
588
- expect(response.maxLogsHit).toBeFalsy();
589
- const expectedNumLogs = numPublicFunctionCalls * numPublicLogs;
590
- expect(logs.length).toEqual(expectedNumLogs);
591
- const targeBlockNumber = targetBlockIndex + INITIAL_L2_BLOCK_NUM;
592
- for (const log of logs){
593
- expect(log.id.blockNumber).toEqual(targeBlockNumber);
594
- expect(log.id.txIndex).toEqual(targetTxIndex);
595
- }
596
- });
597
- it('"fromBlock" and "toBlock" filter params are respected', async ()=>{
598
- // Set "fromBlock" and "toBlock"
599
- const fromBlock = 3;
600
- const toBlock = 7;
601
- const response = await store.getPublicLogs({
602
- fromBlock,
603
- toBlock
604
- });
605
- const logs = response.logs;
606
- expect(response.maxLogsHit).toBeFalsy();
607
- const expectedNumLogs = txsPerBlock * numPublicFunctionCalls * numPublicLogs * (toBlock - fromBlock);
608
- expect(logs.length).toEqual(expectedNumLogs);
609
- for (const log of logs){
610
- const blockNumber = log.id.blockNumber;
611
- expect(blockNumber).toBeGreaterThanOrEqual(fromBlock);
612
- expect(blockNumber).toBeLessThan(toBlock);
613
- }
614
- });
615
- it('"contractAddress" filter param is respected', async ()=>{
616
- // Get a random contract address from the logs
617
- const targetBlockIndex = randomInt(numBlocks);
618
- const targetTxIndex = randomInt(txsPerBlock);
619
- const targetLogIndex = randomInt(numPublicLogs * numPublicFunctionCalls);
620
- const targetContractAddress = blocks[targetBlockIndex].data.body.txEffects[targetTxIndex].publicLogs[targetLogIndex].contractAddress;
621
- const response = await store.getPublicLogs({
622
- contractAddress: targetContractAddress
623
- });
624
- expect(response.maxLogsHit).toBeFalsy();
625
- for (const extendedLog of response.logs){
626
- expect(extendedLog.log.contractAddress.equals(targetContractAddress)).toBeTruthy();
627
- }
628
- });
629
- it('"afterLog" filter param is respected', async ()=>{
630
- // Get a random log as reference
631
- const targetBlockIndex = randomInt(numBlocks);
632
- const targetTxIndex = randomInt(txsPerBlock);
633
- const targetLogIndex = randomInt(numPublicLogs);
634
- const afterLog = new LogId(targetBlockIndex + INITIAL_L2_BLOCK_NUM, targetTxIndex, targetLogIndex);
635
- const response = await store.getPublicLogs({
636
- afterLog
637
- });
638
- const logs = response.logs;
639
- expect(response.maxLogsHit).toBeFalsy();
640
- for (const log of logs){
641
- const logId = log.id;
642
- expect(logId.blockNumber).toBeGreaterThanOrEqual(afterLog.blockNumber);
643
- if (logId.blockNumber === afterLog.blockNumber) {
644
- expect(logId.txIndex).toBeGreaterThanOrEqual(afterLog.txIndex);
645
- if (logId.txIndex === afterLog.txIndex) {
646
- expect(logId.logIndex).toBeGreaterThan(afterLog.logIndex);
647
- }
648
- }
649
- }
650
- });
651
- it('"txHash" filter param is ignored when "afterLog" is set', async ()=>{
652
- // Get random txHash
653
- const txHash = TxHash.random();
654
- const afterLog = new LogId(1, 0, 0);
655
- const response = await store.getPublicLogs({
656
- txHash,
657
- afterLog
658
- });
659
- expect(response.logs.length).toBeGreaterThan(1);
660
- });
661
- it('intersecting works', async ()=>{
662
- let logs = (await store.getPublicLogs({
663
- fromBlock: -10,
664
- toBlock: -5
665
- })).logs;
666
- expect(logs.length).toBe(0);
667
- // "fromBlock" gets correctly trimmed to range and "toBlock" is exclusive
668
- logs = (await store.getPublicLogs({
669
- fromBlock: -10,
670
- toBlock: 5
671
- })).logs;
672
- let blockNumbers = new Set(logs.map((log)=>log.id.blockNumber));
673
- expect(blockNumbers).toEqual(new Set([
674
- 1,
675
- 2,
676
- 3,
677
- 4
678
- ]));
679
- // "toBlock" should be exclusive
680
- logs = (await store.getPublicLogs({
681
- fromBlock: 1,
682
- toBlock: 1
683
- })).logs;
684
- expect(logs.length).toBe(0);
685
- logs = (await store.getPublicLogs({
686
- fromBlock: 10,
687
- toBlock: 5
688
- })).logs;
689
- expect(logs.length).toBe(0);
690
- // both "fromBlock" and "toBlock" get correctly capped to range and logs from all blocks are returned
691
- logs = (await store.getPublicLogs({
692
- fromBlock: -100,
693
- toBlock: +100
694
- })).logs;
695
- blockNumbers = new Set(logs.map((log)=>log.id.blockNumber));
696
- expect(blockNumbers.size).toBe(numBlocks);
697
- // intersecting with "afterLog" works
698
- logs = (await store.getPublicLogs({
699
- fromBlock: 2,
700
- toBlock: 5,
701
- afterLog: new LogId(4, 0, 0)
702
- })).logs;
703
- blockNumbers = new Set(logs.map((log)=>log.id.blockNumber));
704
- expect(blockNumbers).toEqual(new Set([
705
- 4
706
- ]));
707
- logs = (await store.getPublicLogs({
708
- toBlock: 5,
709
- afterLog: new LogId(5, 1, 0)
710
- })).logs;
711
- expect(logs.length).toBe(0);
712
- logs = (await store.getPublicLogs({
713
- fromBlock: 2,
714
- toBlock: 5,
715
- afterLog: new LogId(100, 0, 0)
716
- })).logs;
717
- expect(logs.length).toBe(0);
718
- });
719
- it('"txIndex" and "logIndex" are respected when "afterLog.blockNumber" is equal to "fromBlock"', async ()=>{
720
- // Get a random log as reference
721
- const targetBlockIndex = randomInt(numBlocks);
722
- const targetTxIndex = randomInt(txsPerBlock);
723
- const targetLogIndex = randomInt(numPublicLogs);
724
- const afterLog = new LogId(targetBlockIndex + INITIAL_L2_BLOCK_NUM, targetTxIndex, targetLogIndex);
725
- const response = await store.getPublicLogs({
726
- afterLog,
727
- fromBlock: afterLog.blockNumber
728
- });
729
- const logs = response.logs;
730
- expect(response.maxLogsHit).toBeFalsy();
731
- for (const log of logs){
732
- const logId = log.id;
733
- expect(logId.blockNumber).toBeGreaterThanOrEqual(afterLog.blockNumber);
734
- if (logId.blockNumber === afterLog.blockNumber) {
735
- expect(logId.txIndex).toBeGreaterThanOrEqual(afterLog.txIndex);
736
- if (logId.txIndex === afterLog.txIndex) {
737
- expect(logId.logIndex).toBeGreaterThan(afterLog.logIndex);
738
- }
739
- }
740
- }
741
- });
742
- });
743
- describe('findNullifiersIndexesWithBlock', ()=>{
744
- let blocks;
745
- const numBlocks = 10;
746
- const nullifiersPerBlock = new Map();
747
- beforeEach(async ()=>{
748
- blocks = await timesParallel(numBlocks, (index)=>L2Block.random(index + 1, 1));
749
- blocks.forEach((block, blockIndex)=>{
750
- nullifiersPerBlock.set(blockIndex, block.body.txEffects.flatMap((txEffect)=>txEffect.nullifiers));
751
- });
752
- });
753
- it('returns wrapped nullifiers with blocks if they exist', async ()=>{
754
- await store.addNullifiers(blocks);
755
- const nullifiersToRetrieve = [
756
- ...nullifiersPerBlock.get(0),
757
- ...nullifiersPerBlock.get(5),
758
- Fr.random()
759
- ];
760
- const blockScopedNullifiers = await store.findNullifiersIndexesWithBlock(10, nullifiersToRetrieve);
761
- expect(blockScopedNullifiers).toHaveLength(nullifiersToRetrieve.length);
762
- const [undefinedNullifier] = blockScopedNullifiers.slice(-1);
763
- const realNullifiers = blockScopedNullifiers.slice(0, -1);
764
- realNullifiers.forEach((blockScopedNullifier, index)=>{
765
- expect(blockScopedNullifier).not.toBeUndefined();
766
- const { data, l2BlockNumber } = blockScopedNullifier;
767
- expect(data).toEqual(expect.any(BigInt));
768
- expect(l2BlockNumber).toEqual(index < MAX_NULLIFIERS_PER_TX ? 1 : 6);
769
- });
770
- expect(undefinedNullifier).toBeUndefined();
771
- });
772
- it('returns wrapped nullifiers filtering by blockNumber', async ()=>{
773
- await store.addNullifiers(blocks);
774
- const nullifiersToRetrieve = [
775
- ...nullifiersPerBlock.get(0),
776
- ...nullifiersPerBlock.get(5)
777
- ];
778
- const blockScopedNullifiers = await store.findNullifiersIndexesWithBlock(5, nullifiersToRetrieve);
779
- expect(blockScopedNullifiers).toHaveLength(nullifiersToRetrieve.length);
780
- const undefinedNullifiers = blockScopedNullifiers.slice(-MAX_NULLIFIERS_PER_TX);
781
- const realNullifiers = blockScopedNullifiers.slice(0, -MAX_NULLIFIERS_PER_TX);
782
- realNullifiers.forEach((blockScopedNullifier)=>{
783
- expect(blockScopedNullifier).not.toBeUndefined();
784
- const { data, l2BlockNumber } = blockScopedNullifier;
785
- expect(data).toEqual(expect.any(BigInt));
786
- expect(l2BlockNumber).toEqual(1);
787
- });
788
- undefinedNullifiers.forEach((undefinedNullifier)=>{
789
- expect(undefinedNullifier).toBeUndefined();
790
- });
791
- });
792
- });
793
- });
794
- }