Skip to content

Commit 93878d2

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#22423: test: wallet_listtransactions improvements (speedup, cleanup, logging)
a006d7d test: add logging to wallet_listtransactions (Sebastian Falbesoner) 47915b1 test: remove unneeded/redundant code in wallet_listtransactions (Sebastian Falbesoner) fb6c6a7 test: speedup wallet_listtransactions by whitelisting peers (immediate tx relay) (Sebastian Falbesoner) Pull request description: This PR improves the test `wallet_listtransactions.py` in three ways: * speeds up runtime by a factor of 2-3x by using the good ol' immediate tx relay trick (`[email protected]`) * removes unneeded/redundant code * adds log messages, mostly by turning comments into `self.log.info(...)` calls ACKs for top commit: jonatack: ACK a006d7d kristapsk: ACK a006d7d Tree-SHA512: a91a19f5ebc4d05f0b96c5419683c4c57ac0ef44b64eeb8dd550bd72296fd3a2857a3ba83f755fe4b0b3bd06439973f226070b5d0ce2dee58344dae78cb50290
2 parents 548ca1d + a006d7d commit 93878d2

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

test/functional/test_runner.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@
109109
'p2p_tx_download.py',
110110
'mempool_updatefromblock.py',
111111
'wallet_dump.py --legacy-wallet',
112-
'wallet_listtransactions.py --legacy-wallet',
113-
'wallet_listtransactions.py --descriptors',
114112
'feature_taproot.py --previous_release',
115113
'feature_taproot.py',
116114
'rpc_signer.py',
@@ -159,6 +157,8 @@
159157
'wallet_createwallet.py --legacy-wallet',
160158
'wallet_createwallet.py --usecli',
161159
'wallet_createwallet.py --descriptors',
160+
'wallet_listtransactions.py --legacy-wallet',
161+
'wallet_listtransactions.py --descriptors',
162162
'wallet_watchonly.py --legacy-wallet',
163163
'wallet_watchonly.py --usecli --legacy-wallet',
164164
'wallet_reorgsrestore.py',

test/functional/wallet_listtransactions.py

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
class ListTransactionsTest(BitcoinTestFramework):
1919
def set_test_params(self):
2020
self.num_nodes = 2
21+
# This test isn't testing txn relay/timing, so set whitelist on the
22+
# peers for instant txn relay. This speeds up the test run time 2-3x.
23+
self.extra_args = [["[email protected]"]] * self.num_nodes
2124

2225
def skip_test_if_missing_module(self):
2326
self.skip_if_no_wallet()
2427

2528
def run_test(self):
26-
self.nodes[0].generate(1) # Get out of IBD
27-
self.sync_all()
28-
# Simple send, 0 to 1:
29+
self.log.info("Test simple send from node0 to node1")
2930
txid = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 0.1)
3031
self.sync_all()
3132
assert_array_result(self.nodes[0].listtransactions(),
@@ -34,7 +35,7 @@ def run_test(self):
3435
assert_array_result(self.nodes[1].listtransactions(),
3536
{"txid": txid},
3637
{"category": "receive", "amount": Decimal("0.1"), "confirmations": 0})
37-
# mine a block, confirmations should change:
38+
self.log.info("Test confirmations change after mining a block")
3839
blockhash = self.nodes[0].generate(1)[0]
3940
blockheight = self.nodes[0].getblockheader(blockhash)['height']
4041
self.sync_all()
@@ -45,7 +46,7 @@ def run_test(self):
4546
{"txid": txid},
4647
{"category": "receive", "amount": Decimal("0.1"), "confirmations": 1, "blockhash": blockhash, "blockheight": blockheight})
4748

48-
# send-to-self:
49+
self.log.info("Test send-to-self on node0")
4950
txid = self.nodes[0].sendtoaddress(self.nodes[0].getnewaddress(), 0.2)
5051
assert_array_result(self.nodes[0].listtransactions(),
5152
{"txid": txid, "category": "send"},
@@ -54,7 +55,7 @@ def run_test(self):
5455
{"txid": txid, "category": "receive"},
5556
{"amount": Decimal("0.2")})
5657

57-
# sendmany from node1: twice to self, twice to node2:
58+
self.log.info("Test sendmany from node1: twice to self, twice to node0")
5859
send_to = {self.nodes[0].getnewaddress(): 0.11,
5960
self.nodes[1].getnewaddress(): 0.22,
6061
self.nodes[0].getnewaddress(): 0.33,
@@ -88,6 +89,7 @@ def run_test(self):
8889

8990
if not self.options.descriptors:
9091
# include_watchonly is a legacy wallet feature, so don't test it for descriptor wallets
92+
self.log.info("Test 'include_watchonly' feature (legacy wallet)")
9193
pubkey = self.nodes[1].getaddressinfo(self.nodes[1].getnewaddress())['pubkey']
9294
multisig = self.nodes[1].createmultisig(1, [pubkey])
9395
self.nodes[0].importaddress(multisig["redeemScript"], "watchonly", False, True)
@@ -103,37 +105,38 @@ def run_test(self):
103105

104106
self.run_rbf_opt_in_test()
105107

106-
# Check that the opt-in-rbf flag works properly, for sent and received
107-
# transactions.
108+
108109
def run_rbf_opt_in_test(self):
109-
# Check whether a transaction signals opt-in RBF itself
110+
"""Test the opt-in-rbf flag for sent and received transactions."""
111+
110112
def is_opt_in(node, txid):
113+
"""Check whether a transaction signals opt-in RBF itself."""
111114
rawtx = node.getrawtransaction(txid, 1)
112115
for x in rawtx["vin"]:
113116
if x["sequence"] < 0xfffffffe:
114117
return True
115118
return False
116119

117-
# Find an unconfirmed output matching a certain txid
118120
def get_unconfirmed_utxo_entry(node, txid_to_match):
121+
"""Find an unconfirmed output matching a certain txid."""
119122
utxo = node.listunspent(0, 0)
120123
for i in utxo:
121124
if i["txid"] == txid_to_match:
122125
return i
123126
return None
124127

125-
# 1. Chain a few transactions that don't opt-in.
128+
self.log.info("Test txs w/o opt-in RBF (bip125-replaceable=no)")
129+
# Chain a few transactions that don't opt in.
126130
txid_1 = self.nodes[0].sendtoaddress(self.nodes[1].getnewaddress(), 1)
127131
assert not is_opt_in(self.nodes[0], txid_1)
128132
assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_1}, {"bip125-replaceable": "no"})
129133
self.sync_mempools()
130134
assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_1}, {"bip125-replaceable": "no"})
131135

132-
# Tx2 will build off txid_1, still not opting in to RBF.
136+
# Tx2 will build off tx1, still not opting in to RBF.
133137
utxo_to_use = get_unconfirmed_utxo_entry(self.nodes[0], txid_1)
134138
assert_equal(utxo_to_use["safe"], True)
135139
utxo_to_use = get_unconfirmed_utxo_entry(self.nodes[1], txid_1)
136-
utxo_to_use = get_unconfirmed_utxo_entry(self.nodes[1], txid_1)
137140
assert_equal(utxo_to_use["safe"], False)
138141

139142
# Create tx2 using createrawtransaction
@@ -149,6 +152,7 @@ def get_unconfirmed_utxo_entry(node, txid_to_match):
149152
self.sync_mempools()
150153
assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_2}, {"bip125-replaceable": "no"})
151154

155+
self.log.info("Test txs with opt-in RBF (bip125-replaceable=yes)")
152156
# Tx3 will opt-in to RBF
153157
utxo_to_use = get_unconfirmed_utxo_entry(self.nodes[0], txid_2)
154158
inputs = [{"txid": txid_2, "vout": utxo_to_use["vout"]}]
@@ -179,6 +183,7 @@ def get_unconfirmed_utxo_entry(node, txid_to_match):
179183
self.sync_mempools()
180184
assert_array_result(self.nodes[0].listtransactions(), {"txid": txid_4}, {"bip125-replaceable": "yes"})
181185

186+
self.log.info("Test tx with unknown RBF state (bip125-replaceable=unknown)")
182187
# Replace tx3, and check that tx4 becomes unknown
183188
tx3_b = tx3_modified
184189
tx3_b.vout[0].nValue -= int(Decimal("0.004") * COIN) # bump the fee
@@ -191,15 +196,15 @@ def get_unconfirmed_utxo_entry(node, txid_to_match):
191196
self.sync_mempools()
192197
assert_array_result(self.nodes[1].listtransactions(), {"txid": txid_4}, {"bip125-replaceable": "unknown"})
193198

194-
# Check gettransaction as well:
199+
self.log.info("Test bip125-replaceable status with gettransaction RPC")
195200
for n in self.nodes[0:2]:
196201
assert_equal(n.gettransaction(txid_1)["bip125-replaceable"], "no")
197202
assert_equal(n.gettransaction(txid_2)["bip125-replaceable"], "no")
198203
assert_equal(n.gettransaction(txid_3)["bip125-replaceable"], "yes")
199204
assert_equal(n.gettransaction(txid_3b)["bip125-replaceable"], "yes")
200205
assert_equal(n.gettransaction(txid_4)["bip125-replaceable"], "unknown")
201206

202-
# After mining a transaction, it's no longer BIP125-replaceable
207+
self.log.info("Test mined transactions are no longer bip125-replaceable")
203208
self.nodes[0].generate(1)
204209
assert txid_3b not in self.nodes[0].getrawmempool()
205210
assert_equal(self.nodes[0].gettransaction(txid_3b)["bip125-replaceable"], "no")

0 commit comments

Comments
 (0)