Security analysis tool for EVM bytecode. Supports smart contracts built for Ethereum, Hedera, Quorum, Vechain, Roostock, Tron and other EVM-compatible blockchains.
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.
 
 
 
 
 
 
mythril/tests/util_tests.py

93 lines
2.8 KiB

import pytest
from mythril.ethereum.util import extract_version
test_data = (
("pragma solidity 0.5.0\n", ["0.5.0"]),
("pragma solidity =0.5.0\n", ["0.5.0"]),
("pragma solidity ^0.4.26\n", ["0.4.26"]),
("pragma solidity ^0.6.3;\n", [f"0.6.{x}" for x in range(3, 13)]),
("pragma solidity ^0.6.3 ;\n", [f"0.6.{x}" for x in range(3, 13)]),
(
"pragma solidity ^0.6.3; \n",
[f"0.6.{x}" for x in range(3, 13)],
),
(
"pragma solidity ^0.6.3 ; \n",
[f"0.6.{x}" for x in range(3, 13)],
),
(
"""pragma solidity >=0.4.0 <0.6.0 ;
contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}""",
[f"0.4.{x}" for x in range(11, 27)] + [f"0.5.{x}" for x in range(0, 18)],
),
(
"""
pragma solidity >=0.4.0 <0.6.0
;contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}""",
[f"0.4.{x}" for x in range(11, 27)] + [f"0.5.{x}" for x in range(0, 18)],
),
(
"""
pragma solidity >=0.4.0 <0.6.0
;contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}""",
[f"0.4.{x}" for x in range(11, 27)] + [f"0.5.{x}" for x in range(0, 18)],
),
(
"""
pragma solidity >= 0.5.0 < 0.6.0;
;contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}""",
[f"0.5.{x}" for x in range(0, 18)],
),
(
"""
pragma solidity >= 0 . 4 .0 < 0 . 6 . 0
;contract SimpleStorage {
uint storedData;
function set(uint x) public {
storedData = x;
}
function get() public view returns (uint) {
return storedData;
}
}""",
[f"0.4.{x}" for x in range(11, 27)] + [f"0.5.{x}" for x in range(0, 18)],
),
)
@pytest.mark.parametrize("input_,output", test_data)
def test_sar(input_, output):
assert extract_version(input_) in output