Skip to content

task: add shared network param validation#342

Merged
greatest0fallt1me merged 2 commits into
CalloraOrg:mainfrom
David-patrick-chuks:task/network-param-validation
May 27, 2026
Merged

task: add shared network param validation#342
greatest0fallt1me merged 2 commits into
CalloraOrg:mainfrom
David-patrick-chuks:task/network-param-validation

Conversation

@David-patrick-chuks

@David-patrick-chuks David-patrick-chuks commented May 26, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR adds a shared Zod validator for Stellar network selection and applies it consistently to the existing Stellar-aware network query parameter flow. It standardizes accepted values to testnet and mainnet, preserves the default testnet behavior, and documents the parameter clearly in route docs and the README.

Related Issue

Closes #336

Changes

⚙️ Shared Network Validation

  • [ADD] src/validators/networkSchema.ts
  • Added a reusable networkSchema accepting only testnet and mainnet.
  • Added a shared query schema for Stellar-aware routes.
  • Added a helper to preserve default testnet behavior when the param is omitted.

🌐 Stellar-aware Route Updates

  • [MODIFY] src/app.ts

  • Applied validate({ query: ... }) to GET /api/vault/balance.

  • Documented the network query param and its default directly in the route doc comment.

  • [MODIFY] src/controllers/vaultController.ts

  • Replaced inline network validation with the shared schema parser.

  • Preserved the existing default behavior of using testnet when network is not supplied.

  • Documented accepted values and default behavior in the controller comment.

🧪 Tests

  • [ADD] src/validators/networkSchema.test.ts

  • Added tests for accepted values, rejected values, and default behavior.

  • [MODIFY] src/controllers/vaultController.test.ts

  • Updated route wiring to use the shared validation middleware.

  • Added assertions for consistent 400 validation responses on invalid network values.

  • Kept coverage for default testnet, valid mainnet, and malicious input edge cases.

📘 Documentation

  • [MODIFY] README.md
  • Documented the network query param for Stellar-aware routes.
  • Clarified accepted values and default testnet behavior.

Verification Results

Acceptance Criteria Status
Invalid network values return 400 consistently
Default testnet behavior is preserved
Param is documented
Shared Zod schema is reusable
Vault controller tests pass successfully
Network schema tests pass successfully
Typecheck passes successfully

How to Test

# 1. Confirm you're on the branch
git branch --show-current

# 2. Run the vault controller tests
npm test -- src/controllers/vaultController.test.ts

# 3. Run the vault controller + network schema tests
npm test -- src/controllers/vaultController.test.ts src/validators/networkSchema.test.ts

# 4. Verify typecheck passes
npm run typecheck

# 5. Optional: inspect the changed files
git diff -- src/validators/networkSchema.ts src/controllers/vaultController.ts src/app.ts README.md

Screenshots

✅ Vault controller tests pass

A screenshot of:

npm test -- src/controllers/vaultController.test.ts
image

✅ Shared network schema + controller tests pass

A screenshot of:

npm test -- src/controllers/vaultController.test.ts src/validators/networkSchema.test.ts
image

✅ Typecheck passes

A screenshot of:

npm run typecheck

@drips-wave

drips-wave Bot commented May 26, 2026

Copy link
Copy Markdown

@David-patrick-chuks 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

@greatest0fallt1me greatest0fallt1me merged commit 915d407 into CalloraOrg:main May 27, 2026
1 check failed
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.

Add a good first issue to validate and document the network query param on all Stellar-aware routes

2 participants