use proptest::prelude::*;
const MAX_ACTIONS: usize = 1000;
#[derive(Debug, Clone, Copy)]
pub(super) enum GasTreeAction {
Split(usize),
SplitWithValue(usize, u64),
Spend(usize, u64),
Consume(usize),
Cut(usize, u64),
Reserve(usize, u64),
Lock(usize, u64),
Unlock(usize, u64),
SystemReserve(usize, u64),
SystemUnreserve(usize),
}
pub(super) fn gas_tree_props_test_strategy() -> impl Strategy<Value = (u64, Vec<GasTreeAction>)> {
any::<u64>()
.prop_flat_map(|max_balance| (Just(max_balance), gas_tree_action_strategy(max_balance)))
}
pub(super) fn gas_tree_action_strategy(
max_balance: u64,
) -> impl Strategy<Value = Vec<GasTreeAction>> {
let action_random_variant = (any::<usize>(), 0..max_balance).prop_flat_map(|(id, amount)| {
prop_oneof![
Just(GasTreeAction::SplitWithValue(id, amount)),
Just(GasTreeAction::Spend(id, amount)),
Just(GasTreeAction::Cut(id, amount)),
Just(GasTreeAction::Consume(id)),
Just(GasTreeAction::Split(id)),
Just(GasTreeAction::Reserve(id, amount)),
Just(GasTreeAction::Lock(id, amount)),
Just(GasTreeAction::Unlock(id, amount)),
Just(GasTreeAction::SystemReserve(id, amount)),
Just(GasTreeAction::SystemUnreserve(id))
]
});
prop::collection::vec(action_random_variant, 0..MAX_ACTIONS)
}