@@ -312,6 +312,107 @@ describe("block production", () => {
312
312
expect ( newState ) . toBeUndefined ( ) ;
313
313
} , 30_000 ) ;
314
314
315
+ it ( "should produce txs in non-consecutive blocks" , async ( ) => {
316
+ log . setLevel ( "TRACE" ) ;
317
+
318
+ const privateKey = PrivateKey . random ( ) ;
319
+ const publicKey = privateKey . toPublicKey ( ) ;
320
+
321
+ const privateKey2 = PrivateKey . random ( ) ;
322
+ const publicKey2 = privateKey2 . toPublicKey ( ) ;
323
+
324
+ await mempool . add (
325
+ createTransaction ( {
326
+ runtime,
327
+ method : [ "Balance" , "setBalanceIf" ] ,
328
+ privateKey,
329
+ args : [ publicKey , UInt64 . from ( 100 ) , Bool ( true ) ] ,
330
+ nonce : 0 ,
331
+ } )
332
+ ) ;
333
+
334
+ // let [block, batch] = await blockTrigger.produceBlockAndBatch();
335
+ const block = await blockTrigger . produceBlock ( ) ;
336
+
337
+ expect ( block ) . toBeDefined ( ) ;
338
+
339
+ expect ( block ! . transactions ) . toHaveLength ( 1 ) ;
340
+ expect ( block ! . transactions [ 0 ] . status . toBoolean ( ) ) . toBe ( true ) ;
341
+ expect ( block ! . transactions [ 0 ] . statusMessage ) . toBeUndefined ( ) ;
342
+
343
+ expect ( block ! . transactions [ 0 ] . stateTransitions ) . toHaveLength ( 1 ) ;
344
+ expect ( block ! . transactions [ 0 ] . protocolTransitions ) . toHaveLength ( 2 ) ;
345
+
346
+ await blockTrigger . produceBlock ( ) ;
347
+
348
+ await mempool . add (
349
+ createTransaction ( {
350
+ runtime,
351
+ method : [ "Balance" , "setBalanceIf" ] ,
352
+ privateKey : privateKey2 ,
353
+ args : [ publicKey2 , UInt64 . from ( 100 ) , Bool ( true ) ] ,
354
+ nonce : 0 ,
355
+ } )
356
+ ) ;
357
+ await blockTrigger . produceBlock ( ) ;
358
+
359
+ await mempool . add (
360
+ createTransaction ( {
361
+ runtime,
362
+ method : [ "Balance" , "setBalanceIf" ] ,
363
+ privateKey : privateKey2 ,
364
+ args : [ publicKey2 , UInt64 . from ( 100 ) , Bool ( true ) ] ,
365
+ nonce : 1 ,
366
+ } )
367
+ ) ;
368
+ await blockTrigger . produceBlock ( ) ;
369
+
370
+ await mempool . add (
371
+ createTransaction ( {
372
+ runtime,
373
+ method : [ "Balance" , "setBalanceIf" ] ,
374
+ privateKey : privateKey2 ,
375
+ args : [ publicKey2 , UInt64 . from ( 100 ) , Bool ( true ) ] ,
376
+ nonce : 2 ,
377
+ } )
378
+ ) ;
379
+ await blockTrigger . produceBlock ( ) ;
380
+
381
+ await mempool . add (
382
+ createTransaction ( {
383
+ runtime,
384
+ method : [ "Balance" , "setBalanceIf" ] ,
385
+ privateKey : privateKey2 ,
386
+ args : [ publicKey2 , UInt64 . from ( 100 ) , Bool ( true ) ] ,
387
+ nonce : 3 ,
388
+ } )
389
+ ) ;
390
+ await blockTrigger . produceBlock ( ) ;
391
+
392
+ // Second tx
393
+ await mempool . add (
394
+ createTransaction ( {
395
+ runtime,
396
+ method : [ "Balance" , "setBalanceIf" ] ,
397
+ privateKey,
398
+ args : [ publicKey , UInt64 . from ( 100 ) , Bool ( true ) ] ,
399
+ nonce : 1 ,
400
+ } )
401
+ ) ;
402
+
403
+ log . info ( "Starting second block" ) ;
404
+
405
+ const block2 = await blockTrigger . produceBlock ( ) ;
406
+
407
+ expect ( block2 ) . toBeDefined ( ) ;
408
+
409
+ expect ( block2 ! . transactions ) . toHaveLength ( 1 ) ;
410
+ console . log ( block2 ! . transactions [ 0 ] ) ;
411
+ console . log ( block2 ! . transactions [ 0 ] . statusMessage ) ;
412
+ expect ( block2 ! . transactions [ 0 ] . status . toBoolean ( ) ) . toBe ( true ) ;
413
+ expect ( block2 ! . transactions [ 0 ] . statusMessage ) . toBeUndefined ( ) ;
414
+ } , 60_000 ) ;
415
+
315
416
const numberTxs = 3 ;
316
417
317
418
it ( "should produce block with multiple transaction" , async ( ) => {
0 commit comments