Skip to content

Commit 31f385c

Browse files
author
MarcoFalke
committed
Merge bitcoin/bitcoin#23532: test: add functional test for -startupnotify
1268532 test: add functional test for -startupnotify (Bruno Garcia) Pull request description: This PR adds a functional test for -startupnotify. It basically starts the node passing a command on -startupnotify to create a file on tmp and then, we check if the file has been successfully created. ACKs for top commit: theStack: Tested ACK 1268532 kristapsk: re-ACK 1268532 Tree-SHA512: 5bf3e46124ee5c9d609c9993e6465d5a71a8d2275dcf07c8ce0549f013f7f8863d483b46b7164152f566468a689371ccb87f01cf118c3c9cac5b2be673b61a5c
2 parents bcf2b25 + 1268532 commit 31f385c

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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()

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@
257257
'wallet_bumpfee.py --descriptors',
258258
'wallet_implicitsegwit.py --legacy-wallet',
259259
'rpc_named_arguments.py',
260+
'feature_startupnotify.py',
260261
'wallet_listsinceblock.py --legacy-wallet',
261262
'wallet_listsinceblock.py --descriptors',
262263
'wallet_listdescriptors.py --descriptors',

0 commit comments

Comments
 (0)