Skip to content

Commit

Permalink
chore: test new validation of asset unlocks tests after fork 'withdra…
Browse files Browse the repository at this point in the history
…wals'
  • Loading branch information
knst committed Oct 7, 2024
1 parent 2704003 commit 5fd7b07
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions test/functional/feature_asset_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
assert_equal,
assert_greater_than,
assert_greater_than_or_equal,
softfork_active,
)
from test_framework.wallet_util import bytes_to_wif

Expand Down Expand Up @@ -271,6 +272,7 @@ def run_test(self):
self.test_asset_unlocks(node_wallet, node, pubkey)
self.test_withdrawal_limits(node_wallet, node, pubkey)
self.test_mn_rr(node_wallet, node, pubkey)
self.test_withdrawal_fork(node_wallet, node, pubkey)


def test_asset_locks(self, node_wallet, node, pubkey):
Expand Down Expand Up @@ -430,8 +432,9 @@ def test_asset_unlocks(self, node_wallet, node, pubkey):
self.log.info("Checking that two quorums later it is too late because quorum is not active...")
self.mine_quorum_2_nodes(llmq_type_name='llmq_test_platform', llmq_type=106)
self.log.info("Expecting new reject-reason...")
assert not softfork_active(self.nodes[0], 'withdrawals')
self.check_mempool_result(tx=asset_unlock_tx_too_late,
result_expected={'allowed': False, 'reject-reason' : 'bad-assetunlock-not-active-quorum'})
result_expected={'allowed': False, 'reject-reason' : 'bad-assetunlock-too-old-quorum'})

block_to_reconsider = node.getbestblockhash()
self.log.info("Test block invalidation with asset unlock tx...")
Expand All @@ -445,7 +448,8 @@ def test_asset_unlocks(self, node_wallet, node, pubkey):
self.validate_credit_pool_balance(locked - 2 * COIN)

self.log.info("Forcibly mining asset_unlock_tx_too_late and ensure block is invalid")
self.create_and_check_block([asset_unlock_tx_too_late], expected_error = "bad-assetunlock-not-active-quorum")
assert not softfork_active(self.nodes[0], 'withdrawals')
self.create_and_check_block([asset_unlock_tx_too_late], expected_error = "bad-assetunlock-too-old-quorum")

self.generate(node, 1)

Expand Down Expand Up @@ -636,6 +640,33 @@ def test_mn_rr(self, node_wallet, node, pubkey):
self.generate(node, 1)
assert_equal(locked, self.get_credit_pool_balance())

def test_withdrawal_fork(self, node_wallet, node, pubkey):
self.log.info("Testing asset unlock after 'withdrawal' activation...")

assert softfork_active(self.nodes[0], 'withdrawals')
self.log.info("Generating several txes by same quorum....")

asset_unlock_tx = self.create_assetunlock(501, COIN, pubkey)
asset_unlock_tx_payload = CAssetUnlockTx()
asset_unlock_tx_payload.deserialize(BytesIO(asset_unlock_tx.vExtraPayload))

self.log.info("Check that new Asset Unlock is valid for current quorum")
self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})

while asset_unlock_tx_payload.quorumHash in node.quorum('list')['llmq_test_platform']:
self.log.info(f"Generate one more quorum until signing quorum becomes not available")
self.mine_quorum_2_nodes(llmq_type_name="llmq_test_platform", llmq_type=106)

self.check_mempool_result(tx=asset_unlock_tx, result_expected={'allowed': True, 'fees': {'base': Decimal(str(tiny_amount / COIN))}})

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



if __name__ == '__main__':
AssetLocksTest().main()

0 comments on commit 5fd7b07

Please sign in to comment.