5
5
"""Test longpolling with getblocktemplate."""
6
6
7
7
from decimal import Decimal
8
+ import random
9
+ import threading
8
10
9
11
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
11
14
12
- import threading
13
15
14
16
class LongpollThread (threading .Thread ):
15
17
def __init__ (self , node ):
@@ -29,9 +31,6 @@ def set_test_params(self):
29
31
self .num_nodes = 2
30
32
self .supports_cli = False
31
33
32
- def skip_test_if_missing_module (self ):
33
- self .skip_if_no_wallet ()
34
-
35
34
def run_test (self ):
36
35
self .log .info ("Warning: this test will take about 70 seconds in the best case. Be patient." )
37
36
self .nodes [0 ].generate (10 )
@@ -48,26 +47,32 @@ def run_test(self):
48
47
thr .join (5 ) # wait 5 seconds or until thread exits
49
48
assert thr .is_alive ()
50
49
50
+ miniwallets = [ MiniWallet (node ) for node in self .nodes ]
51
51
# 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
53
53
# check that thread will exit now that new transaction entered mempool
54
54
thr .join (5 ) # wait 5 seconds or until thread exits
55
55
assert not thr .is_alive ()
56
56
57
57
# Test 3: test that longpoll will terminate if we generate a block ourselves
58
58
thr = LongpollThread (self .nodes [0 ])
59
59
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
61
61
thr .join (5 ) # wait 5 seconds or until thread exits
62
62
assert not thr .is_alive ()
63
63
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
+
64
68
# Test 4: test that introducing a new transaction into the mempool will terminate the longpoll
65
69
thr = LongpollThread (self .nodes [0 ])
66
70
thr .start ()
67
71
# generate a random transaction and submit it
68
72
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 )
71
76
# after one minute, every 10 seconds the mempool is probed, so in 80 seconds it should have returned
72
77
thr .join (60 + 20 )
73
78
assert not thr .is_alive ()
0 commit comments