Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Devnet predeployed accounts #192

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix: linter and format
  • Loading branch information
ericnordelo committed Sep 20, 2022
commit 0230a98d9eefc50ade777aac37d39842b998c5c9
2 changes: 1 addition & 1 deletion src/nile/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def assert_event_emitted(tx_exec_info, from_address, name, data):


def normalize_number(number):
"""Normalize hex or int to int"""
"""Normalize hex or int to int."""
if type(number) == str and number.startswith("0x"):
return int(number, 16)
else:
Expand Down
1 change: 1 addition & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Tests module."""
25 changes: 16 additions & 9 deletions tests/commands/test_get_accounts.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
"""Tests for get-accounts command."""
import logging
from requests.exceptions import MissingSchema
from unittest.mock import MagicMock, patch

import pytest
from requests.exceptions import MissingSchema

from nile.core.account import Account
from nile.utils import normalize_number as normalize
from nile.utils.get_accounts import (
_check_and_return_account,
get_accounts,
Expand Down Expand Up @@ -35,13 +36,17 @@
"alias": ALIASES[1],
},
}

# hex to int
_i = lambda x: int(x, 16)

JSON_DATA = [
{"address": _i("0xaaa1"), "private_key": _i("0xbbb1"), "public_key": _i("0xbbb2")},
{"address": _i("0xaaa2"), "private_key": _i("0xbbb3"), "public_key": _i("0xbbb4")},
{
"address": normalize("0xaaa1"),
"private_key": normalize("0xbbb1"),
"public_key": normalize("0xbbb2"),
},
{
"address": normalize("0xaaa2"),
"private_key": normalize("0xbbb3"),
"public_key": normalize("0xbbb4"),
},
]


Expand Down Expand Up @@ -176,8 +181,10 @@ def test_get_predeployed_accounts(mock_response, mock_return_account, mock_gatew
@patch("nile.common.get_gateway", return_value=GATEWAYS)
@patch("nile.utils.get_accounts._check_and_return_account")
@patch("requests.get", return_value=MockResponse(JSON_DATA, 200))
def test_get_predeployed_accounts_logging(mock_response, mock_return_account, mock_gateways, caplog):
# make logs visible to test
def test_get_predeployed_accounts_logging(
mock_response, mock_return_account, mock_gateways, caplog
):
# make logs visible to test
logger = logging.getLogger()

logger.setLevel(logging.INFO)
Expand Down
6 changes: 5 additions & 1 deletion tests/mocks/mock_response.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
""""HTTP response object mock"""
"""HTTP response object mock."""


class MockResponse:
"""Mock class."""

def __init__(self, json_data, status_code):
"""Initialize instance."""
self.json_data = json_data
self.status_code = status_code

def json(self):
"""Return JSON data."""
return self.json_data