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