Skip to content

Commit 2b6dd4e

Browse files
committed
test: use MiniWallet for mempool_package_onemore.py
This test can now be run even with the Bitcoin Core wallet disabled.
1 parent eb3c5c4 commit 2b6dd4e

File tree

1 file changed

+26
-32
lines changed

1 file changed

+26
-32
lines changed

test/functional/mempool_package_onemore.py

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,68 @@
77
size.
88
"""
99

10-
from decimal import Decimal
11-
12-
from test_framework.blocktools import COINBASE_MATURITY
1310
from test_framework.test_framework import BitcoinTestFramework
1411
from test_framework.util import (
1512
assert_equal,
1613
assert_raises_rpc_error,
17-
chain_transaction,
1814
)
15+
from test_framework.wallet import MiniWallet
16+
1917

2018
MAX_ANCESTORS = 25
2119
MAX_DESCENDANTS = 25
2220

21+
2322
class MempoolPackagesTest(BitcoinTestFramework):
2423
def set_test_params(self):
2524
self.num_nodes = 1
2625
self.extra_args = [["-maxorphantx=1000"]]
2726

28-
def skip_test_if_missing_module(self):
29-
self.skip_if_no_wallet()
27+
def chain_tx(self, utxos_to_spend, *, num_outputs=1):
28+
return self.wallet.send_self_transfer_multi(
29+
from_node=self.nodes[0],
30+
utxos_to_spend=utxos_to_spend,
31+
num_outputs=num_outputs)['new_utxos']
3032

3133
def run_test(self):
32-
# Mine some blocks and have them mature.
33-
self.generate(self.nodes[0], COINBASE_MATURITY + 1)
34-
utxo = self.nodes[0].listunspent(10)
35-
txid = utxo[0]['txid']
36-
vout = utxo[0]['vout']
37-
value = utxo[0]['amount']
34+
self.wallet = MiniWallet(self.nodes[0])
35+
self.wallet.rescan_utxos()
3836

39-
fee = Decimal("0.0002")
4037
# MAX_ANCESTORS transactions off a confirmed tx should be fine
4138
chain = []
39+
utxo = self.wallet.get_utxo()
4240
for _ in range(4):
43-
(txid, sent_value) = chain_transaction(self.nodes[0], [txid], [vout], value, fee, 2)
44-
vout = 0
45-
value = sent_value
46-
chain.append([txid, value])
41+
utxo, utxo2 = self.chain_tx([utxo], num_outputs=2)
42+
chain.append(utxo2)
4743
for _ in range(MAX_ANCESTORS - 4):
48-
(txid, sent_value) = chain_transaction(self.nodes[0], [txid], [0], value, fee, 1)
49-
value = sent_value
50-
chain.append([txid, value])
51-
(second_chain, second_chain_value) = chain_transaction(self.nodes[0], [utxo[1]['txid']], [utxo[1]['vout']], utxo[1]['amount'], fee, 1)
44+
utxo, = self.chain_tx([utxo])
45+
chain.append(utxo)
46+
second_chain, = self.chain_tx([self.wallet.get_utxo()])
5247

5348
# Check mempool has MAX_ANCESTORS + 1 transactions in it
5449
assert_equal(len(self.nodes[0].getrawmempool()), MAX_ANCESTORS + 1)
5550

5651
# Adding one more transaction on to the chain should fail.
57-
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many unconfirmed ancestors [limit: 25]", chain_transaction, self.nodes[0], [txid], [0], value, fee, 1)
52+
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many unconfirmed ancestors [limit: 25]", self.chain_tx, [utxo])
5853
# ...even if it chains on from some point in the middle of the chain.
59-
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many descendants", chain_transaction, self.nodes[0], [chain[2][0]], [1], chain[2][1], fee, 1)
60-
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many descendants", chain_transaction, self.nodes[0], [chain[1][0]], [1], chain[1][1], fee, 1)
54+
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many descendants", self.chain_tx, [chain[2]])
55+
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many descendants", self.chain_tx, [chain[1]])
6156
# ...even if it chains on to two parent transactions with one in the chain.
62-
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many descendants", chain_transaction, self.nodes[0], [chain[0][0], second_chain], [1, 0], chain[0][1] + second_chain_value, fee, 1)
57+
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many descendants", self.chain_tx, [chain[0], second_chain])
6358
# ...especially if its > 40k weight
64-
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many descendants", chain_transaction, self.nodes[0], [chain[0][0]], [1], chain[0][1], fee, 350)
59+
assert_raises_rpc_error(-26, "too-long-mempool-chain, too many descendants", self.chain_tx, [chain[0]], num_outputs=350)
6560
# But not if it chains directly off the first transaction
66-
(replacable_txid, replacable_orig_value) = chain_transaction(self.nodes[0], [chain[0][0]], [1], chain[0][1], fee, 1)
61+
replacable_tx = self.wallet.send_self_transfer_multi(from_node=self.nodes[0], utxos_to_spend=[chain[0]])['tx']
6762
# and the second chain should work just fine
68-
chain_transaction(self.nodes[0], [second_chain], [0], second_chain_value, fee, 1)
63+
self.chain_tx([second_chain])
6964

7065
# Make sure we can RBF the chain which used our carve-out rule
71-
second_tx_outputs = {self.nodes[0].getrawtransaction(replacable_txid, True)["vout"][0]['scriptPubKey']['address']: replacable_orig_value - (Decimal(1) / Decimal(100))}
72-
second_tx = self.nodes[0].createrawtransaction([{'txid': chain[0][0], 'vout': 1}], second_tx_outputs)
73-
signed_second_tx = self.nodes[0].signrawtransactionwithwallet(second_tx)
74-
self.nodes[0].sendrawtransaction(signed_second_tx['hex'])
66+
replacable_tx.vout[0].nValue -= 1000000
67+
self.nodes[0].sendrawtransaction(replacable_tx.serialize().hex())
7568

7669
# Finally, check that we added two transactions
7770
assert_equal(len(self.nodes[0].getrawmempool()), MAX_ANCESTORS + 3)
7871

72+
7973
if __name__ == '__main__':
8074
MempoolPackagesTest().main()

0 commit comments

Comments
 (0)