Changeset View
Changeset View
Standalone View
Standalone View
test/functional/rpc_invalidateblock.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2019 The Bitcoin Core developers | # Copyright (c) 2014-2019 The Bitcoin Core developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test the invalidateblock RPC.""" | """Test the invalidateblock RPC.""" | ||||
from test_framework.address import ADDRESS_BCHREG_UNSPENDABLE_DESCRIPTOR | from test_framework.address import ADDRESS_ECREG_UNSPENDABLE_DESCRIPTOR | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
connect_nodes, | connect_nodes, | ||||
wait_until, | wait_until, | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
1, self.nodes[2].get_deterministic_priv_key().address) | 1, self.nodes[2].get_deterministic_priv_key().address) | ||||
self.log.info("Verify all nodes are at the right height") | self.log.info("Verify all nodes are at the right height") | ||||
wait_until(lambda: self.nodes[2].getblockcount() == 3, timeout=5) | wait_until(lambda: self.nodes[2].getblockcount() == 3, timeout=5) | ||||
wait_until(lambda: self.nodes[0].getblockcount() == 4, timeout=5) | wait_until(lambda: self.nodes[0].getblockcount() == 4, timeout=5) | ||||
wait_until(lambda: self.nodes[1].getblockcount() == 4, timeout=5) | wait_until(lambda: self.nodes[1].getblockcount() == 4, timeout=5) | ||||
self.log.info("Verify that we reconsider all ancestors as well") | self.log.info("Verify that we reconsider all ancestors as well") | ||||
blocks = self.nodes[1].generatetodescriptor( | blocks = self.nodes[1].generatetodescriptor( | ||||
10, ADDRESS_BCHREG_UNSPENDABLE_DESCRIPTOR) | 10, ADDRESS_ECREG_UNSPENDABLE_DESCRIPTOR) | ||||
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) | assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) | ||||
# Invalidate the two blocks at the tip | # Invalidate the two blocks at the tip | ||||
self.nodes[1].invalidateblock(blocks[-1]) | self.nodes[1].invalidateblock(blocks[-1]) | ||||
self.nodes[1].invalidateblock(blocks[-2]) | self.nodes[1].invalidateblock(blocks[-2]) | ||||
assert_equal(self.nodes[1].getbestblockhash(), blocks[-3]) | assert_equal(self.nodes[1].getbestblockhash(), blocks[-3]) | ||||
# Reconsider only the previous tip | # Reconsider only the previous tip | ||||
self.nodes[1].reconsiderblock(blocks[-1]) | self.nodes[1].reconsiderblock(blocks[-1]) | ||||
# Should be back at the tip by now | # Should be back at the tip by now | ||||
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) | assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) | ||||
self.log.info("Verify that we reconsider all descendants") | self.log.info("Verify that we reconsider all descendants") | ||||
blocks = self.nodes[1].generatetodescriptor( | blocks = self.nodes[1].generatetodescriptor( | ||||
10, ADDRESS_BCHREG_UNSPENDABLE_DESCRIPTOR) | 10, ADDRESS_ECREG_UNSPENDABLE_DESCRIPTOR) | ||||
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) | assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) | ||||
# Invalidate the two blocks at the tip | # Invalidate the two blocks at the tip | ||||
self.nodes[1].invalidateblock(blocks[-2]) | self.nodes[1].invalidateblock(blocks[-2]) | ||||
self.nodes[1].invalidateblock(blocks[-4]) | self.nodes[1].invalidateblock(blocks[-4]) | ||||
assert_equal(self.nodes[1].getbestblockhash(), blocks[-5]) | assert_equal(self.nodes[1].getbestblockhash(), blocks[-5]) | ||||
# Reconsider only the previous tip | # Reconsider only the previous tip | ||||
self.nodes[1].reconsiderblock(blocks[-4]) | self.nodes[1].reconsiderblock(blocks[-4]) | ||||
# Should be back at the tip by now | # Should be back at the tip by now | ||||
assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) | assert_equal(self.nodes[1].getbestblockhash(), blocks[-1]) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
InvalidateTest().main() | InvalidateTest().main() |