Skip to content

Add enhanced tests for account ID checksum validator endpoint#235

Merged
Sulex45 merged 1 commit into
stellarkit-lab-devtools:mainfrom
darius-daniel:feature/account-checksum-validator
Jun 2, 2026
Merged

Add enhanced tests for account ID checksum validator endpoint#235
Sulex45 merged 1 commit into
stellarkit-lab-devtools:mainfrom
darius-daniel:feature/account-checksum-validator

Conversation

@darius-daniel
Copy link
Copy Markdown

Account ID Checksum Validator Endpoint - Enhanced Test Coverage

Overview

This PR enhances the test coverage for the account ID checksum validator endpoint (/utils/validate-account), ensuring comprehensive validation of Stellar account IDs without hitting Horizon.

Resolves

Closes #221

Changes Made

Test Enhancements

Added 3 additional test cases to tests/utils.validateAccount.test.js:

  1. Invalid checksum detection - Validates that keys with correct format but wrong checksum are properly rejected
  2. Oversized key validation - Ensures keys longer than 56 characters are detected
  3. No Horizon calls verification - Confirms the validation is purely local with no network requests

Implementation Verification

Confirmed the existing endpoint implementation includes:

  • GET /utils/validate-account?id=G... returns { input, isValid, reason }
  • ✅ Uses StrKey.isValidEd25519PublicKey() from @stellar/stellar-sdk
  • ✅ No Horizon API calls - purely local validation
  • ✅ Comprehensive error messages for various failure scenarios

Test Results

PASS  tests/utils.validateAccount.test.js
  GET /utils/validate-account
    ✓ returns isValid: true with reason: null for a valid public key
    ✓ returns isValid: false with a reason when the key has a wrong prefix
    ✓ returns isValid: false with a reason when the key is too short
    ✓ returns isValid: false with a reason when the key contains invalid characters
    ✓ returns 400 when the id parameter is missing
    ✓ returns 400 when the id parameter is an empty string
    ✓ returns isValid: false with a reason when the key has an invalid checksum
    ✓ returns isValid: false with a reason when the key is too long
    ✓ does not make any Horizon API calls

Test Suites: 1 passed, 1 total
Tests:       9 passed, 9 total

Validation Scenarios Covered

  • ✅ Valid Stellar public key (G...)
  • ✅ Invalid prefix (e.g., S... instead of G...)
  • ✅ Invalid length (too short or too long)
  • ✅ Invalid characters (outside base32 alphabet)
  • ✅ Invalid checksum
  • ✅ Missing or empty parameter
  • ✅ Performance verification (no network calls)

API Response Examples

Valid Account ID

GET /utils/validate-account?id=GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN
{
  "success": true,
  "data": {
    "input": "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVN",
    "isValid": true,
    "reason": null
  }
}

Invalid Checksum

GET /utils/validate-account?id=GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVX
{
  "success": true,
  "data": {
    "input": "GA5ZSEJYB37JRC5AVCIA5MOP4RHTM335X2KGX3IHOJAPP5RE34K4KZVX",
    "isValid": false,
    "reason": "Invalid key: checksum verification failed."
  }
}

Files Changed

  • tests/utils.validateAccount.test.js - Added 3 new comprehensive test cases
  • package-lock.json - Updated from npm install

Acceptance Criteria Met

  • GET /utils/validate-account?id=G... returns { input, isValid, reason }
  • Uses StrKey.isValidEd25519PublicKey() from the Stellar SDK
  • No Horizon call made
  • Tests added

Checklist

  • All tests pass
  • No breaking changes
  • Code follows project style guidelines
  • Test coverage is comprehensive
  • Documentation in code comments is accurate

Additional Notes

This endpoint provides a lightweight, fast validation utility for Stellar account IDs that can be used by developers to verify account ID structure before making Horizon API calls, reducing unnecessary network requests and improving application performance.

Closes #221

- Add test for invalid checksum scenario
- Add test for key that is too long
- Add test to verify no Horizon API calls are made
- All 9 tests passing
- Resolves stellarkit-lab-devtools#221
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented Jun 2, 2026

@darius-daniel 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

@Sulex45 Sulex45 merged commit 932d277 into stellarkit-lab-devtools:main Jun 2, 2026
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.

Account ID Checksum Validator Endpoint

2 participants