mirror of https://github.com/ConsenSys/mythril
blockchainethereumsmart-contractssoliditysecurityprogram-analysissecurity-analysissymbolic-execution
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.
115 lines
2.7 KiB
115 lines
2.7 KiB
11 months ago
|
import pytest
|
||
|
import json
|
||
|
import sys
|
||
|
import os
|
||
|
|
||
|
from tests import PROJECT_DIR, TESTDATA
|
||
|
from subprocess import check_output, CalledProcessError
|
||
|
|
||
|
MYTH = str(PROJECT_DIR / "myth")
|
||
|
|
||
|
|
||
|
def output_of(command):
|
||
|
"""
|
||
|
|
||
|
:param command:
|
||
|
:return:
|
||
|
"""
|
||
|
try:
|
||
|
return check_output(command, shell=True).decode("UTF-8")
|
||
|
except CalledProcessError as exc:
|
||
|
return exc.output.decode("UTF-8")
|
||
|
|
||
|
|
||
|
test_data = (
|
||
|
# TODO: The commented tests should be sped up!
|
||
|
# (
|
||
|
# "destruct.sol",
|
||
|
# {
|
||
|
# "TX_COUNT": 5,
|
||
|
# "MODULE": "AccidentallyKillable",
|
||
|
# "ISSUE_COUNT": 1,
|
||
|
# "VERSION": "v0.5.0",
|
||
|
# },
|
||
|
# ),
|
||
|
# (
|
||
|
# "destruct.sol",
|
||
|
# {
|
||
|
# "TX_COUNT": 4,
|
||
|
# "MODULE": "AccidentallyKillable",
|
||
|
# "ISSUE_COUNT": 0,
|
||
|
# "VERSION": "v0.5.0",
|
||
|
# },
|
||
|
# ),
|
||
|
(
|
||
|
"theft.sol",
|
||
|
{"TX_COUNT": 4, "MODULE": "EtherThief", "ISSUE_COUNT": 1, "VERSION": "v0.5.0"},
|
||
|
),
|
||
|
(
|
||
|
"theft.sol",
|
||
|
{"TX_COUNT": 3, "MODULE": "EtherThief", "ISSUE_COUNT": 0, "VERSION": "v0.5.0"},
|
||
|
),
|
||
|
(
|
||
|
"large.sol",
|
||
|
{
|
||
|
"TX_COUNT": 11,
|
||
|
"MODULE": "AccidentallyKillable",
|
||
|
"ISSUE_COUNT": 1,
|
||
|
"VERSION": "v0.5.0",
|
||
|
},
|
||
|
),
|
||
|
(
|
||
|
"large.sol",
|
||
|
{
|
||
|
"TX_COUNT": 10,
|
||
|
"MODULE": "AccidentallyKillable",
|
||
|
"ISSUE_COUNT": 0,
|
||
|
"VERSION": "v0.5.0",
|
||
|
},
|
||
|
),
|
||
|
(
|
||
|
"hash_test.sol",
|
||
|
{
|
||
|
"TX_COUNT": 2,
|
||
|
"MODULE": "AccidentallyKillable",
|
||
|
"ISSUE_COUNT": 1,
|
||
|
"VERSION": "v0.4.24",
|
||
|
},
|
||
|
),
|
||
|
(
|
||
|
"complex.sol",
|
||
|
{
|
||
|
"TX_COUNT": 2,
|
||
|
"MODULE": "AccidentallyKillable",
|
||
|
"ISSUE_COUNT": 1,
|
||
|
"VERSION": "v0.5.0",
|
||
|
},
|
||
|
),
|
||
|
(
|
||
|
"base_case.sol",
|
||
|
{
|
||
|
"TX_COUNT": 1,
|
||
|
"MODULE": "AccidentallyKillable",
|
||
|
"ISSUE_COUNT": 1,
|
||
|
"VERSION": "v0.5.0",
|
||
|
},
|
||
|
),
|
||
|
(
|
||
|
"simple_theft.sol",
|
||
|
{
|
||
|
"TX_COUNT": 1,
|
||
|
"MODULE": "EtherThief",
|
||
|
"ISSUE_COUNT": 0,
|
||
|
"VERSION": "v0.5.0",
|
||
|
},
|
||
|
),
|
||
|
)
|
||
|
|
||
|
|
||
|
@pytest.mark.parametrize("file_name, tx_data", test_data)
|
||
|
def test_analysis(file_name, tx_data):
|
||
|
file_path = str(TESTDATA / "input_contracts" / file_name)
|
||
|
command = f"""python3 {MYTH} analyze {file_path} -t {tx_data["TX_COUNT"]} -o jsonv2 -m {tx_data["MODULE"]} --solver-timeout 60000 --solv {tx_data["VERSION"]} --execution-timeout 300 --enable-summaries"""
|
||
|
output = json.loads(output_of(command))
|
||
|
assert len(output[0]["issues"]) == tx_data["ISSUE_COUNT"]
|