5
5
"""Test RPC commands for signing and verifying messages."""
6
6
7
7
from test_framework .test_framework import BitcoinTestFramework
8
+ from test_framework .util import assert_equal
8
9
9
10
class SignMessagesTest (BitcoinTestFramework ):
10
11
def set_test_params (self ):
@@ -14,20 +15,24 @@ def set_test_params(self):
14
15
def run_test (self ):
15
16
message = 'This is just a test message'
16
17
17
- # Test the signing with a privkey
18
- privKey = 'cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N'
18
+ self . log . info ( 'test signing with priv_key' )
19
+ priv_key = 'cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N'
19
20
address = 'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB'
20
- signature = self . nodes [ 0 ]. signmessagewithprivkey ( privKey , message )
21
-
22
- # Verify the message
21
+ expected_signature = 'INbVnW4e6PeRmsv2Qgu8NuopvrVjkcxob+sX8OcZG0SALhWybUjzMLPdAsXI46YZGb0KQTRii+wWIQzRpG/U+S0='
22
+ signature = self . nodes [ 0 ]. signmessagewithprivkey ( priv_key , message )
23
+ assert_equal ( expected_signature , signature )
23
24
assert (self .nodes [0 ].verifymessage (address , signature , message ))
24
25
25
- # Test the signing with an address with wallet
26
+ self . log . info ( 'test signing with an address with wallet' )
26
27
address = self .nodes [0 ].getnewaddress ()
27
28
signature = self .nodes [0 ].signmessage (address , message )
28
-
29
- # Verify the message
30
29
assert (self .nodes [0 ].verifymessage (address , signature , message ))
31
30
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 ))
36
+
32
37
if __name__ == '__main__' :
33
38
SignMessagesTest ().main ()
0 commit comments