2 # Copyright (c) 2016 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 RPC commands for signing and verifying messages."""
7 from test_framework
.test_framework
import BitcoinTestFramework
8 from test_framework
.util
import assert_equal
10 class SignMessagesTest(BitcoinTestFramework
):
11 def set_test_params(self
):
12 self
.setup_clean_chain
= True
16 message
= 'This is just a test message'
18 self
.log
.info('test signing with priv_key')
19 priv_key
= 'cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N'
20 address
= 'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB'
21 expected_signature
= 'INbVnW4e6PeRmsv2Qgu8NuopvrVjkcxob+sX8OcZG0SALhWybUjzMLPdAsXI46YZGb0KQTRii+wWIQzRpG/U+S0='
22 signature
= self
.nodes
[0].signmessagewithprivkey(priv_key
, message
)
23 assert_equal(expected_signature
, signature
)
24 assert(self
.nodes
[0].verifymessage(address
, signature
, message
))
26 self
.log
.info('test signing with an address with wallet')
27 address
= self
.nodes
[0].getnewaddress()
28 signature
= self
.nodes
[0].signmessage(address
, message
)
29 assert(self
.nodes
[0].verifymessage(address
, signature
, message
))
31 self
.log
.info('test verifying with another address should not work')
32 other_address
= self
.nodes
[0].getnewaddress()
33 other_signature
= self
.nodes
[0].signmessage(other_address
, message
)
34 assert(not self
.nodes
[0].verifymessage(other_address
, signature
, message
))
35 assert(not self
.nodes
[0].verifymessage(address
, other_signature
, message
))
37 if __name__
== '__main__':
38 SignMessagesTest().main()