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 5db2cdf

Browse files
Blocks module test and example files.
1 parent f488fe1 commit 5db2cdf

File tree

4 files changed

+214
-2
lines changed

4 files changed

+214
-2
lines changed
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 2,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"%load_ext autoreload\n",
10+
"%autoreload 2\n",
11+
"import etherscan.blocks as blocks\n",
12+
"import json"
13+
]
14+
},
15+
{
16+
"cell_type": "markdown",
17+
"metadata": {},
18+
"source": [
19+
"## Import our api_key"
20+
]
21+
},
22+
{
23+
"cell_type": "markdown",
24+
"metadata": {},
25+
"source": [
26+
"The JSON keyfile being read in has only one line in the format:\n",
27+
" \n",
28+
" {\"key\" : \"YourApiKey\" }"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"execution_count": 4,
34+
"metadata": {},
35+
"outputs": [],
36+
"source": [
37+
"with open('../../api_key.json', mode='r') as key_file:\n",
38+
" key = json.loads(key_file.read())['key']"
39+
]
40+
},
41+
{
42+
"cell_type": "markdown",
43+
"metadata": {},
44+
"source": [
45+
"## Set up API"
46+
]
47+
},
48+
{
49+
"cell_type": "code",
50+
"execution_count": 5,
51+
"metadata": {},
52+
"outputs": [],
53+
"source": [
54+
"block = 2165403\n",
55+
"api = blocks.Blocks(api_key=key)"
56+
]
57+
},
58+
{
59+
"cell_type": "markdown",
60+
"metadata": {},
61+
"source": [
62+
"## Get the block reward"
63+
]
64+
},
65+
{
66+
"cell_type": "code",
67+
"execution_count": 7,
68+
"metadata": {
69+
"scrolled": false
70+
},
71+
"outputs": [],
72+
"source": [
73+
"reward = api.get_block_reward(block)"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": 9,
79+
"metadata": {},
80+
"outputs": [
81+
{
82+
"data": {
83+
"text/plain": [
84+
"{'blockNumber': '2165403',\n",
85+
" 'timeStamp': '1472533979',\n",
86+
" 'blockMiner': '0x13a06d3dfe21e0db5c016c03ea7d2509f7f8d1e3',\n",
87+
" 'blockReward': '5314181600000000000',\n",
88+
" 'uncles': [{'miner': '0xbcdfc35b86bedf72f0cda046a3c16829a2ef41d1',\n",
89+
" 'unclePosition': '0',\n",
90+
" 'blockreward': '3750000000000000000'},\n",
91+
" {'miner': '0x0d0c9855c722ff0c78f21e43aa275a5b8ea60dce',\n",
92+
" 'unclePosition': '1',\n",
93+
" 'blockreward': '3750000000000000000'}],\n",
94+
" 'uncleInclusionReward': '312500000000000000'}"
95+
]
96+
},
97+
"execution_count": 9,
98+
"metadata": {},
99+
"output_type": "execute_result"
100+
}
101+
],
102+
"source": [
103+
"reward"
104+
]
105+
},
106+
{
107+
"cell_type": "code",
108+
"execution_count": 10,
109+
"metadata": {},
110+
"outputs": [
111+
{
112+
"data": {
113+
"text/plain": [
114+
"'5314181600000000000'"
115+
]
116+
},
117+
"execution_count": 10,
118+
"metadata": {},
119+
"output_type": "execute_result"
120+
}
121+
],
122+
"source": [
123+
"reward['blockReward']"
124+
]
125+
},
126+
{
127+
"cell_type": "code",
128+
"execution_count": 11,
129+
"metadata": {},
130+
"outputs": [
131+
{
132+
"data": {
133+
"text/plain": [
134+
"'312500000000000000'"
135+
]
136+
},
137+
"execution_count": 11,
138+
"metadata": {},
139+
"output_type": "execute_result"
140+
}
141+
],
142+
"source": [
143+
"reward['uncleInclusionReward']"
144+
]
145+
},
146+
{
147+
"cell_type": "code",
148+
"execution_count": null,
149+
"metadata": {},
150+
"outputs": [],
151+
"source": []
152+
}
153+
],
154+
"metadata": {
155+
"kernelspec": {
156+
"display_name": "Python 3",
157+
"language": "python",
158+
"name": "python3"
159+
},
160+
"language_info": {
161+
"codemirror_mode": {
162+
"name": "ipython",
163+
"version": 3
164+
},
165+
"file_extension": ".py",
166+
"mimetype": "text/x-python",
167+
"name": "python",
168+
"nbconvert_exporter": "python",
169+
"pygments_lexer": "ipython3",
170+
"version": "3.7.0"
171+
},
172+
"latex_envs": {
173+
"bibliofile": "biblio.bib",
174+
"cite_by": "apalike",
175+
"current_citInitial": 1,
176+
"eqLabelWithNumbers": true,
177+
"eqNumInitial": 0
178+
},
179+
"toc": {
180+
"nav_menu": {
181+
"height": "121px",
182+
"width": "252px"
183+
},
184+
"navigate_menu": true,
185+
"number_sections": true,
186+
"sideBar": true,
187+
"threshold": 4,
188+
"toc_cell": false,
189+
"toc_section_display": "block",
190+
"toc_window_display": false
191+
}
192+
},
193+
"nbformat": 4,
194+
"nbformat_minor": 2
195+
}

‎examples/blocks/get_block_reward.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
key = json.loads(key_file.read())['key']
66

77
api = Blocks(api_key=key)
8-
reward = api.get_block_reward(5747732)
8+
reward = api.get_block_reward(2165403)
99
print(reward)

‎tests/test_blocks.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import unittest
2+
3+
from etherscan.blocks import Blocks
4+
5+
BLOCK = 2165403
6+
BLOCK_REWARD = '5314181600000000000'
7+
UNCLE_INCLUSION_REWARD = '312500000000000000'
8+
API_KEY = 'YourAPIkey'
9+
10+
11+
class BlocksTestCase(unittest.TestCase):
12+
13+
def test_get_block_reward(self):
14+
api = Blocks(api_key=(API_KEY))
15+
reward_object = api.get_block_reward(BLOCK)
16+
self.assertEqual(reward_object['blockReward'], BLOCK_REWARD)
17+
self.assertEqual(reward_object['uncleInclusionReward'], UNCLE_INCLUSION_REWARD)

‎tests/test_token.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
API_KEY = 'YourAPIkey'
1010

1111

12-
class ProxiesTestCase(unittest.TestCase):
12+
class TokensTestCase(unittest.TestCase):
1313

1414
def test_get_token_supply(self):
1515
api = Tokens(contract_address=CONTRACT_ADDRESS, api_key=(API_KEY))

0 commit comments

Comments
(0)

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