From 4634c01a46b0108a214fe252e9054ffa9d38914d Mon Sep 17 00:00:00 2001 From: David Trail Date: Mon, 26 May 2014 08:03:46 +0200 Subject: [PATCH 1/5] Validateaddress wasn't working for non-valid addresses. --- bitcoin/rpc.py | 8 ++++++-- bitcoin/tests/test_rpc.py | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 bitcoin/tests/test_rpc.py diff --git a/bitcoin/rpc.py b/bitcoin/rpc.py index 768690ef..5a045acd 100644 --- a/bitcoin/rpc.py +++ b/bitcoin/rpc.py @@ -398,6 +398,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']) - r['pubkey'] = unhexlify(r['pubkey']) + 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..277158e5 --- /dev/null +++ b/bitcoin/tests/test_rpc.py @@ -0,0 +1,22 @@ +# 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): + def test_can_validate(self): + 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): + non_working_address = 'LTatMHrYyHcxhxrY27AqFN53bT4TauR86h' + p = Proxy() + r = p.validateAddress(non_working_address) + self.assertEqual(r['isvalid'], False) From a3013a98714878f28ed9a193fb5fadbec58fabfd Mon Sep 17 00:00:00 2001 From: David Trail Date: Mon, 26 May 2014 18:31:29 +0200 Subject: [PATCH 2/5] Nullify tests until bitcoin checks can be done --- bitcoin/tests/test_rpc.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/bitcoin/tests/test_rpc.py b/bitcoin/tests/test_rpc.py index 277158e5..03f3c5af 100644 --- a/bitcoin/tests/test_rpc.py +++ b/bitcoin/tests/test_rpc.py @@ -9,14 +9,16 @@ class Test_RPC(unittest.TestCase): def test_can_validate(self): - working_address = '1CB2fxLGAZEzgaY4pjr4ndeDWJiz3D3AT7' - p = Proxy() - r = p.validateAddress(working_address) - self.assertEqual(r['address'], working_address) - self.assertEqual(r['isvalid'], True) + 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): - non_working_address = 'LTatMHrYyHcxhxrY27AqFN53bT4TauR86h' - p = Proxy() - r = p.validateAddress(non_working_address) - self.assertEqual(r['isvalid'], False) + if False: + non_working_address = 'LTatMHrYyHcxhxrY27AqFN53bT4TauR86h' + p = Proxy() + r = p.validateAddress(non_working_address) + self.assertEqual(r['isvalid'], False) From d94ccaae6b2e3603f2336014bda97412ed9964e6 Mon Sep 17 00:00:00 2001 From: David Trail Date: Mon, 26 May 2014 18:38:15 +0200 Subject: [PATCH 3/5] Fixed error with validating bitcoin addresses --- bitcoin/rpc.py | 6 ------ 1 file changed, 6 deletions(-) diff --git a/bitcoin/rpc.py b/bitcoin/rpc.py index a4adf7ad..e5c4458a 100644 --- a/bitcoin/rpc.py +++ b/bitcoin/rpc.py @@ -446,14 +446,8 @@ def submitblock(self, block, params=None): def validateaddress(self, address): """Return information about an address""" r = self._call('validateaddress', str(address)) -<<<<<<< HEAD - if 'address' in r: - r['address'] = CBitcoinAddress(r['address']) elif 'isvalid' in r: return r # No address returned, only 'isvalid': False if not valid. -======= - r['address'] = CBitcoinAddress(r['address']) ->>>>>>> ec7d1b675d4c86ec852350c1ca3923aaa7c17670 if 'pubkey' in r: r['pubkey'] = unhexlify(r['pubkey']) return r From e8efdfde4cfc0eac557525424b148c0a116db35f Mon Sep 17 00:00:00 2001 From: David Trail Date: Mon, 26 May 2014 18:40:45 +0200 Subject: [PATCH 4/5] Describe why tests are disabled for now --- bitcoin/tests/test_rpc.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bitcoin/tests/test_rpc.py b/bitcoin/tests/test_rpc.py index 03f3c5af..1b260560 100644 --- a/bitcoin/tests/test_rpc.py +++ b/bitcoin/tests/test_rpc.py @@ -8,6 +8,12 @@ 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' From f5ed0650b6afb06ea847b572180d94a05d0d79d8 Mon Sep 17 00:00:00 2001 From: David Trail Date: Mon, 26 May 2014 18:50:12 +0200 Subject: [PATCH 5/5] Oops, should have fixed that properly... --- bitcoin/rpc.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/bitcoin/rpc.py b/bitcoin/rpc.py index e5c4458a..d3cfc55a 100644 --- a/bitcoin/rpc.py +++ b/bitcoin/rpc.py @@ -446,6 +446,8 @@ def submitblock(self, block, params=None): def validateaddress(self, address): """Return information about an address""" r = self._call('validateaddress', str(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: