Skip to content

Commit

Permalink
refactor transfer support, add test contract, add value transfer test
Browse files Browse the repository at this point in the history
  • Loading branch information
tuturu-tech committed Feb 6, 2024
1 parent 7db976f commit a38e45b
Show file tree
Hide file tree
Showing 12 changed files with 2,514 additions and 4 deletions.
8 changes: 5 additions & 3 deletions test_generator/fuzzers/Echidna.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ def _parse_call_object(self, call_dict: dict[Any, Any]) -> tuple[str, str]:
time_delay = int(call_dict["delay"][0], 16)
block_delay = int(call_dict["delay"][1], 16)
has_delay = time_delay > 0 or block_delay > 0
value = int(call_dict["value"], 16)
caller = call_dict["src"]

if call_dict["call"]["tag"] == "NoCall":
template = jinja2.Template(templates["EMPTY"])
Expand All @@ -78,14 +80,14 @@ def _parse_call_object(self, call_dict: dict[Any, Any]) -> tuple[str, str]:

if not function_name:
template = jinja2.Template(templates["TRANSFER"])
call_str = template.render(time_delay=time_delay, block_delay=block_delay)
call_str = template.render(
time_delay=time_delay, block_delay=block_delay, value=value, caller=caller
)
return (call_str, "")

function_parameters = call_dict["call"]["contents"][1]
if len(function_parameters) == 0:
function_parameters = ""
caller = call_dict["src"]
value = int(call_dict["value"], 16)

slither_entry_point = None

Expand Down
3 changes: 2 additions & 1 deletion test_generator/templates/foundry_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
vm.roll(block.number + {{block_delay}});
{%- endif %}
vm.prank({{caller}});
target.transfer({{value}});
(bool success, ) = payable(address(target)).call{value: {{value}}}("");
require(success, "Low level call failed.");
"""

__EMPTY_CALL_TEMPLATE: str = """
Expand Down
10 changes: 10 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,13 @@ def structs_and_enums() -> TestGenerator:
corpus_dir = "corpus-struct"

return TestGenerator(target, target_path, corpus_dir)


@pytest.fixture
def value_transfer() -> TestGenerator:
"""Fixture for the ValueTransfer test contract"""
target = "ValueTransfer"
target_path = "./src/ValueTransfer.sol"
corpus_dir = "corpus-value"

return TestGenerator(target, target_path, corpus_dir)

Large diffs are not rendered by default.

1,022 changes: 1,022 additions & 0 deletions tests/test_data/echidna-corpora/corpus-value/covered.1707213004.html

Large diffs are not rendered by default.

Loading

0 comments on commit a38e45b

Please sign in to comment.