Skip to content

test(env): add comprehensive unit test coverage for validateStellarNetwork (#420) - #424

Open
PINYOPATTANAWASANPORN wants to merge 1 commit into
MergeFi:mainfrom
PINYOPATTANAWASANPORN:test/stellar-network-env-validation-420
Open

PINYOPATTANAWASANPORN wants to merge 1 commit into
MergeFi:mainfrom
PINYOPATTANAWASANPORN:test/stellar-network-env-validation-420

Conversation

@PINYOPATTANAWASANPORN

Copy link
Copy Markdown

Summary of Changes

  • Add a dedicated unit test suite for validateStellarNetwork in src/lib/env.test.ts.
  • Verify acceptance of valid networks: "TESTNET" and "PUBLIC".
  • Verify strict rejection when undefined or empty string "" is supplied (ensuring the lack of a silent default is enforced).
  • Verify case-sensitivity enforcement (rejecting "testnet" and "public").
  • Verify rejection of common near-misses such as "MAINNET" and arbitrary strings.

Root Cause / Technical Context

  • Network selection determines which network passphrase wallet.ts#signTransaction signs transactions with. An incorrect network creates mismatched cryptographic signatures on Soroban escrow contracts.
  • While validateStellarNetwork in src/lib/env.ts was implemented to abort build-time and execution-time configuration errors, src/lib/env.test.ts only tested validateApiUrl, leaving validateStellarNetwork without test coverage.

Verification & Testing

  • Unit tests in src/lib/env.test.ts:
    • accepts TESTNET: asserts validateStellarNetwork("TESTNET") === "TESTNET".
    • accepts PUBLIC: asserts validateStellarNetwork("PUBLIC") === "PUBLIC".
    • rejects undefined (no default allowed): asserts EnvValidationError thrown with /NEXT_PUBLIC_STELLAR_NETWORK is not set/.
    • rejects an empty string: asserts EnvValidationError thrown.
    • rejects lowercase 'testnet' & 'public': asserts case sensitivity rejection with /is not a valid Stellar network/.
    • rejects 'MAINNET' near-miss: asserts EnvValidationError thrown.
    • rejects arbitrary invalid network strings: asserts invalid values throw.

Closes #420

…twork (MergeFi#420)

- Add tests verifying acceptance of valid networks (TESTNET, PUBLIC)
- Verify strict rejection when unset or empty (no default network permitted)
- Verify rejection of case-mismatched networks (testnet, public)
- Verify rejection of near-misses (MAINNET) and invalid network strings
@vercel

vercel Bot commented Sep 17, 2026

Copy link
Copy Markdown

@PINYOPATTANAWASANPORN is attempting to deploy a commit to the chonilius' projects Team on Vercel.

A member of the Team first needs to authorize it.

This branch has not been deployed

No deployments
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.

validateStellarNetwork — the one env function documented as 'too consequential to guess a default for' — has zero test coverage

1 participant