Skip to content

Commit

Permalink
make program with cairo_program fixture quiet
Browse files Browse the repository at this point in the history
  • Loading branch information
enitrat committed Feb 13, 2025
1 parent 8e0737f commit b47b839
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 5 deletions.
4 changes: 3 additions & 1 deletion cairo/tests/ethereum/cancun/test_trie.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
)
from ethereum_types.bytes import Bytes, Bytes32
from ethereum_types.numeric import U256, Uint
from hypothesis import example, given
from hypothesis import Verbosity, example, given, settings
from hypothesis import strategies as st

from cairo_addons.testing.errors import cairo_error, strict_raises
Expand Down Expand Up @@ -79,6 +79,7 @@ def test_common_prefix_length(self, cairo_run, a: Bytes, b: Bytes):
assert common_prefix_length(a, b) == cairo_run("common_prefix_length", a, b)

@given(a=..., b=...)
@settings(verbosity=Verbosity.quiet)
def test_common_prefix_length_should_fail(
self, cairo_programs, cairo_run_py, a: Bytes, b: Bytes
):
Expand All @@ -101,6 +102,7 @@ def test_nibble_list_to_compact(self, cairo_run, x, is_leaf: bool):
)

@given(x=nibble.filter(lambda x: len(x) != 0), is_leaf=...)
@settings(verbosity=Verbosity.quiet)
def test_nibble_list_to_compact_should_raise_when_wrong_remainder(
self, cairo_programs, cairo_run_py, x, is_leaf: bool
):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
ECRECOVER_ADDRESS,
PRE_COMPILED_CONTRACTS,
)
from hypothesis import example, given
from hypothesis import Verbosity, example, given, settings
from hypothesis import strategies as st

from cairo_addons.testing.errors import cairo_error
Expand All @@ -27,6 +27,7 @@ def test_precompile_table_lookup_invalid_addresses(self, cairo_run, address_int)
assert table_address == 0

@given(address=st.sampled_from(list(PRE_COMPILED_CONTRACTS.keys())))
@settings(verbosity=Verbosity.quiet)
def test_precompile_table_lookup_hint_index_out_of_bounds(
self, cairo_programs, cairo_run_py, address
):
Expand All @@ -42,6 +43,7 @@ def test_precompile_table_lookup_hint_index_out_of_bounds(
cairo_run_py("precompile_table_lookup", address_int)

@given(address=st.sampled_from(list(PRE_COMPILED_CONTRACTS.keys())))
@settings(verbosity=Verbosity.quiet)
def test_precompile_table_lookup_hint_index_different_address(
self, cairo_programs, cairo_run_py, address
):
Expand Down
5 changes: 4 additions & 1 deletion cairo/tests/legacy/utils/test_bytes_legacy.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from hypothesis import given
from hypothesis import Verbosity, given, settings
from hypothesis.strategies import binary, integers
from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME

Expand Down Expand Up @@ -39,6 +39,7 @@ def test_should_raise_when_value_sup_31_bytes(self, cairo_run, n):
# This test checks the function fails if the % base is removed from the hint
# All values up to 256 will have the same decomposition if the it is removed
@given(n=integers(min_value=256, max_value=2**248 - 1))
@settings(verbosity=Verbosity.quiet)
def test_should_raise_when_byte_value_not_modulo_base(
self, cairo_programs, cairo_run, n
):
Expand All @@ -63,6 +64,7 @@ def test_should_raise_when_byte_value_not_modulo_base(
!= 0
)
)
@settings(verbosity=Verbosity.quiet)
def test_should_raise_when_bytes_len_is_not_minimal(
self, cairo_programs, cairo_run, n
):
Expand All @@ -76,6 +78,7 @@ def test_should_raise_when_bytes_len_is_not_minimal(
):
cairo_run("test__felt_to_bytes_little", n=n)

@settings(verbosity=Verbosity.quiet)
def test_should_raise_when_bytes_len_is_greater_than_31(
self, cairo_programs, cairo_run
):
Expand Down
6 changes: 5 additions & 1 deletion python/cairo-core/tests/src/cairo_core/test_maths.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from hypothesis import assume, given, settings
from hypothesis import Verbosity, assume, given, settings
from hypothesis import strategies as st
from starkware.cairo.lang.cairo_constants import DEFAULT_PRIME

Expand Down Expand Up @@ -81,6 +81,7 @@ def test_felt252_to_bytes_le_should_panic_on_len_too_big(
value=st.integers(min_value=1, max_value=2**248 - 1),
len_=st.integers(min_value=1, max_value=31),
)
@settings(verbosity=Verbosity.quiet)
def test_felt252_to_bytes_le_should_panic_on_wrong_output(
self, cairo_programs, cairo_run, value, len_
):
Expand All @@ -95,6 +96,7 @@ def test_felt252_to_bytes_le_should_panic_on_wrong_output(
), cairo_error(message="felt252_to_bytes_le: bad output"):
cairo_run("test__felt252_to_bytes_le", value=value, len=len_)

@settings(verbosity=Verbosity.quiet)
def test_felt252_to_bytes_le_should_panic_on_wrong_output_noncanonical(
self, cairo_programs, cairo_run
):
Expand Down Expand Up @@ -148,6 +150,7 @@ def test_felt252_to_bytes_be_should_panic_on_len_too_big(
value=st.integers(min_value=1, max_value=2**248 - 1),
len_=st.integers(min_value=1, max_value=31),
)
@settings(verbosity=Verbosity.quiet)
def test_felt252_to_bytes_be_should_panic_on_wrong_output(
self, cairo_programs, cairo_run, value, len_
):
Expand All @@ -162,6 +165,7 @@ def test_felt252_to_bytes_be_should_panic_on_wrong_output(
), cairo_error(message="felt252_to_bytes_be: bad output"):
cairo_run("test__felt252_to_bytes_be", value=value, len=len_)

@settings(verbosity=Verbosity.quiet)
def test_felt252_to_bytes_be_should_panic_on_wrong_output_noncanonical(
self, cairo_programs, cairo_run
):
Expand Down
13 changes: 12 additions & 1 deletion python/cairo-ec/tests/circuits/test_circuits.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest
from ethereum.crypto.finite_field import PrimeField
from hypothesis import assume, given
from hypothesis import Verbosity, assume, given, settings
from hypothesis import strategies as st
from sympy import sqrt_mod
from sympy.core.numbers import mod_inverse
Expand Down Expand Up @@ -49,6 +49,7 @@ class Curve(ECBase):
class TestCircuits:
class TestModOps:
@given(data=st.data())
@settings(verbosity=Verbosity.quiet)
def test_add(self, cairo_program, cairo_run, prime_cls, st_prime, data):
inputs = {"x": data.draw(st_prime), "y": data.draw(st_prime)}
values_ptr = [limb for v in inputs.values() for limb in int_to_uint384(v)]
Expand Down Expand Up @@ -84,6 +85,7 @@ def test_add(self, cairo_program, cairo_run, prime_cls, st_prime, data):
)

@given(data=st.data())
@settings(verbosity=Verbosity.quiet)
def test_sub(self, cairo_program, cairo_run, prime_cls, st_prime, data):
inputs = {"x": data.draw(st_prime), "y": data.draw(st_prime)}
values_ptr = [limb for v in inputs.values() for limb in int_to_uint384(v)]
Expand Down Expand Up @@ -119,6 +121,7 @@ def test_sub(self, cairo_program, cairo_run, prime_cls, st_prime, data):
)

@given(data=st.data())
@settings(verbosity=Verbosity.quiet)
def test_mul(self, cairo_program, cairo_run, prime_cls, st_prime, data):
inputs = {"x": data.draw(st_prime), "y": data.draw(st_prime)}
values_ptr = [limb for v in inputs.values() for limb in int_to_uint384(v)]
Expand Down Expand Up @@ -154,6 +157,7 @@ def test_mul(self, cairo_program, cairo_run, prime_cls, st_prime, data):
)

@given(data=st.data())
@settings(verbosity=Verbosity.quiet)
def test_div(self, cairo_program, cairo_run, prime, data, prime_cls):
inputs = {
"x": data.draw(st.integers(min_value=0, max_value=prime - 1)),
Expand Down Expand Up @@ -194,6 +198,7 @@ def test_div(self, cairo_program, cairo_run, prime, data, prime_cls):
)

@given(data=st.data())
@settings(verbosity=Verbosity.quiet)
def test_diff_ratio(self, cairo_program, cairo_run, prime_cls, st_prime, data):
inputs = {"x": data.draw(st_prime), "y": data.draw(st_prime)}
assume(inputs["x"] != inputs["y"])
Expand Down Expand Up @@ -233,6 +238,7 @@ def test_diff_ratio(self, cairo_program, cairo_run, prime_cls, st_prime, data):
)

@given(data=st.data())
@settings(verbosity=Verbosity.quiet)
def test_sum_ratio(self, cairo_program, cairo_run, prime_cls, st_prime, data):
inputs = {"x": data.draw(st_prime), "y": data.draw(st_prime)}
assume(inputs["x"] != -inputs["y"])
Expand Down Expand Up @@ -272,6 +278,7 @@ def test_sum_ratio(self, cairo_program, cairo_run, prime_cls, st_prime, data):
)

@given(data=st.data())
@settings(verbosity=Verbosity.quiet)
def test_inv(self, cairo_program, cairo_run, prime, data, prime_cls):
inputs = {
"x": data.draw(st.integers(min_value=1, max_value=prime - 1)),
Expand Down Expand Up @@ -312,6 +319,7 @@ def test_inv(self, cairo_program, cairo_run, prime, data, prime_cls):
)

@given(data=st.data())
@settings(verbosity=Verbosity.quiet)
def test_assert_is_quad_residue(
self, cairo_program, cairo_run, curve, data, st_prime
):
Expand Down Expand Up @@ -346,6 +354,7 @@ def test_assert_is_quad_residue(

class TestEcOps:
@given(data=st.data())
@settings(verbosity=Verbosity.quiet)
def test_ec_add(self, cairo_program, cairo_run, curve, data, st_prime):
seed_p = data.draw(st_prime)
seed_q = data.draw(st_prime)
Expand Down Expand Up @@ -388,6 +397,7 @@ def test_ec_add(self, cairo_program, cairo_run, curve, data, st_prime):
)

@given(data=st.data())
@settings(verbosity=Verbosity.quiet)
def test_ec_double(self, cairo_program, cairo_run, curve, data, st_prime):
seed_p = data.draw(st_prime)
p = curve.random_point(x=seed_p)
Expand Down Expand Up @@ -427,6 +437,7 @@ def test_ec_double(self, cairo_program, cairo_run, curve, data, st_prime):
)

@given(data=st.data())
@settings(verbosity=Verbosity.quiet)
def test_assert_is_on_curve(
self, cairo_program, cairo_run, curve, data, st_prime
):
Expand Down

0 comments on commit b47b839

Please sign in to comment.