Skip to content

feat: testable asset mocks and robust Friendbot error handling - #155

Merged
akargi merged 5 commits into
Chulilee:mainfrom
akargi:feature/asset-mock-config-and-friendbot-errors
Nov 2, 2026
Merged

akargi merged 5 commits into
Chulilee:mainfrom
akargi:feature/asset-mock-config-and-friendbot-errors

Conversation

@akargi

@akargi akargi commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

Summary

Implements the two open issues assigned to Akargi.

#57 — Configurable asset-service mocks

  • Added configureAssetService, getAssetServiceConfig, resetAssetServiceConfig, and simulateAssetServiceFailure to src/services/assetService.ts.
  • Latency, failure probability, the error factory, and the random source are configurable at runtime. Defaults stay at 200 ms with no failures, so existing pages behave exactly as before.
  • One-shot failures give tests a deterministic error path without stubbing Math.random.
  • Invalid latency or error-rate values are rejected with RangeError.
  • Added src/services/__tests__/assetService.test.ts covering defaults, configurable latency, zero-latency mode, queued failures, error-rate failures, validation, and reset behaviour.

#56 — Robust Friendbot error handling

  • Moved Friendbot handling into src/lib/stellar/friendbot.ts; fundWithFriendbot in horizon.ts remains the public entry point.
  • Responses are parsed as JSON first (Horizon problem+json, extras.result_codes.operations / transaction) with a legacy plain-text fallback.
  • Every already-funded response format is treated as an idempotent success: op_already_exists, createAccountAlreadyExist, account already funded to starting balance, and account already exists.
  • Added FriendbotError carrying the normalised code, HTTP status, raw detail, retryable hint, and the original friendbotCode.
  • Invalid addresses, rate limits, 5xx/proxy error pages, network failures, and all account-creation/transaction result codes now produce actionable user-facing messages.
  • Added src/lib/stellar/__tests__/friendbot.test.ts with mocked Friendbot responses for success and failure paths.

Notes for reviewers

  • The asset-service API is additive: no existing caller changed.
  • fundWithFriendbot keeps the same signature; callers in useWallet continue to receive an Error whose message is safe to display.
  • Per instruction, npm install, CI, and the test suite were not run locally. CI will run lint, type-check, Jest, and the production build.

Closes #57
Closes #56

Add runtime configuration for latency, error rate, and injectable randomness, plus a one-shot failure queue so tests and local development can exercise loading and error states without patching the module.

Closes Chulilee#57
Verify the default 200ms delay, zero-latency mode, one-shot failures, error-rate driven failures, validation, and reset behaviour.

Closes Chulilee#57
Parse Horizon problem+json, legacy plain-text failures, and proxy error pages into a FriendbotError that carries the normalised code, HTTP status, raw detail, and retry hint. Every documented account-creation and transaction result code gets actionable guidance, and all already-funded response formats remain idempotent successes.

Closes Chulilee#56
Keep fundWithFriendbot as the public entry point while moving response parsing into the focused friendbot module.

Closes Chulilee#56
Exercise already-funded idempotency, invalid addresses, operation and transaction result codes, rate limits, server pages, unknown bodies, and network failures against a mocked fetch.

Closes Chulilee#56
@vercel

vercel Bot commented Nov 2, 2026

Copy link
Copy Markdown

@akargi is attempting to deploy a commit to the Akargi Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
inter-changabletrade-fricks Ready Ready Preview Nov 2, 2026 8:46pm UTC

@akargi
akargi merged commit e8e78f4 into Chulilee:main Nov 2, 2026
3 checks passed

This branch was successfully deployed

1 active deployment
Preview — e358f11a Deployed Nov 2, 2026 by vercel[bot]
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.

Enhance: assetService mock data lacks configurability for testing Fix: Friendbot funding error handling is fragile

1 participant