Skip to content

Commit

Permalink
Fix wallet_bumpfee.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Neil committed Oct 29, 2024
1 parent 0c707c8 commit bc7b37f
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions test/functional/wallet_bumpfee.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,23 +202,23 @@ def test_bump_back_to_yourself(self):
self.generate(self.nodes[0], 1)

# Create a tx with two outputs. recipient and change.
tx = wallet.send(outputs={wallet.getnewaddress(): 9}, fee_rate=2)
tx = wallet.send(outputs={wallet.getnewaddress(): 9}, fee_rate=500)
tx_info = wallet.gettransaction(txid=tx["txid"], verbose=True)
assert_equal(len(tx_info["decoded"]["vout"]), 2)
assert_equal(len(tx_info["decoded"]["vin"]), 2)

# Bump tx, send coins back to change address.
change_addr = get_change_address(tx["txid"], wallet)[0]
out_amount = 10
bumped = wallet.bumpfee(txid=tx["txid"], options={"fee_rate": 20, "outputs": [{change_addr: out_amount}]})
bumped = wallet.bumpfee(txid=tx["txid"], options={"fee_rate": 900, "outputs": [{change_addr: out_amount}]})
bumped_tx = wallet.gettransaction(txid=bumped["txid"], verbose=True)
assert_equal(len(bumped_tx["decoded"]["vout"]), 1)
assert_equal(len(bumped_tx["decoded"]["vin"]), 2)
assert_equal(bumped_tx["decoded"]["vout"][0]["value"] + bumped["fee"], out_amount)

# Bump tx again, now test send fewer coins back to change address.
out_amount = 6
bumped = wallet.bumpfee(txid=bumped["txid"], options={"fee_rate": 40, "outputs": [{change_addr: out_amount}]})
bumped = wallet.bumpfee(txid=bumped["txid"], options={"fee_rate": 1000, "outputs": [{change_addr: out_amount}]})
bumped_tx = wallet.gettransaction(txid=bumped["txid"], verbose=True)
assert_equal(len(bumped_tx["decoded"]["vout"]), 2)
assert_equal(len(bumped_tx["decoded"]["vin"]), 2)
Expand All @@ -228,7 +228,7 @@ def test_bump_back_to_yourself(self):

# Bump tx again, send more coins back to change address. The process will add another input to cover the target.
out_amount = 12
bumped = wallet.bumpfee(txid=bumped["txid"], options={"fee_rate": 80, "outputs": [{change_addr: out_amount}]})
bumped = wallet.bumpfee(txid=bumped["txid"], options={"fee_rate": 1200, "outputs": [{change_addr: out_amount}]})
bumped_tx = wallet.gettransaction(txid=bumped["txid"], verbose=True)
assert_equal(len(bumped_tx["decoded"]["vout"]), 2)
assert_equal(len(bumped_tx["decoded"]["vin"]), 3)
Expand Down Expand Up @@ -269,38 +269,38 @@ def test_provided_change_pos(self, rbf_node):
def test_single_output(self):
self.log.info("Test that single output txs can be bumped")
node = self.nodes[1]

node.createwallet("single_out_rbf")
wallet = node.get_wallet_rpc("single_out_rbf")

addr = wallet.getnewaddress()
amount = Decimal("0.001")
amount = Decimal("0.009")
# Make 2 UTXOs
self.nodes[0].sendtoaddress(addr, amount)
self.nodes[0].sendtoaddress(addr, amount)
self.generate(self.nodes[0], 1)
utxos = wallet.listunspent()

tx = wallet.sendall(recipients=[wallet.getnewaddress()], fee_rate=2, options={"inputs": [utxos[0]]})

tx = wallet.sendall(recipients=[wallet.getnewaddress()], fee_rate=500, options={"inputs": [utxos[0]]})
# Set the only output with a crazy high feerate as change, should fail as the output would be dust
assert_raises_rpc_error(-4, "The transaction amount is too small to pay the fee", wallet.bumpfee, txid=tx["txid"], options={"fee_rate": 1100, "original_change_index": 0})

assert_raises_rpc_error(-4, "The transaction amount is too small to pay the fee", wallet.bumpfee, txid=tx["txid"], options={"fee_rate": 9100, "original_change_index": 0})
# Specify single output as change successfully
bumped = wallet.bumpfee(txid=tx["txid"], options={"fee_rate": 10, "original_change_index": 0})
bumped = wallet.bumpfee(txid=tx["txid"], options={"fee_rate": 510, "original_change_index": 0})
bumped_tx = wallet.gettransaction(txid=bumped["txid"], verbose=True)
assert_equal(len(bumped_tx["decoded"]["vout"]), 1)
assert_equal(len(bumped_tx["decoded"]["vout"]), 2)
assert_equal(len(bumped_tx["decoded"]["vin"]), 1)
assert_equal(bumped_tx["decoded"]["vout"][0]["value"] + bumped["fee"], amount)
assert_fee_amount(bumped["fee"], bumped_tx["decoded"]["vsize"], Decimal(10) / Decimal(1e8) * 1000)

assert_equal(bumped_tx["decoded"]["vout"][0]["value"] + bumped_tx["decoded"]["vout"][1]["value"] + bumped["fee"], amount)
assert_fee_amount(bumped["fee"], bumped_tx["decoded"]["vsize"], Decimal(510) / Decimal(1e8) * 1000)
# Bumping without specifying change adds a new input and output
bumped = wallet.bumpfee(txid=bumped["txid"], options={"fee_rate": 20})
bumped = wallet.bumpfee(txid=bumped["txid"], options={"fee_rate": 520})
bumped_tx = wallet.gettransaction(txid=bumped["txid"], verbose=True)
assert_equal(len(bumped_tx["decoded"]["vout"]), 2)
assert_equal(len(bumped_tx["decoded"]["vin"]), 2)
assert_fee_amount(bumped["fee"], bumped_tx["decoded"]["vsize"], Decimal(20) / Decimal(1e8) * 1000)

assert_equal(len(bumped_tx["decoded"]["vin"]), 1)
assert_fee_amount(bumped["fee"], bumped_tx["decoded"]["vsize"], Decimal(520) / Decimal(1e8) * 1000)
wallet.unloadwallet()

def test_simple_bumpfee_succeeds(self, mode, rbf_node, peer_node, dest_address):
Expand Down

0 comments on commit bc7b37f

Please sign in to comment.