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.4KB

12345678910111213141516171819202122232425262728293031323334353637383940
  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 *
  8. class SignMessagesTest(BitcoinTestFramework):
  9. def __init__(self):
  10. super().__init__()
  11. self.setup_clean_chain = True
  12. self.num_nodes = 1
  13. def setup_network(self, split=False):
  14. self.nodes = start_nodes(self.num_nodes, self.options.tmpdir)
  15. self.is_network_split = False
  16. def run_test(self):
  17. message = 'This is just a test message'
  18. # Test the signing with a privkey
  19. privKey = 'cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N'
  20. address = 'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB'
  21. signature = self.nodes[0].signmessagewithprivkey(privKey, message)
  22. # Verify the message
  23. assert(self.nodes[0].verifymessage(address, signature, message))
  24. # Test the signing with an address with wallet
  25. address = self.nodes[0].getnewaddress()
  26. signature = self.nodes[0].signmessage(address, message)
  27. # Verify the message
  28. assert(self.nodes[0].verifymessage(address, signature, message))
  29. if __name__ == '__main__':
  30. SignMessagesTest().main()