Skip to content

Commit

Permalink
Add functional testing for bumpfee return_psbt argument
Browse files Browse the repository at this point in the history
  • Loading branch information
instagibbs committed Jul 12, 2019
1 parent 11135a3 commit ab65019
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions test/functional/wallet_bumpfee.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ def run_test(self):
test_locked_wallet_fails(rbf_node, dest_address)
test_change_script_match(rbf_node, dest_address)
test_maxtxfee_fails(self, rbf_node, dest_address)

connect_nodes_bi(self.nodes, 0, 1) # reconnect for next test
test_return_psbt(self, rbf_node, peer_node, dest_address)
# These tests wipe out a number of utxos that are expected in other tests
test_small_output_with_feerate_succeeds(rbf_node, dest_address)
test_no_more_inputs_fails(rbf_node, dest_address)
Expand Down Expand Up @@ -257,6 +260,61 @@ def test_maxtxfee_fails(test, rbf_node, dest_address):
test.restart_node(1, test.extra_args[1])
rbf_node.walletpassphrase(WALLET_PASSPHRASE, WALLET_PASSPHRASE_TIMEOUT)

def test_return_psbt(self, rbf_node, peer_node, dest_address):

# Create transaction to bump with psbt argument set to true
rbfid = spend_one_input(rbf_node, dest_address)
psbt_bump_details = rbf_node.bumpfee(rbfid, {"return_psbt":True})
assert "psbt" in psbt_bump_details
assert "txid" not in psbt_bump_details

# Should be final since we can sign fully, finalize, and submit
finalize_details = rbf_node.finalizepsbt(psbt_bump_details["psbt"])
assert finalize_details["complete"]
rbfid2 = rbf_node.sendrawtransaction(finalize_details["hex"])

# Bump the replacement, this time with flag false
psbt_bump_details = rbf_node.bumpfee(rbfid2, {"return_psbt":False})
assert "psbt" not in psbt_bump_details
assert "txid" in psbt_bump_details

# Bump the replacement one more time, without optional arg
psbt_bump_details_2 = rbf_node.bumpfee(psbt_bump_details["txid"], {})
assert "psbt" not in psbt_bump_details_2
assert "txid" in psbt_bump_details_2

# Clean up mempools
rbf_node.generate(1)
self.sync_blocks()
peer_node.generate(1)
self.sync_all()

# Import peer_node address to watchonly of rbf_node, send funds there
peer_addr = peer_node.getnewaddress()
rbf_node.importpubkey(peer_node.getaddressinfo(peer_addr)["pubkey"])
funding_txid = spend_one_input(rbf_node, peer_addr)
funding_index = None
for i, output in enumerate(rbf_node.getrawtransaction(funding_txid, 1)["vout"]):
if not rbf_node.getaddressinfo(output["scriptPubKey"]["addresses"][0])["ischange"]:
funding_index = i
assert funding_index is not None
rbf_node.generate(1)
self.sync_all()

# Manual spend of funds from last send so rbf_node can watchonly bump
raw_id_3 = peer_node.createrawtransaction([{"txid":funding_txid, "vout":funding_index}], [{peer_addr:Decimal("0.00040000")}], 1, True)
sign_id_3 = peer_node.signrawtransactionwithwallet(raw_id_3)
rbfid3 = peer_node.sendrawtransaction(sign_id_3["hex"])
self.sync_all()

# Test bumping of watchonly, which should only succeed with `return_psbt`

# rbf_node now can't bump, unless return_psbt is given
assert_raises_rpc_error(-4, "Can't sign transaction.", rbf_node.bumpfee, rbfid3)
psbt_bump_details_3 = rbf_node.bumpfee(rbfid3, {"return_psbt":True})
assert "psbt" in psbt_bump_details_3
assert not rbf_node.finalizepsbt(psbt_bump_details_3["psbt"])["complete"]
assert peer_node.walletprocesspsbt(psbt_bump_details_3["psbt"])["complete"]

def test_rebumping(rbf_node, dest_address):
# check that re-bumping the original tx fails, but bumping the bumper succeeds
Expand Down

0 comments on commit ab65019

Please sign in to comment.