Skip to content

Issue #7 — Escrow Creation Tests #591

@yusuftomilola

Description

@yusuftomilola

With helpers in place, the next set of tests validates the core escrow creation flow: the happy path where funds are locked correctly, and two guard cases that reject invalid input before any tokens move. These tests prove the contract correctly snapshots the dispute window at creation time and maintains both the depositor and beneficiary indexes.

Task

Building on the test file from Issue #1, add the following three tests to contracts/payment_escrow/src/test.rs:

  1. test_create_escrow_success — happy path:

    • Sets up a token contract with 10,000 tokens minted to the depositor
    • Calls create_escrow with amount = 5_000, release_after = 0
    • Asserts the returned Escrow struct has correct depositor, beneficiary, amount, status = Pending, dispute_window = DISPUTE_WINDOW, release_after = 0
    • Asserts the contract's token balance is 5_000 (funds moved in)
    • Asserts the depositor's remaining balance is 5_000
  2. test_create_escrow_duplicate_id_fails — guard: duplicate ID rejected:

    • Creates one escrow with id "esc-001"
    • Tries to create a second escrow with the same id
    • Expects panic "Error(Contract, #5)" (EscrowAlreadyExists)
  3. test_create_escrow_zero_amount_fails — guard: zero amount rejected:

    • Calls create_escrow with amount = 0
    • Expects panic "Error(Contract, #11)" (InvalidAmount)

Files to Modify

  • contracts/payment_escrow/src/test.rs

Acceptance Criteria

  • test_create_escrow_success checks all escrow fields and both token balances
  • test_create_escrow_duplicate_id_fails uses #[should_panic(expected = "Error(Contract, #5)")]
  • test_create_escrow_zero_amount_fails uses #[should_panic(expected = "Error(Contract, #11)")]
  • cargo test -p payment_escrow runs 5 tests, all pass
  • cargo clippy -p payment_escrow -- -D warnings passes

Technical Notes

  • Check token balances with TokenClient::new(&env, &token).balance(&address)
  • The contract address (second argument to TokenClient::balance) is the contract_id returned by setup_contract
  • String literals in Soroban tests: String::from_str(&env, "esc-001")
  • All create_escrow args are passed by reference: &depositor, &String::from_str(...), &beneficiary, &5_000i128, &String::from_str(...), &0u64

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions