|
4 | 4 | from etherscan.proxies import Proxies |
5 | 5 |
|
6 | 6 | API_KEY = 'YourAPIkey' |
| 7 | +BLOCK_NUMBER = 2165403 |
| 8 | +BLOCK_DIFFICULTY = 67858873048710 |
| 9 | +UNCLE_INDEX = 0 |
| 10 | +UNCLE_DIFFICULTY = 67858872000134 |
| 11 | +TX_COUNT = 4 |
| 12 | +TX_HASH = "0xed57e2434ddab54526620cbb4dcdaa0c6965027e2cb8556ef4750ed1eafa48c2" |
| 13 | +TX_INDEX = 0 |
| 14 | +TX_ADDRESS = "0x2910543af39aba0cd09dbb2d50200b3e800a63d2" |
| 15 | +STORAGE_ADDRESS = "0x6e03d9cce9d60f3e9f2597e13cd4c54c55330cfd" |
| 16 | +STORAGE_POS = 0 |
| 17 | +STORAGE_CONTENTS = "0x0000000000000000000000003d0768d" \ |
| 18 | + "a09ce77d25e2d998e6a7b6ed4b9116c2d" |
| 19 | +CODE_ADDRESS = "0xf75e354c5edc8efed9b59ee9f67a80845ade7d0c" |
| 20 | +CODE_CONTENTS = "0x3660008037602060003660003473273930d21e01ee25e4c219b6" \ |
| 21 | + "3259d214872220a261235a5a03f21560015760206000f3" |
7 | 22 |
|
8 | 23 |
|
9 | 24 | class ProxiesTestCase(unittest.TestCase): |
10 | 25 |
|
11 | 26 | def test_get_most_recent_block(self): |
12 | 27 | api = Proxies(api_key=API_KEY) |
13 | | - # currently raises an exception even though it should not, see: |
14 | | - # https://github.com/corpetty/py-etherscan-api/issues/32 |
15 | 28 | most_recent = int(api.get_most_recent_block(), 16) |
16 | 29 | print(most_recent) |
17 | 30 | p = re.compile('^[0-9]{7}$') |
18 | 31 | self.assertTrue(p.match(str(most_recent))) |
| 32 | + |
| 33 | + def test_get_block_by_number(self): |
| 34 | + api = Proxies(api_key=API_KEY) |
| 35 | + block = api.get_block_by_number(BLOCK_NUMBER) |
| 36 | + print(block) |
| 37 | + self.assertEqual(block['difficulty'], hex(BLOCK_DIFFICULTY)) |
| 38 | + |
| 39 | + def test_get_uncle_by_blocknumber_index(self): |
| 40 | + api = Proxies(api_key=API_KEY) |
| 41 | + uncle = api.get_uncle_by_blocknumber_index(BLOCK_NUMBER, UNCLE_INDEX) |
| 42 | + print(uncle) |
| 43 | + self.assertEqual(uncle['difficulty'], hex(UNCLE_DIFFICULTY)) |
| 44 | + |
| 45 | + def test_get_block_transaction_count_by_number(self): |
| 46 | + api = Proxies(api_key=API_KEY) |
| 47 | + tx_count = api.get_block_transaction_count_by_number(BLOCK_NUMBER) |
| 48 | + print(tx_count) |
| 49 | + self.assertEqual(tx_count, hex(TX_COUNT)) |
| 50 | + |
| 51 | + def test_get_transaction_by_hash(self): |
| 52 | + api = Proxies(api_key=API_KEY) |
| 53 | + tx = api.get_transaction_by_hash(TX_HASH) |
| 54 | + print(tx) |
| 55 | + self.assertEqual(tx['blockNumber'], hex(BLOCK_NUMBER)) |
| 56 | + |
| 57 | + def test_get_transaction_by_blocknumber_index(self): |
| 58 | + api = Proxies(api_key=API_KEY) |
| 59 | + tx = api.get_transaction_by_blocknumber_index(BLOCK_NUMBER, |
| 60 | + TX_INDEX) |
| 61 | + print(tx) |
| 62 | + self.assertEqual(tx['hash'], TX_HASH) |
| 63 | + |
| 64 | + def test_get_transaction_count(self): |
| 65 | + api = Proxies(api_key=API_KEY) |
| 66 | + tx_count = int(api.get_transaction_count(TX_ADDRESS), 16) |
| 67 | + print(tx_count) |
| 68 | + p = re.compile('^[0-9]*$') |
| 69 | + self.assertTrue(p.match(str(tx_count))) |
| 70 | + |
| 71 | + def test_get_transaction_receipt(self): |
| 72 | + api = Proxies(api_key=API_KEY) |
| 73 | + tx_receipt = api.get_transaction_receipt(TX_HASH) |
| 74 | + print(tx_receipt) |
| 75 | + self.assertEqual(tx_receipt['blockNumber'], hex(BLOCK_NUMBER)) |
| 76 | + |
| 77 | + def test_get_code(self): |
| 78 | + api = Proxies(api_key=API_KEY) |
| 79 | + code_contents = api.get_code(CODE_ADDRESS) |
| 80 | + print(code_contents) |
| 81 | + self.assertEqual(code_contents, CODE_CONTENTS) |
| 82 | + |
| 83 | + def test_get_storage_at(self): |
| 84 | + api = Proxies(api_key=API_KEY) |
| 85 | + storage_contents = api.get_storage_at(STORAGE_ADDRESS, STORAGE_POS) |
| 86 | + print(storage_contents) |
| 87 | + self.assertEqual(storage_contents, STORAGE_CONTENTS) |
| 88 | + |
| 89 | + def test_gas_price(self): |
| 90 | + api = Proxies(api_key=API_KEY) |
| 91 | + price = int(api.gas_price(), 16) |
| 92 | + print(price) |
| 93 | + p = re.compile('^[0-9]*$') |
| 94 | + self.assertTrue(p.match(str(price))) |
0 commit comments