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 Sep 19, 2024
1 parent 596da74 commit 1870106
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 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 @@ -267,6 +268,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 @@ -432,8 +434,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(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 @@ -447,7 +450,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")

node.generate(1)
self.sync_all()
Expand Down Expand Up @@ -650,6 +654,30 @@ def test_mn_rr(self, node_wallet, node, pubkey):
self.sync_all()
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(401, 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(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(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 1870106

Please sign in to comment.