Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1#!/usr/bin/env python32# Copyright (c) 2017-present The Bitcoin Core developers3# Distributed under the MIT software license, see the accompanying4# file COPYING or http://www.opensource.org/licenses/mit-license.php.5"""Test the -uacomment option."""7import re9from test_framework.test_framework import BitcoinTestFramework10from test_framework.test_node import ErrorMatch11from test_framework.util import assert_equal14class UacommentTest(BitcoinTestFramework):15def set_test_params(self):16self.num_nodes = 117self.setup_clean_chain = True19def run_test(self):20self.log.info("test multiple -uacomment")21test_uacomment = self.nodes[0].getnetworkinfo()["subversion"][-12:-1]22assert_equal(test_uacomment, "(testnode0)")24self.restart_node(0, ["-uacomment=foo"])25foo_uacomment = self.nodes[0].getnetworkinfo()["subversion"][-17:-1]26assert_equal(foo_uacomment, "(testnode0; foo)")28self.log.info("test -uacomment max length")29self.stop_node(0)30expected = r"Error: Total length of network version string \([0-9]+\) exceeds maximum length \(256\). Reduce the number or size of uacomments."31self.nodes[0].assert_start_raises_init_error(["-uacomment=" + 'a' * 256], expected, match=ErrorMatch.FULL_REGEX)33self.log.info("test -uacomment unsafe characters")34for unsafe_char in ['/', ':', '(', ')', '₿', '🏃']:35expected = r"Error: User Agent comment \(" + re.escape(unsafe_char) + r"\) contains unsafe characters."36self.nodes[0].assert_start_raises_init_error(["-uacomment=" + unsafe_char], expected, match=ErrorMatch.FULL_REGEX)39if __name__ == '__main__':40UacommentTest(__file__).main()
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.