Skip to content

Commit fddce7e

Browse files
committed
test: use MiniWallet for mining_getblocktemplate_longpoll.py
This test can now be run even with the Bitcoin Core wallet disabled.
1 parent 0d22482 commit fddce7e

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

test/functional/mining_getblocktemplate_longpoll.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
"""Test longpolling with getblocktemplate."""
66

77
from decimal import Decimal
8+
import random
9+
import threading
810

911
from test_framework.test_framework import BitcoinTestFramework
10-
from test_framework.util import get_rpc_proxy, random_transaction
12+
from test_framework.util import get_rpc_proxy
13+
from test_framework.wallet import MiniWallet
1114

12-
import threading
1315

1416
class LongpollThread(threading.Thread):
1517
def __init__(self, node):
@@ -29,9 +31,6 @@ def set_test_params(self):
2931
self.num_nodes = 2
3032
self.supports_cli = False
3133

32-
def skip_test_if_missing_module(self):
33-
self.skip_if_no_wallet()
34-
3534
def run_test(self):
3635
self.log.info("Warning: this test will take about 70 seconds in the best case. Be patient.")
3736
self.nodes[0].generate(10)
@@ -48,26 +47,32 @@ def run_test(self):
4847
thr.join(5) # wait 5 seconds or until thread exits
4948
assert thr.is_alive()
5049

50+
miniwallets = [ MiniWallet(node) for node in self.nodes ]
5151
# Test 2: test that longpoll will terminate if another node generates a block
52-
self.nodes[1].generate(1) # generate a block on another node
52+
miniwallets[1].generate(1) # generate a block on another node
5353
# check that thread will exit now that new transaction entered mempool
5454
thr.join(5) # wait 5 seconds or until thread exits
5555
assert not thr.is_alive()
5656

5757
# Test 3: test that longpoll will terminate if we generate a block ourselves
5858
thr = LongpollThread(self.nodes[0])
5959
thr.start()
60-
self.nodes[0].generate(1) # generate a block on another node
60+
miniwallets[0].generate(1) # generate a block on own node
6161
thr.join(5) # wait 5 seconds or until thread exits
6262
assert not thr.is_alive()
6363

64+
# Add enough mature utxos to the wallets, so that all txs spend confirmed coins
65+
self.nodes[0].generate(100)
66+
self.sync_blocks()
67+
6468
# Test 4: test that introducing a new transaction into the mempool will terminate the longpoll
6569
thr = LongpollThread(self.nodes[0])
6670
thr.start()
6771
# generate a random transaction and submit it
6872
min_relay_fee = self.nodes[0].getnetworkinfo()["relayfee"]
69-
# min_relay_fee is fee per 1000 bytes, which should be more than enough.
70-
(txid, txhex, fee) = random_transaction(self.nodes, Decimal("1.1"), min_relay_fee, Decimal("0.001"), 20)
73+
fee_rate = min_relay_fee + Decimal('0.00000010') * random.randint(0,20)
74+
miniwallets[0].send_self_transfer(from_node=random.choice(self.nodes),
75+
fee_rate=fee_rate)
7176
# after one minute, every 10 seconds the mempool is probed, so in 80 seconds it should have returned
7277
thr.join(60 + 20)
7378
assert not thr.is_alive()

0 commit comments

Comments
 (0)