Merge bitcoin/bitcoin#24749: test: use MiniWallet for mempool_unbroadcast.py

d2ba43fec82af84521f1dbe4475d01888ccf4d0d 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
This commit is contained in:
MarcoFalke 2022-04-05 14:03:41 +02:00 committed by pasta
parent 36e9b5fead
commit 33b9771ebc
No known key found for this signature in database
GPG Key ID: E2F3D7916E722D38

View File

@ -9,21 +9,20 @@ import time
from test_framework.p2p import P2PTxInvStore from test_framework.p2p import P2PTxInvStore
from test_framework.test_framework import BitcoinTestFramework from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import ( from test_framework.util import assert_equal
assert_equal, from test_framework.wallet import MiniWallet
create_confirmed_utxos,
)
MAX_INITIAL_BROADCAST_DELAY = 15 * 60 # 15 minutes in seconds MAX_INITIAL_BROADCAST_DELAY = 15 * 60 # 15 minutes in seconds
class MempoolUnbroadcastTest(BitcoinTestFramework): class MempoolUnbroadcastTest(BitcoinTestFramework):
def set_test_params(self): def set_test_params(self):
self.num_nodes = 2 self.num_nodes = 2
if self.is_wallet_compiled():
def skip_test_if_missing_module(self): self.requires_wallet = True
self.skip_if_no_wallet()
def run_test(self): def run_test(self):
self.wallet = MiniWallet(self.nodes[0])
self.wallet.rescan_utxos()
self.test_broadcast() self.test_broadcast()
self.test_txn_removal() self.test_txn_removal()
@ -31,30 +30,25 @@ class MempoolUnbroadcastTest(BitcoinTestFramework):
self.log.info("Test that mempool reattempts delivery of locally submitted transaction") self.log.info("Test that mempool reattempts delivery of locally submitted transaction")
node = self.nodes[0] node = self.nodes[0]
min_relay_fee = node.getnetworkinfo()["relayfee"]
utxos = create_confirmed_utxos(self, min_relay_fee, node, 10)
self.disconnect_nodes(0, 1) self.disconnect_nodes(0, 1)
self.log.info("Generate transactions that only node 0 knows about") self.log.info("Generate transactions that only node 0 knows about")
# generate a wallet txn if self.is_wallet_compiled():
addr = node.getnewaddress() # generate a wallet txn
wallet_tx_hsh = node.sendtoaddress(addr, 0.0001) addr = node.getnewaddress()
wallet_tx_hsh = node.sendtoaddress(addr, 0.0001)
# generate a txn using sendrawtransaction # generate a txn using sendrawtransaction
us0 = utxos.pop() txFS = self.wallet.create_self_transfer(from_node=node)
inputs = [{"txid": us0["txid"], "vout": us0["vout"]}]
outputs = {addr: 0.0001}
tx = node.createrawtransaction(inputs, outputs)
node.settxfee(min_relay_fee)
txF = node.fundrawtransaction(tx)
txFS = node.signrawtransactionwithwallet(txF["hex"])
rpc_tx_hsh = node.sendrawtransaction(txFS["hex"]) rpc_tx_hsh = node.sendrawtransaction(txFS["hex"])
# check transactions are in unbroadcast using rpc # check transactions are in unbroadcast using rpc
mempoolinfo = self.nodes[0].getmempoolinfo() mempoolinfo = self.nodes[0].getmempoolinfo()
assert_equal(mempoolinfo['unbroadcastcount'], 2) unbroadcast_count = 1
if self.is_wallet_compiled():
unbroadcast_count += 1
assert_equal(mempoolinfo['unbroadcastcount'], unbroadcast_count)
mempool = self.nodes[0].getrawmempool(True) mempool = self.nodes[0].getrawmempool(True)
for tx in mempool: for tx in mempool:
assert_equal(mempool[tx]['unbroadcast'], True) assert_equal(mempool[tx]['unbroadcast'], True)
@ -62,7 +56,8 @@ class MempoolUnbroadcastTest(BitcoinTestFramework):
# check that second node doesn't have these two txns # check that second node doesn't have these two txns
mempool = self.nodes[1].getrawmempool() mempool = self.nodes[1].getrawmempool()
assert rpc_tx_hsh not in mempool assert rpc_tx_hsh not in mempool
assert wallet_tx_hsh not in mempool if self.is_wallet_compiled():
assert wallet_tx_hsh not in mempool
# ensure that unbroadcast txs are persisted to mempool.dat # ensure that unbroadcast txs are persisted to mempool.dat
self.restart_node(0) self.restart_node(0)
@ -75,7 +70,8 @@ class MempoolUnbroadcastTest(BitcoinTestFramework):
self.sync_mempools(timeout=30) self.sync_mempools(timeout=30)
mempool = self.nodes[1].getrawmempool() mempool = self.nodes[1].getrawmempool()
assert rpc_tx_hsh in mempool assert rpc_tx_hsh in mempool
assert wallet_tx_hsh in mempool if self.is_wallet_compiled():
assert wallet_tx_hsh in mempool
# check that transactions are no longer in first node's unbroadcast set # check that transactions are no longer in first node's unbroadcast set
mempool = self.nodes[0].getrawmempool(True) mempool = self.nodes[0].getrawmempool(True)
@ -104,8 +100,7 @@ class MempoolUnbroadcastTest(BitcoinTestFramework):
# since the node doesn't have any connections, it will not receive # since the node doesn't have any connections, it will not receive
# any GETDATAs & thus the transaction will remain in the unbroadcast set. # any GETDATAs & thus the transaction will remain in the unbroadcast set.
addr = node.getnewaddress() txhsh = self.wallet.send_self_transfer(from_node=node)["txid"]
txhsh = node.sendtoaddress(addr, 0.0001)
# check transaction was removed from unbroadcast set due to presence in # check transaction was removed from unbroadcast set due to presence in
# a block # a block