Skip to content

Commit 649c448

Browse files
committed
Reduce test count by focusing on edge cases instead of exhaustiveness
1 parent 1080d11 commit 649c448

File tree

1 file changed

+22
-12
lines changed

1 file changed

+22
-12
lines changed

tests/generators/runners/ssz_generic_cases/ssz_compatible_union.py

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -101,22 +101,33 @@ def invalid_cases():
101101
for name, typ in PRESET_COMPATIBLE_UNIONS.items():
102102
options = typ.options()
103103

104+
# Focus testing on edge cases
105+
unsupported_options_of_interest = {0, 128, 129, 254, 255}
106+
if 127 not in options:
107+
unsupported_options_of_interest.add(127)
108+
for option in options:
109+
for modifier in (-2, -1, 1, 2):
110+
candidate = int(option) + modifier
111+
if candidate >= 0 and candidate not in options:
112+
unsupported_options_of_interest.add(candidate)
113+
unsupported_options_of_interest = sorted(unsupported_options_of_interest)
114+
104115
# No selector and no data. Always invalid
105116
yield (
106117
f"{name}_empty",
107118
invalid_test_case(typ, lambda: b""),
108119
)
109120

110121
# Only selector without any data. Always invalid
111-
for option in range(0, 255):
122+
for option in list(options.keys()) + unsupported_options_of_interest:
112123
yield (
113124
f"{name}_selector_{option}_none",
114125
invalid_test_case(typ, lambda option=option: bytes([option])),
115126
)
116127

117128
for mode in list(RandomizationMode):
118129
# Valid selector but with data from different type option. Not guaranteed to invalidate if data accidentally compatible
119-
for option_a, option_b in permutations(options, 2):
130+
for option_a, option_b in permutations(options.keys(), 2):
120131
elem_type_b = options[option_b]
121132

122133
def the_test(rng, mode=mode, typ=typ, elem_type_b=elem_type_b, option_a=option_a):
@@ -137,18 +148,17 @@ def the_test(rng, mode=mode, typ=typ, elem_type_b=elem_type_b, option_a=option_a
137148
)
138149

139150
# Unsupported type option. Always invalid
140-
for option in range(0, 255):
141-
if option not in options:
151+
for option in unsupported_options_of_interest:
142152

143-
def the_test(rng, mode=mode, typ=typ, option=option):
144-
serialized = serialize(container_case_fn(rng, mode, typ))
145-
serialized = bytes([option]) + serialized[1:]
146-
return serialized
153+
def the_test(rng, mode=mode, typ=typ, option=option):
154+
serialized = serialize(container_case_fn(rng, mode, typ))
155+
serialized = bytes([option]) + serialized[1:]
156+
return serialized
147157

148-
yield (
149-
f"{name}_{mode.to_name()}_selector_{option}_invalid",
150-
invalid_test_case(typ, the_test, rng),
151-
)
158+
yield (
159+
f"{name}_{mode.to_name()}_selector_{option}_invalid",
160+
invalid_test_case(typ, the_test, rng),
161+
)
152162

153163
# Extra byte between selector and data. Not guaranteed to invalidate for variable length data types
154164
def the_test(

0 commit comments

Comments
 (0)