From f894f7979e1b1f39a66ef739efbea3865398812a Mon Sep 17 00:00:00 2001 From: Michael Colburn Date: Fri, 28 May 2021 21:15:45 -0400 Subject: [PATCH] Add tests for the missing-inheritance detector --- .../0.4.25/unimplemented_interface.sol | 9 +++ ...terface.sol.0.4.25.MissingInheritance.json | 58 +++++++++++++++++++ .../0.5.16/unimplemented_interface.sol | 9 +++ ...terface.sol.0.5.16.MissingInheritance.json | 58 +++++++++++++++++++ .../0.6.11/unimplemented_interface.sol | 9 +++ ...terface.sol.0.6.11.MissingInheritance.json | 58 +++++++++++++++++++ .../0.7.6/unimplemented_interface.sol | 9 +++ ...nterface.sol.0.7.6.MissingInheritance.json | 58 +++++++++++++++++++ tests/test_detectors.py | 20 +++++++ 9 files changed, 288 insertions(+) create mode 100644 tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol create mode 100644 tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol.0.4.25.MissingInheritance.json create mode 100644 tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol create mode 100644 tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol.0.5.16.MissingInheritance.json create mode 100644 tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol create mode 100644 tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol.0.6.11.MissingInheritance.json create mode 100644 tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol create mode 100644 tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol.0.7.6.MissingInheritance.json diff --git a/tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol b/tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol new file mode 100644 index 000000000..58149d329 --- /dev/null +++ b/tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol @@ -0,0 +1,9 @@ +interface ISomething { + function f1() external returns(uint); +} + +contract Something { + function f1() external returns(uint){ + return 42; + } +} \ No newline at end of file diff --git a/tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol.0.4.25.MissingInheritance.json b/tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol.0.4.25.MissingInheritance.json new file mode 100644 index 000000000..bb52cfa9b --- /dev/null +++ b/tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol.0.4.25.MissingInheritance.json @@ -0,0 +1,58 @@ +[ + [ + { + "elements": [ + { + "type": "contract", + "name": "Something", + "source_mapping": { + "start": 68, + "length": 89, + "filename_used": "/GENERIC_PATH", + "filename_relative": "tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol", + "filename_absolute": "/GENERIC_PATH", + "filename_short": "tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol", + "is_dependency": false, + "lines": [ + 5, + 6, + 7, + 8, + 9, + 10 + ], + "starting_column": 1, + "ending_column": 0 + } + }, + { + "type": "contract", + "name": "ISomething", + "source_mapping": { + "start": 0, + "length": 66, + "filename_used": "/GENERIC_PATH", + "filename_relative": "tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol", + "filename_absolute": "/GENERIC_PATH", + "filename_short": "tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol", + "is_dependency": false, + "lines": [ + 1, + 2, + 3 + ], + "starting_column": 1, + "ending_column": 2 + } + } + ], + "description": "Something (tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol#5-10) should inherit from ISomething (tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol#1-3)\n", + "markdown": "[Something](tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol#L5-L10) should inherit from [ISomething](tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol#L1-L3)\n", + "first_markdown_element": "tests/detectors/missing-inheritance/0.4.25/unimplemented_interface.sol#L5-L10", + "id": "58962dc72a6c49524a027e8e1615ab92be30f1a0f5ef0eb4a029204687159649", + "check": "missing-inheritance", + "impact": "Informational", + "confidence": "High" + } + ] +] \ No newline at end of file diff --git a/tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol b/tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol new file mode 100644 index 000000000..58149d329 --- /dev/null +++ b/tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol @@ -0,0 +1,9 @@ +interface ISomething { + function f1() external returns(uint); +} + +contract Something { + function f1() external returns(uint){ + return 42; + } +} \ No newline at end of file diff --git a/tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol.0.5.16.MissingInheritance.json b/tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol.0.5.16.MissingInheritance.json new file mode 100644 index 000000000..4dc27f5b5 --- /dev/null +++ b/tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol.0.5.16.MissingInheritance.json @@ -0,0 +1,58 @@ +[ + [ + { + "elements": [ + { + "type": "contract", + "name": "Something", + "source_mapping": { + "start": 68, + "length": 89, + "filename_used": "/GENERIC_PATH", + "filename_relative": "tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol", + "filename_absolute": "/GENERIC_PATH", + "filename_short": "tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol", + "is_dependency": false, + "lines": [ + 5, + 6, + 7, + 8, + 9, + 10 + ], + "starting_column": 1, + "ending_column": 0 + } + }, + { + "type": "contract", + "name": "ISomething", + "source_mapping": { + "start": 0, + "length": 66, + "filename_used": "/GENERIC_PATH", + "filename_relative": "tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol", + "filename_absolute": "/GENERIC_PATH", + "filename_short": "tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol", + "is_dependency": false, + "lines": [ + 1, + 2, + 3 + ], + "starting_column": 1, + "ending_column": 2 + } + } + ], + "description": "Something (tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol#5-10) should inherit from ISomething (tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol#1-3)\n", + "markdown": "[Something](tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol#L5-L10) should inherit from [ISomething](tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol#L1-L3)\n", + "first_markdown_element": "tests/detectors/missing-inheritance/0.5.16/unimplemented_interface.sol#L5-L10", + "id": "58962dc72a6c49524a027e8e1615ab92be30f1a0f5ef0eb4a029204687159649", + "check": "missing-inheritance", + "impact": "Informational", + "confidence": "High" + } + ] +] \ No newline at end of file diff --git a/tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol b/tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol new file mode 100644 index 000000000..58149d329 --- /dev/null +++ b/tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol @@ -0,0 +1,9 @@ +interface ISomething { + function f1() external returns(uint); +} + +contract Something { + function f1() external returns(uint){ + return 42; + } +} \ No newline at end of file diff --git a/tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol.0.6.11.MissingInheritance.json b/tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol.0.6.11.MissingInheritance.json new file mode 100644 index 000000000..800114e0c --- /dev/null +++ b/tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol.0.6.11.MissingInheritance.json @@ -0,0 +1,58 @@ +[ + [ + { + "elements": [ + { + "type": "contract", + "name": "Something", + "source_mapping": { + "start": 68, + "length": 89, + "filename_used": "/GENERIC_PATH", + "filename_relative": "tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol", + "filename_absolute": "/GENERIC_PATH", + "filename_short": "tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol", + "is_dependency": false, + "lines": [ + 5, + 6, + 7, + 8, + 9, + 10 + ], + "starting_column": 1, + "ending_column": 0 + } + }, + { + "type": "contract", + "name": "ISomething", + "source_mapping": { + "start": 0, + "length": 66, + "filename_used": "/GENERIC_PATH", + "filename_relative": "tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol", + "filename_absolute": "/GENERIC_PATH", + "filename_short": "tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol", + "is_dependency": false, + "lines": [ + 1, + 2, + 3 + ], + "starting_column": 1, + "ending_column": 2 + } + } + ], + "description": "Something (tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol#5-10) should inherit from ISomething (tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol#1-3)\n", + "markdown": "[Something](tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol#L5-L10) should inherit from [ISomething](tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol#L1-L3)\n", + "first_markdown_element": "tests/detectors/missing-inheritance/0.6.11/unimplemented_interface.sol#L5-L10", + "id": "58962dc72a6c49524a027e8e1615ab92be30f1a0f5ef0eb4a029204687159649", + "check": "missing-inheritance", + "impact": "Informational", + "confidence": "High" + } + ] +] \ No newline at end of file diff --git a/tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol b/tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol new file mode 100644 index 000000000..58149d329 --- /dev/null +++ b/tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol @@ -0,0 +1,9 @@ +interface ISomething { + function f1() external returns(uint); +} + +contract Something { + function f1() external returns(uint){ + return 42; + } +} \ No newline at end of file diff --git a/tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol.0.7.6.MissingInheritance.json b/tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol.0.7.6.MissingInheritance.json new file mode 100644 index 000000000..7746c4a37 --- /dev/null +++ b/tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol.0.7.6.MissingInheritance.json @@ -0,0 +1,58 @@ +[ + [ + { + "elements": [ + { + "type": "contract", + "name": "Something", + "source_mapping": { + "start": 68, + "length": 89, + "filename_used": "/GENERIC_PATH", + "filename_relative": "tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol", + "filename_absolute": "/GENERIC_PATH", + "filename_short": "tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol", + "is_dependency": false, + "lines": [ + 5, + 6, + 7, + 8, + 9, + 10 + ], + "starting_column": 1, + "ending_column": 0 + } + }, + { + "type": "contract", + "name": "ISomething", + "source_mapping": { + "start": 0, + "length": 66, + "filename_used": "/GENERIC_PATH", + "filename_relative": "tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol", + "filename_absolute": "/GENERIC_PATH", + "filename_short": "tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol", + "is_dependency": false, + "lines": [ + 1, + 2, + 3 + ], + "starting_column": 1, + "ending_column": 2 + } + } + ], + "description": "Something (tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol#5-10) should inherit from ISomething (tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol#1-3)\n", + "markdown": "[Something](tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol#L5-L10) should inherit from [ISomething](tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol#L1-L3)\n", + "first_markdown_element": "tests/detectors/missing-inheritance/0.7.6/unimplemented_interface.sol#L5-L10", + "id": "58962dc72a6c49524a027e8e1615ab92be30f1a0f5ef0eb4a029204687159649", + "check": "missing-inheritance", + "impact": "Informational", + "confidence": "High" + } + ] +] \ No newline at end of file diff --git a/tests/test_detectors.py b/tests/test_detectors.py index 95ff2c797..13f0885b8 100644 --- a/tests/test_detectors.py +++ b/tests/test_detectors.py @@ -1164,6 +1164,26 @@ ALL_TESTS = [ "shift_parameter_mixup.sol", "0.7.6", ), + Test( + all_detectors.MissingInheritance, + "unimplemented_interface.sol", + "0.4.25", + ), + Test( + all_detectors.MissingInheritance, + "unimplemented_interface.sol", + "0.5.16", + ), + Test( + all_detectors.MissingInheritance, + "unimplemented_interface.sol", + "0.6.11", + ), + Test( + all_detectors.MissingInheritance, + "unimplemented_interface.sol", + "0.7.6", + ), ] GENERIC_PATH = "/GENERIC_PATH"