This repository has been archived by the owner on Sep 1, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Infura now requires an API key, fixes #170
Introduces `python-dotenv` to load environment variables and inject API keys for both Etherscan and Infura. Also bumps Pillow version and pins hostpython3 to match python3 closes #166.
- Loading branch information
1 parent
54016df
commit ae984c4
Showing
10 changed files
with
37 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ETHERSCAN_API_KEY=E9K4A1AC8H1V3ZIR1DAIKZ6B961CRXF2DR | ||
WEB3_INFURA_PROJECT_ID=90d5bc91c74e4c6899001dc189da590f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import os | ||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(__file__)) | ||
BASE_DIR = os.path.abspath(os.path.dirname(os.path.dirname(__file__))) | ||
# default pyethapp keystore path | ||
KEYSTORE_DIR_SUFFIX = ".config/pyethapp/keystore/" | ||
API_KEY_PATH = os.path.join(BASE_DIR, 'api_key.json') | ||
ENV_PATH = os.path.join(BASE_DIR, 'env.env') | ||
NO_ACCOUNT_SELECTED_STRING = 'No account selected' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,18 @@ | ||
from unittest import mock | ||
from threading import Thread | ||
|
||
from etherollapp.etheroll.utils import get_etherscan_api_key | ||
from etherollapp.etheroll.utils import run_in_thread | ||
|
||
|
||
class TestUtils: | ||
def test_get_etherscan_api_key(self): | ||
""" | ||
Verifies the key can be retrieved from either: | ||
1) environment | ||
2) file | ||
3) or fallbacks on default key | ||
""" | ||
expected_key = "0102030405060708091011121314151617" | ||
# 1) environment | ||
with mock.patch.dict( | ||
"os.environ", {"ETHERSCAN_API_KEY": expected_key} | ||
): | ||
actual_key = get_etherscan_api_key() | ||
assert actual_key == expected_key | ||
# 2) file | ||
read_data = '{ "key" : "%s" }' % (expected_key) | ||
api_key_path = "api_key.json" | ||
with mock.patch( | ||
"builtins.open", mock.mock_open(read_data=read_data) | ||
) as m_open: | ||
actual_key = get_etherscan_api_key(api_key_path=api_key_path) | ||
assert expected_key == actual_key | ||
# verifies the file was read | ||
assert m_open.call_args_list == [mock.call(api_key_path, mode="r")] | ||
# 3) or fallbacks on default key | ||
with mock.patch("builtins.open") as m_open, mock.patch( | ||
"etherollapp.etheroll.utils.logger" | ||
) as m_logger: | ||
m_open.side_effect = FileNotFoundError | ||
actual_key = get_etherscan_api_key(api_key_path) | ||
assert "YourApiKeyToken" == actual_key | ||
# verifies the fallback warning was logged | ||
assert m_logger.warning.call_args_list == [ | ||
mock.call( | ||
"Cannot get Etherscan API key. " | ||
"File api_key.json not found, " | ||
"defaulting to YourApiKeyToken." | ||
) | ||
] | ||
|
||
def test_run_in_thread(fn): | ||
@run_in_thread | ||
def threaded_sleep(seconds): | ||
from time import sleep | ||
sleep(seconds) | ||
|
||
thread = threaded_sleep(0.1) | ||
assert isinstance(thread, Thread) | ||
assert thread.is_alive() is True | ||
thread.join() | ||
assert thread.is_alive() is False |