Skip to content

test(escrow): enforce non-zero escrow amount tests (#95)#224

Open
Mikkelnice wants to merge 1 commit into
DelegoLabs:mainfrom
Mikkelnice:feat/95-enforce-non-zero-escrow-amount
Open

test(escrow): enforce non-zero escrow amount tests (#95)#224
Mikkelnice wants to merge 1 commit into
DelegoLabs:mainfrom
Mikkelnice:feat/95-enforce-non-zero-escrow-amount

Conversation

@Mikkelnice

@Mikkelnice Mikkelnice commented Jun 25, 2026

Copy link
Copy Markdown

Summary

Closes #95

The validation guard (amount <= 0InvalidAmount) was already implemented in deposit. This PR adds the missing tests required by the acceptance criteria.

Changes

  • contracts/escrow/src/integration_tests.rs: added three tests
    • test_deposit_zero_amount_rejected — zero amount returns InvalidAmount
    • test_deposit_negative_amount_rejected — negative amount returns InvalidAmount
    • test_deposit_valid_amount_succeeds — positive amount deposits successfully

Testing

All three paths (zero, negative, valid) are covered by the new contract tests.

Summary by CodeRabbit

  • Tests
    • Added coverage for escrow deposit amount validation.
    • Confirmed zero and negative deposits are rejected with an invalid amount error.
    • Verified valid deposits succeed, return the expected escrow ID, and credit the escrow account correctly.

@drips-wave

drips-wave Bot commented Jun 25, 2026

Copy link
Copy Markdown

@Mikkelnice Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@coderabbitai

coderabbitai Bot commented Jun 25, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

Adds integration test coverage for escrow deposit amount validation: zero and negative deposits are rejected with InvalidAmount, and a positive deposit succeeds and updates the escrow balance.

Changes

Escrow deposit validation tests

Layer / File(s) Summary
Deposit amount validation tests
contracts/escrow/src/integration_tests.rs
Adds coverage for zero and negative deposit rejection and verifies a valid positive deposit returns escrow id 1 and credits the escrow token balance.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Possibly related PRs

Suggested labels

size/S

Poem

A bunny peeks at escrow land,
Zero and minus? No, not grand.
A hop of one makes balances bloom,
Token bits dance around the room.
Thump-thump—valid deposits feel just right.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR adds tests, but it does not implement the required escrow amount validation in contracts/escrow/src/lib.rs. Add the zero/negative amount guard at the start of the escrow creation flow in lib.rs, then keep the positive-amount behavior and tests.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the added escrow amount validation tests.
Out of Scope Changes check ✅ Passed The changes stay within escrow contract testing and align with the issue scope.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
contracts/escrow/src/integration_tests.rs (1)

291-325: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider asserting no side effects on rejection.

Issue #95 requires zero/negative amounts to be rejected before any state writes or token transfers occur. These tests only assert the returned error; they don't verify that no escrow was created and the escrow contract's token balance stayed 0. Adding those assertions would actually exercise the "before any state writes" requirement rather than just the error code.

♻️ Example assertion to add after each rejection
    let token_client = soroban_sdk::token::Client::new(&t.env, &t.token_contract_id);
    assert_eq!(token_client.balance(&t.escrow_contract_id), 0);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@contracts/escrow/src/integration_tests.rs` around lines 291 - 325, Add
side-effect checks to the rejection tests in test_deposit_zero_amount_rejected
and test_deposit_negative_amount_rejected: after calling
EscrowContractClient::try_deposit, assert that no escrow state was created and
that the escrow contract’s token balance remains 0. Use the existing TestEnv
setup and EscrowContractClient flow, and verify the token balance through the
token client so these tests cover rejection before any writes or transfers
happen.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@contracts/escrow/src/integration_tests.rs`:
- Around line 291-325: Add side-effect checks to the rejection tests in
test_deposit_zero_amount_rejected and test_deposit_negative_amount_rejected:
after calling EscrowContractClient::try_deposit, assert that no escrow state was
created and that the escrow contract’s token balance remains 0. Use the existing
TestEnv setup and EscrowContractClient flow, and verify the token balance
through the token client so these tests cover rejection before any writes or
transfers happen.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: fca3aeed-1df7-493d-8b64-bfa179165ffd

📥 Commits

Reviewing files that changed from the base of the PR and between c6dd0d9 and f264cb1.

📒 Files selected for processing (1)
  • contracts/escrow/src/integration_tests.rs

@ScriptedBro

Copy link
Copy Markdown
Contributor

Fix conflicts

@ScriptedBro

Copy link
Copy Markdown
Contributor

Resolve conflicts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Soroban/Escrow] Enforce Non-Zero Escrow Amount

2 participants