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) 2016-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 Wallet commands for signing and verifying messages."""7from test_framework.test_framework import BitcoinTestFramework8from test_framework.util import (9assert_raises_rpc_error,10)12class SignMessagesWithAddressTest(BitcoinTestFramework):13def set_test_params(self):14self.setup_clean_chain = True15self.num_nodes = 116self.extra_args = [["-addresstype=legacy"]]18def skip_test_if_missing_module(self):19self.skip_if_no_wallet()21def run_test(self):22message = 'This is just a test message'24self.log.info('test signing with an address with wallet')25address = self.nodes[0].getnewaddress()26signature = self.nodes[0].signmessage(address, message)27assert self.nodes[0].verifymessage(address, signature, message)29self.log.info('test verifying with another address should not work')30other_address = self.nodes[0].getnewaddress()31other_signature = self.nodes[0].signmessage(other_address, message)32assert not self.nodes[0].verifymessage(other_address, signature, message)33assert not self.nodes[0].verifymessage(address, other_signature, message)35self.log.info('test parameter validity and error codes')36# signmessage has two required parameters37for num_params in [0, 1, 3, 4, 5]:38param_list = ["dummy"]*num_params39assert_raises_rpc_error(-1, "signmessage", self.nodes[0].signmessage, *param_list)40# invalid key or address provided41assert_raises_rpc_error(-5, "Invalid address", self.nodes[0].signmessage, "invalid_addr", message)44if __name__ == '__main__':45SignMessagesWithAddressTest(__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.