mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-12-01 08:24:21 +01:00
test: refactor: support sending funds with outpoint result
This commit introduces a helper `create_outpoints` to execute the `send` RPC and immediately return the target address outpoints as UTXO dictionary in the common format, making the tests more readable and avoiding unnecessary duplication.
This commit is contained in:
@@ -30,6 +30,7 @@ from .util import (
|
||||
PortSeed,
|
||||
assert_equal,
|
||||
check_json_precision,
|
||||
find_vout_for_address,
|
||||
get_datadir_path,
|
||||
initialize_datadir,
|
||||
p2p_port,
|
||||
@@ -697,6 +698,22 @@ class BitcoinTestFramework(metaclass=BitcoinTestMetaClass):
|
||||
sync_fun() if sync_fun else self.sync_all()
|
||||
return blocks
|
||||
|
||||
def create_outpoints(self, node, *, outputs):
|
||||
"""Send funds to a given list of `{address: amount}` targets using the bitcoind
|
||||
wallet and return the corresponding outpoints as a list of dictionaries
|
||||
`[{"txid": txid, "vout": vout1}, {"txid": txid, "vout": vout2}, ...]`.
|
||||
The result can be used to specify inputs for RPCs like `createrawtransaction`,
|
||||
`createpsbt`, `lockunspent` etc."""
|
||||
assert all(len(output.keys()) == 1 for output in outputs)
|
||||
send_res = node.send(outputs)
|
||||
assert send_res["complete"]
|
||||
utxos = []
|
||||
for output in outputs:
|
||||
address = list(output.keys())[0]
|
||||
vout = find_vout_for_address(node, send_res["txid"], address)
|
||||
utxos.append({"txid": send_res["txid"], "vout": vout})
|
||||
return utxos
|
||||
|
||||
def sync_blocks(self, nodes=None, wait=1, timeout=60):
|
||||
"""
|
||||
Wait until everybody has the same tip.
|
||||
|
||||
Reference in New Issue
Block a user