Skip to content

Commit 5c99bb0

Browse files
author
MarcoFalke
committed
Merge #15247: qa: Use wallet to retrieve raw transactions
fa5278a qa: Use wallet to retrieve raw transactions (MarcoFalke) fa21983 qa: Style-only fixes in touched files (MarcoFalke) Pull request description: Instead of asking the coin database and block storage about a transaction, pull it directly from the wallet in wallet related tests. This refactoring only makes sense in light of #15159. <sub>This product may contain minor stylistic cleanups Tree-SHA512: ec34c7150d873da9f19fead3f7e3f758baba5ef10061942384c470a47a6f320690109be9c5160f0c8bc228272a729653d44c78471455337318f657d6c164ba23
2 parents 3e38d40 + fa5278a commit 5c99bb0

File tree

2 files changed

+40
-29
lines changed

2 files changed

+40
-29
lines changed

test/functional/wallet_abandonconflict.py

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2014-2018 The Bitcoin Core developers
2+
# Copyright (c) 2014-2019 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the abandontransaction RPC.
@@ -13,7 +13,15 @@
1313
from decimal import Decimal
1414

1515
from test_framework.test_framework import BitcoinTestFramework
16-
from test_framework.util import assert_equal, assert_raises_rpc_error, connect_nodes, disconnect_nodes, sync_blocks, sync_mempools
16+
from test_framework.util import (
17+
assert_equal,
18+
assert_raises_rpc_error,
19+
connect_nodes,
20+
disconnect_nodes,
21+
sync_blocks,
22+
sync_mempools,
23+
)
24+
1725

1826
class AbandonConflictTest(BitcoinTestFramework):
1927
def set_test_params(self):
@@ -41,21 +49,21 @@ def run_test(self):
4149

4250
sync_blocks(self.nodes)
4351
newbalance = self.nodes[0].getbalance()
44-
assert(balance - newbalance < Decimal("0.001")) #no more than fees lost
52+
assert balance - newbalance < Decimal("0.001") #no more than fees lost
4553
balance = newbalance
4654

4755
# Disconnect nodes so node0's transactions don't get into node1's mempool
4856
disconnect_nodes(self.nodes[0], 1)
4957

5058
# Identify the 10btc outputs
51-
nA = next(i for i, vout in enumerate(self.nodes[0].getrawtransaction(txA, 1)["vout"]) if vout["value"] == Decimal("10"))
52-
nB = next(i for i, vout in enumerate(self.nodes[0].getrawtransaction(txB, 1)["vout"]) if vout["value"] == Decimal("10"))
53-
nC = next(i for i, vout in enumerate(self.nodes[0].getrawtransaction(txC, 1)["vout"]) if vout["value"] == Decimal("10"))
59+
nA = next(tx_out["vout"] for tx_out in self.nodes[0].gettransaction(txA)["details"] if tx_out["amount"] == Decimal("10"))
60+
nB = next(tx_out["vout"] for tx_out in self.nodes[0].gettransaction(txB)["details"] if tx_out["amount"] == Decimal("10"))
61+
nC = next(tx_out["vout"] for tx_out in self.nodes[0].gettransaction(txC)["details"] if tx_out["amount"] == Decimal("10"))
5462

55-
inputs =[]
63+
inputs = []
5664
# spend 10btc outputs from txA and txB
57-
inputs.append({"txid":txA, "vout":nA})
58-
inputs.append({"txid":txB, "vout":nB})
65+
inputs.append({"txid": txA, "vout": nA})
66+
inputs.append({"txid": txB, "vout": nB})
5967
outputs = {}
6068

6169
outputs[self.nodes[0].getnewaddress()] = Decimal("14.99998")
@@ -64,21 +72,21 @@ def run_test(self):
6472
txAB1 = self.nodes[0].sendrawtransaction(signed["hex"])
6573

6674
# Identify the 14.99998btc output
67-
nAB = next(i for i, vout in enumerate(self.nodes[0].getrawtransaction(txAB1, 1)["vout"]) if vout["value"] == Decimal("14.99998"))
75+
nAB = next(tx_out["vout"] for tx_out in self.nodes[0].gettransaction(txAB1)["details"] if tx_out["amount"] == Decimal("14.99998"))
6876

6977
#Create a child tx spending AB1 and C
7078
inputs = []
71-
inputs.append({"txid":txAB1, "vout":nAB})
72-
inputs.append({"txid":txC, "vout":nC})
79+
inputs.append({"txid": txAB1, "vout": nAB})
80+
inputs.append({"txid": txC, "vout": nC})
7381
outputs = {}
7482
outputs[self.nodes[0].getnewaddress()] = Decimal("24.9996")
7583
signed2 = self.nodes[0].signrawtransactionwithwallet(self.nodes[0].createrawtransaction(inputs, outputs))
7684
txABC2 = self.nodes[0].sendrawtransaction(signed2["hex"])
7785

7886
# Create a child tx spending ABC2
7987
signed3_change = Decimal("24.999")
80-
inputs = [ {"txid":txABC2, "vout":0} ]
81-
outputs = { self.nodes[0].getnewaddress(): signed3_change }
88+
inputs = [{"txid": txABC2, "vout": 0}]
89+
outputs = {self.nodes[0].getnewaddress(): signed3_change}
8290
signed3 = self.nodes[0].signrawtransactionwithwallet(self.nodes[0].createrawtransaction(inputs, outputs))
8391
# note tx is never directly referenced, only abandoned as a child of the above
8492
self.nodes[0].sendrawtransaction(signed3["hex"])
@@ -106,7 +114,7 @@ def run_test(self):
106114
unconfbalance = self.nodes[0].getunconfirmedbalance() + self.nodes[0].getbalance()
107115
assert_equal(unconfbalance, newbalance)
108116
# Also shouldn't show up in listunspent
109-
assert(not txABC2 in [utxo["txid"] for utxo in self.nodes[0].listunspent(0)])
117+
assert not txABC2 in [utxo["txid"] for utxo in self.nodes[0].listunspent(0)]
110118
balance = newbalance
111119

112120
# Abandon original transaction and verify inputs are available again
@@ -146,8 +154,8 @@ def run_test(self):
146154

147155
# Create a double spend of AB1 by spending again from only A's 10 output
148156
# Mine double spend from node 1
149-
inputs =[]
150-
inputs.append({"txid":txA, "vout":nA})
157+
inputs = []
158+
inputs.append({"txid": txA, "vout": nA})
151159
outputs = {}
152160
outputs[self.nodes[1].getnewaddress()] = Decimal("9.9999")
153161
tx = self.nodes[0].createrawtransaction(inputs, outputs)
@@ -173,5 +181,6 @@ def run_test(self):
173181
self.log.info("conflicted has not resumed causing its inputs to be seen as spent. See Issue #7315")
174182
self.log.info(str(balance) + " -> " + str(newbalance) + " ?")
175183

184+
176185
if __name__ == '__main__':
177186
AbandonConflictTest().main()

test/functional/wallet_basic.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/usr/bin/env python3
2-
# Copyright (c) 2014-2018 The Bitcoin Core developers
2+
# Copyright (c) 2014-2019 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
55
"""Test the wallet."""
@@ -19,6 +19,7 @@
1919
wait_until,
2020
)
2121

22+
2223
class WalletTest(BitcoinTestFramework):
2324
def set_test_params(self):
2425
self.num_nodes = 4
@@ -196,7 +197,7 @@ def run_test(self):
196197
txid = self.nodes[2].sendtoaddress(address, 10, "", "", False)
197198
self.nodes[2].generate(1)
198199
self.sync_all([self.nodes[0:3]])
199-
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid)))
200+
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), Decimal('84'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
200201
assert_equal(self.nodes[0].getbalance(), Decimal('10'))
201202

202203
# Send 10 BTC with subtract fee from amount
@@ -205,14 +206,14 @@ def run_test(self):
205206
self.sync_all([self.nodes[0:3]])
206207
node_2_bal -= Decimal('10')
207208
assert_equal(self.nodes[2].getbalance(), node_2_bal)
208-
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid)))
209+
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), Decimal('20'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
209210

210211
# Sendmany 10 BTC
211212
txid = self.nodes[2].sendmany('', {address: 10}, 0, "", [])
212213
self.nodes[2].generate(1)
213214
self.sync_all([self.nodes[0:3]])
214215
node_0_bal += Decimal('10')
215-
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid)))
216+
node_2_bal = self.check_fee_amount(self.nodes[2].getbalance(), node_2_bal - Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
216217
assert_equal(self.nodes[0].getbalance(), node_0_bal)
217218

218219
# Sendmany 10 BTC with subtract fee from amount
@@ -221,7 +222,7 @@ def run_test(self):
221222
self.sync_all([self.nodes[0:3]])
222223
node_2_bal -= Decimal('10')
223224
assert_equal(self.nodes[2].getbalance(), node_2_bal)
224-
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].getrawtransaction(txid)))
225+
node_0_bal = self.check_fee_amount(self.nodes[0].getbalance(), node_0_bal + Decimal('10'), fee_per_byte, self.get_vsize(self.nodes[2].gettransaction(txid)['hex']))
225226

226227
# Test ResendWalletTransactions:
227228
# Create a couple of transactions, then start up a fourth
@@ -239,7 +240,7 @@ def run_test(self):
239240
assert_equal(set(relayed), {txid1, txid2})
240241
sync_mempools(self.nodes)
241242

242-
assert(txid1 in self.nodes[3].getrawmempool())
243+
assert txid1 in self.nodes[3].getrawmempool()
243244

244245
# check if we can list zero value tx as available coins
245246
# 1. create raw_tx
@@ -266,7 +267,7 @@ def run_test(self):
266267
if uTx['txid'] == zero_value_txid:
267268
found = True
268269
assert_equal(uTx['amount'], Decimal('0'))
269-
assert(found)
270+
assert found
270271

271272
# do some -walletbroadcast tests
272273
self.stop_nodes()
@@ -343,7 +344,7 @@ def run_test(self):
343344
self.nodes[1].importaddress(address_to_import)
344345

345346
# 3. Validate that the imported address is watch-only on node1
346-
assert(self.nodes[1].getaddressinfo(address_to_import)["iswatchonly"])
347+
assert self.nodes[1].getaddressinfo(address_to_import)["iswatchonly"]
347348

348349
# 4. Check that the unspents after import are not spendable
349350
assert_array_result(self.nodes[1].listunspent(),
@@ -385,7 +386,7 @@ def run_test(self):
385386
addr = self.nodes[0].getnewaddress()
386387
self.nodes[0].setlabel(addr, label)
387388
assert_equal(self.nodes[0].getaddressinfo(addr)['label'], label)
388-
assert(label in self.nodes[0].listlabels())
389+
assert label in self.nodes[0].listlabels()
389390
self.nodes[0].rpc.ensure_ascii = True # restore to default
390391

391392
# maintenance tests
@@ -444,8 +445,8 @@ def run_test(self):
444445
# Without walletrejectlongchains, we will still generate a txid
445446
# The tx will be stored in the wallet but not accepted to the mempool
446447
extra_txid = self.nodes[0].sendtoaddress(sending_addr, Decimal('0.0001'))
447-
assert(extra_txid not in self.nodes[0].getrawmempool())
448-
assert(extra_txid in [tx["txid"] for tx in self.nodes[0].listtransactions()])
448+
assert extra_txid not in self.nodes[0].getrawmempool()
449+
assert extra_txid in [tx["txid"] for tx in self.nodes[0].listtransactions()]
449450
self.nodes[0].abandontransaction(extra_txid)
450451
total_txs = len(self.nodes[0].listtransactions("*", 99999))
451452

@@ -482,7 +483,7 @@ def run_test(self):
482483
self.nodes[0].generate(1)
483484
destination = self.nodes[1].getnewaddress()
484485
txid = self.nodes[0].sendtoaddress(destination, 0.123)
485-
tx = self.nodes[0].decoderawtransaction(self.nodes[0].getrawtransaction(txid))
486+
tx = self.nodes[0].decoderawtransaction(self.nodes[0].gettransaction(txid)['hex'])
486487
output_addresses = [vout['scriptPubKey']['addresses'][0] for vout in tx["vout"]]
487488
assert len(output_addresses) > 1
488489
for address in output_addresses:
@@ -493,5 +494,6 @@ def run_test(self):
493494
self.nodes[0].setlabel(change, 'foobar')
494495
assert_equal(self.nodes[0].getaddressinfo(change)['ischange'], False)
495496

497+
496498
if __name__ == '__main__':
497499
WalletTest().main()

0 commit comments

Comments
 (0)