Skip to content

Commit

Permalink
Add support for transfer
Browse files Browse the repository at this point in the history
  • Loading branch information
montyly committed Jan 26, 2024
1 parent 91cd32c commit 7db976f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
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}});
"""

__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

0 comments on commit 7db976f

Please sign in to comment.