From d6b3903fef096809a6034375e5b12dfb44e9b4d1 Mon Sep 17 00:00:00 2001 From: freewind Date: Sat, 24 Mar 2018 21:37:05 +0800 Subject: [PATCH] graph generation test --- tests/graph_test.py | 32 + tests/testdata/calls.sol.graph.html | 202 +++ tests/testdata/ether_send.sol.graph.html | 244 ++++ tests/testdata/exceptions.sol.graph.html | 252 ++++ tests/testdata/metacoin.sol.graph.html | 150 +++ tests/testdata/multi_contracts.sol.graph.html | 134 ++ tests/testdata/origin.sol.graph.html | 152 +++ tests/testdata/returnvalue.sol.graph.html | 146 +++ tests/testdata/rubixi.sol.graph.html | 848 ++++++++++++ tests/testdata/suicide.sol.graph.html | 128 ++ tests/testdata/underflow.sol.graph.html | 168 +++ tests/testdata/weak_random.sol.graph.html | 1136 +++++++++++++++++ 12 files changed, 3592 insertions(+) create mode 100644 tests/graph_test.py create mode 100644 tests/testdata/calls.sol.graph.html create mode 100644 tests/testdata/ether_send.sol.graph.html create mode 100644 tests/testdata/exceptions.sol.graph.html create mode 100644 tests/testdata/metacoin.sol.graph.html create mode 100644 tests/testdata/multi_contracts.sol.graph.html create mode 100644 tests/testdata/origin.sol.graph.html create mode 100644 tests/testdata/returnvalue.sol.graph.html create mode 100644 tests/testdata/rubixi.sol.graph.html create mode 100644 tests/testdata/suicide.sol.graph.html create mode 100644 tests/testdata/underflow.sol.graph.html create mode 100644 tests/testdata/weak_random.sol.graph.html diff --git a/tests/graph_test.py b/tests/graph_test.py new file mode 100644 index 00000000..a688cc98 --- /dev/null +++ b/tests/graph_test.py @@ -0,0 +1,32 @@ +from unittest import TestCase +from pathlib import Path + +from mythril.analysis.callgraph import generate_graph +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 + +TEST_FILES = Path(__file__).parent / "testdata" + +class GraphTest(TestCase): + + def test_generate_graph(self): + for input_file in TEST_FILES.iterdir(): + if input_file.is_file and input_file.suffix == '.sol': + 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) + + html = generate_graph(sym) + + expected = (TEST_FILES / (input_file.name + ".graph.html")).read_text() + self.assertEqual(html, expected) diff --git a/tests/testdata/calls.sol.graph.html b/tests/testdata/calls.sol.graph.html new file mode 100644 index 00000000..724fe790 --- /dev/null +++ b/tests/testdata/calls.sol.graph.html @@ -0,0 +1,202 @@ + + + + + + + + + + + + +

Mythril / LASER Symbolic VM

+


+ + + diff --git a/tests/testdata/ether_send.sol.graph.html b/tests/testdata/ether_send.sol.graph.html new file mode 100644 index 00000000..7541c992 --- /dev/null +++ b/tests/testdata/ether_send.sol.graph.html @@ -0,0 +1,244 @@ + + + + + + + + + + + + +

Mythril / LASER Symbolic VM

+


+ + + diff --git a/tests/testdata/exceptions.sol.graph.html b/tests/testdata/exceptions.sol.graph.html new file mode 100644 index 00000000..85dafca1 --- /dev/null +++ b/tests/testdata/exceptions.sol.graph.html @@ -0,0 +1,252 @@ + + + + + + + + + + + + +

Mythril / LASER Symbolic VM

+


+ + + diff --git a/tests/testdata/metacoin.sol.graph.html b/tests/testdata/metacoin.sol.graph.html new file mode 100644 index 00000000..dd6eb6f8 --- /dev/null +++ b/tests/testdata/metacoin.sol.graph.html @@ -0,0 +1,150 @@ + + + + + + + + + + + + +

Mythril / LASER Symbolic VM

+


+ + + diff --git a/tests/testdata/multi_contracts.sol.graph.html b/tests/testdata/multi_contracts.sol.graph.html new file mode 100644 index 00000000..25cc31f9 --- /dev/null +++ b/tests/testdata/multi_contracts.sol.graph.html @@ -0,0 +1,134 @@ + + + + + + + + + + + + +

Mythril / LASER Symbolic VM

+


+ + + diff --git a/tests/testdata/origin.sol.graph.html b/tests/testdata/origin.sol.graph.html new file mode 100644 index 00000000..d2a6fcaf --- /dev/null +++ b/tests/testdata/origin.sol.graph.html @@ -0,0 +1,152 @@ + + + + + + + + + + + + +

Mythril / LASER Symbolic VM

+


+ + + diff --git a/tests/testdata/returnvalue.sol.graph.html b/tests/testdata/returnvalue.sol.graph.html new file mode 100644 index 00000000..9979f2e5 --- /dev/null +++ b/tests/testdata/returnvalue.sol.graph.html @@ -0,0 +1,146 @@ + + + + + + + + + + + + +

Mythril / LASER Symbolic VM

+


+ + + diff --git a/tests/testdata/rubixi.sol.graph.html b/tests/testdata/rubixi.sol.graph.html new file mode 100644 index 00000000..9674c7b8 --- /dev/null +++ b/tests/testdata/rubixi.sol.graph.html @@ -0,0 +1,848 @@ + + + + + + + + + + + + +

Mythril / LASER Symbolic VM

+


+ + + diff --git a/tests/testdata/suicide.sol.graph.html b/tests/testdata/suicide.sol.graph.html new file mode 100644 index 00000000..cb0be9e6 --- /dev/null +++ b/tests/testdata/suicide.sol.graph.html @@ -0,0 +1,128 @@ + + + + + + + + + + + + +

Mythril / LASER Symbolic VM

+


+ + + diff --git a/tests/testdata/underflow.sol.graph.html b/tests/testdata/underflow.sol.graph.html new file mode 100644 index 00000000..5547c89a --- /dev/null +++ b/tests/testdata/underflow.sol.graph.html @@ -0,0 +1,168 @@ + + + + + + + + + + + + +

Mythril / LASER Symbolic VM

+


+ + + diff --git a/tests/testdata/weak_random.sol.graph.html b/tests/testdata/weak_random.sol.graph.html new file mode 100644 index 00000000..7801a895 --- /dev/null +++ b/tests/testdata/weak_random.sol.graph.html @@ -0,0 +1,1136 @@ + + + + + + + + + + + + +

Mythril / LASER Symbolic VM

+


+ + +