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.

signmessages.py 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #!/usr/bin/env python3
  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."""
  6. from test_framework.test_framework import BitcoinTestFramework
  7. from test_framework.util import assert_equal
  8. class SignMessagesTest(BitcoinTestFramework):
  9. def set_test_params(self):
  10. self.setup_clean_chain = True
  11. self.num_nodes = 1
  12. def run_test(self):
  13. message = 'This is just a test message'
  14. self.log.info('test signing with priv_key')
  15. priv_key = 'cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N'
  16. address = 'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB'
  17. expected_signature = 'INbVnW4e6PeRmsv2Qgu8NuopvrVjkcxob+sX8OcZG0SALhWybUjzMLPdAsXI46YZGb0KQTRii+wWIQzRpG/U+S0='
  18. signature = self.nodes[0].signmessagewithprivkey(priv_key, message)
  19. assert_equal(expected_signature, signature)
  20. assert(self.nodes[0].verifymessage(address, signature, message))
  21. self.log.info('test signing with an address with wallet')
  22. address = self.nodes[0].getnewaddress()
  23. signature = self.nodes[0].signmessage(address, message)
  24. assert(self.nodes[0].verifymessage(address, signature, message))
  25. self.log.info('test verifying with another address should not work')
  26. other_address = self.nodes[0].getnewaddress()
  27. other_signature = self.nodes[0].signmessage(other_address, message)
  28. assert(not self.nodes[0].verifymessage(other_address, signature, message))
  29. assert(not self.nodes[0].verifymessage(address, other_signature, message))
  30. if __name__ == '__main__':
  31. SignMessagesTest().main()