2 # Copyright (c) 2017 The Bitcoin Core developers
3 # Distributed under the MIT software license, see the accompanying
4 # file COPYING or http://www.opensource.org/licenses/mit-license.php.
5 """Test the listsincelast RPC."""
7 from test_framework
.test_framework
import BitcoinTestFramework
8 from test_framework
.util
import assert_equal
10 class ListSinceBlockTest (BitcoinTestFramework
):
14 self
.setup_clean_chain
= True
19 `listsinceblock` did not behave correctly when handed a block that was
20 no longer in the main chain:
32 Consider a client that has only seen block `aa3` above. It asks the node
33 to `listsinceblock aa3`. But at some point prior the main chain switched
36 Previously: listsinceblock would find height=4 for block aa3 and compare
37 this to height=5 for the tip of the chain (bb4). It would then return
38 results restricted to bb3-bb4.
40 Now: listsinceblock finds the fork at ab0 and returns results in the
43 This test only checks that [tx0] is present.
46 self
.nodes
[2].generate(101)
49 assert_equal(self
.nodes
[0].getbalance(), 0)
50 assert_equal(self
.nodes
[1].getbalance(), 0)
51 assert_equal(self
.nodes
[2].getbalance(), 50)
52 assert_equal(self
.nodes
[3].getbalance(), 0)
54 # Split network into two
57 # send to nodes[0] from nodes[2]
58 senttx
= self
.nodes
[2].sendtoaddress(self
.nodes
[0].getnewaddress(), 1)
60 # generate on both sides
61 lastblockhash
= self
.nodes
[1].generate(6)[5]
62 self
.nodes
[2].generate(7)
63 self
.log
.info('lastblockhash=%s' % (lastblockhash
))
65 self
.sync_all([self
.nodes
[:2], self
.nodes
[2:]])
69 # listsinceblock(lastblockhash) should now include tx, as seen from nodes[0]
70 lsbres
= self
.nodes
[0].listsinceblock(lastblockhash
)
72 for tx
in lsbres
['transactions']:
73 if tx
['txid'] == senttx
:
76 assert_equal(found
, True)
78 if __name__
== '__main__':
79 ListSinceBlockTest().main()