MCPcopy Create free account
hub / github.com/ElementsProject/lightning / test_rescan

Function test_rescan

tests/test_misc.py:1636–1677  ·  view source on GitHub ↗

Test the rescan option

(node_factory, bitcoind)

Source from the content-addressed store, hash-verified

1634
1635
1636def test_rescan(node_factory, bitcoind):
1637 """Test the rescan option
1638 """
1639 l1 = node_factory.get_node()
1640
1641 # The first start should start at current_height - 30 = 71, make sure
1642 # it's not earlier
1643 l1.daemon.wait_for_log(r'Adding block 101')
1644 assert not l1.daemon.is_in_log(r'Adding block 70')
1645
1646 # Restarting with a higher rescan should go back further
1647 l1.daemon.opts['rescan'] = 50
1648 l1.restart()
1649 l1.daemon.wait_for_log(r'Adding block 101')
1650 assert l1.daemon.is_in_log(r'Adding block 51')
1651 assert not l1.daemon.is_in_log(r'Adding block 50')
1652
1653 # Restarting with an absolute rescan should start from there
1654 l1.daemon.opts['rescan'] = -31
1655 l1.restart()
1656 l1.daemon.wait_for_log(r'Adding block 101')
1657 assert l1.daemon.is_in_log(r'Adding block 31')
1658 assert not l1.daemon.is_in_log(r'Adding block 30')
1659
1660 # Restarting with a future absolute blockheight should *fail* if we
1661 # can't find that height
1662 l1.daemon.opts['rescan'] = -500000
1663 l1.stop()
1664 bitcoind.generate_block(4)
1665 l1.daemon.start(wait_for_initialized=False, stderr_redir=True)
1666 # Will exit with failure code.
1667 assert l1.daemon.wait() == 1
1668 assert l1.daemon.is_in_stderr(r"bitcoind has gone backwards from 500000 to 105 blocks!")
1669
1670 # Restarting with future absolute blockheight is fine if we can find it.
1671 l1.daemon.opts['rescan'] = -105
1672 oldneedle = l1.daemon.logsearch_start
1673 l1.start()
1674 # This could occur before pubkey msg, so move search needle back.
1675 l1.daemon.logsearch_start = oldneedle
1676 l1.daemon.wait_for_log(r'Adding block 105')
1677 assert not l1.daemon.is_in_log(r'Adding block 102')
1678
1679
1680def test_bitcoind_goes_backwards(node_factory, bitcoind):

Callers

nothing calls this directly

Calls 9

wait_for_logMethod · 0.80
is_in_logMethod · 0.80
restartMethod · 0.80
generate_blockMethod · 0.80
is_in_stderrMethod · 0.80
get_nodeMethod · 0.45
stopMethod · 0.45
startMethod · 0.45
waitMethod · 0.45

Tested by

no test coverage detected