Skip to content

Commit

Permalink
Merge bitcoin#24749: test: use MiniWallet for mempool_unbroadcast.py
Browse files Browse the repository at this point in the history
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 bitcoin#20078  .

Top commit has no ACKs.

Tree-SHA512: e4c577899b66855dafca9dab875fa9b9c68b762a8cdb14f3a7547841c4f001e79d62641e6ae202fb56a3f28aeea1779143164c872507ff8da0bd9930a8ed182e
  • Loading branch information
MarcoFalke committed Apr 5, 2022
2 parents d492dc1 + d2ba43f commit ee9af95
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions test/functional/mempool_unbroadcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,60 +9,55 @@

from test_framework.p2p import P2PTxInvStore
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_equal,
create_confirmed_utxos,
)
from test_framework.util import assert_equal
from test_framework.wallet import MiniWallet

MAX_INITIAL_BROADCAST_DELAY = 15 * 60 # 15 minutes in seconds

class MempoolUnbroadcastTest(BitcoinTestFramework):
def set_test_params(self):
self.num_nodes = 2

def skip_test_if_missing_module(self):
self.skip_if_no_wallet()
if self.is_wallet_compiled():
self.requires_wallet = True

def run_test(self):
self.wallet = MiniWallet(self.nodes[0])
self.wallet.rescan_utxos()
self.test_broadcast()
self.test_txn_removal()

def test_broadcast(self):
self.log.info("Test that mempool reattempts delivery of locally submitted transaction")
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.log.info("Generate transactions that only node 0 knows about")

# generate a wallet txn
addr = node.getnewaddress()
wallet_tx_hsh = node.sendtoaddress(addr, 0.0001)
if self.is_wallet_compiled():
# generate a wallet txn
addr = node.getnewaddress()
wallet_tx_hsh = node.sendtoaddress(addr, 0.0001)

# generate a txn using sendrawtransaction
us0 = utxos.pop()
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"])
txFS = self.wallet.create_self_transfer(from_node=node)
rpc_tx_hsh = node.sendrawtransaction(txFS["hex"])

# check transactions are in unbroadcast using rpc
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)
for tx in mempool:
assert_equal(mempool[tx]['unbroadcast'], True)

# check that second node doesn't have these two txns
mempool = self.nodes[1].getrawmempool()
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
self.restart_node(0)
Expand All @@ -75,7 +70,8 @@ def test_broadcast(self):
self.sync_mempools(timeout=30)
mempool = self.nodes[1].getrawmempool()
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
mempool = self.nodes[0].getrawmempool(True)
Expand All @@ -102,8 +98,7 @@ def test_txn_removal(self):

# since the node doesn't have any connections, it will not receive
# any GETDATAs & thus the transaction will remain in the unbroadcast set.
addr = node.getnewaddress()
txhsh = node.sendtoaddress(addr, 0.0001)
txhsh = self.wallet.send_self_transfer(from_node=node)["txid"]

# check transaction was removed from unbroadcast set due to presence in
# a block
Expand Down

0 comments on commit ee9af95

Please sign in to comment.