Skip to content

Commit df18d29

Browse files
committed
[tests] Add -blocknotify functional test
1 parent 9c72a46 commit df18d29

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

test/functional/forknotify.py renamed to test/functional/notifications.py

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,40 @@
22
# Copyright (c) 2014-2016 The Bitcoin Core developers
33
# Distributed under the MIT software license, see the accompanying
44
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5-
"""Test the -alertnotify option."""
5+
"""Test the -alertnotify and -blocknotify options."""
66
import os
77

88
from test_framework.test_framework import BitcoinTestFramework
99
from test_framework.util import assert_equal, wait_until
1010

11-
class ForkNotifyTest(BitcoinTestFramework):
11+
class NotificationsTest(BitcoinTestFramework):
1212
def set_test_params(self):
1313
self.num_nodes = 2
1414

1515
def setup_network(self):
1616
self.alert_filename = os.path.join(self.options.tmpdir, "alert.txt")
17-
self.extra_args = [["-alertnotify=echo %%s >> %s" % self.alert_filename],
17+
self.block_filename = os.path.join(self.options.tmpdir, 'blocks.txt')
18+
self.extra_args = [["-blockversion=2",
19+
"-alertnotify=echo %%s >> %s" % self.alert_filename,
20+
"-blocknotify=echo %%s >> %s" % self.block_filename],
1821
["-blockversion=211"]]
1922
super().setup_network()
2023

2124
def run_test(self):
22-
# Mine 51 up-version blocks. -alertnotify should trigger on the 51st.
23-
self.nodes[1].generate(51)
25+
self.log.info("test -blocknotify")
26+
block_count = 10
27+
blocks = self.nodes[1].generate(block_count)
28+
29+
# wait at most 10 seconds for expected file size before reading the content
30+
wait_until(lambda: os.path.isfile(self.block_filename) and os.stat(self.block_filename).st_size >= (block_count * 65), timeout=10)
31+
32+
# file content should equal the generated blocks hashes
33+
with open(self.block_filename, 'r') as f:
34+
assert_equal(sorted(blocks), sorted(f.read().splitlines()))
35+
36+
# Mine another 41 up-version blocks. -alertnotify should trigger on the 51st.
37+
self.log.info("test -alertnotify")
38+
self.nodes[1].generate(41)
2439
self.sync_all()
2540

2641
# Give bitcoind 10 seconds to write the alert notification
@@ -40,4 +55,4 @@ def run_test(self):
4055
assert_equal(alert_text, alert_text2)
4156

4257
if __name__ == '__main__':
43-
ForkNotifyTest().main()
58+
NotificationsTest().main()

test/functional/test_runner.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@
148148
'example_test.py',
149149
'txn_doublespend.py',
150150
'txn_clone.py --mineblock',
151-
'forknotify.py',
151+
'notifications.py',
152152
'invalidateblock.py',
153153
'p2p-acceptblock.py',
154154
'replace-by-fee.py',

0 commit comments

Comments
 (0)