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:
1 parent
d724bb5291
commit
73a339abc3
9 files changed
+90
-107
No files matched your search
@@ -14,7 +14,6 @@ from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
assert_raises_rpc_error,
|
||||
find_vout_for_address,
|
||||
)
|
||||
from test_framework.messages import (
|
||||
CTxInWitness,
|
||||
@@ -194,13 +193,12 @@ class SignRawTransactionWithWalletTest(BitcoinTestFramework):
|
||||
address = script_to_p2wsh(script)
|
||||
|
||||
# Fund that address and make the spend
|
||||
txid = self.nodes[0].sendtoaddress(address, 1)
|
||||
vout = find_vout_for_address(self.nodes[0], txid, address)
|
||||
utxo1 = self.create_outpoints(self.nodes[0], outputs=[{address: 1}])[0]
|
||||
self.generate(self.nodes[0], 1)
|
||||
utxo = self.nodes[0].listunspent()[0]
|
||||
amt = Decimal(1) + utxo["amount"] - Decimal(0.00001)
|
||||
utxo2 = self.nodes[0].listunspent()[0]
|
||||
amt = Decimal(1) + utxo2["amount"] - Decimal(0.00001)
|
||||
tx = self.nodes[0].createrawtransaction(
|
||||
[{"txid": txid, "vout": vout, "sequence": 1},{"txid": utxo["txid"], "vout": utxo["vout"]}],
|
||||
[{**utxo1, "sequence": 1},{"txid": utxo2["txid"], "vout": utxo2["vout"]}],
|
||||
[{self.nodes[0].getnewaddress(): amt}],
|
||||
self.nodes[0].getblockcount()
|
||||
)
|
||||
@@ -229,13 +227,12 @@ class SignRawTransactionWithWalletTest(BitcoinTestFramework):
|
||||
address = script_to_p2wsh(script)
|
||||
|
||||
# Fund that address and make the spend
|
||||
txid = self.nodes[0].sendtoaddress(address, 1)
|
||||
vout = find_vout_for_address(self.nodes[0], txid, address)
|
||||
utxo1 = self.create_outpoints(self.nodes[0], outputs=[{address: 1}])[0]
|
||||
self.generate(self.nodes[0], 1)
|
||||
utxo = self.nodes[0].listunspent()[0]
|
||||
amt = Decimal(1) + utxo["amount"] - Decimal(0.00001)
|
||||
utxo2 = self.nodes[0].listunspent()[0]
|
||||
amt = Decimal(1) + utxo2["amount"] - Decimal(0.00001)
|
||||
tx = self.nodes[0].createrawtransaction(
|
||||
[{"txid": txid, "vout": vout},{"txid": utxo["txid"], "vout": utxo["vout"]}],
|
||||
[utxo1, {"txid": utxo2["txid"], "vout": utxo2["vout"]}],
|
||||
[{self.nodes[0].getnewaddress(): amt}],
|
||||
self.nodes[0].getblockcount()
|
||||
)
|
||||
|
||||
Reference in new issue
Block a user