2 # Copyright (c) 2017 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."""
7 from test_framework
.test_framework
import BitcoinTestFramework
8 from test_framework
.util
import assert_equal
10 class UacommentTest(BitcoinTestFramework
):
11 def set_test_params(self
):
13 self
.setup_clean_chain
= True
16 self
.log
.info("test multiple -uacomment")
17 test_uacomment
= self
.nodes
[0].getnetworkinfo()["subversion"][-12:-1]
18 assert_equal(test_uacomment
, "(testnode0)")
20 self
.restart_node(0, ["-uacomment=foo"])
21 foo_uacomment
= self
.nodes
[0].getnetworkinfo()["subversion"][-17:-1]
22 assert_equal(foo_uacomment
, "(testnode0; foo)")
24 self
.log
.info("test -uacomment max length")
26 expected
= "Total length of network version string (286) exceeds maximum length (256). Reduce the number or size of uacomments."
27 self
.assert_start_raises_init_error(0, ["-uacomment=" + 'a' * 256], expected
)
29 self
.log
.info("test -uacomment unsafe characters")
30 for unsafe_char
in ['/', ':', '(', ')']:
31 expected
= "User Agent comment (" + unsafe_char
+ ") contains unsafe characters"
32 self
.assert_start_raises_init_error(0, ["-uacomment=" + unsafe_char
], expected
)
34 if __name__
== '__main__':
35 UacommentTest().main()