Add config tests

pull/906/head
Nikhil Parasaram 6 years ago
parent 7f9a3a6bb0
commit 93c1e85433
  1. 3
      .gitignore
  2. 34
      mythril/mythril/mythril_config.py
  3. BIN
      tests/leveldb_dir/geth/chaindata/000660.ldb
  4. BIN
      tests/leveldb_dir/geth/chaindata/000661.ldb
  5. BIN
      tests/leveldb_dir/geth/chaindata/000662.ldb
  6. 1
      tests/leveldb_dir/geth/chaindata/CURRENT
  7. 17
      tests/leveldb_dir/geth/chaindata/LOG
  8. 11
      tests/leveldb_dir/geth/chaindata/LOG.old
  9. BIN
      tests/mythril/__pycache__/mythril_analyzer_test.cpython-36-PYTEST.pyc
  10. BIN
      tests/mythril/__pycache__/mythril_config_test.cpython-36-PYTEST.pyc
  11. BIN
      tests/mythril/__pycache__/mythril_disassembler_test.cpython-36-PYTEST.pyc
  12. BIN
      tests/mythril/__pycache__/mythril_leveldb_test.cpython-36-PYTEST.pyc
  13. 57
      tests/mythril/mythril_config_test.py
  14. 4
      tests/mythril/mythril_leveldb_test.py
  15. 0
      tests/testdata/leveldb_dir/geth/LOCK
  16. 0
      tests/testdata/leveldb_dir/geth/chaindata/000097.ldb
  17. 0
      tests/testdata/leveldb_dir/geth/chaindata/000098.ldb
  18. 0
      tests/testdata/leveldb_dir/geth/chaindata/000109.ldb
  19. 0
      tests/testdata/leveldb_dir/geth/chaindata/000110.ldb
  20. 0
      tests/testdata/leveldb_dir/geth/chaindata/000111.ldb
  21. 0
      tests/testdata/leveldb_dir/geth/chaindata/000112.ldb
  22. 0
      tests/testdata/leveldb_dir/geth/chaindata/000113.ldb
  23. 0
      tests/testdata/leveldb_dir/geth/chaindata/000126.ldb
  24. 0
      tests/testdata/leveldb_dir/geth/chaindata/000127.ldb
  25. 0
      tests/testdata/leveldb_dir/geth/chaindata/000128.ldb
  26. 0
      tests/testdata/leveldb_dir/geth/chaindata/000147.ldb
  27. 0
      tests/testdata/leveldb_dir/geth/chaindata/000148.ldb
  28. 0
      tests/testdata/leveldb_dir/geth/chaindata/000149.ldb
  29. 0
      tests/testdata/leveldb_dir/geth/chaindata/000150.ldb
  30. 0
      tests/testdata/leveldb_dir/geth/chaindata/000151.ldb
  31. 0
      tests/testdata/leveldb_dir/geth/chaindata/000152.ldb
  32. 0
      tests/testdata/leveldb_dir/geth/chaindata/000157.ldb
  33. 0
      tests/testdata/leveldb_dir/geth/chaindata/000158.ldb
  34. 0
      tests/testdata/leveldb_dir/geth/chaindata/000159.ldb
  35. 0
      tests/testdata/leveldb_dir/geth/chaindata/000625.ldb
  36. 0
      tests/testdata/leveldb_dir/geth/chaindata/000626.ldb
  37. 0
      tests/testdata/leveldb_dir/geth/chaindata/000627.ldb
  38. 0
      tests/testdata/leveldb_dir/geth/chaindata/000628.ldb
  39. 0
      tests/testdata/leveldb_dir/geth/chaindata/000634.ldb
  40. 0
      tests/testdata/leveldb_dir/geth/chaindata/000663.log
  41. 0
      tests/testdata/leveldb_dir/geth/chaindata/000664.ldb
  42. 0
      tests/testdata/leveldb_dir/geth/chaindata/000665.ldb
  43. 0
      tests/testdata/leveldb_dir/geth/chaindata/000666.ldb
  44. BIN
      tests/testdata/leveldb_dir/geth/chaindata/000667.ldb
  45. 1
      tests/testdata/leveldb_dir/geth/chaindata/CURRENT
  46. 0
      tests/testdata/leveldb_dir/geth/chaindata/LOCK
  47. 14
      tests/testdata/leveldb_dir/geth/chaindata/LOG
  48. 17
      tests/testdata/leveldb_dir/geth/chaindata/LOG.old
  49. BIN
      tests/testdata/leveldb_dir/geth/chaindata/MANIFEST-000662
  50. 0
      tests/testdata/leveldb_dir/geth/nodekey
  51. 0
      tests/testdata/leveldb_dir/geth/nodes/000026.log
  52. 0
      tests/testdata/leveldb_dir/geth/nodes/000028.ldb
  53. 0
      tests/testdata/leveldb_dir/geth/nodes/CURRENT
  54. 0
      tests/testdata/leveldb_dir/geth/nodes/LOCK
  55. 0
      tests/testdata/leveldb_dir/geth/nodes/LOG
  56. 0
      tests/testdata/leveldb_dir/geth/nodes/MANIFEST-000027
  57. 0
      tests/testdata/leveldb_dir/geth/transactions.rlp
  58. 0
      tests/testdata/leveldb_dir/history
  59. 2
      tests/testdata/mythril_config_inputs/config.ini

3
.gitignore vendored

@ -175,7 +175,8 @@ lol*
coverage_html_report/
tests/testdata/outputs_current/
tests/testdata/outputs_current_laser_result/
tests/mythril_dir/signatures.db
tests/testdata/mythril_dir/signatures.db
tests/testdata/leveldb_dir/
# VSCode
.vscode

@ -30,6 +30,7 @@ class MythrilConfig:
Initializes the mythril dir and config.ini file
:return: The mythril dir's path
"""
try:
mythril_dir = os.environ["MYTHRIL_DIR"]
except KeyError:
@ -121,13 +122,13 @@ class MythrilConfig:
:param leveldb_fallback_dir: The leveldb dir to use by default for searches
:return: None
"""
config.set("defaults", "#Default chaindata locations:", None)
config.set("defaults", "#– Mac: ~/Library/Ethereum/geth/chaindata", None)
config.set("defaults", "#– Linux: ~/.ethereum/geth/chaindata", None)
config.set("defaults", "#Default chaindata locations:", "")
config.set("defaults", "#– Mac: ~/Library/Ethereum/geth/chaindata", "")
config.set("defaults", "#– Linux: ~/.ethereum/geth/chaindata", "")
config.set(
"defaults",
"#– Windows: %USERPROFILE%\\AppData\\Roaming\\Ethereum\\geth\\chaindata",
None,
"",
)
config.set("defaults", "leveldb_dir", leveldb_fallback_dir)
@ -139,18 +140,16 @@ class MythrilConfig:
:return: None
"""
config.set(
"defaults", "#– To connect to Infura use dynamic_loading: infura", None
"defaults", "#– To connect to Infura use dynamic_loading: infura", ""
)
config.set(
"defaults",
"#– To connect to Rpc use "
"dynamic_loading: HOST:PORT / ganache / infura-[network_name]",
None,
"",
)
config.set(
"defaults",
"#– To connect to local host use dynamic_loading: localhost",
None,
"defaults", "#– To connect to local host use dynamic_loading: localhost", ""
)
config.set("defaults", "dynamic_loading", "infura")
@ -166,7 +165,8 @@ class MythrilConfig:
def set_api_rpc(self, rpc: str = None, rpctls: bool = False) -> None:
"""
Sets the RPC mode to either ganache or infura
Sets the RPC mode to either of ganache or infura
:param rpc: either of the strings - ganache, infura-mainnet, infura-rinkeby, infura-kovan, infura-ropsten
"""
if rpc == "ganache":
rpcconfig = ("localhost", 8545, False)
@ -204,9 +204,17 @@ class MythrilConfig:
dynamic_loading = config.get("defaults", "dynamic_loading")
else:
dynamic_loading = "infura"
if dynamic_loading == "infura":
self._set_rpc(dynamic_loading)
def _set_rpc(self, rpc_type: str) -> None:
"""
Sets rpc based on the type
:param rpc_type: The type of connection: like infura, ganache, localhost
:return:
"""
if rpc_type == "infura":
self.set_api_rpc_infura()
elif dynamic_loading == "localhost":
elif rpc_type == "localhost":
self.set_api_rpc_localhost()
else:
self.set_api_rpc(dynamic_loading)
self.set_api_rpc(rpc_type)

@ -1,17 +0,0 @@
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 ]

@ -1,11 +0,0 @@
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 ]

@ -1 +1,58 @@
import pytest
from configparser import ConfigParser
from pathlib import Path
from mythril.mythril import MythrilConfig
from mythril.exceptions import CriticalError
def test_config_path_dynloading():
config = MythrilConfig()
config.config_path = (
Path(__file__).parent.parent / "testdata/mythril_config_inputs/config.ini"
)
config.set_api_from_config_path()
assert config.eth.host == "mainnet.infura.io"
assert config.eth.port == 443
rpc_types_tests = [
("infura", "mainnet.infura.io", 443, True),
("ganache", "localhost", 8545, True),
("infura-rinkeby", "rinkeby.infura.io", 443, True),
("infura-ropsten", "ropsten.infura.io", 443, True),
("infura-kovan", "kovan.infura.io", 443, True),
("localhost", "localhost", 8545, True),
("localhost:9022", "localhost", 9022, True),
("pinfura", None, None, False),
("infura-finkeby", None, None, False),
]
@pytest.mark.parametrize("rpc_type,host,port,success", rpc_types_tests)
def test_set_rpc(rpc_type, host, port, success):
config = MythrilConfig()
if success:
config._set_rpc(rpc_type)
assert config.eth.host == host
assert config.eth.port == port
else:
with pytest.raises(CriticalError):
config._set_rpc(rpc_type)
def test_leveldb_config_addition():
config = ConfigParser()
config.add_section("defaults")
MythrilConfig._add_leveldb_option(config, "test")
assert config.has_section("defaults")
assert config.get("defaults", "leveldb_dir") == "test"
def test_dynld_config_addition():
config = ConfigParser()
config.add_section("defaults")
MythrilConfig._add_dynamic_loading_option(config)
assert config.has_section("defaults")
assert config.get("defaults", "dynamic_loading") == "infura"

@ -7,7 +7,9 @@ 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"))
config.set_api_leveldb(
str(Path(__file__).parent.parent / "testdata/leveldb_dir/geth/chaindata")
)
def test_leveldb_code_search():

@ -0,0 +1,14 @@
2019/02/07-20:32:39.782911 7f4b33cb8740 Recovering log #661
2019/02/07-20:32:39.894296 7f4b33cb8740 Delete type=2 #665
2019/02/07-20:32:39.894811 7f4b33cb8740 Delete type=3 #660
2019/02/07-20:32:39.894841 7f4b33cb8740 Delete type=2 #666
2019/02/07-20:32:39.895374 7f4b33cb8740 Delete type=0 #661
2019/02/07-20:32:39.895402 7f4b33cb8740 Delete type=2 #663
2019/02/07-20:32:39.895895 7f4b33cb8740 Delete type=2 #662
2019/02/07-20:32:39.896203 7f4b33cb8740 Delete type=2 #667
2019/02/07-20:32:39.896471 7f4b33cb8740 Delete type=2 #664
2019/02/07-20:36:10.182792 7f4b2646f700 Compacting 1@1 + 7@2 files
2019/02/07-20:36:10.377208 7f4b2646f700 Generated table #664@1: 81883 keys, 2123472 bytes
2019/02/07-20:36:10.473184 7f4b2646f700 Generated table #665@1: 45465 keys, 2114646 bytes
2019/02/07-20:36:10.573873 7f4b2646f700 Generated table #666@1: 45437 keys, 2115685 bytes
2019/02/07-20:36:10.589417 7f4b2646f700 compacted to: files[ 0 4 20 0 0 0 0 ]

@ -0,0 +1,17 @@
2019/02/07-20:26:25.270926 7fea389c0740 Recovering log #659
2019/02/07-20:26:25.362761 7fea389c0740 Delete type=2 #665
2019/02/07-20:26:25.363180 7fea389c0740 Delete type=0 #659
2019/02/07-20:26:25.363198 7fea389c0740 Delete type=2 #661
2019/02/07-20:26:25.363654 7fea389c0740 Delete type=2 #663
2019/02/07-20:26:25.364051 7fea389c0740 Delete type=2 #662
2019/02/07-20:26:25.364384 7fea389c0740 Delete type=3 #658
2019/02/07-20:26:25.364408 7fea389c0740 Delete type=2 #664
2019/02/07-20:26:25.364732 7fea389c0740 Delete type=2 #660
2019/02/07-20:29:58.614533 7fea26ffd700 Compacting 1@1 + 7@2 files
2019/02/07-20:29:58.748543 7fea26ffd700 Generated table #662@1: 81883 keys, 2123472 bytes
2019/02/07-20:29:58.871096 7fea26ffd700 Generated table #663@1: 45465 keys, 2114646 bytes
2019/02/07-20:29:58.982738 7fea26ffd700 Generated table #664@1: 45437 keys, 2115685 bytes
2019/02/07-20:29:59.105425 7fea26ffd700 Generated table #665@1: 48074 keys, 2122150 bytes
2019/02/07-20:29:59.272913 7fea26ffd700 Generated table #666@1: 50323 keys, 2131426 bytes
2019/02/07-20:29:59.418496 7fea26ffd700 Generated table #667@1: 48817 keys, 2130856 bytes
2019/02/07-20:29:59.418683 7fea26ffd700 compacted to: files[ 0 4 20 0 0 0 0 ]

@ -0,0 +1,2 @@
[defaults]
dynamic_loading = infura
Loading…
Cancel
Save