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

Integration tests for prepare_os_context #114

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ clean:
run-python-test: $(COMPILED_TESTS)
PYENV_VERSION=pypy3.7-7.3.9 . cairo-rs-py-env/bin/activate && \
maturin develop && \
python3 hints_tests.py && \
python3 get_builtins_initial_stack.py && \
./run_python_tests.sh && \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the PYENV_VERSION still the same here? I'm not entirely sure if the venv takes care of that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as i know yes, venv takes care about the python version with which the tests are ran.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make sure?

deactivate

full-test: test run-python-test
7 changes: 7 additions & 0 deletions run_python_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
echo "Running hint tests"
python3 tests/hints_tests.py
python3 tests/get_builtins_initial_stack.py

echo "Running prepare_os_context integration tests"
python3 tests/prepare_os_context.py
Comment on lines +2 to +7
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
def new_runner(program_name: str):
with open(f"cairo_programs/{program_name}.json") as file:
return cairo_rs_py.CairoRunner(file.read(), "main", "all", False)

def test_program(program_name: str):
runner = new_runner(program_name)

Expand Down
File renamed without changes.
34 changes: 34 additions & 0 deletions tests/prepare_os_context.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import cairo_rs_py

def init_runner(program_name):
with open(f"cairo_programs/{program_name}.json") as file:
return cairo_rs_py.CairoRunner(file.read(), "main", "small", False)


def prepare_os_context_without_builtins(runner):
syscall_segment = runner.add_segment()
os_context = [syscall_segment]
os_context.extend(runner.get_builtins_initial_stack())
return os_context

def prepare_os_context_with_builtins(runner):
syscall_segment = runner.add_segment()
os_context = [syscall_segment]
runner.initialize_function_runner()
os_context.extend(runner.get_builtins_initial_stack())
return os_context


if __name__ == "__main__":
runner = init_runner("get_builtins_initial_stack")
print("initialize no builtin")
expected_output = [(0,0)]
context = prepare_os_context_without_builtins(runner)
assert str(context) == str(expected_output)

print("initialize builtins")
runner = init_runner("get_builtins_initial_stack")
context = prepare_os_context_with_builtins(runner)
expected_output = [(0, 0), ('output', [(3, 0)]), ('pedersen', [(4, 0)]), ('range_check', [(5, 0)]), ('bitwise', [(6, 0)]), ('ec_op', [(7, 0)])]
assert str(context) == str(expected_output)
print("prepare_os_context tests passed")