Skip to content

Commit

Permalink
Add missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
forefy committed Mar 14, 2024
1 parent fd926e8 commit 800dfda
Show file tree
Hide file tree
Showing 5 changed files with 1,967 additions and 1 deletion.
2 changes: 1 addition & 1 deletion tests/test_missing_reentrancy_guard.py
Original file line number Diff line number Diff line change
Expand Up @@ -1579,4 +1579,4 @@ def test_missing_reentrancy_guard(vulnerable_ast):
ast_json,
src_paths,
)
assert "Line 12 Columns 5-33" in results["results"][0]["lines"]
assert "Line 12 Columns 4-33" in results["results"][0]["lines"]
66 changes: 66 additions & 0 deletions tests/test_unspecific_pragma_detector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import json
import pytest
from eburger.serializer import reduce_json
from eburger.yaml_parser import process_yaml


@pytest.fixture
def vulnerable_ast() -> tuple[dict, list]:
ast_json = """{
"sources": {
"vulnerable_contracts/unspecific_pragma_detector.sol": {
"AST": {
"absolutePath": "vulnerable_contracts/unspecific_pragma_detector.sol",
"exportedSymbols": {
"OutOfControlContract": [
2
]
},
"id": 3,
"license": "MIT",
"nodeType": "SourceUnit",
"nodes": [
{
"id": 1,
"literals": [
"solidity",
"^",
"0.8",
".0"
],
"nodeType": "PragmaDirective",
"src": "32:23:0"
},
{
"abstract": false,
"baseContracts": [],
"contractDependencies": [],
"contractKind": "contract",
"fullyImplemented": true,
"id": 2,
"linearizedBaseContracts": [
2
],
"name": "OutOfControlContract",
"nodeType": "ContractDefinition",
"nodes": [],
"scope": 3,
"src": "57:32:0"
}
],
"src": "32:58:0"
}
}
}
}"""
return json.loads(ast_json)


def test_unspecific_pragma_detector(vulnerable_ast):
ast_json, src_paths = reduce_json(vulnerable_ast)
results = process_yaml(
"eburger/templates/unspecific_pragma_detector.yaml",
ast_json,
src_paths,
)
assert "Line 2 Columns 1-24" in results["results"][0]["lines"]
Loading

0 comments on commit 800dfda

Please sign in to comment.