aboutsummaryrefslogtreecommitdiff
path: root/test/functional/wallet_fundrawtransaction.py
diff options
context:
space:
mode:
Diffstat (limited to 'test/functional/wallet_fundrawtransaction.py')
-rwxr-xr-xtest/functional/wallet_fundrawtransaction.py37
1 files changed, 15 insertions, 22 deletions
diff --git a/test/functional/wallet_fundrawtransaction.py b/test/functional/wallet_fundrawtransaction.py
index 77611649ac..a331ba997e 100755
--- a/test/functional/wallet_fundrawtransaction.py
+++ b/test/functional/wallet_fundrawtransaction.py
@@ -22,7 +22,6 @@ from test_framework.util import (
assert_greater_than_or_equal,
assert_raises_rpc_error,
count_bytes,
- find_vout_for_address,
get_fee,
)
from test_framework.wallet_util import generate_keypair, WalletUnlock
@@ -85,14 +84,13 @@ class RawTransactionsTest(BitcoinTestFramework):
Unlock all UTXOs except the watchonly one
"""
to_keep = []
- if self.watchonly_txid is not None and self.watchonly_vout is not None:
- to_keep.append({"txid": self.watchonly_txid, "vout": self.watchonly_vout})
+ if self.watchonly_utxo is not None:
+ to_keep.append(self.watchonly_utxo)
wallet.lockunspent(True)
wallet.lockunspent(False, to_keep)
def run_test(self):
- self.watchonly_txid = None
- self.watchonly_vout = None
+ self.watchonly_utxo = None
self.log.info("Connect nodes, set fees, generate blocks, and sync")
self.min_relay_tx_fee = self.nodes[0].getnetworkinfo()['relayfee']
# This test is not meant to test fee estimation and we'd like
@@ -163,11 +161,10 @@ class RawTransactionsTest(BitcoinTestFramework):
watchonly_pubkey = self.nodes[0].getaddressinfo(watchonly_address)["pubkey"]
self.watchonly_amount = Decimal(200)
wwatch.importpubkey(watchonly_pubkey, "", True)
- self.watchonly_txid = self.nodes[0].sendtoaddress(watchonly_address, self.watchonly_amount)
+ self.watchonly_utxo = self.create_outpoints(self.nodes[0], outputs=[{watchonly_address: self.watchonly_amount}])[0]
# Lock UTXO so nodes[0] doesn't accidentally spend it
- self.watchonly_vout = find_vout_for_address(self.nodes[0], self.watchonly_txid, watchonly_address)
- self.nodes[0].lockunspent(False, [{"txid": self.watchonly_txid, "vout": self.watchonly_vout}])
+ self.nodes[0].lockunspent(False, [self.watchonly_utxo])
self.nodes[0].sendtoaddress(self.nodes[3].get_wallet_rpc(self.default_wallet_name).getnewaddress(), self.watchonly_amount / 10)
@@ -738,7 +735,7 @@ class RawTransactionsTest(BitcoinTestFramework):
result = wwatch.fundrawtransaction(rawtx, True)
res_dec = self.nodes[0].decoderawtransaction(result["hex"])
assert_equal(len(res_dec["vin"]), 1)
- assert_equal(res_dec["vin"][0]["txid"], self.watchonly_txid)
+ assert_equal(res_dec["vin"][0]["txid"], self.watchonly_utxo['txid'])
assert "fee" in result.keys()
assert_greater_than(result["changepos"], -1)
@@ -758,7 +755,7 @@ class RawTransactionsTest(BitcoinTestFramework):
result = wwatch.fundrawtransaction(rawtx, includeWatching=True, changeAddress=w3.getrawchangeaddress(), subtractFeeFromOutputs=[0])
res_dec = self.nodes[0].decoderawtransaction(result["hex"])
assert_equal(len(res_dec["vin"]), 1)
- assert res_dec["vin"][0]["txid"] == self.watchonly_txid
+ assert res_dec["vin"][0]["txid"] == self.watchonly_utxo['txid']
assert_greater_than(result["fee"], 0)
assert_equal(result["changepos"], -1)
@@ -970,10 +967,9 @@ class RawTransactionsTest(BitcoinTestFramework):
self.log.info("Test fundrawtxn subtract fee from outputs with preset inputs that are sufficient")
addr = self.nodes[0].getnewaddress()
- txid = self.nodes[0].sendtoaddress(addr, 10)
- vout = find_vout_for_address(self.nodes[0], txid, addr)
+ utxo = self.create_outpoints(self.nodes[0], outputs=[{addr: 10}])[0]
- rawtx = self.nodes[0].createrawtransaction([{'txid': txid, 'vout': vout}], [{self.nodes[0].getnewaddress(): 5}])
+ rawtx = self.nodes[0].createrawtransaction([utxo], [{self.nodes[0].getnewaddress(): 5}])
fundedtx = self.nodes[0].fundrawtransaction(rawtx, subtractFeeFromOutputs=[0])
signedtx = self.nodes[0].signrawtransactionwithwallet(fundedtx['hex'])
self.nodes[0].sendrawtransaction(signedtx['hex'])
@@ -1264,14 +1260,12 @@ class RawTransactionsTest(BitcoinTestFramework):
addr = wallet.getnewaddress(address_type="bech32")
ext_addr = self.nodes[0].getnewaddress(address_type="bech32")
- txid = self.nodes[0].send([{addr: 5}, {ext_addr: 5}])["txid"]
- vout = find_vout_for_address(self.nodes[0], txid, addr)
- ext_vout = find_vout_for_address(self.nodes[0], txid, ext_addr)
+ utxo, ext_utxo = self.create_outpoints(self.nodes[0], outputs=[{addr: 5}, {ext_addr: 5}])
self.nodes[0].sendtoaddress(wallet.getnewaddress(address_type="bech32"), 5)
self.generate(self.nodes[0], 1)
- rawtx = wallet.createrawtransaction([{'txid': txid, 'vout': vout}], [{self.nodes[0].getnewaddress(address_type="bech32"): 8}])
+ rawtx = wallet.createrawtransaction([utxo], [{self.nodes[0].getnewaddress(address_type="bech32"): 8}])
fundedtx = wallet.fundrawtransaction(rawtx, fee_rate=10, change_type="bech32")
# with 71-byte signatures we should expect following tx size
# tx overhead (10) + 2 inputs (41 each) + 2 p2wpkh (31 each) + (segwit marker and flag (2) + 2 p2wpkh 71 byte sig witnesses (107 each)) / witness scaling factor (4)
@@ -1279,7 +1273,7 @@ class RawTransactionsTest(BitcoinTestFramework):
assert_equal(fundedtx['fee'] * COIN, tx_size * 10)
# Using the other output should have 72 byte sigs
- rawtx = wallet.createrawtransaction([{'txid': txid, 'vout': ext_vout}], [{self.nodes[0].getnewaddress(): 13}])
+ rawtx = wallet.createrawtransaction([ext_utxo], [{self.nodes[0].getnewaddress(): 13}])
ext_desc = self.nodes[0].getaddressinfo(ext_addr)["desc"]
fundedtx = wallet.fundrawtransaction(rawtx, fee_rate=10, change_type="bech32", solving_data={"descriptors": [ext_desc]})
# tx overhead (10) + 3 inputs (41 each) + 2 p2wpkh(31 each) + (segwit marker and flag (2) + 2 p2wpkh 71 bytes sig witnesses (107 each) + p2wpkh 72 byte sig witness (108)) / witness scaling factor (4)
@@ -1298,10 +1292,9 @@ class RawTransactionsTest(BitcoinTestFramework):
addr = wallet.getnewaddress()
inputs = []
for i in range(0, 2):
- txid = self.nodes[2].sendtoaddress(addr, 5)
- self.sync_mempools()
- vout = find_vout_for_address(wallet, txid, addr)
- inputs.append((txid, vout))
+ utxo = self.create_outpoints(self.nodes[2], outputs=[{addr: 5}])[0]
+ inputs.append((utxo['txid'], utxo['vout']))
+ self.sync_mempools()
# Unsafe inputs are ignored by default.
rawtx = wallet.createrawtransaction([], [{self.nodes[2].getnewaddress(): 7.5}])