|
45 | 45 | llmq_type_test = 106 # LLMQType::LLMQ_TEST_PLATFORM |
46 | 46 | tiny_amount = int(Decimal("0.0007") * COIN) |
47 | 47 | blocks_in_one_day = 576 |
| 48 | +HEIGHT_DIFF_EXPIRING = 48 |
48 | 49 |
|
49 | 50 | class AssetLocksTest(DashTestFramework): |
50 | 51 | def set_test_params(self): |
@@ -272,7 +273,7 @@ def run_test(self): |
272 | 273 | self.test_asset_unlocks(node_wallet, node, pubkey) |
273 | 274 | self.test_withdrawal_limits(node_wallet, node, pubkey) |
274 | 275 | 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) |
276 | 277 |
|
277 | 278 |
|
278 | 279 | def test_asset_locks(self, node_wallet, node, pubkey): |
@@ -347,7 +348,7 @@ def test_asset_unlocks(self, node_wallet, node, pubkey): |
347 | 348 | asset_unlock_tx_duplicate_index = copy.deepcopy(asset_unlock_tx) |
348 | 349 | # modify this tx with duplicated index to make a hash of tx different, otherwise tx would be refused too early |
349 | 350 | 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 |
351 | 352 |
|
352 | 353 | self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}}) |
353 | 354 | self.check_mempool_result(tx=asset_unlock_tx_too_big_fee, |
@@ -640,33 +641,45 @@ def test_mn_rr(self, node_wallet, node, pubkey): |
640 | 641 | self.generate(node, 1) |
641 | 642 | assert_equal(locked, self.get_credit_pool_balance()) |
642 | 643 |
|
643 | | - def test_withdrawal_fork(self, node_wallet, node, pubkey): |
| 644 | + def test_withdrawal_fork(self, node_wallet, pubkey): |
644 | 645 | self.log.info("Testing asset unlock after 'withdrawal' activation...") |
| 646 | + assert softfork_active(node_wallet, 'withdrawals') |
645 | 647 |
|
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)) |
648 | 654 |
|
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))}}) |
652 | 657 |
|
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))}}) |
655 | 665 |
|
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'] |
658 | 668 | 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'] |
659 | 670 |
|
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 |
661 | 678 |
|
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") |
666 | 680 | self.mine_quorum_2_nodes(llmq_type_name="llmq_test_platform", llmq_type=106) |
667 | 681 | self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': False, 'reject-reason': 'bad-assetunlock-too-old-quorum'}) |
668 | 682 |
|
669 | 683 |
|
670 | | - |
671 | 684 | if __name__ == '__main__': |
672 | 685 | AssetLocksTest().main() |
0 commit comments