|
7 | 7 | size.
|
8 | 8 | """
|
9 | 9 |
|
10 |
| -from decimal import Decimal |
11 |
| - |
12 |
| -from test_framework.blocktools import COINBASE_MATURITY |
13 | 10 | from test_framework.test_framework import BitcoinTestFramework
|
14 | 11 | from test_framework.util import (
|
15 | 12 | assert_equal,
|
16 | 13 | assert_raises_rpc_error,
|
17 |
| - chain_transaction, |
18 | 14 | )
|
| 15 | +from test_framework.wallet import MiniWallet |
| 16 | + |
19 | 17 |
|
20 | 18 | MAX_ANCESTORS = 25
|
21 | 19 | MAX_DESCENDANTS = 25
|
22 | 20 |
|
| 21 | + |
23 | 22 | class MempoolPackagesTest(BitcoinTestFramework):
|
24 | 23 | def set_test_params(self):
|
25 | 24 | self.num_nodes = 1
|
26 | 25 | self.extra_args = [["-maxorphantx=1000"]]
|
27 | 26 |
|
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'] |
30 | 32 |
|
31 | 33 | 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() |
38 | 36 |
|
39 |
| - fee = Decimal("0.0002") |
40 | 37 | # MAX_ANCESTORS transactions off a confirmed tx should be fine
|
41 | 38 | chain = []
|
| 39 | + utxo = self.wallet.get_utxo() |
42 | 40 | 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) |
47 | 43 | 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()]) |
52 | 47 |
|
53 | 48 | # Check mempool has MAX_ANCESTORS + 1 transactions in it
|
54 | 49 | assert_equal(len(self.nodes[0].getrawmempool()), MAX_ANCESTORS + 1)
|
55 | 50 |
|
56 | 51 | # 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]) |
58 | 53 | # ...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]]) |
61 | 56 | # ...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]) |
63 | 58 | # ...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) |
65 | 60 | # 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'] |
67 | 62 | # 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]) |
69 | 64 |
|
70 | 65 | # 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()) |
75 | 68 |
|
76 | 69 | # Finally, check that we added two transactions
|
77 | 70 | assert_equal(len(self.nodes[0].getrawmempool()), MAX_ANCESTORS + 3)
|
78 | 71 |
|
| 72 | + |
79 | 73 | if __name__ == '__main__':
|
80 | 74 | MempoolPackagesTest().main()
|
0 commit comments