@@ -152,6 +152,8 @@ def check_mempool_size(self):
152
152
def check_mempool_result (self , result_expected , tx ):
153
153
"""Wrapper to check result of testmempoolaccept on node_0's mempool"""
154
154
result_expected ['txid' ] = tx .rehash ()
155
+ if result_expected ['allowed' ]:
156
+ result_expected ['vsize' ] = tx .get_vsize ()
155
157
156
158
result_test = self .nodes [0 ].testmempoolaccept ([tx .serialize ().hex ()])
157
159
@@ -190,7 +192,6 @@ def set_sporks(self):
190
192
191
193
self .nodes [0 ].sporkupdate ("SPORK_17_QUORUM_DKG_ENABLED" , spork_enabled )
192
194
self .nodes [0 ].sporkupdate ("SPORK_19_CHAINLOCKS_ENABLED" , spork_disabled )
193
- self .nodes [0 ].sporkupdate ("SPORK_3_INSTANTSEND_BLOCK_FILTERING" , spork_disabled )
194
195
self .nodes [0 ].sporkupdate ("SPORK_2_INSTANTSEND_ENABLED" , spork_disabled )
195
196
self .wait_for_sporks_same ()
196
197
@@ -261,6 +262,13 @@ def run_test(self):
261
262
key .generate ()
262
263
pubkey = key .get_pubkey ().get_bytes ()
263
264
265
+ self .test_asset_locks (node_wallet , node , pubkey )
266
+ self .test_asset_unlocks (node_wallet , node , pubkey )
267
+ self .test_withdrawal_limits (node_wallet , node , pubkey )
268
+ self .test_mn_rr (node_wallet , node , pubkey )
269
+
270
+
271
+ def test_asset_locks (self , node_wallet , node , pubkey ):
264
272
self .log .info ("Testing asset lock..." )
265
273
locked_1 = 10 * COIN + 141421
266
274
locked_2 = 10 * COIN + 314159
@@ -272,7 +280,7 @@ def run_test(self):
272
280
asset_lock_tx = self .create_assetlock (coin , locked_1 , pubkey )
273
281
274
282
275
- self .check_mempool_result (tx = asset_lock_tx , result_expected = {'allowed' : True , 'vsize' : asset_lock_tx . get_vsize (), ' fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
283
+ self .check_mempool_result (tx = asset_lock_tx , result_expected = {'allowed' : True , 'fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
276
284
self .validate_credit_pool_balance (0 )
277
285
txid_in_block = self .send_tx (asset_lock_tx )
278
286
assert "assetLockTx" in node .getrawtransaction (txid_in_block , 1 )
@@ -287,9 +295,9 @@ def run_test(self):
287
295
288
296
# tx is mined, let's get blockhash
289
297
self .log .info ("Invalidate block with asset lock tx..." )
290
- block_hash_1 = node_wallet .gettransaction (txid_in_block )['blockhash' ]
298
+ self . block_hash_1 = node_wallet .gettransaction (txid_in_block )['blockhash' ]
291
299
for inode in self .nodes :
292
- inode .invalidateblock (block_hash_1 )
300
+ inode .invalidateblock (self . block_hash_1 )
293
301
assert_equal (self .get_credit_pool_balance (node = inode ), 0 )
294
302
node .generate (3 )
295
303
self .sync_all ()
@@ -303,7 +311,7 @@ def run_test(self):
303
311
self .validate_credit_pool_balance (locked_2 )
304
312
self .log .info ("Reconsider old blocks..." )
305
313
for inode in self .nodes :
306
- inode .reconsiderblock (block_hash_1 )
314
+ inode .reconsiderblock (self . block_hash_1 )
307
315
self .validate_credit_pool_balance (locked_1 )
308
316
self .sync_all ()
309
317
@@ -317,10 +325,14 @@ def run_test(self):
317
325
318
326
self .validate_credit_pool_balance (locked_1 )
319
327
328
+
329
+ def test_asset_unlocks (self , node_wallet , node , pubkey ):
320
330
self .log .info ("Testing asset unlock..." )
321
331
322
332
self .log .info ("Generating several txes by same quorum...." )
323
- self .validate_credit_pool_balance (locked_1 )
333
+ locked = self .get_credit_pool_balance ()
334
+
335
+ self .validate_credit_pool_balance (locked )
324
336
asset_unlock_tx = self .create_assetunlock (101 , COIN , pubkey )
325
337
asset_unlock_tx_late = self .create_assetunlock (102 , COIN , pubkey )
326
338
asset_unlock_tx_too_late = self .create_assetunlock (103 , COIN , pubkey )
@@ -331,7 +343,7 @@ def run_test(self):
331
343
asset_unlock_tx_duplicate_index .vout [0 ].nValue += COIN
332
344
too_late_height = node .getblockcount () + 48
333
345
334
- self .check_mempool_result (tx = asset_unlock_tx , result_expected = {'allowed' : True , 'vsize' : asset_unlock_tx . get_vsize (), ' fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
346
+ self .check_mempool_result (tx = asset_unlock_tx , result_expected = {'allowed' : True , 'fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
335
347
self .check_mempool_result (tx = asset_unlock_tx_too_big_fee ,
336
348
result_expected = {'allowed' : False , 'reject-reason' : 'max-fee-exceeded' })
337
349
self .check_mempool_result (tx = asset_unlock_tx_zero_fee ,
@@ -346,8 +358,15 @@ def run_test(self):
346
358
347
359
assert_equal (asset_unlock_tx_payload .quorumHash , int (self .mninfo [0 ].node .quorum ("selectquorum" , llmq_type_test , 'e6c7a809d79f78ea85b72d5df7e9bd592aecf151e679d6e976b74f053a7f9056' )["quorumHash" ], 16 ))
348
360
361
+ self .log .info ("Test no IS for asset unlock..." )
362
+ self .nodes [0 ].sporkupdate ("SPORK_2_INSTANTSEND_ENABLED" , 0 )
363
+ self .wait_for_sporks_same ()
364
+
349
365
txid = self .send_tx (asset_unlock_tx )
350
- assert "assetUnlockTx" in node .getrawtransaction (txid , 1 )
366
+ is_id = node_wallet .sendtoaddress (node_wallet .getnewaddress (), 1 )
367
+ for node in self .nodes :
368
+ self .wait_for_instantlock (is_id , node )
369
+
351
370
352
371
tip = self .nodes [0 ].getblockcount ()
353
372
indexes_statuses_no_height = self .nodes [0 ].getassetunlockstatuses (["101" , "102" , "300" ])
@@ -356,13 +375,30 @@ def run_test(self):
356
375
assert_equal ([{'index' : 101 , 'status' : 'unknown' }, {'index' : 102 , 'status' : 'unknown' }, {'index' : 300 , 'status' : 'unknown' }], indexes_statuses_height )
357
376
358
377
359
- self .mempool_size += 1
378
+ rawtx = node .getrawtransaction (txid , 1 )
379
+ rawtx_is = node .getrawtransaction (is_id , 1 )
380
+ assert_equal (rawtx ["instantlock" ], False )
381
+ assert_equal (rawtx_is ["instantlock" ], True )
382
+ assert_equal (rawtx ["chainlock" ], False )
383
+ assert_equal (rawtx_is ["chainlock" ], False )
384
+ assert not "confirmations" in rawtx
385
+ assert not "confirmations" in rawtx_is
386
+ # disable back IS
387
+ self .set_sporks ()
388
+
389
+ assert "assetUnlockTx" in node .getrawtransaction (txid , 1 )
390
+
391
+ self .mempool_size += 2
360
392
self .check_mempool_size ()
361
- self .validate_credit_pool_balance (locked_1 )
393
+ self .validate_credit_pool_balance (locked )
362
394
node .generate (1 )
363
395
self .sync_all ()
364
- self .validate_credit_pool_balance (locked_1 - COIN )
365
- self .mempool_size -= 1
396
+ assert_equal (rawtx ["instantlock" ], False )
397
+ assert_equal (rawtx ["chainlock" ], False )
398
+ rawtx = node .getrawtransaction (txid , 1 )
399
+ assert_equal (rawtx ["confirmations" ], 1 )
400
+ self .validate_credit_pool_balance (locked - COIN )
401
+ self .mempool_size -= 2
366
402
self .check_mempool_size ()
367
403
block_asset_unlock = node .getrawtransaction (asset_unlock_tx .rehash (), 1 )['blockhash' ]
368
404
@@ -373,18 +409,18 @@ def run_test(self):
373
409
self .log .info ("Mining next quorum to check tx 'asset_unlock_tx_late' is still valid..." )
374
410
self .mine_quorum (llmq_type_name = "llmq_test_platform" , llmq_type = 106 )
375
411
self .log .info ("Checking credit pool amount is same..." )
376
- self .validate_credit_pool_balance (locked_1 - 1 * COIN )
377
- self .check_mempool_result (tx = asset_unlock_tx_late , result_expected = {'allowed' : True , 'vsize' : asset_unlock_tx_late . get_vsize (), ' fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
412
+ self .validate_credit_pool_balance (locked - 1 * COIN )
413
+ self .check_mempool_result (tx = asset_unlock_tx_late , result_expected = {'allowed' : True , 'fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
378
414
self .log .info ("Checking credit pool amount still is same..." )
379
- self .validate_credit_pool_balance (locked_1 - 1 * COIN )
415
+ self .validate_credit_pool_balance (locked - 1 * COIN )
380
416
self .send_tx (asset_unlock_tx_late )
381
417
node .generate (1 )
382
418
self .sync_all ()
383
- self .validate_credit_pool_balance (locked_1 - 2 * COIN )
419
+ self .validate_credit_pool_balance (locked - 2 * COIN )
384
420
385
421
self .log .info ("Generating many blocks to make quorum far behind (even still active)..." )
386
422
self .slowly_generate_batch (too_late_height - node .getblockcount () - 1 )
387
- self .check_mempool_result (tx = asset_unlock_tx_too_late , result_expected = {'allowed' : True , 'vsize' : asset_unlock_tx_too_late . get_vsize (), ' fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
423
+ self .check_mempool_result (tx = asset_unlock_tx_too_late , result_expected = {'allowed' : True , 'fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
388
424
node .generate (1 )
389
425
self .sync_all ()
390
426
self .check_mempool_result (tx = asset_unlock_tx_too_late ,
@@ -400,28 +436,34 @@ def run_test(self):
400
436
self .log .info ("Test block invalidation with asset unlock tx..." )
401
437
for inode in self .nodes :
402
438
inode .invalidateblock (block_asset_unlock )
403
- self .validate_credit_pool_balance (locked_1 )
439
+ self .validate_credit_pool_balance (locked )
404
440
self .slowly_generate_batch (50 )
405
- self .validate_credit_pool_balance (locked_1 )
441
+ self .validate_credit_pool_balance (locked )
406
442
for inode in self .nodes :
407
443
inode .reconsiderblock (block_to_reconsider )
408
- self .validate_credit_pool_balance (locked_1 - 2 * COIN )
444
+ self .validate_credit_pool_balance (locked - 2 * COIN )
409
445
410
446
self .log .info ("Forcibly mining asset_unlock_tx_too_late and ensure block is invalid..." )
411
447
self .create_and_check_block ([asset_unlock_tx_too_late ], expected_error = "bad-assetunlock-not-active-quorum" )
412
448
413
449
node .generate (1 )
414
450
self .sync_all ()
415
451
416
- self .validate_credit_pool_balance (locked_1 - 2 * COIN )
417
- self .validate_credit_pool_balance (block_hash = block_hash_1 , expected = locked_1 )
452
+ self .validate_credit_pool_balance (locked - 2 * COIN )
453
+ self .validate_credit_pool_balance (block_hash = self .block_hash_1 , expected = locked )
454
+
455
+ self .log .info ("Forcibly mine asset_unlock_tx_full and ensure block is invalid..." )
456
+ self .create_and_check_block ([asset_unlock_tx_duplicate_index ], expected_error = "bad-assetunlock-duplicated-index" )
457
+
418
458
419
- self .log .info ("Checking too big withdrawal... expected to not be mined" )
459
+ def test_withdrawal_limits (self , node_wallet , node , pubkey ):
460
+ self .log .info ("Testing withdrawal limits..." )
461
+ self .log .info ("Too big withdrawal is expected to not be mined" )
420
462
asset_unlock_tx_full = self .create_assetunlock (201 , 1 + self .get_credit_pool_balance (), pubkey )
421
463
422
464
self .log .info ("Checking that transaction with exceeding amount accepted by mempool..." )
423
465
# Mempool doesn't know about the size of the credit pool
424
- self .check_mempool_result (tx = asset_unlock_tx_full , result_expected = {'allowed' : True , 'vsize' : asset_unlock_tx_full . get_vsize (), ' fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
466
+ self .check_mempool_result (tx = asset_unlock_tx_full , result_expected = {'allowed' : True , 'fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
425
467
426
468
txid_in_block = self .send_tx (asset_unlock_tx_full )
427
469
node .generate (1 )
@@ -434,7 +476,7 @@ def run_test(self):
434
476
435
477
self .mempool_size += 1
436
478
asset_unlock_tx_full = self .create_assetunlock (301 , self .get_credit_pool_balance (), pubkey )
437
- self .check_mempool_result (tx = asset_unlock_tx_full , result_expected = {'allowed' : True , 'vsize' : asset_unlock_tx_full . get_vsize (), ' fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
479
+ self .check_mempool_result (tx = asset_unlock_tx_full , result_expected = {'allowed' : True , 'fees' : {'base' : Decimal (str (tiny_amount / COIN ))}})
438
480
439
481
txid_in_block = self .send_tx (asset_unlock_tx_full )
440
482
node .generate (1 )
@@ -444,14 +486,12 @@ def run_test(self):
444
486
assert txid_in_block in block ['tx' ]
445
487
self .validate_credit_pool_balance (0 )
446
488
447
- self .log .info ("Forcibly mine asset_unlock_tx_full and ensure block is invalid..." )
448
- self .create_and_check_block ([asset_unlock_tx_duplicate_index ], expected_error = "bad-assetunlock-duplicated-index" )
449
-
450
489
self .log .info ("Fast forward to the next day to reset all current unlock limits..." )
451
490
self .slowly_generate_batch (blocks_in_one_day + 1 )
452
491
self .mine_quorum (llmq_type_name = "llmq_test_platform" , llmq_type = 106 )
453
492
454
493
total = self .get_credit_pool_balance ()
494
+ coins = node_wallet .listunspent ()
455
495
while total <= 10_900 * COIN :
456
496
self .log .info (f"Collecting coins in pool... Collected { total } /{ 10_900 * COIN } " )
457
497
coin = coins .pop ()
@@ -541,11 +581,13 @@ def run_test(self):
541
581
assert_equal (new_total , self .get_credit_pool_balance ())
542
582
self .check_mempool_size ()
543
583
544
- # activate MN_RR reallocation
584
+
585
+ def test_mn_rr (self , node_wallet , node , pubkey ):
545
586
self .log .info ("Activate mn_rr..." )
587
+ locked = self .get_credit_pool_balance ()
546
588
self .activate_mn_rr (expected_activation_height = node .getblockcount () + 12 * 3 )
547
589
self .log .info (f'height: { node .getblockcount ()} credit: { self .get_credit_pool_balance ()} ' )
548
- assert_equal (new_total , self .get_credit_pool_balance ())
590
+ assert_equal (locked , self .get_credit_pool_balance ())
549
591
550
592
bt = node .getblocktemplate ()
551
593
platform_reward = bt ['masternode' ][0 ]['amount' ]
@@ -556,18 +598,19 @@ def run_test(self):
556
598
assert_equal (all_mn_rewards , bt ['coinbasevalue' ] * 3 // 4 ) # 75/25 mn/miner reward split
557
599
assert_equal (platform_reward , all_mn_rewards * 375 // 1000 ) # 0.375 platform share
558
600
assert_equal (platform_reward , 31916328 )
559
- assert_equal (new_total , self .get_credit_pool_balance ())
601
+ assert_equal (locked , self .get_credit_pool_balance ())
560
602
node .generate (1 )
561
603
self .sync_all ()
562
- new_total += platform_reward
563
- assert_equal (new_total , self .get_credit_pool_balance ())
604
+ locked += platform_reward
605
+ assert_equal (locked , self .get_credit_pool_balance ())
564
606
607
+ coins = node_wallet .listunspent ()
565
608
coin = coins .pop ()
566
609
self .send_tx (self .create_assetlock (coin , COIN , pubkey ))
567
- new_total += platform_reward + COIN
610
+ locked += platform_reward + COIN
568
611
node .generate (1 )
569
612
self .sync_all ()
570
- assert_equal (new_total , self .get_credit_pool_balance ())
613
+ assert_equal (locked , self .get_credit_pool_balance ())
571
614
572
615
573
616
if __name__ == '__main__' :
0 commit comments