Skip to content

Wandoo - #1430

Merged
Wilfred007 merged 17 commits into
Gildado:mainfrom
wandooadzer-cmyk:Wandoo
Aug 17, 2026
Merged

Wandoo#1430
Wilfred007 merged 17 commits into
Gildado:mainfrom
wandooadzer-cmyk:Wandoo

Conversation

@wandooadzer-cmyk

Copy link
Copy Markdown
Contributor

Summary

Fixes the escrow settlement gap in cross_asset_payment where update_status could mark a payment as "complete" or "failed" without transferring escrowed funds, permanently locking them in the contract.

What Changed

  • Contract (lib.rs): Added missing UpgradeVersionUnchanged error variant and PAYMENT_TIMEOUT_LEDGERS constant that prevented compilation
  • State Machine (lib.rs): Restricted validate_status_transition so update_status can only advance payments to process. Terminal transitions (complete/failed) must go through complete_payment/fail_payment which transfer escrowed funds as part of the state change
  • Tests (test.rs): Updated 19 existing tests that relied on update_status to reach terminal states — they now use complete_payment/fail_payment
  • Tests (test_escrow.rs): Added 5 new settlement tests covering happy-path settlement, double-settlement prevention, settlement-after-cancellation blocking, update_status bypass prevention, and exhaustive state exit-path coverage

Testing

cargo test -p cross_asset_payment --target aarch64-apple-darwin

86 tests passing (81 existing + 5 new), 0 failures.

New tests:

  • test_settle_happy_path_transfers_funds_to_recipient — funds move to recipient on settlement
  • test_double_settlement_prevented — second complete_payment call blocked
  • test_settle_after_fail_is_blocked — settlement blocked after refund
  • test_update_status_cannot_bypass_settlementupdate_status cannot reach terminal states
  • test_every_payment_state_has_exit_path — all 5 paths (pending→complete, pending→process→complete, pending→failed, pending→process→failed, pending→expired) resolve escrow

Documentation

N/A

Checklist

  • I added or updated tests for the change.
  • I updated documentation where needed, or explained why it was not needed.
  • If this change touches the UI, I verified responsive behavior and accessibility.

Accessibility / Responsiveness

N/A — contract-only change, no UI impact.

Closes #446

Notes

Breaking change: update_status can no longer transition payments directly to complete or failed. Any off-chain code or admin tooling that relied on update_status for terminal transitions must switch to complete_payment (for settlement) or fail_payment (for refunds). The pending → process transition via update_status is unchanged.

wandooadzer-cmyk added 9 commits August 16, 2026 13:30
…ariant and PAYMENT_TIMEOUT_LEDGERS constant

The mark_upgrade function referenced CrossAssetPaymentError::UpgradeVersionUnchanged
which was not defined in the error enum, causing a compilation error. Similarly,
initiate_payment used PAYMENT_TIMEOUT_LEDGERS which was never defined.

- Add UpgradeVersionUnchanged = 17 to CrossAssetPaymentError enum
- Add PAYMENT_TIMEOUT_LEDGERS constant (17,280 ledgers ≈ 24 hours at 5s intervals)
…sitions

Previously, update_status could transition a payment directly to 'complete'
or 'failed' without moving escrowed funds. This created dead-end states where
funds were permanently locked — neither settled to the recipient nor refunded
to the sender.

Now update_status only allows pending → process. Terminal transitions
(complete/failed) must go through complete_payment/fail_payment which
transfer escrowed funds as part of the state change.

This closes the gap where a payment could reach a terminal status with
funds still locked in the contract.
… machine

Update 19 tests that relied on update_status to reach terminal states
(complete/failed). These tests now use complete_payment and fail_payment
which are the correct entry points for terminal transitions.

Affected tests:
- Valid transition tests now use complete_payment/fail_payment
- Invalid transition tests reach terminal via settlement functions
- Double-transition tests use try_complete_payment/try_fail_payment
- State machine and amount tests use proper settlement paths
- Admin transfer test fixed to use valid 'process' status
…elease

Add 5 new tests covering the settlement flow:
- test_settle_happy_path_transfers_funds_to_recipient: verifies funds move
- test_double_settlement_prevented: second settle blocked after first
- test_settle_after_fail_is_blocked: settle blocked after refund
- test_update_status_cannot_bypass_settlement: update_status cannot reach
  terminal states, funds remain safely locked until proper settlement
- test_every_payment_state_has_exit_path: all 5 state paths (pending→complete,
  pending→process→complete, pending→failed, pending→process→failed,
  pending→expired) resolve escrowed funds

Total: 86 tests passing (81 existing + 5 new)
- Add dev-dist to globalIgnores to skip generated workbox files
- Fix syntax error in helpers.ts (STANDALONE passphrase → STANDALONE_PASSPHRASE)
- Remove unused imports: beforeEach, hash, ContractSpec
- Remove unused variables: simUpload, returnVal, isClearingCache, handleClearOfflineData, completedStepIndex
- Add AuthResponse type to Login.tsx to replace unsafe any from response.json()
- Wrap async onSubmit/onClick handlers with void to fix no-misused-promises
- Add vitest.sdk.config.ts to tsconfig.eslint.json includes
- Disable no-redundant-type-constituents for test files (SDK TransactionResponse type)
stellar-cli 27.1.0 requires rustc 1.93.0 but CI runners have rustc 1.89.0.
Pin to 25.2.0 which supports the current rustc version.
Run prettier --write to resolve all formatting inconsistencies.
…and fix i18n mocks

- Add src/__tests__/sdk/** to vitest exclude list (SDK tests need live
  Stellar network, run separately via vitest.sdk.config.ts)
- Add initReactI18next to react-i18next mocks in Settings, PayrollScheduler,
  and SettingsErrorIsolation tests (required by src/i18n.ts import)
Tests expected translated button text ('Download QR', 'Print QR') but
the component uses translation keys. Added useTranslation mock with the
required walletQr.* translations.
@Wilfred007

Copy link
Copy Markdown
Collaborator

Kindly check failing checks @wandooadzer-cmyk thank you

wandooadzer-cmyk added 8 commits August 17, 2026 09:00
- Add global react-i18next mock in setup.ts that loads English translations
  from en/translation.json and handles fallback parameters
- Export I18nextProvider and Trans from the mock for tests that use them
- Add useAuth and useWallet mocks to Login.test.tsx
- Add @tanstack/react-query mock to BulkPayrollUpload.test.tsx

Reduces test failures from 88 to 14 (remaining are pre-existing structural
issues in component assertions).
- Add extern crate std for catch_unwind support
- Replace cpu_instruction_count/memory_bytes_count with
  cpu_instruction_cost/memory_bytes_cost (SDK API change)
- Replace env.ledger().set(n) with env.ledger().set_sequence_number(n)
- Replace std::panic::catch_unwind with client.try_execute_batch
- Fix p2 variable reference to payments3
- Fix weekly/monthly limit tests to advance ledger sequence properly
  (daily limit requires 17,280 ledgers between resets)

All194 tests passing.
Add PendingAdmin and StateVersion to DataKey enum, and
NoPendingAdminTransfer/NotProposedAdmin to ContractError enum.
These were referenced in the admin transfer logic but never defined,
causing compilation failure.
The verify-build job had no prior build step, so -s caused all
contracts to fail with 'WASM artifact not found'. Let the verify
script build the contracts itself.
stellar CLI v25+ builds to wasm32v1-none instead of wasm32-unknown-unknown.
Update verify_contract.sh and verify.yml to auto-detect the correct
WASM output directory.
@Wilfred007
Wilfred007 merged commit 11c4a25 into Gildado:main Aug 17, 2026
5 checks passed
@Wilfred007

Copy link
Copy Markdown
Collaborator

Thank you @wandooadzer-cmyk for your contributions

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.

#149: Implement Search Query for Employees API

2 participants