Skip to content

Commit 7f72b21

Browse files
author
Kotsias, Panagiotis-Christos
committed
Added unittests
1 parent 2a2f271 commit 7f72b21

File tree

3 files changed

+150
-0
lines changed

3 files changed

+150
-0
lines changed

run_tests.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/bash
2+
clear
3+
coverage run -m unittest discover && coverage report -m

test/configs/stable.json

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"get_eth_balance": {
3+
"module": "accounts",
4+
"kwargs": {
5+
"wallet": "0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a"
6+
}
7+
},
8+
"get_eth_balance_multiple": {
9+
"module": "accounts",
10+
"kwargs": {
11+
"wallets": [
12+
"0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
13+
"0x63a9975ba31b0b9626b34300f7f627147df1f526",
14+
"0x198ef1ec325a96cc354c7266a038be8b5c558f67"
15+
]
16+
}
17+
},
18+
"get_hist_eth_balance_by_block": {
19+
"module": "accounts",
20+
"kwargs": {
21+
"wallet": "0xde0b295669a9fd93d5f28d9ec85e40f4cb697bae",
22+
"block": 8000000
23+
}
24+
},
25+
"get_normal_txs_by_address": {
26+
"module": "accounts",
27+
"kwargs": {
28+
"wallet": "0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
29+
"startblock": 0,
30+
"endblock": 99999999,
31+
"sort": "asc"
32+
}
33+
},
34+
"get_normal_txs_by_address_paginated": {
35+
"module": "accounts",
36+
"kwargs": {
37+
"wallet": "0xddbd2b932c763ba5b1b7ae3b362eac3e8d40121a",
38+
"startblock": 0,
39+
"endblock": 99999999,
40+
"page": 1,
41+
"offset": 10,
42+
"sort": "asc"
43+
}
44+
},
45+
"get_internal_txs_by_address": {
46+
"module": "accounts",
47+
"kwargs": {
48+
"wallet": "0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3",
49+
"startblock": 0,
50+
"endblock": 2702578,
51+
"sort": "asc"
52+
}
53+
},
54+
"get_internal_txs_by_address_paginated": {
55+
"module": "accounts",
56+
"kwargs": {
57+
"wallet": "0x2c1ba59d6f58433fb1eaee7d20b26ed83bda51a3",
58+
"startblock": 0,
59+
"endblock": 2702578,
60+
"page": 1,
61+
"offset": 10,
62+
"sort": "asc"
63+
}
64+
},
65+
"get_internal_txs_by_txhash": {
66+
"module": "accounts",
67+
"kwargs": {
68+
"txhash": "0x40eb908387324f2b575b4879cd9d7188f69c8fc9d87c901b9e2daaea4b442170"
69+
}
70+
},
71+
"get_internal_txs_by_block_range_paginated": {
72+
"module": "accounts",
73+
"kwargs": {
74+
"startblock": 0,
75+
"endblock": 2702578,
76+
"page": 1,
77+
"offset": 10,
78+
"sort": "asc"
79+
}
80+
},
81+
"get_erc20_token_transfer_events_by_address": {
82+
"module": "accounts",
83+
"kwargs": {
84+
"wallet": "0x4e83362442b8d1bec281594cea3050c8eb01311c",
85+
"startblock": 0,
86+
"endblock": 999999999,
87+
"sort": "asc"
88+
}
89+
},
90+
"get_erc721_token_transfer_events_by_address": {
91+
"module": "accounts",
92+
"kwargs": {
93+
"wallet": "0x6975be450864c02b4613023c2152ee0743572325",
94+
"startblock": 0,
95+
"endblock": 999999999,
96+
"sort": "asc"
97+
}
98+
},
99+
"get_mined_blocks_by_address": {
100+
"module": "accounts",
101+
"kwargs": {
102+
"wallet": "0x9dd134d14d1e65f84b706d6f205cd5b1cd03a46b"
103+
}
104+
}
105+
}

test/test_client.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
from unittest import TestCase
2+
import json
3+
4+
from etherscan.client import Client
5+
6+
_CONFIG_PATH = "test/configs/stable.json"
7+
_API_KEY = "3PTZ5UHY7I9GGD74FJY6SXYS6JSVY295E5"
8+
9+
10+
def load(fname):
11+
with open(fname, "r") as f:
12+
return json.load(f)
13+
14+
15+
class TestModule(TestCase):
16+
_MODULE = ""
17+
18+
def test_methods(self):
19+
print(f"\nMODULE: {self._MODULE}")
20+
config = load(_CONFIG_PATH)
21+
client = Client.from_config(_CONFIG_PATH, _API_KEY)
22+
for fun, v in config.items():
23+
if not fun.startswith("_"):
24+
if v["module"] == self._MODULE:
25+
res, status, msg = getattr(client, fun)(**v["kwargs"])
26+
print(f"METHOD: {fun}, STATUS: {status}")
27+
28+
29+
class TestAccounts(TestModule):
30+
_MODULE = "accounts"
31+
32+
33+
class TestContracts(TestModule):
34+
_MODULE = "contracts"
35+
36+
37+
class TestTokens(TestModule):
38+
_MODULE = "tokens"
39+
40+
41+
class TestTransactions(TestModule):
42+
_MODULE = "transactions"

0 commit comments

Comments
 (0)