Skip to content

Add tests for create_contract bounds (MAX_MILESTONES and MAX_TOTAL_ESCROW_STROOPS) #329

@mikewheeleer

Description

@mikewheeleer

Description

create_contract enforces TooManyMilestones when milestone_amounts.len() > MAX_MILESTONES (10), InvalidMilestoneAmount for non-positive amounts or totals over MAX_TOTAL_ESCROW_STROOPS, and PotentialOverflow via safe_add_amounts. The orphaned test_bounds.rs covers some of this but is not compiled. Add wired tests for all bounds.

Requirements and context

  • Scoped to TalentTrust escrow Soroban contract (contracts/escrow).
  • Assert: exactly 10 milestones succeeds; 11 panics TooManyMilestones; zero/negative milestone panics InvalidMilestoneAmount; total over MAX_TOTAL_ESCROW_STROOPS panics; near-i128::MAX amounts panic PotentialOverflow.
  • Assert InvalidParticipant when client == freelancer and EmptyMilestones for an empty vector.
  • Acceptance: each guard in create_contract has a dedicated case.
  • Must be secure, tested, and documented.

Suggested execution

  • Fork the repo and create a branch:
    • git checkout -b test/create-contract-bounds
  • Implement changes:
    • contracts/escrow/src/test/milestone_schedule.rs
    • Tests: contracts/escrow/src/test/milestone_schedule.rs
    • Docs: docs/escrow/milestone-validation.md
    • Include rustdoc/NatSpec-style doc comments on public functions
    • Validate security assumptions (auth, overflow, fail-closed state machine, storage TTL, fee accounting)

Test and commit

  • Run tests: cargo test
  • Cover edge cases (unauthorized callers, double release/refund, expired approvals, fee rounding, paused state)
  • Include test output and security notes in the PR

Example commit message

test(escrow): cover create_contract bounds and overflow

Guidelines

  • Minimum 95% test coverage on new/changed code
  • Clear documentation
  • Timeframe: 96 hours from assignment

Metadata

Metadata

Type

No fields configured for Task.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions