|
24 | 24 | from test_framework.test_framework import BitcoinTestFramework
|
25 | 25 | from test_framework.util import (
|
26 | 26 | assert_equal,
|
| 27 | + assert_fee_amount, |
27 | 28 | assert_greater_than,
|
28 | 29 | assert_raises_rpc_error,
|
29 | 30 | get_fee,
|
@@ -111,6 +112,7 @@ def run_test(self):
|
111 | 112 | test_no_more_inputs_fails(self, rbf_node, dest_address)
|
112 | 113 | self.test_bump_back_to_yourself()
|
113 | 114 | self.test_provided_change_pos(rbf_node)
|
| 115 | + self.test_single_output() |
114 | 116 |
|
115 | 117 | # Context independent tests
|
116 | 118 | test_feerate_checks_replaced_outputs(self, rbf_node, peer_node)
|
@@ -263,6 +265,43 @@ def test_provided_change_pos(self, rbf_node):
|
263 | 265 | assert_greater_than(change_value, new_change_value)
|
264 | 266 |
|
265 | 267 |
|
| 268 | + def test_single_output(self): |
| 269 | + self.log.info("Test that single output txs can be bumped") |
| 270 | + node = self.nodes[1] |
| 271 | + |
| 272 | + node.createwallet("single_out_rbf") |
| 273 | + wallet = node.get_wallet_rpc("single_out_rbf") |
| 274 | + |
| 275 | + addr = wallet.getnewaddress() |
| 276 | + amount = Decimal("0.001") |
| 277 | + # Make 2 UTXOs |
| 278 | + self.nodes[0].sendtoaddress(addr, amount) |
| 279 | + self.nodes[0].sendtoaddress(addr, amount) |
| 280 | + self.generate(self.nodes[0], 1) |
| 281 | + utxos = wallet.listunspent() |
| 282 | + |
| 283 | + tx = wallet.sendall(recipients=[wallet.getnewaddress()], fee_rate=2, options={"inputs": [utxos[0]]}) |
| 284 | + |
| 285 | + # Reduce the only output with a crazy high feerate, should fail as the output would be dust |
| 286 | + assert_raises_rpc_error(-4, "The transaction amount is too small to pay the fee", wallet.bumpfee, txid=tx["txid"], options={"fee_rate": 1100, "reduce_output": 0}) |
| 287 | + |
| 288 | + # Reduce the only output successfully |
| 289 | + bumped = wallet.bumpfee(txid=tx["txid"], options={"fee_rate": 10, "reduce_output": 0}) |
| 290 | + bumped_tx = wallet.gettransaction(txid=bumped["txid"], verbose=True) |
| 291 | + assert_equal(len(bumped_tx["decoded"]["vout"]), 1) |
| 292 | + assert_equal(len(bumped_tx["decoded"]["vin"]), 1) |
| 293 | + assert_equal(bumped_tx["decoded"]["vout"][0]["value"] + bumped["fee"], amount) |
| 294 | + assert_fee_amount(bumped["fee"], bumped_tx["decoded"]["vsize"], Decimal(10) / Decimal(1e8) * 1000) |
| 295 | + |
| 296 | + # Bumping without reducing adds a new input and output |
| 297 | + bumped = wallet.bumpfee(txid=bumped["txid"], options={"fee_rate": 20}) |
| 298 | + bumped_tx = wallet.gettransaction(txid=bumped["txid"], verbose=True) |
| 299 | + assert_equal(len(bumped_tx["decoded"]["vout"]), 2) |
| 300 | + assert_equal(len(bumped_tx["decoded"]["vin"]), 2) |
| 301 | + assert_fee_amount(bumped["fee"], bumped_tx["decoded"]["vsize"], Decimal(20) / Decimal(1e8) * 1000) |
| 302 | + |
| 303 | + wallet.unloadwallet() |
| 304 | + |
266 | 305 | def test_simple_bumpfee_succeeds(self, mode, rbf_node, peer_node, dest_address):
|
267 | 306 | self.log.info('Test simple bumpfee: {}'.format(mode))
|
268 | 307 | rbfid = spend_one_input(rbf_node, dest_address)
|
|
0 commit comments