diff --git a/bitcoin/rpc.py b/bitcoin/rpc.py index d124979f..d3cfc55a 100644 --- a/bitcoin/rpc.py +++ b/bitcoin/rpc.py @@ -446,7 +446,10 @@ def submitblock(self, block, params=None): def validateaddress(self, address): """Return information about an address""" r = self._call('validateaddress', str(address)) - r['address'] = CBitcoinAddress(r['address']) + if 'address' in r: + r['address'] = CBitcoinAddress(r['address']) + elif 'isvalid' in r: + return r # No address returned, only 'isvalid': False if not valid. if 'pubkey' in r: r['pubkey'] = unhexlify(r['pubkey']) return r diff --git a/bitcoin/tests/test_rpc.py b/bitcoin/tests/test_rpc.py new file mode 100644 index 00000000..1b260560 --- /dev/null +++ b/bitcoin/tests/test_rpc.py @@ -0,0 +1,30 @@ +# Distributed under the MIT/X11 software license, see the accompanying +# file COPYING or http://www.opensource.org/licenses/mit-license.php. + +from __future__ import absolute_import, division, print_function, unicode_literals + +import unittest + +from bitcoin.rpc import Proxy + +class Test_RPC(unittest.TestCase): + ''' + Tests disabled, see discussion below. + "Looks like your unit tests won't work if Bitcoin Core isn't running; + maybe they in turn need to check that and disable the test if core isn't available?" + https://github.com/petertodd/python-bitcoinlib/pull/10 + ''' + def test_can_validate(self): + if False: + working_address = '1CB2fxLGAZEzgaY4pjr4ndeDWJiz3D3AT7' + p = Proxy() + r = p.validateAddress(working_address) + self.assertEqual(r['address'], working_address) + self.assertEqual(r['isvalid'], True) + + def test_cannot_validate(self): + if False: + non_working_address = 'LTatMHrYyHcxhxrY27AqFN53bT4TauR86h' + p = Proxy() + r = p.validateAddress(non_working_address) + self.assertEqual(r['isvalid'], False)