18
18
class ListTransactionsTest (BitcoinTestFramework ):
19
19
def set_test_params (self ):
20
20
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
21
24
22
25
def skip_test_if_missing_module (self ):
23
26
self .skip_if_no_wallet ()
24
27
25
28
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" )
29
30
txid = self .nodes [0 ].sendtoaddress (self .nodes [1 ].getnewaddress (), 0.1 )
30
31
self .sync_all ()
31
32
assert_array_result (self .nodes [0 ].listtransactions (),
@@ -34,7 +35,7 @@ def run_test(self):
34
35
assert_array_result (self .nodes [1 ].listtransactions (),
35
36
{"txid" : txid },
36
37
{"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" )
38
39
blockhash = self .nodes [0 ].generate (1 )[0 ]
39
40
blockheight = self .nodes [0 ].getblockheader (blockhash )['height' ]
40
41
self .sync_all ()
@@ -45,7 +46,7 @@ def run_test(self):
45
46
{"txid" : txid },
46
47
{"category" : "receive" , "amount" : Decimal ("0.1" ), "confirmations" : 1 , "blockhash" : blockhash , "blockheight" : blockheight })
47
48
48
- # send-to-self:
49
+ self . log . info ( "Test send-to-self on node0" )
49
50
txid = self .nodes [0 ].sendtoaddress (self .nodes [0 ].getnewaddress (), 0.2 )
50
51
assert_array_result (self .nodes [0 ].listtransactions (),
51
52
{"txid" : txid , "category" : "send" },
@@ -54,7 +55,7 @@ def run_test(self):
54
55
{"txid" : txid , "category" : "receive" },
55
56
{"amount" : Decimal ("0.2" )})
56
57
57
- # sendmany from node1: twice to self, twice to node2:
58
+ self . log . info ( "Test sendmany from node1: twice to self, twice to node0" )
58
59
send_to = {self .nodes [0 ].getnewaddress (): 0.11 ,
59
60
self .nodes [1 ].getnewaddress (): 0.22 ,
60
61
self .nodes [0 ].getnewaddress (): 0.33 ,
@@ -88,6 +89,7 @@ def run_test(self):
88
89
89
90
if not self .options .descriptors :
90
91
# 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)" )
91
93
pubkey = self .nodes [1 ].getaddressinfo (self .nodes [1 ].getnewaddress ())['pubkey' ]
92
94
multisig = self .nodes [1 ].createmultisig (1 , [pubkey ])
93
95
self .nodes [0 ].importaddress (multisig ["redeemScript" ], "watchonly" , False , True )
@@ -103,37 +105,38 @@ def run_test(self):
103
105
104
106
self .run_rbf_opt_in_test ()
105
107
106
- # Check that the opt-in-rbf flag works properly, for sent and received
107
- # transactions.
108
+
108
109
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
+
110
112
def is_opt_in (node , txid ):
113
+ """Check whether a transaction signals opt-in RBF itself."""
111
114
rawtx = node .getrawtransaction (txid , 1 )
112
115
for x in rawtx ["vin" ]:
113
116
if x ["sequence" ] < 0xfffffffe :
114
117
return True
115
118
return False
116
119
117
- # Find an unconfirmed output matching a certain txid
118
120
def get_unconfirmed_utxo_entry (node , txid_to_match ):
121
+ """Find an unconfirmed output matching a certain txid."""
119
122
utxo = node .listunspent (0 , 0 )
120
123
for i in utxo :
121
124
if i ["txid" ] == txid_to_match :
122
125
return i
123
126
return None
124
127
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.
126
130
txid_1 = self .nodes [0 ].sendtoaddress (self .nodes [1 ].getnewaddress (), 1 )
127
131
assert not is_opt_in (self .nodes [0 ], txid_1 )
128
132
assert_array_result (self .nodes [0 ].listtransactions (), {"txid" : txid_1 }, {"bip125-replaceable" : "no" })
129
133
self .sync_mempools ()
130
134
assert_array_result (self .nodes [1 ].listtransactions (), {"txid" : txid_1 }, {"bip125-replaceable" : "no" })
131
135
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.
133
137
utxo_to_use = get_unconfirmed_utxo_entry (self .nodes [0 ], txid_1 )
134
138
assert_equal (utxo_to_use ["safe" ], True )
135
139
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 )
137
140
assert_equal (utxo_to_use ["safe" ], False )
138
141
139
142
# Create tx2 using createrawtransaction
@@ -149,6 +152,7 @@ def get_unconfirmed_utxo_entry(node, txid_to_match):
149
152
self .sync_mempools ()
150
153
assert_array_result (self .nodes [0 ].listtransactions (), {"txid" : txid_2 }, {"bip125-replaceable" : "no" })
151
154
155
+ self .log .info ("Test txs with opt-in RBF (bip125-replaceable=yes)" )
152
156
# Tx3 will opt-in to RBF
153
157
utxo_to_use = get_unconfirmed_utxo_entry (self .nodes [0 ], txid_2 )
154
158
inputs = [{"txid" : txid_2 , "vout" : utxo_to_use ["vout" ]}]
@@ -179,6 +183,7 @@ def get_unconfirmed_utxo_entry(node, txid_to_match):
179
183
self .sync_mempools ()
180
184
assert_array_result (self .nodes [0 ].listtransactions (), {"txid" : txid_4 }, {"bip125-replaceable" : "yes" })
181
185
186
+ self .log .info ("Test tx with unknown RBF state (bip125-replaceable=unknown)" )
182
187
# Replace tx3, and check that tx4 becomes unknown
183
188
tx3_b = tx3_modified
184
189
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):
191
196
self .sync_mempools ()
192
197
assert_array_result (self .nodes [1 ].listtransactions (), {"txid" : txid_4 }, {"bip125-replaceable" : "unknown" })
193
198
194
- # Check gettransaction as well:
199
+ self . log . info ( "Test bip125-replaceable status with gettransaction RPC" )
195
200
for n in self .nodes [0 :2 ]:
196
201
assert_equal (n .gettransaction (txid_1 )["bip125-replaceable" ], "no" )
197
202
assert_equal (n .gettransaction (txid_2 )["bip125-replaceable" ], "no" )
198
203
assert_equal (n .gettransaction (txid_3 )["bip125-replaceable" ], "yes" )
199
204
assert_equal (n .gettransaction (txid_3b )["bip125-replaceable" ], "yes" )
200
205
assert_equal (n .gettransaction (txid_4 )["bip125-replaceable" ], "unknown" )
201
206
202
- # After mining a transaction, it's no longer BIP125 -replaceable
207
+ self . log . info ( "Test mined transactions are no longer bip125 -replaceable" )
203
208
self .nodes [0 ].generate (1 )
204
209
assert txid_3b not in self .nodes [0 ].getrawmempool ()
205
210
assert_equal (self .nodes [0 ].gettransaction (txid_3b )["bip125-replaceable" ], "no" )
0 commit comments