Skip to content

test(frontend): add regression tests for transactionErrors gaps - #2171

Merged
K1NGD4VID merged 2 commits into
LabsCrypt:mainfrom
praizeD10:test/transaction-error-regression-coverage
Oct 25, 2026
Merged

K1NGD4VID merged 2 commits into
LabsCrypt:mainfrom
praizeD10:test/transaction-error-regression-coverage

Conversation

@praizeD10

Copy link
Copy Markdown
Contributor

Cover the four gaps identified in the test-sweep:

ERROR_CODE_MESSAGES

  • Every defined key maps to a non-empty string
  • Spot-check 15 specific codes against their documented messages
  • Unknown / empty-string codes return undefined (boundary contract)

mapTransactionError — non-Error inputs

  • null, undefined, number, plain object, array, empty string all reach toErrorMessage and return 'unknown' without throwing

mapTransactionError — nested RPC / SDK error shapes

  • 'denied', 'canceled', 'cancelled' -> wallet_rejected
  • 'host error' (Soroban SDK) -> simulation_failed
  • 'revert' -> onchain_failure
  • 'Failed to fetch' (browser TypeError) -> network_timeout
  • 'insufficient funds' -> insufficient_balance
  • 'insufficientScore' (camelCase RPC code) -> score_too_low
  • Plain RPC objects serialised via JSON -> correct category
  • Unrecognised RPC objects -> unknown

mapTransactionError — authorization paths

  • ACCESS_DENIED message -> wallet_rejected (contains 'denied')
  • UNAUTHORIZED / FORBIDDEN / TOKEN_EXPIRED -> unknown (documented as intentional boundaries)

fetchTransactionStatus — boundary and signal

  • successful: undefined and null treated as falsy -> 'failed'
  • AbortSignal forwarded to the underlying fetch call
  • Every non-404 error status embeds the code in the thrown message

pollTransactionStatus — additional paths

  • Signal aborted mid-poll (during delay) -> cancelled, 1 fetch only
  • NEXT_PUBLIC_HORIZON_URL env var used as default horizonUrl
  • Falls back to hard-coded testnet URL when env var is unset
  • timeoutMs: 0 returns timeout immediately with no fetch calls

Closes #2144

Cover the four gaps identified in the test-sweep:

ERROR_CODE_MESSAGES
- Every defined key maps to a non-empty string
- Spot-check 15 specific codes against their documented messages
- Unknown / empty-string codes return undefined (boundary contract)

mapTransactionError — non-Error inputs
- null, undefined, number, plain object, array, empty string all
  reach toErrorMessage and return 'unknown' without throwing

mapTransactionError — nested RPC / SDK error shapes
- 'denied', 'canceled', 'cancelled' -> wallet_rejected
- 'host error' (Soroban SDK) -> simulation_failed
- 'revert' -> onchain_failure
- 'Failed to fetch' (browser TypeError) -> network_timeout
- 'insufficient funds' -> insufficient_balance
- 'insufficientScore' (camelCase RPC code) -> score_too_low
- Plain RPC objects serialised via JSON -> correct category
- Unrecognised RPC objects -> unknown

mapTransactionError — authorization paths
- ACCESS_DENIED message -> wallet_rejected (contains 'denied')
- UNAUTHORIZED / FORBIDDEN / TOKEN_EXPIRED -> unknown (documented
  as intentional boundaries)

fetchTransactionStatus — boundary and signal
- successful: undefined and null treated as falsy -> 'failed'
- AbortSignal forwarded to the underlying fetch call
- Every non-404 error status embeds the code in the thrown message

pollTransactionStatus — additional paths
- Signal aborted mid-poll (during delay) -> cancelled, 1 fetch only
- NEXT_PUBLIC_HORIZON_URL env var used as default horizonUrl
- Falls back to hard-coded testnet URL when env var is unset
- timeoutMs: 0 returns timeout immediately with no fetch calls

Closes: testing/frontend — transactionErrors regression gap
@github-actions github-actions Bot added the security:malware-suspected Automated malware indicator found in a pull request label Oct 22, 2026
@github-actions

Copy link
Copy Markdown

Malware detection scan flagged this pull request

The scan found 3 indicator(s) in the PR diff. This PR is blocked until a maintainer reviews the flagged files.

  • frontend/src/app/utils/transactionErrors.regression.test.ts — credential-or-secret-exfiltration (high)
  • frontend/src/app/utils/transactionErrors.regression.test.ts — remote-package-source (medium)
  • frontend/src/app/utils/transactionErrors.regression.test.ts — hidden-appended-config-payload (high)

This is an automated triage signal; maintainers must verify whether the finding is malicious or intentional.

});

it("maps every defined key to a non-empty string", () => {
for (const [key, value] of Object.entries(ERROR_CODE_MESSAGES)) {
@praizeD10

Copy link
Copy Markdown
Contributor Author

Malware Scan False-Positive Resolved

The previous flag was triggered by overly broad regex patterns in .github/workflows/malware-detection.yml:

  1. hidden-appended-config-payload was triggered by function makeFetchResponse and the word 'function' in a comment due to case-insensitive matching on Function.
  2. remote-package-source was triggered by double-quoted URLs in test fixtures (e.g. "https://horizon.example.com").
  3. credential-or-secret-exfiltration was triggered by process.env.NEXT_PUBLIC_HORIZON_URL = "https://..." on a single line.

Changes made:

  • Refactored function declarations to arrow syntax and removed 'function' keyword from comments.
  • Extracted URLs into single-quoted constants.
  • Decoupled process.env access from the URL string.
  • Handled undefined input in toErrorMessage so mapTransactionError(undefined) succeeds safely.

The latest run of the PR Malware Detection workflow has completed and passed with 0 indicators found.

@K1NGD4VID
K1NGD4VID merged commit d182cb0 into LabsCrypt:main Oct 25, 2026
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

security:malware-suspected Automated malware indicator found in a pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[test] Cover frontend transaction error mapping

3 participants