Security analysis tool for EVM bytecode. Supports smart contracts built for Ethereum, Hedera, Quorum, Vechain, Roostock, Tron and other EVM-compatible blockchains.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mythril/tests/report_test.py

47 lines
2.1 KiB

from unittest import TestCase
from mythril.analysis.report import Report
from mythril.analysis.security import fire_lasers
from mythril.analysis.symbolic import SymExecWrapper
from mythril.ether import util
from mythril.ether.soliditycontract import SolidityContract
7 years ago
import json
from tests import *
def _fix_path(text):
return text.replace(str(TESTDATA), "<TESTDATA>")
7 years ago
def _fix_debug_data(json_str):
read_json = json.loads(json_str)
for issue in read_json["issues"]:
issue["debug"] = "<DEBUG-DATA>"
7 years ago
return json.dumps(read_json, indent=4)
7 years ago
class AnalysisReportTest(TestCase):
def test_reports(self):
for input_file in (TESTDATA / "inputs").iterdir():
7 years ago
contract = SolidityContract(str(input_file), name=None, solc_args=None)
sym = SymExecWrapper(contract, address=(util.get_indexed_address(0)))
issues = fire_lasers(sym)
for issue in issues:
issue.add_code_info(contract)
report = Report()
for issue in issues:
report.append_issue(issue)
# Useful for generating output file
# (TESTDATA_OUTPUTS / (input_file.name + ".text")).write_text(_fix_path(report.as_text()))
# (TESTDATA_OUTPUTS / (input_file.name + ".json")).write_text(_fix_path(_fix_debug_data(report.as_json())))
# (TESTDATA_OUTPUTS / (input_file.name + ".markdown")).write_text(_fix_path(report.as_markdown()))
7 years ago
text = (TESTDATA / "outputs" / (input_file.name + ".text")).read_text()
json_report = (TESTDATA / "outputs" / (input_file.name + ".json")).read_text()
markdown = (TESTDATA / "outputs" / (input_file.name + ".markdown")).read_text()
7 years ago
self.assertEqual(_fix_path(report.as_text()), text, "{}: text report is changed".format(str(input_file)))
self.assertEqual(_fix_path(report.as_markdown()), markdown, "{}: markdown report is changed".format(str(input_file)))
self.assertEqual(_fix_path(_fix_debug_data(report.as_json())), json_report, "{}: json report is changed".format(str(input_file)))