From be769901ed10ae5184221e3daa20a55a7ab7e9e8 Mon Sep 17 00:00:00 2001
From: Holger <holger@nahrstaedt.de>
Date: Sun, 14 Oct 2018 15:09:16 +0200
Subject: [PATCH] Fix Brainkey.suggest() for python 2.7

Unit test added for keygen and suggest()
---
 README.rst                         | 2 +-
 beemgraphenebase/account.py        | 5 ++++-
 tests/beem/test_cli.py             | 5 +++++
 tests/beemgraphene/test_account.py | 4 ++++
 4 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/README.rst b/README.rst
index 640d397b..05eb93b5 100644
--- a/README.rst
+++ b/README.rst
@@ -2,7 +2,7 @@ beem - Unofficial Python Library for Steem
 ===============================================
 
 beem is an unofficial python library for steem, which is created new from scratch from `python-bitshares`_
-The library name is derived from a beam maschine, similar to the analogy between steem and steam. beem includes `python-graphenelib`_.
+The library name is derived from a beam machine, similar to the analogy between steem and steam. beem includes `python-graphenelib`_.
 
 .. image:: https://img.shields.io/pypi/v/beem.svg
     :target: https://pypi.python.org/pypi/beem/
diff --git a/beemgraphenebase/account.py b/beemgraphenebase/account.py
index 3542acb6..c175ba86 100644
--- a/beemgraphenebase/account.py
+++ b/beemgraphenebase/account.py
@@ -132,7 +132,10 @@ class BrainKey(object):
         if not len(dict_lines) == 49744:
             raise AssertionError()
         for j in range(0, word_count):
-            num = int.from_bytes(os.urandom(2), byteorder="little")
+            urand = os.urandom(2)
+            if isinstance(urand, str):
+                urand = py23_bytes(urand, 'ascii')
+            num = int.from_bytes(urand, byteorder="little")
             rndMult = num / 2 ** 16  # returns float between 0..1 (inclusive)
             wIdx = round(len(dict_lines) * rndMult)
             brainkey[j] = dict_lines[wIdx]
diff --git a/tests/beem/test_cli.py b/tests/beem/test_cli.py
index 840b7965..44475e5a 100644
--- a/tests/beem/test_cli.py
+++ b/tests/beem/test_cli.py
@@ -145,6 +145,11 @@ class Testcases(unittest.TestCase):
         result = runner.invoke(cli, ['walletinfo'])
         self.assertEqual(result.exit_code, 0)
 
+    def test_keygen(self):
+        runner = CliRunner()
+        result = runner.invoke(cli, ['keygen'])
+        self.assertEqual(result.exit_code, 0)
+
     def test_set(self):
         runner = CliRunner()
         result = runner.invoke(cli, ['-o', 'set', 'set_default_vote_weight', '100'])
diff --git a/tests/beemgraphene/test_account.py b/tests/beemgraphene/test_account.py
index fbd387cb..ad5ccdf0 100644
--- a/tests/beemgraphene/test_account.py
+++ b/tests/beemgraphene/test_account.py
@@ -157,6 +157,10 @@ class Testcases(unittest.TestCase):
                           ],
                          [b, b, b, b, b, b, b])
 
+    def test_BrainKey_suggest(self):
+        b = BrainKey()
+        self.assertTrue(len(b.suggest()) > 0)
+
     def test_BrainKey_sequences(self):
         b = BrainKey("COLORER BICORN KASBEKE FAERIE LOCHIA GOMUTI SOVKHOZ Y GERMAL AUNTIE PERFUMY TIME FEATURE GANGAN CELEMIN MATZO")
         keys = ["5Hsbn6kXio4bb7eW5bX7kTp2sdkmbzP8kGWoau46Cf7en7T1RRE",
-- 
GitLab