Add leveldb tests

pull/906/head
Nikhil Parasaram 6 years ago
parent df3861486f
commit 2bd2f9aafd
  1. 12
      mythril/mythril/mythril_leveldb.py
  2. 0
      tests/leveldb_dir/geth/LOCK
  3. BIN
      tests/leveldb_dir/geth/chaindata/000097.ldb
  4. BIN
      tests/leveldb_dir/geth/chaindata/000098.ldb
  5. BIN
      tests/leveldb_dir/geth/chaindata/000109.ldb
  6. BIN
      tests/leveldb_dir/geth/chaindata/000110.ldb
  7. BIN
      tests/leveldb_dir/geth/chaindata/000111.ldb
  8. BIN
      tests/leveldb_dir/geth/chaindata/000112.ldb
  9. BIN
      tests/leveldb_dir/geth/chaindata/000113.ldb
  10. BIN
      tests/leveldb_dir/geth/chaindata/000126.ldb
  11. BIN
      tests/leveldb_dir/geth/chaindata/000127.ldb
  12. BIN
      tests/leveldb_dir/geth/chaindata/000128.ldb
  13. BIN
      tests/leveldb_dir/geth/chaindata/000147.ldb
  14. BIN
      tests/leveldb_dir/geth/chaindata/000148.ldb
  15. BIN
      tests/leveldb_dir/geth/chaindata/000149.ldb
  16. BIN
      tests/leveldb_dir/geth/chaindata/000150.ldb
  17. BIN
      tests/leveldb_dir/geth/chaindata/000151.ldb
  18. BIN
      tests/leveldb_dir/geth/chaindata/000152.ldb
  19. BIN
      tests/leveldb_dir/geth/chaindata/000157.ldb
  20. BIN
      tests/leveldb_dir/geth/chaindata/000158.ldb
  21. BIN
      tests/leveldb_dir/geth/chaindata/000159.ldb
  22. BIN
      tests/leveldb_dir/geth/chaindata/000625.ldb
  23. BIN
      tests/leveldb_dir/geth/chaindata/000626.ldb
  24. BIN
      tests/leveldb_dir/geth/chaindata/000627.ldb
  25. BIN
      tests/leveldb_dir/geth/chaindata/000628.ldb
  26. BIN
      tests/leveldb_dir/geth/chaindata/000634.ldb
  27. 0
      tests/leveldb_dir/geth/chaindata/000655.log
  28. BIN
      tests/leveldb_dir/geth/chaindata/000656.ldb
  29. BIN
      tests/leveldb_dir/geth/chaindata/000657.ldb
  30. BIN
      tests/leveldb_dir/geth/chaindata/000658.ldb
  31. BIN
      tests/leveldb_dir/geth/chaindata/000659.ldb
  32. BIN
      tests/leveldb_dir/geth/chaindata/000660.ldb
  33. BIN
      tests/leveldb_dir/geth/chaindata/000661.ldb
  34. BIN
      tests/leveldb_dir/geth/chaindata/000662.ldb
  35. 1
      tests/leveldb_dir/geth/chaindata/CURRENT
  36. 0
      tests/leveldb_dir/geth/chaindata/LOCK
  37. 17
      tests/leveldb_dir/geth/chaindata/LOG
  38. 11
      tests/leveldb_dir/geth/chaindata/LOG.old
  39. BIN
      tests/leveldb_dir/geth/chaindata/MANIFEST-000654
  40. 1
      tests/leveldb_dir/geth/nodekey
  41. BIN
      tests/leveldb_dir/geth/nodes/000026.log
  42. BIN
      tests/leveldb_dir/geth/nodes/000028.ldb
  43. 1
      tests/leveldb_dir/geth/nodes/CURRENT
  44. 0
      tests/leveldb_dir/geth/nodes/LOCK
  45. 128
      tests/leveldb_dir/geth/nodes/LOG
  46. BIN
      tests/leveldb_dir/geth/nodes/MANIFEST-000027
  47. 0
      tests/leveldb_dir/geth/transactions.rlp
  48. 4
      tests/leveldb_dir/history
  49. 37
      tests/mythril/mythril_leveldb_test.py

@ -15,7 +15,7 @@ class MythrilLevelDB:
:param leveldb: Leveldb path
"""
self.level_db = leveldb
self.leveldb = leveldb
def search_db(self, search):
"""
@ -33,17 +33,17 @@ class MythrilLevelDB:
print("Address: " + address + ", balance: " + str(balance))
try:
self.level_db.search(search, search_callback)
self.leveldb.search(search, search_callback)
except SyntaxError:
raise CriticalError("Syntax error in search expression.")
def contract_hash_to_address(self, hash):
def contract_hash_to_address(self, contract_hash):
"""
Returns address of the corresponding hash by searching the leveldb
:param hash: Hash to be searched
:param contract_hash: Hash to be searched
"""
if not re.match(r"0x[a-fA-F0-9]{64}", hash):
if not re.match(r"0x[a-fA-F0-9]{64}", contract_hash):
raise CriticalError("Invalid address hash. Expected format is '0x...'.")
print(self.level_db.contract_hash_to_address(hash))
print(self.leveldb.contract_hash_to_address(contract_hash))

@ -0,0 +1,17 @@
2019/02/07-18:07:34.962750 7ff1404c2740 Recovering log #653
2019/02/07-18:07:35.053949 7ff1404c2740 Delete type=2 #655
2019/02/07-18:07:35.055109 7ff1404c2740 Delete type=2 #659
2019/02/07-18:07:35.056193 7ff1404c2740 Delete type=3 #652
2019/02/07-18:07:35.056285 7ff1404c2740 Delete type=2 #657
2019/02/07-18:07:35.057351 7ff1404c2740 Delete type=2 #656
2019/02/07-18:07:35.058359 7ff1404c2740 Delete type=2 #658
2019/02/07-18:07:35.059656 7ff1404c2740 Delete type=2 #654
2019/02/07-18:07:35.060963 7ff1404c2740 Delete type=0 #653
2019/02/07-18:10:59.173100 7ff1327b9700 Compacting 1@1 + 7@2 files
2019/02/07-18:10:59.314520 7ff1327b9700 Generated table #656@1: 81883 keys, 2123472 bytes
2019/02/07-18:10:59.438928 7ff1327b9700 Generated table #657@1: 45465 keys, 2114646 bytes
2019/02/07-18:10:59.673460 7ff1327b9700 Generated table #658@1: 45437 keys, 2115685 bytes
2019/02/07-18:10:59.785100 7ff1327b9700 Generated table #659@1: 48074 keys, 2122150 bytes
2019/02/07-18:10:59.930253 7ff1327b9700 Generated table #660@1: 50323 keys, 2131426 bytes
2019/02/07-18:11:00.066163 7ff1327b9700 Generated table #661@1: 48817 keys, 2130856 bytes
2019/02/07-18:11:00.084794 7ff1327b9700 compacted to: files[ 0 4 20 0 0 0 0 ]

@ -0,0 +1,11 @@
2019/02/07-18:03:01.949759 7fda91fee740 Recovering log #651
2019/02/07-18:03:02.013668 7fda91fee740 Delete type=0 #651
2019/02/07-18:03:02.013768 7fda91fee740 Delete type=3 #650
2019/02/07-18:06:09.042466 7fda77fff700 Compacting 1@1 + 7@2 files
2019/02/07-18:06:09.170379 7fda77fff700 Generated table #654@1: 81883 keys, 2123472 bytes
2019/02/07-18:06:09.327300 7fda77fff700 Generated table #655@1: 45465 keys, 2114646 bytes
2019/02/07-18:06:09.459949 7fda77fff700 Generated table #656@1: 45437 keys, 2115685 bytes
2019/02/07-18:06:09.594981 7fda77fff700 Generated table #657@1: 48074 keys, 2122150 bytes
2019/02/07-18:06:09.763079 7fda77fff700 Generated table #658@1: 50323 keys, 2131426 bytes
2019/02/07-18:06:09.919488 7fda77fff700 Generated table #659@1: 48817 keys, 2130856 bytes
2019/02/07-18:06:09.919604 7fda77fff700 compacted to: files[ 0 4 20 0 0 0 0 ]

@ -0,0 +1 @@
2bdd7b2dc7ecfe3050a1b93ab7af6617093da4af0e88dfa3cb8fe3eea7bb7662

@ -0,0 +1,128 @@
=============== Aug 2, 2018 (IST) ===============
15:14:32.205811 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
15:14:32.266053 db@open opening
15:14:32.266317 version@stat F·[] S·0B[] Sc·[]
15:14:32.299779 db@janitor F·2 G·0
15:14:32.299794 db@open done T·33.705668ms
15:14:44.873709 db@close closing
15:14:44.873731 db@close done T·20.408µs
=============== Aug 2, 2018 (IST) ===============
15:14:53.347217 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
15:14:53.347317 version@stat F·[] S·0B[] Sc·[]
15:14:53.347323 db@open opening
15:14:53.347350 journal@recovery F·1
15:14:53.348799 journal@recovery recovering @1
15:14:53.384904 memdb@flush created L0@2 N·150 S·7KiB "n:\x00..ail,v103":"version,v1"
15:14:53.386135 version@stat F·[1] S·7KiB[7KiB] Sc·[0.25]
15:14:53.442461 db@janitor F·3 G·0
15:14:53.442480 db@open done T·95.152372ms
15:16:33.049092 db@close closing
15:16:33.049141 db@close done T·48.525µs
=============== Aug 2, 2018 (IST) ===============
15:16:50.167061 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
15:16:50.167209 version@stat F·[1] S·7KiB[7KiB] Sc·[0.25]
15:16:50.167219 db@open opening
15:16:50.167256 journal@recovery F·1
15:16:50.168671 journal@recovery recovering @3
15:16:50.209364 memdb@flush created L0@5 N·644 S·30KiB "n:\x01..ail,v280":"n:\xfd..ail,v224"
15:16:50.210844 version@stat F·[2] S·38KiB[38KiB] Sc·[0.50]
15:16:50.277183 db@janitor F·4 G·0
15:16:50.277199 db@open done T·109.97423ms
15:16:50.278963 table@compaction L0·2 -> L1·0 S·38KiB Q·796
15:16:50.323429 table@build created L1@8 N·578 S·33KiB "n:\x00..ail,v103":"version,v1"
15:16:50.323521 version@stat F·[0 1] S·33KiB[0B 33KiB] Sc·[0.00 0.00]
15:16:50.345986 table@compaction committed F-1 S-5KiB Ke·0 D·216 T·66.977974ms
15:16:50.346067 table@remove removed @5
15:16:50.346099 table@remove removed @2
15:18:08.296045 db@close closing
15:18:08.296076 db@close done T·29.725µs
=============== Aug 2, 2018 (IST) ===============
15:18:45.392079 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
15:18:45.392213 version@stat F·[0 1] S·33KiB[0B 33KiB] Sc·[0.00 0.00]
15:18:45.392221 db@open opening
15:18:45.392254 journal@recovery F·1
15:18:45.393510 journal@recovery recovering @6
15:18:45.436279 memdb@flush created L0@9 N·459 S·23KiB "n:\x00..ing,v1082":"n:\xfe..ail,v964"
15:18:45.437589 version@stat F·[1 1] S·56KiB[23KiB 33KiB] Sc·[0.25 0.00]
15:18:45.481661 db@janitor F·4 G·0
15:18:45.481678 db@open done T·89.452709ms
15:18:45.483981 table@compaction L0·1 -> L1·1 S·56KiB Q·1256
15:18:45.526716 table@build created L1@12 N·885 S·50KiB "n:\x00..ing,v1082":"version,v1"
15:18:45.526822 version@stat F·[0 1] S·50KiB[0B 50KiB] Sc·[0.00 0.00]
15:18:45.549234 table@compaction committed F-1 S-6KiB Ke·0 D·152 T·65.209259ms
15:18:45.549299 table@remove removed @9
15:18:45.549338 table@remove removed @8
15:19:55.069446 db@close closing
15:19:55.069475 db@close done T·28.254µs
=============== Aug 2, 2018 (IST) ===============
15:20:04.087151 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
15:20:04.087664 version@stat F·[0 1] S·50KiB[0B 50KiB] Sc·[0.00 0.00]
15:20:04.087701 db@open opening
15:20:04.087835 journal@recovery F·1
15:20:04.092741 journal@recovery recovering @10
15:20:04.134293 memdb@flush created L0@13 N·439 S·21KiB "n:\x02..ail,v1549":"n:\xfa..ail,v1287"
15:20:04.139718 version@stat F·[1 1] S·72KiB[21KiB 50KiB] Sc·[0.25 0.00]
15:20:04.203301 db@janitor F·4 G·0
15:20:04.203362 db@open done T·115.642485ms
15:20:04.212745 table@compaction L0·1 -> L1·1 S·72KiB Q·1696
15:20:04.258940 table@build created L1@16 N·1186 S·67KiB "n:\x00..ing,v1082":"version,v1"
15:20:04.259021 version@stat F·[0 1] S·67KiB[0B 67KiB] Sc·[0.00 0.00]
15:20:04.281654 table@compaction committed F-1 S-4KiB Ke·0 D·138 T·68.817623ms
15:20:04.281730 table@remove removed @13
15:20:04.281779 table@remove removed @12
15:21:42.450234 db@close closing
15:21:42.450322 db@close done T·84.577µs
=============== Aug 2, 2018 (IST) ===============
15:21:52.563151 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
15:21:52.563627 version@stat F·[0 1] S·67KiB[0B 67KiB] Sc·[0.00 0.00]
15:21:52.563662 db@open opening
15:21:52.563795 journal@recovery F·1
15:21:52.568789 journal@recovery recovering @14
15:21:52.611840 memdb@flush created L0@17 N·600 S·28KiB "n:\x02..ing,v1795":"n:\xfd..ong,v1860"
15:21:52.617139 version@stat F·[1 1] S·95KiB[28KiB 67KiB] Sc·[0.25 0.00]
15:21:52.656312 db@janitor F·4 G·0
15:21:52.656419 db@open done T·92.739296ms
15:21:52.668548 table@compaction L0·1 -> L1·1 S·95KiB Q·2297
15:21:52.723247 table@build created L1@20 N·1555 S·86KiB "n:\x00..ing,v1082":"version,v1"
15:21:52.723301 version@stat F·[0 1] S·86KiB[0B 86KiB] Sc·[0.00 0.00]
15:21:52.745714 table@compaction committed F-1 S-8KiB Ke·0 D·231 T·77.093781ms
15:21:52.745797 table@remove removed @17
15:21:52.745848 table@remove removed @16
15:22:52.173124 db@close closing
15:22:52.173174 db@close done T·49.001µs
=============== Aug 2, 2018 (IST) ===============
15:23:02.333013 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
15:23:02.333607 version@stat F·[0 1] S·86KiB[0B 86KiB] Sc·[0.00 0.00]
15:23:02.333645 db@open opening
15:23:02.333820 journal@recovery F·1
15:23:02.339127 journal@recovery recovering @18
15:23:02.402190 memdb@flush created L0@21 N·409 S·22KiB "n:\x01..ing,v2522":"n:\xfd..ail,v2614"
15:23:02.408191 version@stat F·[1 1] S·108KiB[22KiB 86KiB] Sc·[0.25 0.00]
15:23:02.447827 db@janitor F·4 G·0
15:23:02.447888 db@open done T·114.220635ms
15:23:02.458568 table@compaction L0·1 -> L1·1 S·108KiB Q·2707
15:23:02.502706 table@build created L1@24 N·1868 S·102KiB "n:\x00..ing,v1082":"version,v1"
15:23:02.502799 version@stat F·[0 1] S·102KiB[0B 102KiB] Sc·[0.00 0.00]
15:23:02.547275 table@compaction committed F-1 S-5KiB Ke·0 D·96 T·88.620636ms
15:23:02.547348 table@remove removed @21
15:23:02.547395 table@remove removed @20
15:24:21.688122 db@close closing
15:24:21.688185 db@close done T·60.473µs
=============== Feb 7, 2019 (IST) ===============
16:09:20.869498 log@legend F·NumFile S·FileSize N·Entry C·BadEntry B·BadBlock Ke·KeyError D·DroppedEntry L·Level Q·SeqNum T·TimeElapsed
16:09:20.903227 version@stat F·[0 1] S·102KiB[0B 102KiB] Sc·[0.00 0.00]
16:09:20.903245 db@open opening
16:09:20.903309 journal@recovery F·1
16:09:20.905020 journal@recovery recovering @22
16:09:20.942643 memdb@flush created L0@25 N·551 S·27KiB "n:\x01..ail,v3020":"n:\xff..ail,v3021"
16:09:20.944518 version@stat F·[1 1] S·130KiB[27KiB 102KiB] Sc·[0.25 0.00]
16:09:20.983348 db@janitor F·4 G·0
16:09:20.983420 db@open done T·80.161941ms
16:09:21.011768 table@compaction L0·1 -> L1·1 S·130KiB Q·3259
16:09:21.030323 table@build created L1@28 N·2212 S·123KiB "n:\x00..ing,v1082":"version,v1"
16:09:21.030372 version@stat F·[0 1] S·123KiB[0B 123KiB] Sc·[0.00 0.00]
16:09:21.036431 table@compaction committed F-1 S-7KiB Ke·0 D·207 T·24.625754ms
16:09:21.036508 table@remove removed @25
16:09:21.036572 table@remove removed @24
16:09:23.786865 db@close closing
16:09:23.786997 db@close done T·149.485µs

@ -0,0 +1,4 @@
eth.sync
eth
eth.syncing

@ -0,0 +1,37 @@
import io
import pytest
from contextlib import redirect_stdout
from pathlib import Path
from mythril.mythril import MythrilLevelDB, MythrilConfig
from mythril.exceptions import CriticalError
config = MythrilConfig()
config.set_api_leveldb(str(Path(__file__).parent / "../leveldb_dir/geth/chaindata"))
def test_leveldb_code_search():
leveldb_search = MythrilLevelDB(leveldb=config.eth_db)
f = io.StringIO()
with redirect_stdout(f):
leveldb_search.search_db("code#PUSH#")
out = f.getvalue()
assert len(out.split("\n")) == 67
assert "0xddbb615cb2ffaff7233d8a6f3601621de94795e1" in out
def test_leveldb_hash_search_incorrect_input():
leveldb_search = MythrilLevelDB(leveldb=config.eth_db)
with pytest.raises(CriticalError):
leveldb_search.contract_hash_to_address("0x23")
def test_leveldb_hash_search_correct_input():
leveldb_search = MythrilLevelDB(leveldb=config.eth_db)
f = io.StringIO()
with redirect_stdout(f):
leveldb_search.contract_hash_to_address(
"0x0464e651bcc40de28fc7fcde269218d16850bac9689da5f4a6bd640fd3cdf6aa"
)
out = f.getvalue()
assert out == "0xddbb615cb2ffaff7233d8a6f3601621de94795e1\n"
Loading…
Cancel
Save