Skip to content

test: add unit tests for sequence cache, account lock, progress tracker, auth attempt tracker - #749

Merged
DeFiVC merged 4 commits into
ChainLearnOfficial:mainfrom
uche001-dev:test/unit-tests-sequence-lock-progress-auth
Oct 21, 2026
Merged

DeFiVC merged 4 commits into
ChainLearnOfficial:mainfrom
uche001-dev:test/unit-tests-sequence-lock-progress-auth

Conversation

@uche001-dev

Copy link
Copy Markdown

Summary

Adds (and in one case expands) unit test coverage for four previously-untested or thinly-tested modules: the Stellar sequence cache, the account-lock utility, the on-chain progress-tracker read, and the auth attempt tracker's lockout-expiration path.

closes #588
closes #589
closes #590
closes #598

Changes

#588 - Sequence cache (src/stellar/sequence-cache.ts)

New tests/unit/stellar/sequence-cache.test.ts. Covers:

  • getNextSequence() cache hit (Redis EXISTS true, atomic increment)
  • Cache miss represented both as false and as null from the Lua script, falling back to Horizon via stellarClient.getAccount and seeding with the account's current sequence
  • The SEED_AND_INCREMENT_SCRIPT NX-collision case where another process seeds first
  • Concurrent calls for two different accounts resolving independently
  • invalidate() deleting the key, writing an audit log entry, and not throwing when the audit log call rejects
  • resetTo() setting the key with the configured TTL

#589 - Account lock utility (src/utils/account-lock.ts)

New tests/unit/utils/account-lock.test.ts. Covers:

  • Lock acquisition/release around a successful call
  • Lock release after the wrapped function throws (so the lock doesn't leak on error)
  • Serialization of two concurrent calls for the same account (asserted via execution order)
  • Two concurrent calls for different accounts running without serializing
  • The configured 10s acquisition timeout, using fake timers to avoid a slow real-time test

#590 - Progress tracker (src/stellar/progress-tracker.ts)

New tests/unit/stellar/progress-tracker.test.ts. Covers:

  • Successful hash retrieval and decode
  • Returning null when the contract isn't configured (no Soroban call made)
  • Returning null when the decoded value isn't a string
  • Returning null and logging a warning when the simulation reports an error, or has no retval
  • Returning null and logging a warning when the RPC call throws

Note: new StellarSdk.Contract(id) validates the strkey checksum, so the mocked contract ID in these tests had to be a validly-formatted (though undeployed) contract address, not an arbitrary placeholder string. An earlier draft used a bogus ID and every test silently fell into the catch block instead of exercising the intended code path.

#598 - Auth attempt tracker (src/utils/auth-attempt-tracker.ts)

Expanded the existing tests/unit/utils/auth-attempt-tracker.test.ts (already had good coverage for attempt counting, lockout triggering/escalation, and clearing). Added:

  • Explicit lockout expiration cases: ttl of 0 and the missing-key -2 sentinel both report not-locked-out
  • clearAuthFailures to checkAuthLockout round-trip, asserting a cleared address is reported as not locked out

Test plan

  • npx vitest run on the 4 touched/added test files: 32/32 passing
  • Full suite regression check: ran npx vitest run on this branch and, in a separate git worktree off upstream/main, on a clean npm ci baseline. Diffed the sorted list of FAIL lines from both runs: identical, 89 pre-existing failing test files in both, confirming these changes introduce zero regressions
  • npx eslint on the 4 touched test files: no errors or warnings

Caveats

  • The pre-existing failures across the rest of the suite (SEP-10 auth logger.debug issues, a waitlist-service undefined property access, a lock TTL mismatch, etc.) are not touched by this PR and were failing identically on a clean upstream/main checkout before any of these changes. They're out of scope here.
  • None of the four issues' deliverables were already present upstream; all four required genuinely new or expanded test files.

Uche Okafor added 4 commits October 21, 2026 18:50
)

Covers getNextSequence cache hit/miss (both false and null miss
representations), the NX-seed race with another process, concurrent
calls for different accounts, invalidate(), and resetTo().
…ial#589)

Covers lock acquisition/release on success and on a thrown error,
serialization of concurrent calls for the same account, independent
execution for different accounts, and the configured timeout.
…l#590)

Covers getOnChainContentHash hash retrieval, missing contract config,
simulation errors/missing retval/non-string decode, and RPC failures.
…ficial#598)

Add coverage for lockout expiration (ttl 0 and the missing-key -2
case) and for checkAuthLockout reporting not-locked-out again after
clearAuthFailures runs.
@drips-wave

drips-wave Bot commented Oct 21, 2026

Copy link
Copy Markdown

@uche001-dev 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

@DeFiVC
DeFiVC merged commit f48b83b into ChainLearnOfficial:main Oct 21, 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

2 participants