Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 663b54a

Browse files
Merge pull request #44 from AndreMiras/feature/fix_unit_tests
Fixes unit tests and linting
2 parents 18ee101 + 0344ed0 commit 663b54a

File tree

4 files changed

+26
-17
lines changed

4 files changed

+26
-17
lines changed

‎etherscan/accounts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
class Account(Client):
66
PAGE_NUM_PATTERN = re.compile(
7-
'[1-9](?:\d{0,2})(?:,\d{3})*(?:\.\d*[1-9])?|0?\.\d*[1-9]|0')
7+
r'[1-9](?:\d{0,2})(?:,\d{3})*(?:\.\d*[1-9])?|0?\.\d*[1-9]|0')
88

99
def __init__(self, address=Client.dao_address, api_key='YourApiKeyToken'):
1010
Client.__init__(self, address=address, api_key=api_key)

‎etherscan/client.ropsten.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ class BadRequest(ClientException):
3030
"""Invalid request passed"""
3131

3232

33-
# Assume user puts his API key in the api_key.json file under variable name "key"
33+
# API key must be in the api_key.json file under variable name "key"
3434
class Client(object):
3535
dao_address = '0xbb9bc244d798123fde783fcc1c72d3bb8c189413'
3636

3737
# Constants
38-
PREFIX = 'https://api-ropsten.etherscan.io/api?' # TESTNET
38+
PREFIX = 'https://api-ropsten.etherscan.io/api?' # TESTNET
3939
MODULE = 'module='
4040
ACTION = '&action='
4141
CONTRACT_ADDRESS = '&contractaddress='
@@ -101,7 +101,8 @@ def __init__(self, address, api_key=''):
101101
self.url_dict[self.ADDRESS] = address
102102

103103
def build_url(self):
104-
self.url = self.PREFIX + ''.join([param + val if val else '' for param, val in self.url_dict.items()])
104+
self.url = self.PREFIX + ''.join(
105+
[parm + val if val else '' for parm, val in self.url_dict.items()])
105106

106107
def connect(self):
107108
# TODO: deal with "unknown exception" error
@@ -119,14 +120,15 @@ def connect(self):
119120
return data
120121
else:
121122
raise EmptyResponse(data.get('message', 'no message'))
122-
raise BadRequest("Problem with connection, status code: %s" % req.status_code)
123+
raise BadRequest(
124+
f"Problem with connection, status code: {req.status_code}")
123125

124126
def check_and_get_api(self):
125127
if self.url_dict[self.API_KEY]: # Check if api_key is empty string
126128
pass
127129
else:
128-
self.url_dict[self.API_KEY] = input('Please type your EtherScan.io API key: ')
130+
self.url_dict[self.API_KEY] = input(
131+
'Please type your EtherScan.io API key: ')
129132

130133
def check_keys_api(self, data):
131-
return all (k in data for k in ('jsonrpc', 'id', 'result'))
132-
134+
return all(k in data for k in ('jsonrpc', 'id', 'result'))

‎etherscan/contracts.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@ def get_sourcecode(self):
1616
self.url_dict[self.ACTION] = 'getsourcecode'
1717
self.build_url()
1818
req = self.connect()
19-
return req['result']
19+
return req['result']

‎tests/test_accounts.py

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,25 @@
22

33
from etherscan.accounts import Account
44

5-
SINGLE_BALANCE = '40807168566070000000000'
5+
SINGLE_BALANCE = '40807178566070000000000'
66
SINGLE_ACCOUNT = '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a'
7-
MULTI_ACCOUNT = ['0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a',
8-
'0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a']
7+
MULTI_ACCOUNT = [
8+
'0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a',
9+
'0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a',
10+
]
911
MULTI_BALANCE = [
10-
{'account': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a',
11-
'balance': '40807168566070000000000'},
12-
{'account': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a',
13-
'balance': '40807168566070000000000'}
12+
{
13+
'account': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a',
14+
'balance': '40807178566070000000000'
15+
},
16+
{
17+
'account': '0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a',
18+
'balance': '40807178566070000000000',
19+
}
1420
]
1521
API_KEY = 'YourAPIkey'
1622

23+
1724
class AccountsTestCase(unittest.TestCase):
1825

1926
def test_get_balance(self):
@@ -22,4 +29,4 @@ def test_get_balance(self):
2229

2330
def test_get_balance_multi(self):
2431
api = Account(address=MULTI_ACCOUNT, api_key=API_KEY)
25-
self.assertEqual(api.get_balance_multiple(), MULTI_BALANCE)
32+
self.assertEqual(api.get_balance_multiple(), MULTI_BALANCE)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /