Skip to content

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

Closed

Description

@chonilius

Problem

src/lib/env.test.ts is 41 lines long and contains exactly one describe block: "validateApiUrl — scheme restriction", with 8 test cases thoroughly covering validateApiUrl. validateStellarNetwork has zero test coverage — grep -n "validateStellarNetwork" src/lib/env.test.ts returns nothing.

This is the more consequential of the two functions in this file, by its own doc comment's own admission:

/**
 * Validates `NEXT_PUBLIC_STELLAR_NETWORK`. Deliberately has no default —
 * unlike `NEXT_PUBLIC_API_URL` below, the wrong value here doesn't just
 * point at the wrong backend, it makes `wallet.ts#signTransaction` sign
 * with the wrong network passphrase (testnet passphrase in what's meant to
 * be a production build, or the reverse), which fails confusingly at the
 * Soroban contract layer at best. Network selection is too consequential
 * to guess a default for, so an unset or misspelled value fails the build
 * instead of silently picking one.
 */
export function validateStellarNetwork(raw: string | undefined): StellarNetwork {
  if (raw === undefined || raw === "") { throw new EnvValidationError(...); }
  if (!VALID_STELLAR_NETWORKS.includes(raw as StellarNetwork)) { throw new EnvValidationError(...); }
  return raw as StellarNetwork;
}

It has three distinct branches (each documented as intentional and each throwing a distinct, carefully-worded EnvValidationError message) — unset/empty, invalid-but-non-empty (the doc comment even calls out "MAINNET" and lowercase "public" as "common near-misses that are not accepted"), and valid — and none of them is exercised by a test.

Impact

This function is the single build-time safeguard against exactly the failure mode its own comment describes as worst-case: a build silently signing transactions with the wrong Stellar network passphrase. validateApiUrl (the less consequential of the two functions, by the file's own reasoning) has 8 tests; the function whose entire reason for existing is "too consequential to guess a default for" has none. A regression here — e.g. accidentally allowing a case-insensitive match, or silently adding a default — would defeat the exact protection #26 was filed to establish, with no test to catch it.

Suggested fix

Add a describe("validateStellarNetwork") block to env.test.ts covering: throws with "is not set" for undefined/""; throws with "is not a valid Stellar network" for "MAINNET", "public" (lowercase), and other near-misses; and returns the value unchanged for exactly "TESTNET" and "PUBLIC".

Activity

  1. added
    bug
    testing
    on Sep 17, 2026
  2. ranjeet150 commented on Sep 18, 2026

    @ranjeet150

    Hi there,

    I would like to resolve this issue. Here is my proposed execution plan:

    • Implementation: Add comprehensive test coverage for validateStellarNetwork — the one env function documented as 'too consequential to guess a default for' — has zero test coverage verifying edge cases and failure scenarios.
    • Testing: Ensure zero flake and 100% green pass rate across the test suite.

    I can start working on this right away. Please assign!

  3. added
    Stellar Wave
    on Sep 23, 2026
  4. oniololade60-coder commented on Sep 23, 2026

    @oniololade60-coder

    @oniololade60-coder has applied to work on this issue as part of the Stellar Wave Program's 9th wave.

    Hello Maintainer, I’ve gone through the issue details and I’m confident I can deliver a solution that fully meets the project requirements. I’d appreciate being assigned to this task.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @oniololade60-coder to this issue.

  5. Dev-Dare4 commented on Sep 23, 2026

    @Dev-Dare4

    @badmusdare4 has applied to work on this issue as part of the Stellar Wave Program's 9th wave.

    Hello maintainer, kindly assign this issue to me.

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @badmusdare4 to this issue.

  6. olamidemutiat300-debug commented on Sep 23, 2026

    @olamidemutiat300-debug

    @olamidemutiat300-debug has applied to work on this issue as part of the Stellar Wave Program's 9th wave.

    Hi , I would like to work on this issue

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @olamidemutiat300-debug to this issue.

  7. chinoyenmose commented on Sep 23, 2026

    @chinoyenmose
    Contributor

    @chinoyenmose has applied to work on this issue as part of the Stellar Wave Program's 9th wave.

    Please can u assign this issue to me

    ℹ️ Repo Maintainers: To accept this application, review their application or assign @chinoyenmose to this issue.

  8. drips-wave commented on Sep 23, 2026

    @drips-wave

    Congratulations, @chinoyenmose! 🎉 Your application was accepted by the repo's maintainers, and the issue is due on September 30, 2026.

    🧑‍💻 @chinoyenmose: Please resolve the issue such that the repo's maintainers have enough time to review your contribution before the due date. You'll earn Points for completing the issue on-time, which will make you eligible for a share of the Stellar Wave Program's reward pool.

    Warning

    When opening a PR, please link it to this issue to ensure it gets tracked accurately. Points are awarded when this issue is marked as completed by the maintainer.

    🤠 Repo maintainers: Please keep an eye on the contributor's progress and review their work before the due date. You can manage this issue, including adjusting its complexity and points, here.

    🌊 Happy Wave 🌊

  9. added 2 commits that reference this issue on Sep 25, 2026
  10. drips-wave commented on Sep 25, 2026

    @drips-wave

    This issue has been completed by @chinoyenmose as part of the Stellar Wave Program's 9th Wave 🥳

    😎 @chinoyenmose: You earned 200 Points for completing this issue! After the current Wave ends, you'll be eligible for a percentage of the Wave's reward pool based on the percentage of total points you've earned. Learn more here. You can also Leave a review to share your experience working on this issue.

    🧑‍💻 Repo maintainers: How'd the contributor do? Leave a review to share your experience working with them.

  11. removed
    Stellar Wave
    on Oct 15, 2026
  12. added
    Stellar Wave
    on Oct 15, 2026
  13. removed
    Stellar Wave
    on Oct 15, 2026
  14. added
    Stellar Wave
    on Oct 15, 2026
  15. removed
    Stellar Wave
    on Oct 15, 2026
  16. added
    Stellar Wave
    on Oct 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Stellar Wavebugtesting

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions