Skip to content

Commit 60ced90

Browse files
committed
test: fix intermittent issue in feature_bip68_sequence
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.
1 parent 7be7e62 commit 60ced90

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

test/functional/mempool_compatibility.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@ def run_test(self):
4747
# unbroadcasted_tx won't pass old_node's `MemPoolAccept::PreChecks`.
4848
self.connect_nodes(0, 1)
4949
self.sync_blocks()
50-
self.stop_node(1)
5150

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

5757
self.log.info("Move mempool.dat from old to new node")
5858
old_node_mempool = os.path.join(old_node.datadir, self.chain, 'mempool.dat')

test/functional/mempool_persist.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ def run_test(self):
191191
def test_persist_unbroadcast(self):
192192
node0 = self.nodes[0]
193193
self.start_node(0)
194+
self.start_node(2)
194195

195196
# clear out mempool
196197
self.generate(node0, 1, sync_fun=self.no_op)

test/functional/test_framework/wallet.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,12 @@ def get_utxo(self, *, txid: str = '', vout: Optional[int] = None, mark_as_spent=
218218
txid: get the first utxo we find from a specific transaction
219219
"""
220220
self._utxos = sorted(self._utxos, key=lambda k: (k['value'], -k['height'])) # Put the largest utxo last
221+
blocks_height = self._test_node.getblockchaininfo()['blocks']
222+
mature_coins = list(filter(lambda utxo: not utxo['coinbase'] or COINBASE_MATURITY - 1 <= blocks_height - utxo['height'], self._utxos))
221223
if txid:
222224
utxo_filter: Any = filter(lambda utxo: txid == utxo['txid'], self._utxos)
223225
else:
224-
utxo_filter = reversed(self._utxos) # By default the largest utxo
226+
utxo_filter = reversed(mature_coins) # By default the largest utxo
225227
if vout is not None:
226228
utxo_filter = filter(lambda utxo: vout == utxo['vout'], utxo_filter)
227229
index = self._utxos.index(next(utxo_filter))

0 commit comments

Comments
 (0)