Skip to content

Commit aab552f

Browse files
committed
test: use MiniWallet for feature_maxuploadtarget.py
This test can now be run even with the Bitcoin Core wallet disabled.
1 parent 23e8c70 commit aab552f

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

test/functional/feature_maxuploadtarget.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,19 @@
1313
from collections import defaultdict
1414
import time
1515

16-
from test_framework.messages import CInv, MSG_BLOCK, msg_getdata
16+
from test_framework.messages import (
17+
CInv,
18+
MSG_BLOCK,
19+
msg_getdata,
20+
)
1721
from test_framework.p2p import P2PInterface
1822
from test_framework.test_framework import BitcoinTestFramework
19-
from test_framework.util import assert_equal, mine_large_block
23+
from test_framework.util import (
24+
assert_equal,
25+
mine_large_block,
26+
)
27+
from test_framework.wallet import MiniWallet
28+
2029

2130
class TestP2PConn(P2PInterface):
2231
def __init__(self):
@@ -41,12 +50,6 @@ def set_test_params(self):
4150
]]
4251
self.supports_cli = False
4352

44-
# Cache for utxos, as the listunspent may take a long time later in the test
45-
self.utxo_cache = []
46-
47-
def skip_test_if_missing_module(self):
48-
self.skip_if_no_wallet()
49-
5053
def run_test(self):
5154
# Before we connect anything, we first set the time on the node
5255
# to be in the past, otherwise things break because the CNode
@@ -55,7 +58,8 @@ def run_test(self):
5558
self.nodes[0].setmocktime(old_time)
5659

5760
# Generate some old blocks
58-
self.generate(self.nodes[0], 130)
61+
self.wallet = MiniWallet(self.nodes[0])
62+
self.generate(self.wallet, 130)
5963

6064
# p2p_conns[0] will only request old blocks
6165
# p2p_conns[1] will only request new blocks
@@ -66,7 +70,7 @@ def run_test(self):
6670
p2p_conns.append(self.nodes[0].add_p2p_connection(TestP2PConn()))
6771

6872
# Now mine a big block
69-
mine_large_block(self, self.nodes[0], self.utxo_cache)
73+
mine_large_block(self, self.wallet, self.nodes[0])
7074

7175
# Store the hash; we'll request this later
7276
big_old_block = self.nodes[0].getbestblockhash()
@@ -77,7 +81,7 @@ def run_test(self):
7781
self.nodes[0].setmocktime(int(time.time()) - 2*60*60*24)
7882

7983
# Mine one more block, so that the prior block looks old
80-
mine_large_block(self, self.nodes[0], self.utxo_cache)
84+
mine_large_block(self, self.wallet, self.nodes[0])
8185

8286
# We'll be requesting this new block too
8387
big_new_block = self.nodes[0].getbestblockhash()

test/functional/test_framework/util.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -573,17 +573,17 @@ def create_lots_of_big_transactions(node, txouts, utxos, num, fee):
573573
return txids
574574

575575

576-
def mine_large_block(test_framework, node, utxos=None):
576+
def mine_large_block(test_framework, mini_wallet, node):
577577
# generate a 66k transaction,
578578
# and 14 of them is close to the 1MB block limit
579-
num = 14
580579
txouts = gen_return_txouts()
581-
utxos = utxos if utxos is not None else []
582-
if len(utxos) < num:
583-
utxos.clear()
584-
utxos.extend(node.listunspent())
585-
fee = 100 * node.getnetworkinfo()["relayfee"]
586-
create_lots_of_big_transactions(node, txouts, utxos, num, fee=fee)
580+
from .messages import COIN
581+
fee = 100 * int(node.getnetworkinfo()["relayfee"] * COIN)
582+
for _ in range(14):
583+
tx = mini_wallet.create_self_transfer(from_node=node, fee_rate=0, mempool_valid=False)['tx']
584+
tx.vout[0].nValue -= fee
585+
tx.vout.extend(txouts)
586+
mini_wallet.sendrawtransaction(from_node=node, tx_hex=tx.serialize().hex())
587587
test_framework.generate(node, 1)
588588

589589

0 commit comments

Comments
 (0)