-
Notifications
You must be signed in to change notification settings - Fork 134
Closed
Labels
Beta-CampaignCampaign: Beta-CampaignCampaign: Beta-Campaigngood first issueGood for newcomersGood for newcomerssoroban-contract
Description
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:
-
test_create_escrow_success— happy path:- Sets up a token contract with 10,000 tokens minted to the depositor
- Calls
create_escrowwithamount = 5_000,release_after = 0 - Asserts the returned
Escrowstruct has correctdepositor,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
-
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)
- Creates one escrow with id
-
test_create_escrow_zero_amount_fails— guard: zero amount rejected:- Calls
create_escrowwithamount = 0 - Expects panic
"Error(Contract, #11)"(InvalidAmount)
- Calls
Files to Modify
contracts/payment_escrow/src/test.rs
Acceptance Criteria
-
test_create_escrow_successchecks all escrow fields and both token balances -
test_create_escrow_duplicate_id_failsuses#[should_panic(expected = "Error(Contract, #5)")] -
test_create_escrow_zero_amount_failsuses#[should_panic(expected = "Error(Contract, #11)")] -
cargo test -p payment_escrowruns 5 tests, all pass -
cargo clippy -p payment_escrow -- -D warningspasses
Technical Notes
- Check token balances with
TokenClient::new(&env, &token).balance(&address) - The contract address (second argument to
TokenClient::balance) is thecontract_idreturned bysetup_contract - String literals in Soroban tests:
String::from_str(&env, "esc-001") - All
create_escrowargs are passed by reference:&depositor,&String::from_str(...),&beneficiary,&5_000i128,&String::from_str(...),&0u64
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Beta-CampaignCampaign: Beta-CampaignCampaign: Beta-Campaigngood first issueGood for newcomersGood for newcomerssoroban-contract