@@ -53,7 +53,7 @@ describe('Account Compression', () => {
5353
5454 await provider . connection . confirmTransaction (
5555 await provider . connection . requestAirdrop ( payer , 1e10 ) ,
56- 'confirmed'
56+ 'confirmed' ,
5757 ) ;
5858 } ) ;
5959
@@ -89,41 +89,58 @@ describe('Account Compression', () => {
8989 another = anotherKeyPair . publicKey ;
9090 await provider . connection . confirmTransaction (
9191 await provider . connection . requestAirdrop ( another , 1e10 ) ,
92- 'confirmed'
92+ 'confirmed' ,
9393 ) ;
9494 } ) ;
9595 it ( 'Should be able to finalize the tree' , async ( ) => {
9696 const merkleTreeRaw = new MerkleTree ( leaves ) ;
9797 const root = merkleTreeRaw . root ;
9898 const leaf = leaves [ leaves . length - 1 ] ;
9999
100- const finalize = createFinalizeMerkleTreeWithRootIx ( cmt , payer , root , leaf , leaves . length - 1 , merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ) ;
100+ const finalize = createFinalizeMerkleTreeWithRootIx (
101+ cmt ,
102+ payer ,
103+ root ,
104+ leaf ,
105+ leaves . length - 1 ,
106+ merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ,
107+ ) ;
101108
102109 await execute ( provider , [ finalize ] , [ payerKeypair ] ) ;
103110
104111 const splCMT = await ConcurrentMerkleTreeAccount . fromAccountAddress ( connection , cmt ) ;
105112 assert ( splCMT . getMaxBufferSize ( ) === size , 'Buffer size does not match' ) ;
106- assert ( splCMT . getCanopyDepth ( ) === canopyDepth , 'Canopy depth does not match: expected ' + canopyDepth + ' but got ' + splCMT . getCanopyDepth ( ) ) ;
113+ assert (
114+ splCMT . getCanopyDepth ( ) === canopyDepth ,
115+ 'Canopy depth does not match: expected ' + canopyDepth + ' but got ' + splCMT . getCanopyDepth ( ) ,
116+ ) ;
107117 assert ( splCMT . getBufferSize ( ) == 1 , 'Buffer size does not match' ) ;
108118 } ) ;
109119 it ( 'Should fail to append canopy node for a tree without canopy' , async ( ) => {
110120 const appendIx = createAppendCanopyNodesIx ( cmt , payer , [ crypto . randomBytes ( 32 ) ] , 0 ) ;
111121 try {
112122 await execute ( provider , [ appendIx ] , [ payerKeypair ] ) ;
113123 assert ( false , 'Canopy appending should have failed to execute for a tree without canopy' ) ;
114- } catch { }
124+ } catch { }
115125 } ) ;
116126 it ( 'Should fail to finalize the tree with another payer authority' , async ( ) => {
117127 const merkleTreeRaw = new MerkleTree ( leaves ) ;
118128 const root = merkleTreeRaw . root ;
119129 const leaf = leaves [ leaves . length - 1 ] ;
120130
121- const finalize = createFinalizeMerkleTreeWithRootIx ( cmt , another , root , leaf , leaves . length - 1 , merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ) ;
131+ const finalize = createFinalizeMerkleTreeWithRootIx (
132+ cmt ,
133+ another ,
134+ root ,
135+ leaf ,
136+ leaves . length - 1 ,
137+ merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ,
138+ ) ;
122139
123140 try {
124141 await execute ( provider , [ finalize ] , [ anotherKeyPair ] ) ;
125142 assert ( false , 'Finalizing with another payer should have failed' ) ;
126- } catch { }
143+ } catch { }
127144 } ) ;
128145 it ( 'Should fail to finalize the tree with a wrong proof' , async ( ) => {
129146 const merkleTreeRaw = new MerkleTree ( leaves ) ;
@@ -140,25 +157,30 @@ describe('Account Compression', () => {
140157 try {
141158 await execute ( provider , [ finalize ] , [ payerKeypair ] ) ;
142159 assert ( false , 'Finalizing with a wrong proof should have failed' ) ;
143- } catch { }
160+ } catch { }
144161 } ) ;
145162 it ( 'Should fail to double finalize the tree' , async ( ) => {
146163 const merkleTreeRaw = new MerkleTree ( leaves ) ;
147164 const root = merkleTreeRaw . root ;
148165 const leaf = leaves [ leaves . length - 1 ] ;
149166
150- const finalize = createFinalizeMerkleTreeWithRootIx ( cmt , payer , root , leaf , leaves . length - 1 , merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ) ;
167+ const finalize = createFinalizeMerkleTreeWithRootIx (
168+ cmt ,
169+ payer ,
170+ root ,
171+ leaf ,
172+ leaves . length - 1 ,
173+ merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ,
174+ ) ;
151175
152176 await execute ( provider , [ finalize ] , [ payerKeypair ] ) ;
153177
154178 try {
155179 await execute ( provider , [ finalize ] , [ payerKeypair ] ) ;
156180 assert ( false , 'Double finalizing should have failed' ) ;
157- } catch { }
181+ } catch { }
158182 } ) ;
159- }
160-
161- ) ;
183+ } ) ;
162184 describe ( 'Having prepared a tree with canopy' , ( ) => {
163185 const depth = 3 ;
164186 const size = 8 ;
@@ -190,7 +212,7 @@ describe('Account Compression', () => {
190212 another = anotherKeyPair . publicKey ;
191213 await provider . connection . confirmTransaction (
192214 await provider . connection . requestAirdrop ( another , 1e10 ) ,
193- 'confirmed'
215+ 'confirmed' ,
194216 ) ;
195217 } ) ;
196218 it ( 'Should be able to append a single canopy node' , async ( ) => {
@@ -210,40 +232,57 @@ describe('Account Compression', () => {
210232 try {
211233 await execute ( provider , [ appendIx ] , [ anotherKeyPair ] ) ;
212234 assert ( false , 'Appending with another payer should have failed' ) ;
213- } catch { }
235+ } catch { }
214236 } ) ;
215237 it ( 'Should fail to append canopy nodes over the limit' , async ( ) => {
216- const appendIx = createAppendCanopyNodesIx ( cmt , payer , Array . from ( { length : 3 } , ( ) => crypto . randomBytes ( 32 ) ) , 0 ) ;
238+ const appendIx = createAppendCanopyNodesIx (
239+ cmt ,
240+ payer ,
241+ Array . from ( { length : 3 } , ( ) => crypto . randomBytes ( 32 ) ) ,
242+ 0 ,
243+ ) ;
217244 try {
218245 await execute ( provider , [ appendIx ] , [ payerKeypair ] ) ;
219246 assert ( false , 'Appending over the limit should have failed' ) ;
220- } catch { }
247+ } catch { }
221248 } ) ;
222249 it ( 'Should fail to append canopy nodes over the limit starting from the last index' , async ( ) => {
223- const appendIx = createAppendCanopyNodesIx ( cmt , payer , Array . from ( { length : 2 } , ( ) => crypto . randomBytes ( 32 ) ) , 1 ) ;
250+ const appendIx = createAppendCanopyNodesIx (
251+ cmt ,
252+ payer ,
253+ Array . from ( { length : 2 } , ( ) => crypto . randomBytes ( 32 ) ) ,
254+ 1 ,
255+ ) ;
224256 try {
225257 await execute ( provider , [ appendIx ] , [ payerKeypair ] ) ;
226258 assert ( false , 'Appending over the limit should have failed' ) ;
227- } catch { }
259+ } catch { }
228260 } ) ;
229261 it ( 'Should fail to append 0 canopy nodes' , async ( ) => {
230262 const appendIx = createAppendCanopyNodesIx ( cmt , payer , [ ] , 0 ) ;
231263 try {
232264 await execute ( provider , [ appendIx ] , [ payerKeypair ] ) ;
233265 assert ( false , 'Appending 0 nodes should have failed' ) ;
234- } catch { }
266+ } catch { }
235267 } ) ;
236268 it ( 'Should fail to finalize the tree without canopy' , async ( ) => {
237269 const merkleTreeRaw = new MerkleTree ( leaves ) ;
238270 const root = merkleTreeRaw . root ;
239271 const leaf = leaves [ leaves . length - 1 ] ;
240272
241- const finalize = createFinalizeMerkleTreeWithRootIx ( cmt , payer , root , leaf , leaves . length - 1 , merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ) ;
273+ const finalize = createFinalizeMerkleTreeWithRootIx (
274+ cmt ,
275+ payer ,
276+ root ,
277+ leaf ,
278+ leaves . length - 1 ,
279+ merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ,
280+ ) ;
242281
243282 try {
244283 await execute ( provider , [ finalize ] , [ payerKeypair ] ) ;
245284 assert ( false , 'Finalizing without canopy should have failed' ) ;
246- } catch { }
285+ } catch { }
247286 } ) ;
248287 it ( 'Should fail to finalize the tree with an incomplete canopy' , async ( ) => {
249288 const merkleTreeRaw = new MerkleTree ( leaves ) ;
@@ -252,87 +291,189 @@ describe('Account Compression', () => {
252291
253292 const appendIx = createAppendCanopyNodesIx ( cmt , payer , [ merkleTreeRaw . leaves [ 0 ] . parent ! . node ! ] , 0 ) ;
254293 await execute ( provider , [ appendIx ] , [ payerKeypair ] ) ;
255- const finalize = createFinalizeMerkleTreeWithRootIx ( cmt , payer , root , leaf , leaves . length - 1 , merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ) ;
294+ const finalize = createFinalizeMerkleTreeWithRootIx (
295+ cmt ,
296+ payer ,
297+ root ,
298+ leaf ,
299+ leaves . length - 1 ,
300+ merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ,
301+ ) ;
256302
257303 try {
258304 await execute ( provider , [ finalize ] , [ payerKeypair ] ) ;
259305 assert ( false , 'Finalization for an incomplete canopy should have failed' ) ;
260- } catch { }
306+ } catch { }
261307 } ) ;
262308 it ( 'Should finalize the tree with a complete canopy' , async ( ) => {
263309 const merkleTreeRaw = new MerkleTree ( leaves ) ;
264310 const root = merkleTreeRaw . root ;
265311 const leaf = leaves [ leaves . length - 1 ] ;
266312
267313 // take every second leaf and append it's parent node to the canopy
268- const appendIx = createAppendCanopyNodesIx ( cmt , payer , merkleTreeRaw . leaves . filter ( ( _ , i ) => i % 2 === 0 ) . map ( leaf => leaf . parent ! . node ! ) , 0 ) ;
314+ const appendIx = createAppendCanopyNodesIx (
315+ cmt ,
316+ payer ,
317+ merkleTreeRaw . leaves . filter ( ( _ , i ) => i % 2 === 0 ) . map ( leaf => leaf . parent ! . node ! ) ,
318+ 0 ,
319+ ) ;
269320 await execute ( provider , [ appendIx ] , [ payerKeypair ] ) ;
270- const finalize = createFinalizeMerkleTreeWithRootIx ( cmt , payer , root , leaf , leaves . length - 1 , merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ) ;
321+ const finalize = createFinalizeMerkleTreeWithRootIx (
322+ cmt ,
323+ payer ,
324+ root ,
325+ leaf ,
326+ leaves . length - 1 ,
327+ merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ,
328+ ) ;
271329 await execute ( provider , [ finalize ] , [ payerKeypair ] ) ;
272330 } ) ;
273331 it ( 'Should be able to setup canopy with several transactions' , async ( ) => {
274332 const merkleTreeRaw = new MerkleTree ( leaves ) ;
275333 const root = merkleTreeRaw . root ;
276334 const leaf = leaves [ leaves . length - 1 ] ;
277335 // take every second leaf of the first half of a tree and append it's parent node to the canopy
278- const appendIx = createAppendCanopyNodesIx ( cmt , payer , merkleTreeRaw . leaves . slice ( 0 , leaves . length / 2 ) . filter ( ( _ , i ) => i % 2 === 0 ) . map ( leaf => leaf . parent ! . node ! ) , 0 ) ;
336+ const appendIx = createAppendCanopyNodesIx (
337+ cmt ,
338+ payer ,
339+ merkleTreeRaw . leaves
340+ . slice ( 0 , leaves . length / 2 )
341+ . filter ( ( _ , i ) => i % 2 === 0 )
342+ . map ( leaf => leaf . parent ! . node ! ) ,
343+ 0 ,
344+ ) ;
279345 await execute ( provider , [ appendIx ] , [ payerKeypair ] ) ;
280346 // take every second leaf of the second half of a tree and append it's parent node to the canopy
281- const appendIx2 = createAppendCanopyNodesIx ( cmt , payer , merkleTreeRaw . leaves . slice ( leaves . length / 2 ) . filter ( ( _ , i ) => i % 2 === 0 ) . map ( leaf => leaf . parent ! . node ! ) , 2 ) ;
347+ const appendIx2 = createAppendCanopyNodesIx (
348+ cmt ,
349+ payer ,
350+ merkleTreeRaw . leaves
351+ . slice ( leaves . length / 2 )
352+ . filter ( ( _ , i ) => i % 2 === 0 )
353+ . map ( leaf => leaf . parent ! . node ! ) ,
354+ 2 ,
355+ ) ;
282356 await execute ( provider , [ appendIx2 ] , [ payerKeypair ] ) ;
283- const finalize = createFinalizeMerkleTreeWithRootIx ( cmt , payer , root , leaf , leaves . length - 1 , merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ) ;
357+ const finalize = createFinalizeMerkleTreeWithRootIx (
358+ cmt ,
359+ payer ,
360+ root ,
361+ leaf ,
362+ leaves . length - 1 ,
363+ merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ,
364+ ) ;
284365 await execute ( provider , [ finalize ] , [ payerKeypair ] ) ;
285366 } ) ;
286367 it ( 'Should be able to setup canopy with several transactions in reverse order' , async ( ) => {
287368 const merkleTreeRaw = new MerkleTree ( leaves ) ;
288369 const root = merkleTreeRaw . root ;
289370 const leaf = leaves [ leaves . length - 1 ] ;
290371
291- const appendIx = createAppendCanopyNodesIx ( cmt , payer , merkleTreeRaw . leaves . slice ( leaves . length / 2 ) . filter ( ( _ , i ) => i % 2 === 0 ) . map ( leaf => leaf . parent ! . node ! ) , 2 ) ;
372+ const appendIx = createAppendCanopyNodesIx (
373+ cmt ,
374+ payer ,
375+ merkleTreeRaw . leaves
376+ . slice ( leaves . length / 2 )
377+ . filter ( ( _ , i ) => i % 2 === 0 )
378+ . map ( leaf => leaf . parent ! . node ! ) ,
379+ 2 ,
380+ ) ;
292381 await execute ( provider , [ appendIx ] , [ payerKeypair ] ) ;
293- const appendIx2 = createAppendCanopyNodesIx ( cmt , payer , merkleTreeRaw . leaves . slice ( 0 , leaves . length / 2 ) . filter ( ( _ , i ) => i % 2 === 0 ) . map ( leaf => leaf . parent ! . node ! ) , 0 ) ;
382+ const appendIx2 = createAppendCanopyNodesIx (
383+ cmt ,
384+ payer ,
385+ merkleTreeRaw . leaves
386+ . slice ( 0 , leaves . length / 2 )
387+ . filter ( ( _ , i ) => i % 2 === 0 )
388+ . map ( leaf => leaf . parent ! . node ! ) ,
389+ 0 ,
390+ ) ;
294391 await execute ( provider , [ appendIx2 ] , [ payerKeypair ] ) ;
295- const finalize = createFinalizeMerkleTreeWithRootIx ( cmt , payer , root , leaf , leaves . length - 1 , merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ) ;
392+ const finalize = createFinalizeMerkleTreeWithRootIx (
393+ cmt ,
394+ payer ,
395+ root ,
396+ leaf ,
397+ leaves . length - 1 ,
398+ merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ,
399+ ) ;
296400 await execute ( provider , [ finalize ] , [ payerKeypair ] ) ;
297401 } ) ;
298402 it ( 'Should be able to replace a canopy node' , async ( ) => {
299403 const merkleTreeRaw = new MerkleTree ( leaves ) ;
300404 const root = merkleTreeRaw . root ;
301405 const leaf = leaves [ leaves . length - 1 ] ;
302406
303- const appendIx = createAppendCanopyNodesIx ( cmt , payer , merkleTreeRaw . leaves . slice ( 0 , leaves . length / 2 ) . filter ( ( _ , i ) => i % 2 === 0 ) . map ( leaf => leaf . parent ! . node ! ) , 0 ) ;
407+ const appendIx = createAppendCanopyNodesIx (
408+ cmt ,
409+ payer ,
410+ merkleTreeRaw . leaves
411+ . slice ( 0 , leaves . length / 2 )
412+ . filter ( ( _ , i ) => i % 2 === 0 )
413+ . map ( leaf => leaf . parent ! . node ! ) ,
414+ 0 ,
415+ ) ;
304416 await execute ( provider , [ appendIx ] , [ payerKeypair ] ) ;
305417 const appendIx2 = createAppendCanopyNodesIx ( cmt , payer , [ crypto . randomBytes ( 32 ) ] , 2 ) ;
306418 await execute ( provider , [ appendIx2 ] , [ payerKeypair ] ) ;
307- const replaceIx = createAppendCanopyNodesIx ( cmt , payer , merkleTreeRaw . leaves . slice ( leaves . length / 2 ) . filter ( ( _ , i ) => i % 2 === 0 ) . map ( leaf => leaf . parent ! . node ! ) , 2 ) ;
419+ const replaceIx = createAppendCanopyNodesIx (
420+ cmt ,
421+ payer ,
422+ merkleTreeRaw . leaves
423+ . slice ( leaves . length / 2 )
424+ . filter ( ( _ , i ) => i % 2 === 0 )
425+ . map ( leaf => leaf . parent ! . node ! ) ,
426+ 2 ,
427+ ) ;
308428 await execute ( provider , [ replaceIx ] , [ payerKeypair ] ) ;
309- const finalize = createFinalizeMerkleTreeWithRootIx ( cmt , payer , root , leaf , leaves . length - 1 , merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ) ;
429+ const finalize = createFinalizeMerkleTreeWithRootIx (
430+ cmt ,
431+ payer ,
432+ root ,
433+ leaf ,
434+ leaves . length - 1 ,
435+ merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ,
436+ ) ;
310437 await execute ( provider , [ finalize ] , [ payerKeypair ] ) ;
311438 } ) ;
312439 it ( 'Should fail to replace a canopy node for a finalised tree' , async ( ) => {
313440 const merkleTreeRaw = new MerkleTree ( leaves ) ;
314441 const root = merkleTreeRaw . root ;
315442 const leaf = leaves [ leaves . length - 1 ] ;
316443
317- const appendIx = createAppendCanopyNodesIx ( cmt , payer , merkleTreeRaw . leaves . filter ( ( _ , i ) => i % 2 === 0 ) . map ( leaf => leaf . parent ! . node ! ) , 0 ) ;
444+ const appendIx = createAppendCanopyNodesIx (
445+ cmt ,
446+ payer ,
447+ merkleTreeRaw . leaves . filter ( ( _ , i ) => i % 2 === 0 ) . map ( leaf => leaf . parent ! . node ! ) ,
448+ 0 ,
449+ ) ;
318450 await execute ( provider , [ appendIx ] , [ payerKeypair ] ) ;
319- const finalize = createFinalizeMerkleTreeWithRootIx ( cmt , payer , root , leaf , leaves . length - 1 , merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ) ;
451+ const finalize = createFinalizeMerkleTreeWithRootIx (
452+ cmt ,
453+ payer ,
454+ root ,
455+ leaf ,
456+ leaves . length - 1 ,
457+ merkleTreeRaw . getProof ( leaves . length - 1 ) . proof ,
458+ ) ;
320459 await execute ( provider , [ finalize ] , [ payerKeypair ] ) ;
321460 const replaceIx = createAppendCanopyNodesIx ( cmt , payer , [ crypto . randomBytes ( 32 ) ] , 0 ) ;
322461 try {
323462 await execute ( provider , [ replaceIx ] , [ payerKeypair ] ) ;
324463 assert ( false , 'Replacing a canopy node for a finalised tree should have failed' ) ;
325- } catch { }
464+ } catch { }
326465 } ) ;
327466 it ( 'Should fail to initialize an empty tree after preparing a tree' , async ( ) => {
328- const ixs = [ createInitEmptyMerkleTreeIx ( cmt , payer , {
329- maxBufferSize : size ,
330- maxDepth : depth ,
331- } ) ] ;
467+ const ixs = [
468+ createInitEmptyMerkleTreeIx ( cmt , payer , {
469+ maxBufferSize : size ,
470+ maxDepth : depth ,
471+ } ) ,
472+ ] ;
332473 try {
333474 await execute ( provider , ixs , [ payerKeypair ] ) ;
334475 assert ( false , 'Initializing an empty tree after preparing a tree should have failed' ) ;
335- } catch { }
476+ } catch { }
336477 } ) ;
337478 } ) ;
338479
0 commit comments