5
5
"""Test the listsincelast RPC."""
6
6
7
7
from test_framework .test_framework import BitcoinTestFramework
8
+ from test_framework .messages import BIP125_SEQUENCE_NUMBER
8
9
from test_framework .util import (
9
10
assert_array_result ,
10
11
assert_equal ,
11
12
assert_raises_rpc_error ,
12
13
connect_nodes ,
13
14
)
14
15
16
+ from decimal import Decimal
15
17
16
18
class ListSinceBlockTest (BitcoinTestFramework ):
17
19
def set_test_params (self ):
@@ -33,6 +35,7 @@ def run_test(self):
33
35
self .test_reorg ()
34
36
self .test_double_spend ()
35
37
self .test_double_send ()
38
+ self .double_spends_filtered ()
36
39
37
40
def test_no_blockhash (self ):
38
41
txid = self .nodes [2 ].sendtoaddress (self .nodes [0 ].getnewaddress (), 1 )
@@ -291,5 +294,51 @@ def test_double_send(self):
291
294
if tx ['txid' ] == txid1 :
292
295
assert_equal (tx ['confirmations' ], 2 )
293
296
297
+ def double_spends_filtered (self ):
298
+ '''
299
+ `listsinceblock` was returning conflicted transactions even if they
300
+ occurred before the specified cutoff blockhash
301
+ '''
302
+ spending_node = self .nodes [2 ]
303
+ dest_address = spending_node .getnewaddress ()
304
+
305
+ tx_input = dict (
306
+ sequence = BIP125_SEQUENCE_NUMBER , ** next (u for u in spending_node .listunspent ()))
307
+ rawtx = spending_node .createrawtransaction (
308
+ [tx_input ], {dest_address : tx_input ["amount" ] - Decimal ("0.00051000" ),
309
+ spending_node .getrawchangeaddress (): Decimal ("0.00050000" )})
310
+ signedtx = spending_node .signrawtransactionwithwallet (rawtx )
311
+ orig_tx_id = spending_node .sendrawtransaction (signedtx ["hex" ])
312
+ original_tx = spending_node .gettransaction (orig_tx_id )
313
+
314
+ double_tx = spending_node .bumpfee (orig_tx_id )
315
+
316
+ # check that both transactions exist
317
+ block_hash = spending_node .listsinceblock (
318
+ spending_node .getblockhash (spending_node .getblockcount ()))
319
+ original_found = False
320
+ double_found = False
321
+ for tx in block_hash ['transactions' ]:
322
+ if tx ['txid' ] == original_tx ['txid' ]:
323
+ original_found = True
324
+ if tx ['txid' ] == double_tx ['txid' ]:
325
+ double_found = True
326
+ assert_equal (original_found , True )
327
+ assert_equal (double_found , True )
328
+
329
+ lastblockhash = spending_node .generate (1 )[0 ]
330
+
331
+ # check that neither transaction exists
332
+ block_hash = spending_node .listsinceblock (lastblockhash )
333
+ original_found = False
334
+ double_found = False
335
+ for tx in block_hash ['transactions' ]:
336
+ if tx ['txid' ] == original_tx ['txid' ]:
337
+ original_found = True
338
+ if tx ['txid' ] == double_tx ['txid' ]:
339
+ double_found = True
340
+ assert_equal (original_found , False )
341
+ assert_equal (double_found , False )
342
+
294
343
if __name__ == '__main__' :
295
344
ListSinceBlockTest ().main ()
0 commit comments