Skip to main content

arkhe_runtime_testkit/
arbitrary.rs

1//! `proptest::Arbitrary` impl for Runtime primitive types.
2//!
3//! Cover each type's value domain precisely — spec boundary values
4//! (TypeCode range boundary / BoundedString N limit / Tick monotone)
5//! are injected directly into the fuzz path.
6
7use proptest::prelude::*;
8
9use arkhe_forge_core::typecode;
10
11/// Core Component TypeCode range strategy — `0x0003_0000..=0x0003_0EFF`.
12pub fn core_component_typecode() -> impl Strategy<Value = u32> {
13    typecode::CORE_COMPONENT.0..=typecode::CORE_COMPONENT.1
14}
15
16/// Core Event TypeCode range strategy — `0x0003_0F00..=0x0003_FFFF`.
17pub fn core_event_typecode() -> impl Strategy<Value = u32> {
18    typecode::CORE_EVENT.0..=typecode::CORE_EVENT.1
19}
20
21/// Canonical Activity verb range strategy — `0x0002_0001..=0x0002_03FF`.
22pub fn canonical_verb_typecode() -> impl Strategy<Value = u32> {
23    typecode::CORE_VERB_CANONICAL.0..=typecode::CORE_VERB_CANONICAL.1
24}
25
26/// Shell-scoped TypeCode strategy — used by the `shell_id` brand fuzz suite.
27pub fn shell_scoped_typecode() -> impl Strategy<Value = u32> {
28    typecode::SHELL_SCOPED.0..=typecode::SHELL_SCOPED.1
29}
30
31/// Tick value strategy — fuzz the full u64 domain.
32pub fn tick_value() -> impl Strategy<Value = u64> {
33    0u64..=u64::MAX
34}
35
36/// NonZeroU64 entity id strategy — inherits L0 A6.
37pub fn entity_id_nz() -> impl Strategy<Value = core::num::NonZeroU64> {
38    (1u64..=u64::MAX).prop_map(|v| {
39        // 1..=u64::MAX guarantees NonZeroU64::new returns Some — safe path.
40        core::num::NonZeroU64::new(v).unwrap_or(core::num::NonZeroU64::MIN)
41    })
42}