Skip to content

Commit

Permalink
[test] Test single-output transaction bumpfee
Browse files Browse the repository at this point in the history
  • Loading branch information
kallewoof committed Apr 16, 2019
1 parent 09bb143 commit e82c8ff
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/functional/wallet_bumpfee.py
Expand Up @@ -78,6 +78,8 @@ def run_test(self):
test_rebumping_not_replaceable(rbf_node, dest_address)
test_unconfirmed_not_spendable(rbf_node, rbf_node_address)
test_bumpfee_metadata(rbf_node, dest_address)
test_single_output_bump(rbf_node, dest_address)
test_explicit_reduce_output(rbf_node, dest_address)
test_locked_wallet_fails(rbf_node, dest_address)
test_change_script_match(rbf_node, dest_address)
# These tests wipe out a number of utxos that are expected in other tests
Expand Down Expand Up @@ -336,6 +338,43 @@ def get_change_address(tx):
bumped_rate_tx = rbf_node.bumpfee(bumped_total_tx["txid"])
assert_equal(change_addresses, get_change_address(bumped_rate_tx['txid']))

def test_single_output_bump(node, dest_address):
tx_input = dict(
sequence=BIP125_SEQUENCE_NUMBER, **next(u for u in node.listunspent() if u["amount"] == Decimal("0.00100000")))
rawtx = node.createrawtransaction([tx_input], {dest_address: Decimal("0.00099000")})
signedtx = node.signrawtransactionwithwallet(rawtx)
txid = node.sendrawtransaction(signedtx["hex"])
bumped_tx = node.bumpfee(txid, {"reduce_output": 0})
bumped_txob = node.getrawtransaction(bumped_tx["txid"], True)
# Only one vout
assert_equal(1, len(bumped_txob["vout"]))
# The vout should have decreased in value, which means 0.00099 > value
assert_greater_than(Decimal("0.00099000"), bumped_txob["vout"][0]["value"])

def test_explicit_reduce_output(node, dest_address):
txid = spend_one_input(node, dest_address)
txidob = node.getrawtransaction(txid, True)
# OOB checks
assert_raises_rpc_error(-8, "Invalid reduce_output parameter", node.bumpfee, txid, {"reduce_output": -2})
assert_raises_rpc_error(-8, "Change output out of bounds", node.bumpfee, txid, {"reduce_output": len(txidob["vout"])})
# Type checks
assert_raises_rpc_error(-3, "Expected type number", node.bumpfee, txid, {"reduce_output": False})
assert_raises_rpc_error(-3, "Expected type number", node.bumpfee, txid, {"reduce_output": True})
assert_raises_rpc_error(-3, "Expected type number", node.bumpfee, txid, {"reduce_output": "HELLO"})
# Figure out which is which
spendidx = 0 if txidob["vout"][0]["value"] == Decimal("0.00050000") else 1
bumped_tx = node.bumpfee(txid, {"reduce_output": spendidx})
bumped_txob = node.getrawtransaction(bumped_tx["txid"], True)
assert_greater_than(Decimal("0.00050000"), bumped_txob["vout"][spendidx]["value"])
assert_equal(Decimal("0.00049000"), bumped_txob["vout"][1 - spendidx]["value"])
txid = spend_one_input(node, dest_address)
txidob = node.getrawtransaction(txid, True)
spendidx = 0 if txidob["vout"][0]["value"] == Decimal("0.00050000") else 1
bumped_tx = node.bumpfee(txid, {"reduce_output": 1 - spendidx})
bumped_txob = node.getrawtransaction(bumped_tx["txid"], True)
assert_equal(Decimal("0.00050000"), bumped_txob["vout"][spendidx]["value"])
assert_greater_than(Decimal("0.00049000"), bumped_txob["vout"][1 - spendidx]["value"])

def spend_one_input(node, dest_address, change_size=Decimal("0.00049000")):
tx_input = dict(
sequence=BIP125_SEQUENCE_NUMBER, **next(u for u in node.listunspent() if u["amount"] == Decimal("0.00100000")))
Expand Down

0 comments on commit e82c8ff

Please sign in to comment.