Skip to content

Commit

Permalink
Merge pull request #858 from crytic/dev-baseline-tests
Browse files Browse the repository at this point in the history
Add missing tests for detectors
  • Loading branch information
montyly committed Aug 1, 2022
2 parents 4532be2 + 6d3149a commit 8e65393
Show file tree
Hide file tree
Showing 47 changed files with 3,636 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
contract Test {

function functionWithDeprecatedThrow() public constant {
// Deprecated: Change msg.gas -> gasleft()
if(msg.gas == msg.value) {
// Deprecated: Change throw -> revert()
throw;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,176 @@
[
[
{
"elements": [
{
"type": "node",
"name": "msg.gas == msg.value",
"source_mapping": {
"start": 140,
"length": 20,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"is_dependency": false,
"lines": [
5
],
"starting_column": 12,
"ending_column": 32
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "functionWithDeprecatedThrow",
"source_mapping": {
"start": 21,
"length": 229,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"is_dependency": false,
"lines": [
3,
4,
5,
6,
7,
8,
9
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Test",
"source_mapping": {
"start": 0,
"length": 252,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "functionWithDeprecatedThrow()"
}
}
}
}
],
"description": "Deprecated standard detected msg.gas == msg.value (tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol#5):\n\t- Usage of \"msg.gas\" should be replaced with \"gasleft()\"\n",
"markdown": "Deprecated standard detected [msg.gas == msg.value](tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol#L5):\n\t- Usage of \"msg.gas\" should be replaced with \"gasleft()\"\n",
"first_markdown_element": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol#L5",
"id": "e779713eabc28919356310f06b9413a8a3b7e9e713026d6cfae2d9f6839c1e57",
"check": "deprecated-standards",
"impact": "Informational",
"confidence": "High"
},
{
"elements": [
{
"type": "node",
"name": "",
"source_mapping": {
"start": 228,
"length": 5,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"is_dependency": false,
"lines": [
7
],
"starting_column": 13,
"ending_column": 18
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "functionWithDeprecatedThrow",
"source_mapping": {
"start": 21,
"length": 229,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"is_dependency": false,
"lines": [
3,
4,
5,
6,
7,
8,
9
],
"starting_column": 5,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "Test",
"source_mapping": {
"start": 0,
"length": 252,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6,
7,
8,
9,
10,
11
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "functionWithDeprecatedThrow()"
}
}
}
}
],
"description": "Deprecated standard detected THROW (tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol#7):\n\t- Usage of \"throw\" should be replaced with \"revert()\"\n",
"markdown": "Deprecated standard detected [THROW](tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol#L7):\n\t- Usage of \"throw\" should be replaced with \"revert()\"\n",
"first_markdown_element": "tests/detectors/deprecated-standards/0.4.25/deprecated_calls.sol#L7",
"id": "5fbf4a42467953d0fd8d0661cbb4eeb81d4b40f69ae3820196bf10c4be53044e",
"check": "deprecated-standards",
"impact": "Informational",
"confidence": "High"
}
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract A {
function f(uint a, uint b, uint c) public returns (uint) {
return (a / b) * c;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
[
[
{
"elements": [
{
"type": "function",
"name": "f",
"source_mapping": {
"start": 14,
"length": 92,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
2,
3,
4
],
"starting_column": 2,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 0,
"length": 108,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "f(uint256,uint256,uint256)"
}
},
{
"type": "node",
"name": "(a / b) * c",
"source_mapping": {
"start": 81,
"length": 18,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
3
],
"starting_column": 9,
"ending_column": 27
},
"type_specific_fields": {
"parent": {
"type": "function",
"name": "f",
"source_mapping": {
"start": 14,
"length": 92,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
2,
3,
4
],
"starting_column": 2,
"ending_column": 6
},
"type_specific_fields": {
"parent": {
"type": "contract",
"name": "A",
"source_mapping": {
"start": 0,
"length": 108,
"filename_used": "/GENERIC_PATH",
"filename_relative": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"filename_absolute": "/GENERIC_PATH",
"filename_short": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol",
"is_dependency": false,
"lines": [
1,
2,
3,
4,
5,
6
],
"starting_column": 1,
"ending_column": 0
}
},
"signature": "f(uint256,uint256,uint256)"
}
}
}
}
],
"description": "A.f(uint256,uint256,uint256) (tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol#2-4) performs a multiplication on the result of a division:\n\t-(a / b) * c (tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol#3)\n",
"markdown": "[A.f(uint256,uint256,uint256)](tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol#L2-L4) performs a multiplication on the result of a division:\n\t-[(a / b) * c](tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol#L3)\n",
"first_markdown_element": "tests/detectors/divide-before-multiply/0.4.25/divide_before_multiply.sol#L2-L4",
"id": "fe40e2f72824d1270402b09af057ec7364af1ad2f8c48ef4df72fc27012b3186",
"check": "divide-before-multiply",
"impact": "Medium",
"confidence": "Medium"
}
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
contract A {
function f(uint a, uint b, uint c) public returns (uint) {
return (a / b) * c;
}
}
Loading

0 comments on commit 8e65393

Please sign in to comment.