0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-02 09:46:52 -05:00

Merge bitcoin/bitcoin#24533: test: use MiniWallet for feature_maxuploadtarget.py

aab552fa30 test: use MiniWallet for feature_maxuploadtarget.py (Sebastian Falbesoner)

Pull request description:

  This PR enables one more of the non-wallet functional tests (feature_maxuploadtarget.py) to be run even with the Bitcoin Core wallet disabled by using the MiniWallet instead, as proposed in https://github.com/bitcoin/bitcoin/issues/20078. Note that the adapted helper function `mine_large_block` is currently only is used in this test, i.e. there was no need to change any others.

ACKs for top commit:
  brunoerg:
    crACK aab552fa30

Tree-SHA512: 82fb962ae40e3717419b063af295fc03ac5d5dfe4266dee8ba7f6c86800ede1d32f8fa632c189c30e982badf0c6083fcf6eca4798221f6e284c5e01a8b1a1ed9
This commit is contained in:
MarcoFalke 2022-03-13 09:43:24 +01:00
commit f94784f5bc
No known key found for this signature in database
GPG key ID: CE2B75697E69A548
2 changed files with 23 additions and 19 deletions

View file

@ -13,10 +13,19 @@ if uploadtarget has been reached.
from collections import defaultdict from collections import defaultdict
import time import time
from test_framework.messages import CInv, MSG_BLOCK, msg_getdata from test_framework.messages import (
CInv,
MSG_BLOCK,
msg_getdata,
)
from test_framework.p2p import P2PInterface from test_framework.p2p import P2PInterface
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import assert_equal, mine_large_block from test_framework.util import (
assert_equal,
mine_large_block,
)
from test_framework.wallet import MiniWallet
class TestP2PConn(P2PInterface): class TestP2PConn(P2PInterface):
def __init__(self): def __init__(self):
@ -41,12 +50,6 @@ class MaxUploadTest(BitcoinTestFramework):
]] ]]
self.supports_cli = False self.supports_cli = False
# Cache for utxos, as the listunspent may take a long time later in the test
self.utxo_cache = []
def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
def run_test(self): def run_test(self):
# Before we connect anything, we first set the time on the node # Before we connect anything, we first set the time on the node
# to be in the past, otherwise things break because the CNode # to be in the past, otherwise things break because the CNode
@ -55,7 +58,8 @@ class MaxUploadTest(BitcoinTestFramework):
self.nodes[0].setmocktime(old_time) self.nodes[0].setmocktime(old_time)
# Generate some old blocks # Generate some old blocks
self.generate(self.nodes[0], 130) self.wallet = MiniWallet(self.nodes[0])
self.generate(self.wallet, 130)
# p2p_conns[0] will only request old blocks # p2p_conns[0] will only request old blocks
# p2p_conns[1] will only request new blocks # p2p_conns[1] will only request new blocks
@ -66,7 +70,7 @@ class MaxUploadTest(BitcoinTestFramework):
p2p_conns.append(self.nodes[0].add_p2p_connection(TestP2PConn())) p2p_conns.append(self.nodes[0].add_p2p_connection(TestP2PConn()))
# Now mine a big block # Now mine a big block
mine_large_block(self, self.nodes[0], self.utxo_cache) mine_large_block(self, self.wallet, self.nodes[0])
# Store the hash; we'll request this later # Store the hash; we'll request this later
big_old_block = self.nodes[0].getbestblockhash() big_old_block = self.nodes[0].getbestblockhash()
@ -77,7 +81,7 @@ class MaxUploadTest(BitcoinTestFramework):
self.nodes[0].setmocktime(int(time.time()) - 2*60*60*24) self.nodes[0].setmocktime(int(time.time()) - 2*60*60*24)
# Mine one more block, so that the prior block looks old # Mine one more block, so that the prior block looks old
mine_large_block(self, self.nodes[0], self.utxo_cache) mine_large_block(self, self.wallet, self.nodes[0])
# We'll be requesting this new block too # We'll be requesting this new block too
big_new_block = self.nodes[0].getbestblockhash() big_new_block = self.nodes[0].getbestblockhash()

View file

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