You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.9 KiB
46 lines
1.9 KiB
9 years ago
|
#!/usr/bin/env python3
|
||
6 years ago
|
# Copyright (c) 2016-2019 The Bitcoin Core developers
|
||
9 years ago
|
# Distributed under the MIT software license, see the accompanying
|
||
|
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||
3 years ago
|
"""Test Wallet commands for signing and verifying messages."""
|
||
9 years ago
|
|
||
|
from test_framework.test_framework import BitcoinTestFramework
|
||
5 years ago
|
from test_framework.util import (
|
||
|
assert_raises_rpc_error,
|
||
|
)
|
||
9 years ago
|
|
||
3 years ago
|
class SignMessagesWithAddressTest(BitcoinTestFramework):
|
||
8 years ago
|
def set_test_params(self):
|
||
9 years ago
|
self.setup_clean_chain = True
|
||
|
self.num_nodes = 1
|
||
7 years ago
|
self.extra_args = [["-addresstype=legacy"]]
|
||
9 years ago
|
|
||
6 years ago
|
def skip_test_if_missing_module(self):
|
||
|
self.skip_if_no_wallet()
|
||
|
|
||
9 years ago
|
def run_test(self):
|
||
|
message = 'This is just a test message'
|
||
|
|
||
7 years ago
|
self.log.info('test signing with an address with wallet')
|
||
9 years ago
|
address = self.nodes[0].getnewaddress()
|
||
|
signature = self.nodes[0].signmessage(address, message)
|
||
6 years ago
|
assert self.nodes[0].verifymessage(address, signature, message)
|
||
9 years ago
|
|
||
7 years ago
|
self.log.info('test verifying with another address should not work')
|
||
|
other_address = self.nodes[0].getnewaddress()
|
||
|
other_signature = self.nodes[0].signmessage(other_address, message)
|
||
6 years ago
|
assert not self.nodes[0].verifymessage(other_address, signature, message)
|
||
|
assert not self.nodes[0].verifymessage(address, other_signature, message)
|
||
7 years ago
|
|
||
5 years ago
|
self.log.info('test parameter validity and error codes')
|
||
3 years ago
|
# signmessage has two required parameters
|
||
5 years ago
|
for num_params in [0, 1, 3, 4, 5]:
|
||
|
param_list = ["dummy"]*num_params
|
||
|
assert_raises_rpc_error(-1, "signmessage", self.nodes[0].signmessage, *param_list)
|
||
|
# invalid key or address provided
|
||
|
assert_raises_rpc_error(-5, "Invalid address", self.nodes[0].signmessage, "invalid_addr", message)
|
||
3 years ago
|
|
||
5 years ago
|
|
||
9 years ago
|
if __name__ == '__main__':
|
||
3 years ago
|
SignMessagesWithAddressTest().main()
|