Skip to content

feat: add startup config validation for Soroban environment (#72)#112

Merged
ritik4ever merged 2 commits intoritik4ever:mainfrom
cyber-excel10:feat/issue-72-startup-validation
Mar 29, 2026
Merged

feat: add startup config validation for Soroban environment (#72)#112
ritik4ever merged 2 commits intoritik4ever:mainfrom
cyber-excel10:feat/issue-72-startup-validation

Conversation

@cyber-excel10
Copy link
Copy Markdown
Contributor

Closes #72

Description

This PR implements startup configuration validation for the Soroban environment, addressing issue #72.

When the backend starts, it now validates all Soroban-related environment variables immediately and fails fast with helpful error messages if config is invalid. This prevents silent failures and makes debugging easier.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Changes Made

Backend

  • Created backend/src/config/validateEnv.ts — Zod-based validation for all environment variables
  • Validates CONTRACT_ID (56 chars, starts with C) and SERVER_PRIVATE_KEY (56 chars, starts with S)
  • Supports SOROBAN_DISABLED=true flag for local development without on-chain config
  • Returns ValidatedConfig interface with all validated settings
  • Calls process.exit(1) on validation failure with descriptive error messages

Testing

  • Created backend/src/config/validateEnv.test.ts — 30+ test cases using vitest
  • Created backend/test-validateEnv.js — Manual test guide with 10 scenarios
  • All acceptance criteria verified

Documentation

  • Updated README.md section 8 with validation behavior and startup config details
  • Added environment variable table with required vs optional distinction
  • Documented SOROBAN_DISABLED mode for local development

Acceptance Criteria

  • Invalid config fails fast with helpful messages
  • Optional vs required config is clearly distinguished
  • Local non-chain development can still run intentionally
  • README stays aligned with validation rules

Testing Instructions

Run Unit Tests

cd backend
npm install
npm test -- src/config/validateEnv.test.ts

Manual Testing

cd backend
node test-validateEnv.js

This displays all 10 test scenarios with expected behaviors.

Test Scenarios Covered

  1. Local development with SOROBAN_DISABLED=true
  2. Missing CONTRACT_ID when Soroban enabled ❌
  3. Missing SERVER_PRIVATE_KEY when Soroban enabled ❌
  4. Invalid CONTRACT_ID format ❌
  5. Invalid SERVER_PRIVATE_KEY format ❌
  6. Valid Soroban configuration ✅
  7. Custom PORT parsing ✅
  8. Invalid PORT
  9. Custom ALLOWED_ASSETS
  10. Invalid RPC_URL

Verification Checklist

  • Code follows project style (ESLint, Prettier)
  • No console.log or debug statements left behind
  • Error handling is appropriate
  • No hardcoded secrets or sensitive data
  • Tests are included for new features
  • Existing tests still pass
  • README updated
  • No unnecessary dependencies added

Notes

  • TypeScript warnings about missing vitest and @types/node are just IDE hints they will resolve after running npm install

  • The validation runs at startup before any routes are initialized

  • validateEnv() is called in backend/src/index.ts line 408

  • All defaults match README section 8 specifications

…er#72)

- Validate CONTRACT_ID and SERVER_PRIVATE_KEY at startup
- Fail fast with helpful error messages for invalid config
- Support SOROBAN_DISABLED=true for local development
- Distinguish between required and optional environment variables
- Add comprehensive test suite with 30+ test cases
- Update README section 8 with validation behavior documentation
- All acceptance criteria met
@vercel
Copy link
Copy Markdown

vercel bot commented Mar 28, 2026

Someone is attempting to deploy a commit to the ritik4ever's projects Team on Vercel.

A member of the Team first needs to authorize it.

@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 28, 2026

@cyber-excel10 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

@ritik4ever ritik4ever merged commit f32f3c6 into ritik4ever:main Mar 29, 2026
1 of 3 checks passed
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 Startup Config Validation For Soroban Environment

2 participants