mirror of https://github.com/ConsenSys/mythril
Add statespace tests (#1248)
* Fix mypy issues * Fix the statespace problem, and remove weirdness in graph tests * Fix black * Remove weird Z which popped up * Add a comment in graph test Co-authored-by: JoranHonig <JoranHonig@users.noreply.github.com>pull/1307/head
parent
3e167282e7
commit
c965339959
@ -1,45 +1,25 @@ |
||||
from mythril.analysis.callgraph import generate_graph |
||||
""" |
||||
This test only checks whether dumping is successful, not whether the dumped state space makes sense |
||||
""" |
||||
from mythril.mythril import MythrilAnalyzer, MythrilDisassembler |
||||
from mythril.ethereum import util |
||||
from mythril.solidity.soliditycontract import EVMContract |
||||
from tests import ( |
||||
BaseTestCase, |
||||
TESTDATA_INPUTS, |
||||
TESTDATA_OUTPUTS_EXPECTED, |
||||
TESTDATA_OUTPUTS_CURRENT, |
||||
) |
||||
import re |
||||
from tests import TESTDATA_INPUTS |
||||
|
||||
|
||||
class GraphTest(BaseTestCase): |
||||
def test_generate_graph(self): |
||||
for input_file in TESTDATA_INPUTS.iterdir(): |
||||
output_expected = TESTDATA_OUTPUTS_EXPECTED / ( |
||||
input_file.name + ".graph.html" |
||||
) |
||||
output_current = TESTDATA_OUTPUTS_CURRENT / ( |
||||
input_file.name + ".graph.html" |
||||
) |
||||
def test_generate_graph(): |
||||
for input_file in TESTDATA_INPUTS.iterdir(): |
||||
if input_file.name != "origin.sol.o": |
||||
continue |
||||
contract = EVMContract(input_file.read_text()) |
||||
disassembler = MythrilDisassembler() |
||||
disassembler.contracts.append(contract) |
||||
analyzer = MythrilAnalyzer( |
||||
disassembler=disassembler, |
||||
strategy="dfs", |
||||
execution_timeout=5, |
||||
max_depth=30, |
||||
address=(util.get_indexed_address(0)), |
||||
) |
||||
|
||||
contract = EVMContract(input_file.read_text()) |
||||
disassembler = MythrilDisassembler() |
||||
disassembler.contracts.append(contract) |
||||
analyzer = MythrilAnalyzer( |
||||
disassembler=disassembler, |
||||
strategy="dfs", |
||||
execution_timeout=5, |
||||
max_depth=30, |
||||
address=(util.get_indexed_address(0)), |
||||
) |
||||
|
||||
html = analyzer.graph_html(transaction_count=1) |
||||
output_current.write_text(html) |
||||
|
||||
lines_expected = re.findall( |
||||
r"'label': '.*'", str(output_current.read_text()) |
||||
) |
||||
lines_found = re.findall(r"'label': '.*'", str(output_current.read_text())) |
||||
if not (lines_expected == lines_found): |
||||
self.found_changed_files(input_file, output_expected, output_current) |
||||
|
||||
self.assert_and_show_changed_files() |
||||
analyzer.graph_html(transaction_count=1) |
||||
|
@ -0,0 +1,23 @@ |
||||
from mythril.mythril import MythrilAnalyzer, MythrilDisassembler |
||||
from mythril.ethereum import util |
||||
from mythril.solidity.soliditycontract import EVMContract |
||||
from tests import TESTDATA_INPUTS |
||||
|
||||
|
||||
def test_statespace_dump(): |
||||
for input_file in TESTDATA_INPUTS.iterdir(): |
||||
if input_file.name not in ("origin.sol.o", "suicide.sol.o"): |
||||
# It's too slow, so it's better to skip some tests. |
||||
continue |
||||
contract = EVMContract(input_file.read_text()) |
||||
disassembler = MythrilDisassembler() |
||||
disassembler.contracts.append(contract) |
||||
analyzer = MythrilAnalyzer( |
||||
disassembler=disassembler, |
||||
strategy="dfs", |
||||
execution_timeout=5, |
||||
max_depth=30, |
||||
address=(util.get_indexed_address(0)), |
||||
) |
||||
|
||||
analyzer.dump_statespace(contract=contract) |
Loading…
Reference in new issue