|
| 1 | +#!/usr/bin/env python2 |
| 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 | + |
| 6 | +from test_framework.test_framework import BitcoinTestFramework |
| 7 | +from test_framework.util import * |
| 8 | + |
| 9 | + |
| 10 | +class SignMessagesTest(BitcoinTestFramework): |
| 11 | + """Tests RPC commands for signing and verifying messages.""" |
| 12 | + |
| 13 | + def setup_chain(self): |
| 14 | + print('Initializing test directory ' + self.options.tmpdir) |
| 15 | + initialize_chain_clean(self.options.tmpdir, 1) |
| 16 | + |
| 17 | + def setup_network(self, split=False): |
| 18 | + self.nodes = start_nodes(1, self.options.tmpdir) |
| 19 | + self.is_network_split = False |
| 20 | + |
| 21 | + def run_test(self): |
| 22 | + message = 'This is just a test message' |
| 23 | + |
| 24 | + # Test the signing with a privkey |
| 25 | + privKey = 'cUeKHd5orzT3mz8P9pxyREHfsWtVfgsfDjiZZBcjUBAaGk1BTj7N' |
| 26 | + address = 'mpLQjfK79b7CCV4VMJWEWAj5Mpx8Up5zxB' |
| 27 | + signature = self.nodes[0].signmessagewithprivkey(privKey, message) |
| 28 | + |
| 29 | + # Verify the message |
| 30 | + assert(self.nodes[0].verifymessage(address, signature, message)) |
| 31 | + |
| 32 | + # Test the signing with an address with wallet |
| 33 | + address = self.nodes[0].getnewaddress() |
| 34 | + signature = self.nodes[0].signmessage(address, message) |
| 35 | + |
| 36 | + # Verify the message |
| 37 | + assert(self.nodes[0].verifymessage(address, signature, message)) |
| 38 | + |
| 39 | +if __name__ == '__main__': |
| 40 | + SignMessagesTest().main() |
0 commit comments