Skip to content

Commit ee9af95

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#24749: test: use MiniWallet for mempool_unbroadcast.py
d2ba43f test: use MiniWallet for mempool_unbroadcast.py (Ayush Sharma) Pull request description: This PR enables one of the non-wallet functional tests (mempool_unbroadcast.py) to be run even with the Bitcoin Core wallet disabled by using the MiniWallet instead, as proposed in #20078 . Top commit has no ACKs. Tree-SHA512: e4c577899b66855dafca9dab875fa9b9c68b762a8cdb14f3a7547841c4f001e79d62641e6ae202fb56a3f28aeea1779143164c872507ff8da0bd9930a8ed182e
2 parents d492dc1 + d2ba43f commit ee9af95

File tree

1 file changed

+20
-25
lines changed

1 file changed

+20
-25
lines changed

test/functional/mempool_unbroadcast.py

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,60 +9,55 @@
99

1010
from test_framework.p2p import P2PTxInvStore
1111
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
1614

1715
MAX_INITIAL_BROADCAST_DELAY = 15 * 60 # 15 minutes in seconds
1816

1917
class MempoolUnbroadcastTest(BitcoinTestFramework):
2018
def set_test_params(self):
2119
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
2522

2623
def run_test(self):
24+
self.wallet = MiniWallet(self.nodes[0])
25+
self.wallet.rescan_utxos()
2726
self.test_broadcast()
2827
self.test_txn_removal()
2928

3029
def test_broadcast(self):
3130
self.log.info("Test that mempool reattempts delivery of locally submitted transaction")
3231
node = self.nodes[0]
3332

34-
min_relay_fee = node.getnetworkinfo()["relayfee"]
35-
utxos = create_confirmed_utxos(self, min_relay_fee, node, 10)
36-
3733
self.disconnect_nodes(0, 1)
3834

3935
self.log.info("Generate transactions that only node 0 knows about")
4036

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)
4441

4542
# 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)
5344
rpc_tx_hsh = node.sendrawtransaction(txFS["hex"])
5445

5546
# check transactions are in unbroadcast using rpc
5647
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)
5852
mempool = self.nodes[0].getrawmempool(True)
5953
for tx in mempool:
6054
assert_equal(mempool[tx]['unbroadcast'], True)
6155

6256
# check that second node doesn't have these two txns
6357
mempool = self.nodes[1].getrawmempool()
6458
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
6661

6762
# ensure that unbroadcast txs are persisted to mempool.dat
6863
self.restart_node(0)
@@ -75,7 +70,8 @@ def test_broadcast(self):
7570
self.sync_mempools(timeout=30)
7671
mempool = self.nodes[1].getrawmempool()
7772
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
7975

8076
# check that transactions are no longer in first node's unbroadcast set
8177
mempool = self.nodes[0].getrawmempool(True)
@@ -102,8 +98,7 @@ def test_txn_removal(self):
10298

10399
# since the node doesn't have any connections, it will not receive
104100
# 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"]
107102

108103
# check transaction was removed from unbroadcast set due to presence in
109104
# a block

0 commit comments

Comments
 (0)