-
Notifications
You must be signed in to change notification settings - Fork 979
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add try/catch, add tests, refactor guidance/echidna to reduce pylint …
…exceptions
- Loading branch information
Showing
3 changed files
with
106 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from pathlib import Path | ||
|
||
from slither import Slither | ||
from slither.printers.guidance.echidna import _extract_constants, ConstantValue | ||
|
||
TEST_DATA_DIR = Path(__file__).resolve().parent / "test_data" | ||
|
||
|
||
def test_enum_max_min(solc_binary_path) -> None: | ||
solc_path = solc_binary_path("0.8.19") | ||
slither = Slither(Path(TEST_DATA_DIR, "constantfolding.sol").as_posix(), solc=solc_path) | ||
|
||
contracts = slither.get_contract_from_name("A") | ||
|
||
constants = _extract_constants(contracts)[0]["A"]["use()"] | ||
|
||
assert set(constants) == { | ||
ConstantValue(value="2", type="uint256"), | ||
ConstantValue(value="10", type="uint256"), | ||
ConstantValue(value="100", type="uint256"), | ||
ConstantValue(value="4294967295", type="uint32"), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
type MyType is uint256; | ||
|
||
contract A{ | ||
|
||
enum E{ | ||
a,b,c | ||
} | ||
|
||
|
||
uint a = 10; | ||
E b = type(E).max; | ||
uint c = type(uint32).max; | ||
MyType d = MyType.wrap(100); | ||
|
||
function use() public returns(uint){ | ||
E e = b; | ||
return a +c + MyType.unwrap(d); | ||
} | ||
} |