mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-08 13:49:35 +02: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:
@@ -23,7 +23,6 @@ from test_framework.script_util import key_to_p2pkh_script, script_to_p2sh_scrip
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_raises_rpc_error,
|
||||
find_vout_for_address,
|
||||
sha256sum_file,
|
||||
)
|
||||
from test_framework.wallet_util import (
|
||||
@@ -310,14 +309,14 @@ class WalletMigrationTest(BitcoinTestFramework):
|
||||
# Received watchonly tx that is then spent
|
||||
import_sent_addr = default.getnewaddress()
|
||||
imports0.importaddress(import_sent_addr)
|
||||
received_sent_watchonly_txid = default.sendtoaddress(import_sent_addr, 10)
|
||||
received_sent_watchonly_vout = find_vout_for_address(self.nodes[0], received_sent_watchonly_txid, import_sent_addr)
|
||||
send = default.sendall(recipients=[default.getnewaddress()], inputs=[{"txid": received_sent_watchonly_txid, "vout": received_sent_watchonly_vout}])
|
||||
received_sent_watchonly_utxo = self.create_outpoints(node=default, outputs=[{import_sent_addr: 10}])[0]
|
||||
|
||||
send = default.sendall(recipients=[default.getnewaddress()], inputs=[received_sent_watchonly_utxo])
|
||||
sent_watchonly_txid = send["txid"]
|
||||
|
||||
self.generate(self.nodes[0], 1)
|
||||
received_watchonly_tx_info = imports0.gettransaction(received_watchonly_txid, True)
|
||||
received_sent_watchonly_tx_info = imports0.gettransaction(received_sent_watchonly_txid, True)
|
||||
received_sent_watchonly_tx_info = imports0.gettransaction(received_sent_watchonly_utxo["txid"], True)
|
||||
|
||||
balances = imports0.getbalances()
|
||||
spendable_bal = balances["mine"]["trusted"]
|
||||
@@ -332,7 +331,7 @@ class WalletMigrationTest(BitcoinTestFramework):
|
||||
assert_equal(imports0.getwalletinfo()["descriptors"], True)
|
||||
self.assert_is_sqlite("imports0")
|
||||
assert_raises_rpc_error(-5, "Invalid or non-wallet transaction id", imports0.gettransaction, received_watchonly_txid)
|
||||
assert_raises_rpc_error(-5, "Invalid or non-wallet transaction id", imports0.gettransaction, received_sent_watchonly_txid)
|
||||
assert_raises_rpc_error(-5, "Invalid or non-wallet transaction id", imports0.gettransaction, received_sent_watchonly_utxo['txid'])
|
||||
assert_raises_rpc_error(-5, "Invalid or non-wallet transaction id", imports0.gettransaction, sent_watchonly_txid)
|
||||
assert_equal(len(imports0.listtransactions(include_watchonly=True)), 1)
|
||||
imports0.gettransaction(received_txid)
|
||||
@@ -347,7 +346,7 @@ class WalletMigrationTest(BitcoinTestFramework):
|
||||
received_migrated_watchonly_tx_info = watchonly.gettransaction(received_watchonly_txid)
|
||||
assert_equal(received_watchonly_tx_info["time"], received_migrated_watchonly_tx_info["time"])
|
||||
assert_equal(received_watchonly_tx_info["timereceived"], received_migrated_watchonly_tx_info["timereceived"])
|
||||
received_sent_migrated_watchonly_tx_info = watchonly.gettransaction(received_sent_watchonly_txid)
|
||||
received_sent_migrated_watchonly_tx_info = watchonly.gettransaction(received_sent_watchonly_utxo["txid"])
|
||||
assert_equal(received_sent_watchonly_tx_info["time"], received_sent_migrated_watchonly_tx_info["time"])
|
||||
assert_equal(received_sent_watchonly_tx_info["timereceived"], received_sent_migrated_watchonly_tx_info["timereceived"])
|
||||
watchonly.gettransaction(sent_watchonly_txid)
|
||||
|
||||
Reference in New Issue
Block a user