Skip to content

[Testing] Add property-based fuzz tests for MockEnvBuilder using arbitrary crate #789

Description

@ekelemepraise-code

Summary

The MockEnvBuilder accepts a wide range of inputs (sequence numbers, timestamps, balances) that could produce edge-case panics. Property-based testing with arbitrary would catch these before users encounter them.

Scope

Test the following properties:

  1. Sequence/Timestamp monotonicityat_sequence(u32::MAX) should not panic
  2. Account balance overflow — very large Stroops values are handled gracefully
  3. Duplicate account names — second .with_account("alice", ...) either overwrites or errors predictably
  4. Empty symbol string.with_token("", 6) fails with a clear message

Implementation

Add to contracts/crucible/src/tests.rs or a new contracts/crucible/tests/property.rs:

use arbitrary::Arbitrary;

#[derive(Arbitrary, Debug)]
struct EnvConfig {
    sequence: u32,
    timestamp: u64,
    accounts: Vec<(String, u64)>,
}

fn roundtrip(config: EnvConfig) {
    // should never panic, regardless of inputs
    let _ = MockEnv::builder()
        .at_sequence(config.sequence)
        .at_timestamp(config.timestamp)
        .build();
}

Acceptance Criteria

  • arbitrary added as dev-dependency
  • At least 5 property tests covering edge cases listed above
  • CI runs property tests with cargo test

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave program

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions