Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for transfer #6

Merged
merged 2 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions test_generator/fuzzers/Echidna.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ def _parse_call_object(self, call_dict: dict[Any, Any]) -> tuple[str, str]:
return (call_str, "")

function_name = call_dict["call"]["contents"][0]

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

function_parameters = call_dict["call"]["contents"][1]
if len(function_parameters) == 0:
function_parameters = ""
Expand Down
12 changes: 9 additions & 3 deletions test_generator/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,18 @@ def create_poc(self) -> str:
full_path = os.path.join(self.fuzzer.reproducer_dir, entry)

if os.path.isfile(full_path):
with open(full_path, "r", encoding="utf-8") as file:
file_list.append(json.load(file))
try:
with open(full_path, "r", encoding="utf-8") as file:
file_list.append(json.load(file))
except Exception: # pylint: disable=broad-except
print(f"Fail on {full_path}")

# 2. Parse each reproducer file and add each test function to the functions list
for idx, file in enumerate(file_list):
tests_list.append(self.fuzzer.parse_reproducer(file, idx))
try:
tests_list.append(self.fuzzer.parse_reproducer(file, idx))
except Exception: # pylint: disable=broad-except
print(f"Parsing fail on {file}: index: {idx}")

# 4. Generate the test file
template = jinja2.Template(templates["CONTRACT"])
Expand Down
10 changes: 10 additions & 0 deletions test_generator/templates/foundry_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@
{%- endif %}
"""

__TRANSFER__TEMPLATE: str = """
{%- if has_delay -%}
vm.warp(block.timestamp + {{time_delay}});
vm.roll(block.number + {{block_delay}});
{%- endif %}
vm.prank({{caller}});
target.transfer({{value}});
tuturu-tech marked this conversation as resolved.
Show resolved Hide resolved
"""

__EMPTY_CALL_TEMPLATE: str = """
// This is an empty call which just increases the block number and timestamp
vm.warp(block.timestamp + {{time_delay}});
Expand All @@ -60,6 +69,7 @@
templates: dict = {
"CONTRACT": __CONTRACT_TEMPLATE,
"CALL": __CALL_TEMPLATE,
"TRANSFER": __TRANSFER__TEMPLATE,
"EMPTY_CALL": __EMPTY_CALL_TEMPLATE,
"TEST": __TEST_TEMPLATE,
"INTERFACE": __INTERFACE_TEMPLATE,
Expand Down
Loading