Skip to content

Commit c5dfa90

Browse files
committed
[tests] Add uacomment tests
Checks for setting the value, max length and reserved characters
1 parent 8928093 commit c5dfa90

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
'resendwallettransactions.py',
125125
'minchainwork.py',
126126
'p2p-fingerprint.py',
127+
'uacomment.py',
127128
]
128129

129130
EXTENDED_SCRIPTS = [

test/functional/uacomment.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env python3
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."""
6+
7+
from test_framework.test_framework import BitcoinTestFramework
8+
from test_framework.util import assert_equal
9+
10+
class UacommentTest(BitcoinTestFramework):
11+
def set_test_params(self):
12+
self.num_nodes = 1
13+
self.setup_clean_chain = True
14+
15+
def run_test(self):
16+
self.log.info("test multiple -uacomment")
17+
test_uacomment = self.nodes[0].getnetworkinfo()["subversion"][-12:-1]
18+
assert_equal(test_uacomment, "(testnode0)")
19+
20+
self.restart_node(0, ["-uacomment=foo"])
21+
foo_uacomment = self.nodes[0].getnetworkinfo()["subversion"][-17:-1]
22+
assert_equal(foo_uacomment, "(testnode0; foo)")
23+
24+
self.log.info("test -uacomment max length")
25+
self.stop_node(0)
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)
28+
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)
33+
34+
if __name__ == '__main__':
35+
UacommentTest().main()

0 commit comments

Comments
 (0)