fix: migrate legacy tests, log silent catches, harden test config, fix TOCTOU in deductCredits - #506
Merged
DeFiVC merged 2 commits intoSep 30, 2026
Conversation
…x TOCTOU in deductCredits Migrates the 12 remaining src/test/ files to tests/unit/ or tests/e2e/ by what each actually exercises (mocked service calls vs real HTTP via app.inject), preserving history via git mv and fixing import depths. Removes the now-unused src/test include glob from vitest.config.ts. Adds structured logger.warn/error calls to 8 catch blocks that previously failed silently across resilience.ts, auth/refresh-token services, reward claim handling, and batch enroll/mint loops. The 4 originally-named locations in lock.ts and cache/* were already fixed by prior commits before this branch was cut. Replaces the hardcoded test-mode config fallbacks in config/index.ts: DATABASE_URL/JWT_SECRET/STELLAR_PLATFORM_SECRET now throw a clear error naming exactly which vars are missing instead of silently defaulting to credential-shaped strings; non-critical vars still default, but to an obviously-fake placeholder. Adds .env.test.example documenting every test-mode variable. Fixes a TOCTOU race in deductCredits: the separate balance-check then UPDATE is replaced with a single atomic UPDATE whose WHERE clause enforces credits >= amount under the row lock, so a concurrent deduction or grant can no longer race the check.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
closes #473
closes #474
closes #475
closes #476
Test plan