Skip to content

Commit 0c8b377

Browse files
committed
test: fix test_withdrawal_fork
1 parent 9889d8f commit 0c8b377

File tree

1 file changed

+31
-18
lines changed

1 file changed

+31
-18
lines changed

test/functional/feature_asset_locks.py

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
llmq_type_test = 106 # LLMQType::LLMQ_TEST_PLATFORM
4646
tiny_amount = int(Decimal("0.0007") * COIN)
4747
blocks_in_one_day = 576
48+
HEIGHT_DIFF_EXPIRING = 48
4849

4950
class AssetLocksTest(DashTestFramework):
5051
def set_test_params(self):
@@ -272,7 +273,7 @@ def run_test(self):
272273
self.test_asset_unlocks(node_wallet, node, pubkey)
273274
self.test_withdrawal_limits(node_wallet, node, pubkey)
274275
self.test_mn_rr(node_wallet, node, pubkey)
275-
self.test_withdrawal_fork(node_wallet, node, pubkey)
276+
self.test_withdrawal_fork(node_wallet, pubkey)
276277

277278

278279
def test_asset_locks(self, node_wallet, node, pubkey):
@@ -347,7 +348,7 @@ def test_asset_unlocks(self, node_wallet, node, pubkey):
347348
asset_unlock_tx_duplicate_index = copy.deepcopy(asset_unlock_tx)
348349
# modify this tx with duplicated index to make a hash of tx different, otherwise tx would be refused too early
349350
asset_unlock_tx_duplicate_index.vout[0].nValue += COIN
350-
too_late_height = node.getblockcount() + 48
351+
too_late_height = node.getblockcount() + HEIGHT_DIFF_EXPIRING
351352

352353
self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})
353354
self.check_mempool_result(tx=asset_unlock_tx_too_big_fee,
@@ -640,33 +641,45 @@ def test_mn_rr(self, node_wallet, node, pubkey):
640641
self.generate(node, 1)
641642
assert_equal(locked, self.get_credit_pool_balance())
642643

643-
def test_withdrawal_fork(self, node_wallet, node, pubkey):
644+
def test_withdrawal_fork(self, node_wallet, pubkey):
644645
self.log.info("Testing asset unlock after 'withdrawal' activation...")
646+
assert softfork_active(node_wallet, 'withdrawals')
645647

646-
assert softfork_active(self.nodes[0], 'withdrawals')
647-
self.log.info("Generating several txes by same quorum....")
648+
index = 501
649+
while True:
650+
self.log.info(f"Generating new Asset Unlock tx, index={index}...")
651+
asset_unlock_tx = self.create_assetunlock(index, COIN, pubkey)
652+
asset_unlock_tx_payload = CAssetUnlockTx()
653+
asset_unlock_tx_payload.deserialize(BytesIO(asset_unlock_tx.vExtraPayload))
648654

649-
asset_unlock_tx = self.create_assetunlock(501, COIN, pubkey)
650-
asset_unlock_tx_payload = CAssetUnlockTx()
651-
asset_unlock_tx_payload.deserialize(BytesIO(asset_unlock_tx.vExtraPayload))
655+
self.log.info("Check that Asset Unlock tx is valid for current quorum")
656+
self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})
652657

653-
self.log.info("Check that new Asset Unlock is valid for current quorum")
654-
self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})
658+
quorumHash_str = format(asset_unlock_tx_payload.quorumHash, '064x')
659+
assert quorumHash_str in node_wallet.quorum('list')['llmq_test_platform']
660+
661+
while quorumHash_str != node_wallet.quorum('list')['llmq_test_platform'][-1]:
662+
self.log.info("Generate one more quorum until signing quorum becomes the last one in the list")
663+
self.mine_quorum_2_nodes(llmq_type_name="llmq_test_platform", llmq_type=106)
664+
self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})
655665

656-
while asset_unlock_tx_payload.quorumHash in node.quorum('list')['llmq_test_platform']:
657-
self.log.info(f"Generate one more quorum until signing quorum becomes not available")
666+
self.log.info("Generate one more quorum after which signing quorum is gone but Asset Unlock tx is still valid")
667+
assert quorumHash_str in node_wallet.quorum('list')['llmq_test_platform']
658668
self.mine_quorum_2_nodes(llmq_type_name="llmq_test_platform", llmq_type=106)
669+
assert quorumHash_str not in node_wallet.quorum('list')['llmq_test_platform']
659670

660-
self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})
671+
if asset_unlock_tx_payload.requestedHeight + HEIGHT_DIFF_EXPIRING > node_wallet.getblockcount():
672+
self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})
673+
break
674+
else:
675+
self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': False, 'reject-reason' : 'bad-assetunlock-too-late'})
676+
self.log.info("Asset Unlock tx expired, let's try again...")
677+
index += 1
661678

662-
self.log.info(f"Generate one more quorum after which asset unlock meant to be still valid")
663-
self.mine_quorum_2_nodes(llmq_type_name="llmq_test_platform", llmq_type=106)
664-
self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})
665-
self.log.info(f"Generate one more quorum after which asset unlock meant to be expired")
679+
self.log.info("Generate one more quorum after which signing quorum becomes too old")
666680
self.mine_quorum_2_nodes(llmq_type_name="llmq_test_platform", llmq_type=106)
667681
self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': False, 'reject-reason': 'bad-assetunlock-too-old-quorum'})
668682

669683

670-
671684
if __name__ == '__main__':
672685
AssetLocksTest().main()

0 commit comments

Comments
 (0)