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
@@ -7,7 +7,6 @@
|
||||
from test_framework.test_framework import BitcoinTestFramework
|
||||
from test_framework.util import (
|
||||
assert_equal,
|
||||
find_vout_for_address
|
||||
)
|
||||
from test_framework.messages import (
|
||||
COIN,
|
||||
@@ -35,8 +34,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'])
|
||||
@@ -56,13 +55,13 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
self.nodes[0].settxfee(.001)
|
||||
|
||||
node0_address1 = self.nodes[0].getnewaddress(address_type=output_type)
|
||||
node0_txid1 = self.nodes[0].sendtoaddress(node0_address1, 1219)
|
||||
node0_tx1 = self.nodes[0].gettransaction(node0_txid1)
|
||||
self.nodes[0].lockunspent(False, [{"txid":node0_txid1, "vout": find_vout_for_address(self.nodes[0], node0_txid1, node0_address1)}])
|
||||
node0_utxo1 = self.create_outpoints(self.nodes[0], outputs=[{node0_address1: 1219}])[0]
|
||||
node0_tx1 = self.nodes[0].gettransaction(node0_utxo1['txid'])
|
||||
self.nodes[0].lockunspent(False, [node0_utxo1])
|
||||
|
||||
node0_address2 = self.nodes[0].getnewaddress(address_type=output_type)
|
||||
node0_txid2 = self.nodes[0].sendtoaddress(node0_address2, 29)
|
||||
node0_tx2 = self.nodes[0].gettransaction(node0_txid2)
|
||||
node0_utxo2 = self.create_outpoints(self.nodes[0], outputs=[{node0_address2: 29}])[0]
|
||||
node0_tx2 = self.nodes[0].gettransaction(node0_utxo2['txid'])
|
||||
|
||||
assert_equal(self.nodes[0].getbalance(),
|
||||
starting_balance + node0_tx1["fee"] + node0_tx2["fee"])
|
||||
@@ -71,8 +70,8 @@ class TxnMallTest(BitcoinTestFramework):
|
||||
node1_address = self.nodes[1].getnewaddress()
|
||||
|
||||
# Send tx1, and another transaction tx2 that won't be cloned
|
||||
txid1 = self.spend_txid(node0_txid1, find_vout_for_address(self.nodes[0], node0_txid1, node0_address1), {node1_address: 40})
|
||||
txid2 = self.spend_txid(node0_txid2, find_vout_for_address(self.nodes[0], node0_txid2, node0_address2), {node1_address: 20})
|
||||
txid1 = self.spend_utxo(node0_utxo1, {node1_address: 40})
|
||||
txid2 = self.spend_utxo(node0_utxo2, {node1_address: 20})
|
||||
|
||||
# Construct a clone of tx1, to be malleated
|
||||
rawtx1 = self.nodes[0].getrawtransaction(txid1, 1)
|
||||
|
||||
Reference in new issue
Block a user