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