Repository: mikeshultz/ledger-eth-lib (language: python)

Issue:
Issue with comms.py
When I want to retrieve the accounts from the ledger (v0.7.1), I have this error : 
```bash
File "../lib/python3.8/site-packages/ledgereth/comms.py", line 168, in init_dongle
    if not is_usable_version(DONGLE_CONFIG_CACHE):
NameError: name 'DONGLE_CONFIG_CACHE' is not defined
```
The workaround that I found is the initialisation of the global variables 

```python
DONGLE_CACHE: Dongle = None
DONGLE_CONFIG_CACHE: bytes = None
```
Let me know if I can give you more information in order to help you


Discussion / hints:
Thanks for the report.  Looking into it.

Fix patch:
diff --git a/ledgereth/_meta.py b/ledgereth/_meta.py
index cad57f6..510f3c6 100644
--- a/ledgereth/_meta.py
+++ b/ledgereth/_meta.py
@@ -1,3 +1,3 @@
 author = "Mike Shultz"
 email = "mike@mikeshultz.com"
-version = "0.7.1"
+version = "0.7.2"
diff --git a/ledgereth/comms.py b/ledgereth/comms.py
index e32fb9f..5b5348b 100644
--- a/ledgereth/comms.py
+++ b/ledgereth/comms.py
@@ -1,3 +1,5 @@
+from typing import Optional
+
 from eth_utils import add_0x_prefix
 from ledgerblue.comm import getDongle
 from ledgerblue.commException import CommException
@@ -7,8 +9,8 @@
 from ledgereth.exceptions import LedgerError
 from ledgereth.objects import ISO7816Command
 
-DONGLE_CACHE: Dongle
-DONGLE_CONFIG_CACHE: bytes
+DONGLE_CACHE: Optional[Dongle] = None
+DONGLE_CONFIG_CACHE: Optional[bytes] = None
 
 
 class LedgerCommands:
diff --git a/setup.cfg b/setup.cfg
index b0e7b25..d4258f4 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,5 +1,5 @@
 [bumpversion]
-current_version = 0.7.1
+current_version = 0.7.2
 commit = True
 tag = True
 


Test patch:
diff --git a/tests/test_comms.py b/tests/test_comms.py
index 9184790..f485708 100644
--- a/tests/test_comms.py
+++ b/tests/test_comms.py
@@ -20,6 +20,7 @@
     decode_response_version_from_config,
     dongle_send,
     dongle_send_data,
+    init_dongle,
 )
 from ledgereth.constants import (
     DATA_CHUNK_SIZE,
@@ -52,6 +53,26 @@ def test_chunks(data_size):
     assert b"".join(parts) == data
 
 
+def test_comms_init_dongle_patched(monkeypatch, yield_dongle):
+    with yield_dongle() as dongle:
+
+        def _getDongle(debug=False):
+            return dongle
+
+        monkeypatch.setattr("ledgereth.comms.getDongle", _getDongle)
+
+        dong = init_dongle()
+        # In this case, it's the same instance we passed it
+        assert dong == dongle
+
+
+def test_comms_init_dongle_mockdongle(yield_dongle):
+    with yield_dongle() as dongle:
+        dong = init_dongle(dongle)
+        # In this case, it's the same instance we passed it
+        assert dong == dongle
+
+
 def test_comms_config(yield_dongle):
     with yield_dongle() as dongle:
         resp = dongle_send(dongle, GET_CONFIGURATION)