9
9
10
10
from test_framework .p2p import P2PTxInvStore
11
11
from test_framework .test_framework import BitcoinTestFramework
12
- from test_framework .util import (
13
- assert_equal ,
14
- create_confirmed_utxos ,
15
- )
12
+ from test_framework .util import assert_equal
13
+ from test_framework .wallet import MiniWallet
16
14
17
15
MAX_INITIAL_BROADCAST_DELAY = 15 * 60 # 15 minutes in seconds
18
16
19
17
class MempoolUnbroadcastTest (BitcoinTestFramework ):
20
18
def set_test_params (self ):
21
19
self .num_nodes = 2
22
-
23
- def skip_test_if_missing_module (self ):
24
- self .skip_if_no_wallet ()
20
+ if self .is_wallet_compiled ():
21
+ self .requires_wallet = True
25
22
26
23
def run_test (self ):
24
+ self .wallet = MiniWallet (self .nodes [0 ])
25
+ self .wallet .rescan_utxos ()
27
26
self .test_broadcast ()
28
27
self .test_txn_removal ()
29
28
30
29
def test_broadcast (self ):
31
30
self .log .info ("Test that mempool reattempts delivery of locally submitted transaction" )
32
31
node = self .nodes [0 ]
33
32
34
- min_relay_fee = node .getnetworkinfo ()["relayfee" ]
35
- utxos = create_confirmed_utxos (self , min_relay_fee , node , 10 )
36
-
37
33
self .disconnect_nodes (0 , 1 )
38
34
39
35
self .log .info ("Generate transactions that only node 0 knows about" )
40
36
41
- # generate a wallet txn
42
- addr = node .getnewaddress ()
43
- wallet_tx_hsh = node .sendtoaddress (addr , 0.0001 )
37
+ if self .is_wallet_compiled ():
38
+ # generate a wallet txn
39
+ addr = node .getnewaddress ()
40
+ wallet_tx_hsh = node .sendtoaddress (addr , 0.0001 )
44
41
45
42
# generate a txn using sendrawtransaction
46
- us0 = utxos .pop ()
47
- inputs = [{"txid" : us0 ["txid" ], "vout" : us0 ["vout" ]}]
48
- outputs = {addr : 0.0001 }
49
- tx = node .createrawtransaction (inputs , outputs )
50
- node .settxfee (min_relay_fee )
51
- txF = node .fundrawtransaction (tx )
52
- txFS = node .signrawtransactionwithwallet (txF ["hex" ])
43
+ txFS = self .wallet .create_self_transfer (from_node = node )
53
44
rpc_tx_hsh = node .sendrawtransaction (txFS ["hex" ])
54
45
55
46
# check transactions are in unbroadcast using rpc
56
47
mempoolinfo = self .nodes [0 ].getmempoolinfo ()
57
- assert_equal (mempoolinfo ['unbroadcastcount' ], 2 )
48
+ unbroadcast_count = 1
49
+ if self .is_wallet_compiled ():
50
+ unbroadcast_count += 1
51
+ assert_equal (mempoolinfo ['unbroadcastcount' ], unbroadcast_count )
58
52
mempool = self .nodes [0 ].getrawmempool (True )
59
53
for tx in mempool :
60
54
assert_equal (mempool [tx ]['unbroadcast' ], True )
61
55
62
56
# check that second node doesn't have these two txns
63
57
mempool = self .nodes [1 ].getrawmempool ()
64
58
assert rpc_tx_hsh not in mempool
65
- assert wallet_tx_hsh not in mempool
59
+ if self .is_wallet_compiled ():
60
+ assert wallet_tx_hsh not in mempool
66
61
67
62
# ensure that unbroadcast txs are persisted to mempool.dat
68
63
self .restart_node (0 )
@@ -75,7 +70,8 @@ def test_broadcast(self):
75
70
self .sync_mempools (timeout = 30 )
76
71
mempool = self .nodes [1 ].getrawmempool ()
77
72
assert rpc_tx_hsh in mempool
78
- assert wallet_tx_hsh in mempool
73
+ if self .is_wallet_compiled ():
74
+ assert wallet_tx_hsh in mempool
79
75
80
76
# check that transactions are no longer in first node's unbroadcast set
81
77
mempool = self .nodes [0 ].getrawmempool (True )
@@ -102,8 +98,7 @@ def test_txn_removal(self):
102
98
103
99
# since the node doesn't have any connections, it will not receive
104
100
# any GETDATAs & thus the transaction will remain in the unbroadcast set.
105
- addr = node .getnewaddress ()
106
- txhsh = node .sendtoaddress (addr , 0.0001 )
101
+ txhsh = self .wallet .send_self_transfer (from_node = node )["txid" ]
107
102
108
103
# check transaction was removed from unbroadcast set due to presence in
109
104
# a block
0 commit comments