Changeset View
Changeset View
Standalone View
Standalone View
test/functional/feature_notifications.py
#!/usr/bin/env python3 | #!/usr/bin/env python3 | ||||
# Copyright (c) 2014-2019 The Bitcoin Core developers | # Copyright (c) 2014-2019 The Bitcoin Core developers | ||||
# Copyright (c) 2018 The Bitcoin developers | # Copyright (c) 2018 The Bitcoin developers | ||||
# Distributed under the MIT software license, see the accompanying | # Distributed under the MIT software license, see the accompanying | ||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | # file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
"""Test the -alertnotify, -blocknotify and -walletnotify options.""" | """Test the -alertnotify, -blocknotify and -walletnotify options.""" | ||||
import os | import os | ||||
from test_framework.address import ADDRESS_ECREG_UNSPENDABLE, keyhash_to_p2pkh | from test_framework.address import ADDRESS_ECREG_UNSPENDABLE, keyhash_to_p2pkh | ||||
from test_framework.test_framework import BitcoinTestFramework | from test_framework.test_framework import BitcoinTestFramework | ||||
from test_framework.util import ( | from test_framework.util import ( | ||||
assert_equal, | assert_equal, | ||||
connect_nodes, | connect_nodes, | ||||
disconnect_nodes, | disconnect_nodes, | ||||
hex_str_to_bytes, | hex_str_to_bytes, | ||||
wait_until, | |||||
) | ) | ||||
FORK_WARNING_MESSAGE = "Warning: Large-work fork detected, forking after block {}" | FORK_WARNING_MESSAGE = "Warning: Large-work fork detected, forking after block {}" | ||||
# Linux allow all characters other than \x00 | # Linux allow all characters other than \x00 | ||||
# Windows disallow control characters (0-31) and /\?%:|"<> | # Windows disallow control characters (0-31) and /\?%:|"<> | ||||
FILE_CHAR_START = 32 if os.name == 'nt' else 1 | FILE_CHAR_START = 32 if os.name == 'nt' else 1 | ||||
FILE_CHAR_END = 128 | FILE_CHAR_END = 128 | ||||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Lines | def run_test(self): | ||||
self.nodes[0].generatetoaddress(1, ADDRESS_ECREG_UNSPENDABLE) | self.nodes[0].generatetoaddress(1, ADDRESS_ECREG_UNSPENDABLE) | ||||
invalid_block = self.nodes[0].getbestblockhash() | invalid_block = self.nodes[0].getbestblockhash() | ||||
self.nodes[0].generatetoaddress(7, ADDRESS_ECREG_UNSPENDABLE) | self.nodes[0].generatetoaddress(7, ADDRESS_ECREG_UNSPENDABLE) | ||||
# Invalidate a large branch, which should trigger an alert. | # Invalidate a large branch, which should trigger an alert. | ||||
self.nodes[0].invalidateblock(invalid_block) | self.nodes[0].invalidateblock(invalid_block) | ||||
# Give bitcoind 10 seconds to write the alert notification | # Give bitcoind 10 seconds to write the alert notification | ||||
wait_until(lambda: len(os.listdir(self.alertnotify_dir)), timeout=10) | self.wait_until(lambda: len(os.listdir(self.alertnotify_dir)), | ||||
timeout=10) | |||||
# The notification command is unable to properly handle the spaces on | # The notification command is unable to properly handle the spaces on | ||||
# windows. Skip the content check in this case. | # windows. Skip the content check in this case. | ||||
if os.name != 'nt': | if os.name != 'nt': | ||||
assert FORK_WARNING_MESSAGE.format( | assert FORK_WARNING_MESSAGE.format( | ||||
fork_block) in os.listdir(self.alertnotify_dir) | fork_block) in os.listdir(self.alertnotify_dir) | ||||
for notify_file in os.listdir(self.alertnotify_dir): | for notify_file in os.listdir(self.alertnotify_dir): | ||||
Show All 15 Lines |