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
@@ -8,8 +8,6 @@ from decimal import Decimal
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
find_output,
|
||||
find_vout_for_address
|
||||
)
|
||||
|
||||
|
||||
@@ -31,8 +29,8 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
super().setup_network()
|
||||
self.disconnect_nodes(1, 2)
|
||||
|
||||
def spend_txid(self, txid, vout, outputs):
|
||||
inputs = [{"txid": txid, "vout": vout}]
|
||||
def spend_utxo(self, utxo, outputs):
|
||||
inputs = [utxo]
|
||||
tx = self.nodes[0].createrawtransaction(inputs, outputs)
|
||||
tx = self.nodes[0].fundrawtransaction(tx)
|
||||
tx = self.nodes[0].signrawtransactionwithwallet(tx['hex'])
|
||||
@@ -54,13 +52,13 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
|
||||
# Assign coins to foo and bar addresses:
|
||||
node0_address_foo = self.nodes[0].getnewaddress()
|
||||
fund_foo_txid = self.nodes[0].sendtoaddress(node0_address_foo, 1219)
|
||||
fund_foo_tx = self.nodes[0].gettransaction(fund_foo_txid)
|
||||
self.nodes[0].lockunspent(False, [{"txid":fund_foo_txid, "vout": find_vout_for_address(self.nodes[0], fund_foo_txid, node0_address_foo)}])
|
||||
fund_foo_utxo = self.create_outpoints(self.nodes[0], outputs=[{node0_address_foo: 1219}])[0]
|
||||
fund_foo_tx = self.nodes[0].gettransaction(fund_foo_utxo['txid'])
|
||||
self.nodes[0].lockunspent(False, [fund_foo_utxo])
|
||||
|
||||
node0_address_bar = self.nodes[0].getnewaddress()
|
||||
fund_bar_txid = self.nodes[0].sendtoaddress(node0_address_bar, 29)
|
||||
fund_bar_tx = self.nodes[0].gettransaction(fund_bar_txid)
|
||||
fund_bar_utxo = self.create_outpoints(node=self.nodes[0], outputs=[{node0_address_bar: 29}])[0]
|
||||
fund_bar_tx = self.nodes[0].gettransaction(fund_bar_utxo['txid'])
|
||||
|
||||
assert_equal(self.nodes[0].getbalance(),
|
||||
starting_balance + fund_foo_tx["fee"] + fund_bar_tx["fee"])
|
||||
@@ -71,13 +69,7 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
# First: use raw transaction API to send 1240 BTC to node1_address,
|
||||
# but don't broadcast:
|
||||
doublespend_fee = Decimal('-.02')
|
||||
rawtx_input_0 = {}
|
||||
rawtx_input_0["txid"] = fund_foo_txid
|
||||
rawtx_input_0["vout"] = find_output(self.nodes[0], fund_foo_txid, 1219)
|
||||
rawtx_input_1 = {}
|
||||
rawtx_input_1["txid"] = fund_bar_txid
|
||||
rawtx_input_1["vout"] = find_output(self.nodes[0], fund_bar_txid, 29)
|
||||
inputs = [rawtx_input_0, rawtx_input_1]
|
||||
inputs = [fund_foo_utxo, fund_bar_utxo]
|
||||
change_address = self.nodes[0].getnewaddress()
|
||||
outputs = {}
|
||||
outputs[node1_address] = 1240
|
||||
@@ -87,8 +79,8 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
assert_equal(doublespend["complete"], True)
|
||||
|
||||
# Create two spends using 1 50 BTC coin each
|
||||
txid1 = self.spend_txid(fund_foo_txid, find_vout_for_address(self.nodes[0], fund_foo_txid, node0_address_foo), {node1_address: 40})
|
||||
txid2 = self.spend_txid(fund_bar_txid, find_vout_for_address(self.nodes[0], fund_bar_txid, node0_address_bar), {node1_address: 20})
|
||||
txid1 = self.spend_utxo(fund_foo_utxo, {node1_address: 40})
|
||||
txid2 = self.spend_utxo(fund_bar_utxo, {node1_address: 20})
|
||||
|
||||
# Have node0 mine a block:
|
||||
if (self.options.mine_block):
|
||||
|
||||
Reference in new issue
Block a user