Skip to content

Commit fa40eb5

Browse files
author
MarcoFalke
committed
test: Speed up mempool_spend_coinbase.py
1 parent fa29382 commit fa40eb5

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

test/functional/mempool_spend_coinbase.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,41 @@
2020
class MempoolSpendCoinbaseTest(BitcoinTestFramework):
2121
def set_test_params(self):
2222
self.num_nodes = 1
23-
self.setup_clean_chain = True
2423

2524
def run_test(self):
2625
wallet = MiniWallet(self.nodes[0])
2726

28-
wallet.generate(200)
29-
chain_height = self.nodes[0].getblockcount()
30-
assert_equal(chain_height, 200)
27+
# Invalidate two blocks, so that miniwallet has access to a coin that will mature in the next block
28+
chain_height = 198
29+
self.nodes[0].invalidateblock(self.nodes[0].getblockhash(chain_height + 1))
30+
assert_equal(chain_height, self.nodes[0].getblockcount())
3131

3232
# Coinbase at height chain_height-100+1 ok in mempool, should
3333
# get mined. Coinbase at height chain_height-100+2 is
3434
# too immature to spend.
35-
b = [self.nodes[0].getblockhash(n) for n in range(101, 103)]
36-
coinbase_txids = [self.nodes[0].getblock(h)['tx'][0] for h in b]
37-
utxo_101 = wallet.get_utxo(txid=coinbase_txids[0])
38-
utxo_102 = wallet.get_utxo(txid=coinbase_txids[1])
35+
wallet.scan_blocks(start=chain_height - 100 + 1, num=1)
36+
utxo_mature = wallet.get_utxo()
37+
wallet.scan_blocks(start=chain_height - 100 + 2, num=1)
38+
utxo_immature = wallet.get_utxo()
3939

40-
spend_101_id = wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_101)["txid"]
40+
spend_mature_id = wallet.send_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_mature)["txid"]
4141

42-
# coinbase at height 102 should be too immature to spend
43-
immature_tx = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_102, mempool_valid=False)
42+
# other coinbase should be too immature to spend
43+
immature_tx = wallet.create_self_transfer(from_node=self.nodes[0], utxo_to_spend=utxo_immature, mempool_valid=False)
4444
assert_raises_rpc_error(-26,
4545
"bad-txns-premature-spend-of-coinbase",
4646
lambda: self.nodes[0].sendrawtransaction(immature_tx['hex']))
4747

48-
# mempool should have just spend_101:
49-
assert_equal(self.nodes[0].getrawmempool(), [spend_101_id])
48+
# mempool should have just the mature one
49+
assert_equal(self.nodes[0].getrawmempool(), [spend_mature_id])
5050

51-
# mine a block, spend_101 should get confirmed
51+
# mine a block, mature one should get confirmed
5252
self.nodes[0].generate(1)
5353
assert_equal(set(self.nodes[0].getrawmempool()), set())
5454

55-
# ... and now height 102 can be spent:
56-
spend_102_id = self.nodes[0].sendrawtransaction(immature_tx['hex'])
57-
assert_equal(self.nodes[0].getrawmempool(), [spend_102_id])
55+
# ... and now previously immature can be spent:
56+
spend_new_id = self.nodes[0].sendrawtransaction(immature_tx['hex'])
57+
assert_equal(self.nodes[0].getrawmempool(), [spend_new_id])
5858

5959

6060
if __name__ == '__main__':

0 commit comments

Comments
 (0)