diff options
author | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2023-08-13 16:02:10 +0200 |
---|---|---|
committer | Sebastian Falbesoner <sebastian.falbesoner@gmail.com> | 2023-10-24 11:13:51 +0200 |
commit | 73a339abc3c864461c8b8830e139c8ec51570243 (patch) | |
tree | a9ff47a204e234ecd78b85adcf88f8947015c7d2 /test/functional/wallet_txn_doublespend.py | |
parent | d724bb52910c4a4a7609d5e685740cd675dd25a7 (diff) | |
download | bitcoin-73a339abc3c864461c8b8830e139c8ec51570243.tar.xz |
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.
Diffstat (limited to 'test/functional/wallet_txn_doublespend.py')
-rwxr-xr-x | test/functional/wallet_txn_doublespend.py | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/test/functional/wallet_txn_doublespend.py b/test/functional/wallet_txn_doublespend.py index 38ebfe0d7a..3cd0cd3207 100755 --- a/test/functional/wallet_txn_doublespend.py +++ b/test/functional/wallet_txn_doublespend.py @@ -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): |