From 73a339abc3c864461c8b8830e139c8ec51570243 Mon Sep 17 00:00:00 2001 From: Sebastian Falbesoner Date: Sun, 13 Aug 2023 16:02:10 +0200 Subject: 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. --- test/functional/test_framework/test_framework.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/functional/test_framework/test_framework.py') diff --git a/test/functional/test_framework/test_framework.py b/test/functional/test_framework/test_framework.py index 4e6d245b5f..70b3943478 100755 --- a/test/functional/test_framework/test_framework.py +++ b/test/functional/test_framework/test_framework.py @@ -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. -- cgit v1.2.3