From fde33e6fc63af0b8d0d5331c067652d15bbdbdcc Mon Sep 17 00:00:00 2001
From: Holger Nahrstaedt <holger@nahrstaedt.de>
Date: Thu, 1 Mar 2018 18:46:08 +0100
Subject: [PATCH] Fix unittest for python 3

---
 beemgraphenebase/base58.py      | 4 ++--
 beemgraphenebase/py23.py        | 9 ++++++++-
 tests/beemgraphene/test_py23.py | 9 +++++++--
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/beemgraphenebase/base58.py b/beemgraphenebase/base58.py
index b3942492..fc77ca45 100644
--- a/beemgraphenebase/base58.py
+++ b/beemgraphenebase/base58.py
@@ -8,7 +8,7 @@ from builtins import object
 from builtins import chr
 from future.utils import python_2_unicode_compatible
 from binascii import hexlify, unhexlify
-from .py23 import py23_bytes, bytes_types, integer_types, string_types, text_type
+from .py23 import py23_bytes, py23_chr, bytes_types, integer_types, string_types, text_type
 import hashlib
 import sys
 import string
@@ -124,7 +124,7 @@ def base58decode(base58_str):
     leading_zeroes_count = 0
     for b in base58_text:
         if isinstance(b, integer_types):
-            n = n * 58 + BASE58_ALPHABET.find(chr(b))
+            n = n * 58 + BASE58_ALPHABET.find(py23_chr(b))
         else:
             n = n * 58 + BASE58_ALPHABET.find(b)
         if n == 0:
diff --git a/beemgraphenebase/py23.py b/beemgraphenebase/py23.py
index 8221e60c..9d0e3943 100644
--- a/beemgraphenebase/py23.py
+++ b/beemgraphenebase/py23.py
@@ -2,7 +2,7 @@ from __future__ import absolute_import
 from __future__ import division
 from __future__ import print_function
 from __future__ import unicode_literals
-from builtins import bytes, int, str
+from builtins import bytes, int, str, chr
 import sys
 
 PY2 = sys.version_info[0] == 2
@@ -31,3 +31,10 @@ def py23_bytes(item, encoding=None):
             return bytes(item, encoding)
         else:
             return bytes(item)
+
+
+def py23_chr(item):
+    if PY2:
+        return chr(item)
+    else:
+        return bytes([item])
diff --git a/tests/beemgraphene/test_py23.py b/tests/beemgraphene/test_py23.py
index e07392ed..bfd195b6 100644
--- a/tests/beemgraphene/test_py23.py
+++ b/tests/beemgraphene/test_py23.py
@@ -7,6 +7,7 @@ import pytest
 import unittest
 from beemgraphenebase.py23 import (
     py23_bytes,
+    py23_chr,
     bytes_types,
     integer_types,
     string_types,
@@ -105,10 +106,14 @@ class Testcases(unittest.TestCase):
     def test_string_types(self):
         a = 'abc'
         b = u'abc'
-        c = b'abc'
         self.assertTrue(isinstance(a, string_types))
         self.assertTrue(isinstance(b, string_types))
-        self.assertTrue(isinstance(c, string_types))
+
+    def test_chr(self):
+        BASE58_ALPHABET = b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
+        self.assertEqual(BASE58_ALPHABET.find(py23_chr(4)), -1)
+        self.assertEqual(BASE58_ALPHABET.find(b"Z"), 32)
+        self.assertEqual(BASE58_ALPHABET.find(py23_bytes("Z", "ascii")), 32)
 
 
 if __name__ == '__main__':
-- 
GitLab