feature_uacomment.py raw
1 #!/usr/bin/env python3
2 # Copyright (c) 2017-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 the -uacomment option."""
6
7 import re
8
9 from test_framework.test_framework import BitcoinTestFramework
10 from test_framework.test_node import ErrorMatch
11 from test_framework.util import assert_equal
12
13
14 class UacommentTest(BitcoinTestFramework):
15 def set_test_params(self):
16 self.num_nodes = 1
17 self.setup_clean_chain = True
18
19 def run_test(self):
20 self.log.info("test multiple -uacomment")
21 test_uacomment = self.nodes[0].getnetworkinfo()["subversion"][-12:-1]
22 assert_equal(test_uacomment, "(testnode0)")
23
24 self.restart_node(0, ["-uacomment=foo"])
25 foo_uacomment = self.nodes[0].getnetworkinfo()["subversion"][-17:-1]
26 assert_equal(foo_uacomment, "(testnode0; foo)")
27
28 self.log.info("test -uacomment max length")
29 self.stop_node(0)
30 expected = r"Error: Total length of network version string \([0-9]+\) exceeds maximum length \(256\). Reduce the number or size of uacomments."
31 self.nodes[0].assert_start_raises_init_error(["-uacomment=" + 'a' * 256], expected, match=ErrorMatch.FULL_REGEX)
32
33 self.log.info("test -uacomment unsafe characters")
34 for unsafe_char in ['/', ':', '(', ')', '₿', '🏃']:
35 expected = r"Error: User Agent comment \(" + re.escape(unsafe_char) + r"\) contains unsafe characters."
36 self.nodes[0].assert_start_raises_init_error(["-uacomment=" + unsafe_char], expected, match=ErrorMatch.FULL_REGEX)
37
38
39 if __name__ == '__main__':
40 UacommentTest(__file__).main()
41