Skip to content

Commit

Permalink
Merge pull request #3468 from wenceslas-sanchez/dev
Browse files Browse the repository at this point in the history
🐛 Fix redundant SSZ generic tests
  • Loading branch information
hwwhww committed Aug 4, 2023
2 parents 36d9ea6 + 522ab42 commit 8d6a405
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
28 changes: 17 additions & 11 deletions tests/generators/ssz_generic/ssz_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ class BitsStruct(Container):
E: Bitvector[8]


def container_case_fn(rng: Random, mode: RandomizationMode, typ: Type[View]):
def container_case_fn(rng: Random, mode: RandomizationMode, typ: Type[View], chaos: bool=False):

This comment has been minimized.

Copy link
@GH0STFVCE

GH0STFVCE Aug 6, 2023

Locate (address) and wormhole

return get_random_ssz_object(rng, typ,
max_bytes_length=2000,
max_list_length=2000,
mode=mode, chaos=False)
mode=mode, chaos=chaos)


PRESET_CONTAINERS: Dict[str, Tuple[Type[View], Sequence[int]]] = {
Expand All @@ -68,17 +68,23 @@ def valid_cases():
for (name, (typ, offsets)) in PRESET_CONTAINERS.items():
for mode in [RandomizationMode.mode_zero, RandomizationMode.mode_max]:
yield f'{name}_{mode.to_name()}', valid_test_case(lambda: container_case_fn(rng, mode, typ))
random_modes = [RandomizationMode.mode_random, RandomizationMode.mode_zero, RandomizationMode.mode_max]
if len(offsets) != 0:
random_modes.extend([RandomizationMode.mode_nil_count,
RandomizationMode.mode_one_count,
RandomizationMode.mode_max_count])
for mode in random_modes:
for variation in range(10):
yield f'{name}_{mode.to_name()}_{variation}', \
valid_test_case(lambda: container_case_fn(rng, mode, typ))

if len(offsets) == 0:
modes = [RandomizationMode.mode_random, RandomizationMode.mode_zero, RandomizationMode.mode_max]
else:
modes = list(RandomizationMode)

for mode in modes:
for variation in range(3):
yield f'{name}_{mode.to_name()}_chaos_{variation}', \
valid_test_case(lambda: container_case_fn(rng, mode, typ, chaos=True))
# Notes: Below is the second wave of iteration, and only the random mode is selected
# for container without offset since ``RandomizationMode.mode_zero`` and ``RandomizationMode.mode_max``
# are deterministic.
modes = [RandomizationMode.mode_random] if len(offsets) == 0 else list(RandomizationMode)
for mode in modes:
for variation in range(10):
yield f'{name}_{mode.to_name()}_{variation}', \
valid_test_case(lambda: container_case_fn(rng, mode, typ))


Expand Down
9 changes: 6 additions & 3 deletions tests/generators/ssz_generic/ssz_uints.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ def uint_case_fn(rng: Random, mode: RandomizationMode, typ: Type[BasicView]):
def valid_cases():
rng = Random(1234)
for uint_type in UINT_TYPES:
mode = RandomizationMode.mode_random
byte_len = uint_type.type_byte_length()
yield f'uint_{byte_len * 8}_last_byte_empty', \
valid_test_case(lambda: uint_type((2 ** ((byte_len - 1) * 8)) - 1))
for variation in range(5):
for mode in [RandomizationMode.mode_random, RandomizationMode.mode_zero, RandomizationMode.mode_max]:
yield f'uint_{byte_len * 8}_{mode.to_name()}_{variation}', \
valid_test_case(lambda: uint_case_fn(rng, mode, uint_type))
yield f'uint_{byte_len * 8}_{mode.to_name()}_{variation}', \
valid_test_case(lambda: uint_case_fn(rng, mode, uint_type))
for mode in [RandomizationMode.mode_zero, RandomizationMode.mode_max]:
yield f'uint_{byte_len * 8}_{mode.to_name()}', \
valid_test_case(lambda: uint_case_fn(rng, mode, uint_type))


def invalid_cases():
Expand Down

0 comments on commit 8d6a405

Please sign in to comment.