Skip to content

Commit

Permalink
test: fix intermittent issue in feature_bip68_sequence
Browse files Browse the repository at this point in the history
To avoid `bad-txns-premature-spend-of-coinbase` error,
when getting a utxo (using `get_utxo`) to create a new
transaction `get_utxo` shouldn't return by default
immature coinbase.
  • Loading branch information
brunoerg committed May 19, 2023
1 parent 7be7e62 commit 60ced90
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion test/functional/mempool_compatibility.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ def run_test(self):
# unbroadcasted_tx won't pass old_node's `MemPoolAccept::PreChecks`.
self.connect_nodes(0, 1)
self.sync_blocks()
self.stop_node(1)

self.log.info("Add a transaction to mempool on old node and shutdown")
old_tx_hash = new_wallet.send_self_transfer(from_node=old_node)["txid"]
assert old_tx_hash in old_node.getrawmempool()
self.stop_node(0)
self.stop_node(1)

self.log.info("Move mempool.dat from old to new node")
old_node_mempool = os.path.join(old_node.datadir, self.chain, 'mempool.dat')
Expand Down
1 change: 1 addition & 0 deletions test/functional/mempool_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def run_test(self):
def test_persist_unbroadcast(self):
node0 = self.nodes[0]
self.start_node(0)
self.start_node(2)

# clear out mempool
self.generate(node0, 1, sync_fun=self.no_op)
Expand Down
4 changes: 3 additions & 1 deletion test/functional/test_framework/wallet.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,12 @@ def get_utxo(self, *, txid: str = '', vout: Optional[int] = None, mark_as_spent=
txid: get the first utxo we find from a specific transaction
"""
self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height'])) # Put the largest utxo last
blocks_height = self._test_node.getblockchaininfo()['blocks']
mature_coins = list(filter(lambda utxo: not utxo['coinbase'] or COINBASE_MATURITY - 1 <= blocks_height - utxo['height'], self._utxos))
if txid:
utxo_filter: Any = filter(lambda utxo: txid == utxo['txid'], self._utxos)
else:
utxo_filter = reversed(self._utxos) # By default the largest utxo
utxo_filter = reversed(mature_coins) # By default the largest utxo
if vout is not None:
utxo_filter = filter(lambda utxo: vout == utxo['vout'], utxo_filter)
index = self._utxos.index(next(utxo_filter))
Expand Down

0 comments on commit 60ced90

Please sign in to comment.