Skip to content

Commit e32d558

Browse files
Refactor progressive list tests to only include supported operations
Co-authored-by: michaelsproul <4452260+michaelsproul@users.noreply.github.com>
1 parent 64b80f8 commit e32d558

File tree

1 file changed

+23
-63
lines changed

1 file changed

+23
-63
lines changed

src/tests/proptest/operations.rs

Lines changed: 23 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -198,50 +198,32 @@ where
198198
}
199199

200200
/// Strategy for generating operations for ProgressiveList.
201-
/// Since ProgressiveList has no length limit, we use a fixed index range.
202-
fn arb_op_progressive<'a, T, S>(strategy: &'a S, n: usize) -> impl Strategy<Value = Op<T>> + 'a
201+
/// Only includes operations that are currently implemented for ProgressiveList.
202+
fn arb_op_progressive<'a, T, S>(strategy: &'a S) -> impl Strategy<Value = Op<T>> + 'a
203203
where
204204
T: Debug + Clone + 'a,
205205
S: Strategy<Value = T> + 'a,
206206
{
207-
// For ProgressiveList, we mainly want to test push, len, iter, and tree_hash
208-
// since get, set, iter_from, pop_front, etc. are not implemented yet.
209-
let a_block = prop_oneof![
207+
// Only include operations that are currently implemented for ProgressiveList:
208+
// Len, Push, Iter, TreeHash, and Debase (SSZ roundtrip)
209+
prop_oneof![
210210
Just(Op::Len),
211-
arb_index(n).prop_map(Op::Get),
212-
(arb_index(n), strategy).prop_map(|(index, value)| Op::Set(index, value)),
213-
(arb_index(n), strategy).prop_map(|(index, value)| Op::SetCowWithIntoMut(index, value)),
214-
(arb_index(n), strategy).prop_map(|(index, value)| Op::SetCowWithMakeMut(index, value)),
215211
strategy.prop_map(Op::Push),
216212
Just(Op::Iter),
217-
arb_index(n).prop_map(Op::IterFrom),
218-
arb_index(n).prop_map(Op::PopFront),
219-
Just(Op::ApplyUpdates),
220-
];
221-
let b_block = prop_oneof![
222213
Just(Op::TreeHash),
223-
Just(Op::Checkpoint),
224-
Just(Op::Rebase),
225214
Just(Op::Debase),
226-
Just(Op::FromIntoRoundtrip),
227-
Just(Op::IntraRebase),
228-
];
229-
prop_oneof![
230-
10 => a_block,
231-
6 => b_block
232215
]
233216
}
234217

235218
fn arb_ops_progressive<'a, T, S>(
236219
strategy: &'a S,
237-
n: usize,
238220
limit: usize,
239221
) -> impl Strategy<Value = Vec<Op<T>>> + 'a
240222
where
241223
T: Debug + Clone + 'a,
242224
S: Strategy<Value = T> + 'a,
243225
{
244-
proptest::collection::vec(arb_op_progressive(strategy, n), 1..limit)
226+
proptest::collection::vec(arb_op_progressive(strategy), 1..limit)
245227
}
246228

247229
fn apply_ops_progressive_list<T>(
@@ -251,63 +233,40 @@ fn apply_ops_progressive_list<T>(
251233
) where
252234
T: Value + Debug + Send + Sync,
253235
{
254-
let mut checkpoint = list.clone();
255-
256236
for op in ops {
257237
match op {
258238
Op::Len => {
259239
assert_eq!(list.len(), spec.len());
260240
}
261-
Op::Get(_) => {
262-
// No-op: ProgressiveList doesn't implement get yet
263-
}
264-
Op::Set(_, _) => {
265-
// No-op: ProgressiveList doesn't implement set yet
266-
}
267-
Op::SetCowWithIntoMut(_, _) => {
268-
// No-op: ProgressiveList doesn't implement set yet
269-
}
270-
Op::SetCowWithMakeMut(_, _) => {
271-
// No-op: ProgressiveList doesn't implement set yet
272-
}
273241
Op::Push(value) => {
274242
list.push(value.clone()).expect("push should succeed");
275243
spec.push(value);
276244
}
277245
Op::Iter => {
278246
assert!(list.iter().eq(spec.iter()));
279247
}
280-
Op::IterFrom(_) => {
281-
// No-op: ProgressiveList doesn't implement iter_from yet
282-
}
283-
Op::PopFront(_) => {
284-
// No-op: ProgressiveList doesn't implement pop_front yet
285-
}
286-
Op::ApplyUpdates => {
287-
// No-op: ProgressiveList doesn't have apply_updates
288-
}
289-
Op::Checkpoint => {
290-
checkpoint = list.clone();
291-
}
292248
Op::TreeHash => {
293249
list.tree_hash_root();
294250
}
295-
Op::Rebase => {
296-
// No-op: ProgressiveList doesn't implement rebase yet
297-
let _ = &checkpoint;
298-
}
299251
Op::Debase => {
300252
let ssz_bytes = list.as_ssz_bytes();
301253
let new_list = ProgressiveList::from_ssz_bytes(&ssz_bytes).expect("SSZ decode");
302254
assert_eq!(new_list, *list);
303255
*list = new_list;
304256
}
305-
Op::FromIntoRoundtrip => {
306-
// No-op: No corresponding Vector type for ProgressiveList
307-
}
308-
Op::IntraRebase => {
309-
// No-op: ProgressiveList doesn't implement intra_rebase yet
310-
}
257+
// These operations are not implemented for ProgressiveList yet and
258+
// are not generated by arb_op_progressive, but we handle them for completeness.
259+
Op::Get(_)
260+
| Op::Set(_, _)
261+
| Op::SetCowWithIntoMut(_, _)
262+
| Op::SetCowWithMakeMut(_, _)
263+
| Op::IterFrom(_)
264+
| Op::PopFront(_)
265+
| Op::ApplyUpdates
266+
| Op::Checkpoint
267+
| Op::Rebase
268+
| Op::FromIntoRoundtrip
269+
| Op::IntraRebase => {}
311270
}
312271
}
313272
}
@@ -632,8 +591,9 @@ mod vect {
632591
vect_test!(large_1024, Large, U1024, arb_large());
633592
}
634593

635-
/// Maximum length for progressive list tests.
636-
/// We use smaller sizes than the regular list tests since progressive lists can grow unbounded.
594+
/// Maximum initial length for progressive list tests.
595+
/// This is used to cap the initial list size for reasonable test execution time.
596+
/// Compare to list tests which can use up to 1024 elements (U1024).
637597
const PROGRESSIVE_LIST_MAX_LEN: usize = 128;
638598

639599
macro_rules! progressive_list_test {
@@ -646,7 +606,7 @@ macro_rules! progressive_list_test {
646606
#[test]
647607
fn $name(
648608
init in arb_progressive_list::<$T, _>(&$strat, PROGRESSIVE_LIST_MAX_LEN),
649-
ops in arb_ops_progressive::<$T, _>(&$strat, PROGRESSIVE_LIST_MAX_LEN, OP_LIMIT)
609+
ops in arb_ops_progressive::<$T, _>(&$strat, OP_LIMIT)
650610
) {
651611
let mut list = ProgressiveList::<$T>::try_from_iter(init.clone()).unwrap();
652612
let mut spec = ProgressiveSpec::<$T>::new(init);

0 commit comments

Comments
 (0)