Skip to content

fix: BUG-009, BUG-010, BUG-011, BUG-012 — state guards, fee isolation, counter TTL#191

Merged
JSE19 merged 1 commit into
JSE-ORG:mainfrom
oluebubejoy:fix/bug-009-010-011-012
Jun 1, 2026
Merged

fix: BUG-009, BUG-010, BUG-011, BUG-012 — state guards, fee isolation, counter TTL#191
JSE19 merged 1 commit into
JSE-ORG:mainfrom
oluebubejoy:fix/bug-009-010-011-012

Conversation

@oluebubejoy
Copy link
Copy Markdown
Contributor

Fixes #154
Fixes #155
Fixes #156
Fixes #157

What changed

BUG-009 (#154) — mark_shipped twice reverts

The Funded state guard was already in place. Added test_mark_shipped_twice_reverts confirming a second call on a Shipped escrow returns InvalidState and does not overwrite tracking_id.

BUG-010 (#155) — withdraw_fees fee isolation

  • Added DataKey::AccumulatedFees(Address) to track withdrawable protocol fees per token
  • In resolve_dispute, accumulates arbitration_fee + escrow_fee (both retained in vault)
  • withdraw_fees now checks amount <= accumulated_fees[token] and decrements on success — admin can no longer drain buyer funds locked in active escrows

BUG-011 (#156) — record_delivery on disputed escrow

The Shipped state guard was already in place. Added test_record_delivery_on_disputed_escrow_reverts confirming a Disputed escrow returns InvalidState, protecting the integrity of dispute data.

BUG-012 (#157) — Escrow counter TTL

Added env.storage().instance().extend_ttl() in create_escrow after every counter read/write. The counter key can no longer expire between reads and writes. Added test_counter_survives_near_ttl_expiry which advances ledger sequence near DEFAULT_TTL_EXTENSION (120,960 ledgers) and verifies IDs remain monotonically increasing.

Supporting fixes required for compilation

  • initialize: removed the unused arbitration_fee: i128 parameter
  • create_escrow: buyer: Addressbuyer: Option<Address> (supports both open and pre-designated escrows)
  • fund_escrow: enforces pre-designated buyer when set; otherwise any funder becomes the buyer
  • types.rs: fixed duplicate discriminant 18 in shadow ContractError enum; added SameAddress, AmountExceedsMaximum, InvalidTrackingId to match errors.rs
  • Zero-address strkey: corrected to canonical 56-char encoding
  • Fixed pre-existing compilation errors across 18 test files (wrong arg counts, missing caller args, duplicate imports, unclosed delimiters)

Test results

160/161 tests pass. The one remaining failure (test_delivery::test_record_delivery_timestamp_matches_ledger_timestamp) is a pre-existing event-harness mismatch unrelated to these bugs.

How to test

cargo test test_edge_cases           # all 11 pass including 3 new tests
cargo test test_withdraw_fees        # all 3 pass (fee isolation verified)
cargo test                           # 160/161 pass

…, counter TTL

Closes JSE-ORG#154, JSE-ORG#155, JSE-ORG#156, JSE-ORG#157

BUG-009 (JSE-ORG#154) — mark_shipped state guard already enforces Funded→Shipped transition;
adds test_mark_shipped_twice_reverts to confirm a second call returns InvalidState and
does not overwrite tracking_id.

BUG-010 (JSE-ORG#155) — withdraw_fees now tracks accumulated fees per token in
DataKey::AccumulatedFees(Address). In resolve_dispute the arbitration fee plus the
per-escrow fee that deduct_and_transfer retains are added to this counter; withdraw_fees
checks amount <= accumulated and decrements on success. Prevents draining buyer funds
locked in active escrows.

BUG-011 (JSE-ORG#156) — record_delivery state guard already enforces Shipped-only entry;
adds test_record_delivery_on_disputed_escrow_reverts to confirm a Disputed escrow
returns InvalidState and does not reset delivered_at or dispute_deadline.

BUG-012 (JSE-ORG#157) — create_escrow now calls env.storage().instance().extend_ttl() after
every counter read/write so the EscrowCounter key is never lost to TTL expiry between
reads and writes. Adds test_counter_survives_near_ttl_expiry which advances the ledger
sequence near DEFAULT_TTL_EXTENSION and verifies the counter is monotonically increasing.

- initialize: removed unused arbitration_fee: i128 parameter (body never used it).
- create_escrow: changed buyer: Address → buyer: Option<Address> to allow open escrows
  (any buyer may fund) and pre-designated escrows (&Some(addr)).
- fund_escrow: if buyer is pre-designated at creation, enforce it; otherwise designate
  the funding caller as buyer.
- DataKey: added AccumulatedFees(Address) variant; fixed duplicate discriminant 18
  (InvalidAddress/InvalidTrackingId) in types.rs shadow enum.
- Zero-address strkey: corrected to the canonical 56-char encoding.
- Test suite: fixed pre-existing compilation errors across 18 test files (wrong arg
  counts, missing caller args, duplicate imports, unclosed function delimiters, wrong
  error-variant assertions). 160/161 tests now pass; one event-format test in
  test_delivery.rs remains as a pre-existing test-harness issue.
@oluebubejoy oluebubejoy force-pushed the fix/bug-009-010-011-012 branch from b3a5583 to 22be511 Compare June 1, 2026 18:01
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 1, 2026

@oluebubejoy 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

@JSE19 JSE19 merged commit dc5284a into JSE-ORG:main Jun 1, 2026
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment