feature_startupnotify.py raw
1 #!/usr/bin/env python3
2 # Copyright (c) 2020-present 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 -startupnotify."""
6 from test_framework.test_framework import BitcoinTestFramework
7 from test_framework.util import (
8 assert_equal,
9 )
10
11 NODE_DIR = "node0"
12 FILE_NAME = "test.txt"
13
14
15 class StartupNotifyTest(BitcoinTestFramework):
16 def set_test_params(self):
17 self.num_nodes = 1
18
19 def run_test(self):
20 tmpdir_file = self.nodes[0].datadir_path / FILE_NAME
21 assert not tmpdir_file.exists()
22
23 self.log.info("Test -startupnotify command is run when node starts")
24 self.restart_node(0, extra_args=[f"-startupnotify=echo '{FILE_NAME}' >> {NODE_DIR}/{FILE_NAME}"])
25 self.wait_until(lambda: tmpdir_file.exists())
26
27 self.log.info("Test -startupnotify is executed once")
28
29 def get_count():
30 with open(tmpdir_file, "r") as f:
31 file_content = f.read()
32 return file_content.count(FILE_NAME)
33
34 self.wait_until(lambda: get_count() > 0)
35 assert_equal(get_count(), 1)
36
37 self.log.info("Test node is fully started")
38 assert_equal(self.nodes[0].getblockcount(), 200)
39
40
41 if __name__ == '__main__':
42 StartupNotifyTest(__file__).main()
43