Skip to content

Commit

Permalink
feat: improve improved funtional test feature_asset_locks.py to test …
Browse files Browse the repository at this point in the history
…more

 - rollback of block with tx Asset Lock
 - rollback of block with tx Asset Unlock
 - duplicate 'asset unlock' tx for new block

asset unlock rollback and reconsider
  • Loading branch information
knst committed Oct 4, 2022
1 parent f3fe87d commit 16478ce
Showing 1 changed file with 42 additions and 3 deletions.
45 changes: 42 additions & 3 deletions test/functional/feature_asset_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,17 +169,37 @@ def run_test(self):
node.generate(13)
self.sync_all()

assert_equal(get_credit_pool_amount(node), locked_1)

# tx is mined, let's get blockhash
self.log.info("Invalidate block with asset lock tx...")
block_hash_1 = node.gettransaction(txid_in_block)['blockhash']
self.log.info(block_hash_1)
for inode in self.nodes:
inode.invalidateblock(block_hash_1)
node.generate(3)
self.sync_all()
assert_equal(get_credit_pool_amount(node), 0)
self.log.info("Resubmit asset lock tx to new chain...")
txid_in_block = node.sendrawtransaction(hexstring=asset_lock_tx.serialize().hex(), maxfeerate=0)
node.generate(3)
self.sync_all()

assert_equal(get_credit_pool_amount(node), locked_1)

self.log.info("Mining a quorum...")
self.mine_quorum()
node.generate(3)
self.sync_all()
assert_equal(get_credit_pool_amount(node), locked_1)
self.log.info("Reconsider old blocks...")
for inode in self.nodes:
inode.reconsiderblock(block_hash_1)
assert_equal(get_credit_pool_amount(node), locked_1)
self.sync_all()

self.log.info("Mine a quorum...")
self.mine_quorum()
node.generate(3)
self.sync_all()
assert_equal(get_credit_pool_amount(node), locked_1)

self.log.info("Testing asset unlock...")
asset_unlock_tx = create_assetunlock(node, self.mninfo, 101, COIN, pubkey)
Expand All @@ -197,6 +217,25 @@ def run_test(self):
assert_equal(asset_unlock_tx_payload.quorumHash, int(self.mninfo[0].node.quorum("selectquorum", llmq_type_test, 'e6c7a809d79f78ea85b72d5df7e9bd592aecf151e679d6e976b74f053a7f9056')["quorumHash"], 16))

node.sendrawtransaction(hexstring=asset_unlock_tx.serialize().hex(), maxfeerate=0)
node.generate(1)
self.sync_all()
try:
node.sendrawtransaction(hexstring=asset_unlock_tx.serialize().hex(), maxfeerate=0)
raise AssertionError("Transaction should not be mined: double copy")
except JSONRPCException as e:
assert "Transaction already in block chain" in e.error['message']

self.log.info("Invalidate block with asset unlock tx...")
block_asset_unlock = node.getbestblockhash()
for inode in self.nodes:
inode.invalidateblock(block_asset_unlock)
assert_equal(get_credit_pool_amount(node), locked_1)
# TODO: strange, fails if generate there new blocks
#node.generate(3)
#self.sync_all()
for inode in self.nodes:
inode.reconsiderblock(block_asset_unlock)
assert_equal(get_credit_pool_amount(node), locked_1 - COIN)

# mine next quorum, tx should be still accepted
self.mine_quorum()
Expand Down

0 comments on commit 16478ce

Please sign in to comment.