Add graph analysis test

pull/906/head
Nikhil Parasaram 6 years ago
parent 7752b16021
commit d15ff852ee
  1. 11
      mythril/mythril/mythril_analyzer.py
  2. 2
      mythril/mythril/mythril_disassembler.py
  3. 13
      tests/graph_test.py
  4. 2
      tests/mythril/mythril_analyzer_test.py

@ -49,7 +49,7 @@ class MythrilAnalyzer:
def dump_statespace(
self,
strategy: str,
contract: List[EVMContract],
contract: List[EVMContract] = None,
address: Optional[str] = None,
max_depth: Optional[int] = None,
execution_timeout: Optional[int] = None,
@ -68,7 +68,7 @@ class MythrilAnalyzer:
:return: The serialized state space
"""
sym = SymExecWrapper(
contract,
contract or self.contracts[0],
address,
strategy,
dynloader=DynLoader(
@ -87,13 +87,14 @@ class MythrilAnalyzer:
def graph_html(
self,
strategy: str,
contract: List[EVMContract],
address: str,
contract: List[EVMContract] = None,
max_depth: Optional[int] = None,
enable_physics: bool = False,
phrackify: bool = False,
execution_timeout: Optional[int] = None,
create_timeout: Optional[int] = None,
transaction_count: Optional[int] = None,
enable_iprof: bool = False,
) -> str:
"""
@ -106,11 +107,12 @@ class MythrilAnalyzer:
:param phrackify: If true generates Phrack-style call graph
:param execution_timeout: The total execution timeout of the contract
:param create_timeout: The total contract creation timeout
:param transaction_count: The amount of transactions to be executed
:param enable_iprof: Enables/disables instruction profiler
:return: The generated graph in html format
"""
sym = SymExecWrapper(
contract,
contract or self.contracts[0],
address,
strategy,
dynloader=DynLoader(
@ -120,6 +122,7 @@ class MythrilAnalyzer:
),
max_depth=max_depth,
execution_timeout=execution_timeout,
transaction_count=transaction_count,
create_timeout=create_timeout,
enable_iprof=enable_iprof,
)

@ -21,7 +21,7 @@ log = logging.getLogger(__name__)
class MythrilDisassembler:
def __init__(
self,
eth: Optional[EthJsonRpc],
eth: Optional[EthJsonRpc] = None,
solc_version: str = None,
solc_args: str = None,
enable_online_lookup: bool = False,

@ -1,5 +1,5 @@
from mythril.analysis.callgraph import generate_graph
from mythril.analysis.symbolic import SymExecWrapper
from mythril.mythril import MythrilAnalyzer, MythrilDisassembler
from mythril.ethereum import util
from mythril.solidity.soliditycontract import EVMContract
from tests import (
@ -22,16 +22,17 @@ class GraphTest(BaseTestCase):
)
contract = EVMContract(input_file.read_text())
disassembler = MythrilDisassembler()
disassembler.contracts.append(contract)
analyzer = MythrilAnalyzer(disassembler)
sym = SymExecWrapper(
contract,
address=(util.get_indexed_address(0)),
html = analyzer.graph_html(
strategy="dfs",
transaction_count=1,
execution_timeout=5,
max_depth=30,
address=(util.get_indexed_address(0)),
)
html = generate_graph(sym)
output_current.write_text(html)
lines_expected = re.findall(

@ -4,8 +4,6 @@ from mythril.mythril import MythrilDisassembler, MythrilAnalyzer
def test_fire_lasers():
disassembler = MythrilDisassembler(eth=None)
print(str((Path(__file__).parent.parent / "testdata/input_contracts/origin.sol")))
print(Path(__file__))
disassembler.load_from_solidity(
[
str(

Loading…
Cancel
Save