Skip to content

test(asset_scaling): pin getAssets prefix-match bug (failing)#141

Open
gfyrag wants to merge 1 commit into
mainfrom
test/asset-scaling-prefix-match-bug
Open

test(asset_scaling): pin getAssets prefix-match bug (failing)#141
gfyrag wants to merge 1 commit into
mainfrom
test/asset-scaling-prefix-match-bug

Conversation

@gfyrag
Copy link
Copy Markdown
Contributor

@gfyrag gfyrag commented Jun 3, 2026

Summary

Failing regression test demonstrating a pre-existing bug in
internal/interpreter/asset_scaling.go::getAssets. CI is intentionally
red
on this branch — see the stacked fix PR below.

getAssets(balance, baseAsset) uses strings.HasPrefix(asset, baseAsset)
to gather scaled variants of an asset. The match is too loose:

Stored key Should match USD? Currently matches?
USD yes
USD/2 yes
USDT no
USDT/2 no
USD_RED (color-suffix-encoded) no
USD_RED/2 no

Because the result map is keyed by precision scale only, an entry
like USD_RED/2 = 500 silently overwrites the true USD/2 = 2 value
in the scaling pool — corrupting any subsequent conversion. The result
is non-deterministic (last-write-wins on randomized map iteration), so
the failing test is structured as three deterministic sub-tests rather
than one composite assertion.

Stack

PR What it does Target
this PR (#141) Adds the failing regression test main
#140 Tightens getAssets to exact base + base/N match this branch

Merging the fix flips the test green.

Test plan

  • TestGetAssetsRejectsSpuriousPrefixMatches fails locally with
    sub-test failures for USDT and USD_RED prefix pollution.
  • All other tests stay green.

🤖 Generated with Claude Code

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jun 3, 2026

Review Change Stack

Walkthrough

This PR adds a targeted test case TestGetAssetsRejectsSpuriousPrefixMatches to internal/interpreter/asset_scaling_test.go that validates the getAssets function correctly matches asset base names exactly, including precision variants, while rejecting assets that merely share a string prefix.

Changes

Asset Prefix Matching Test

Layer / File(s) Summary
Prefix matching validation test for getAssets
internal/interpreter/asset_scaling_test.go
New test TestGetAssetsRejectsSpuriousPrefixMatches with multiple sub-tests verifies that getAssets accepts exact base names (USD) and precision variants (USD/2, USD/3) while rejecting prefix-only matches (USDT, USD_RED).

🎯 2 (Simple) | ⏱️ ~8 minutes

🐰 A test hops through the asset names with care,
Rejecting false prefixes in the pair,
Exact matches shine, precision in view,
USDT stays out—only USD is true!

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The PR title accurately describes the primary change: adding a test that pins (documents) a prefix-match bug in getAssets, and the (failing) notation clearly indicates the test is intentionally failing.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description clearly explains the bug in getAssets, provides a detailed table of matching behavior, and contextualizes the failing test as part of a stacked fix strategy.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch test/asset-scaling-prefix-match-bug

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 3, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.00%. Comparing base (5cc059f) to head (ff49c47).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #141      +/-   ##
==========================================
+ Coverage   66.96%   67.00%   +0.03%     
==========================================
  Files          47       47              
  Lines        5068     5068              
==========================================
+ Hits         3394     3396       +2     
+ Misses       1477     1476       -1     
+ Partials      197      196       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

`getAssets(balance, baseAsset)` uses `strings.HasPrefix(asset, baseAsset)`,
which accidentally matches any asset whose key shares the base name as a
string prefix:

  - `USDT` and `USDT/2` are matched as scaled variants of `USD`
  - `USD_RED` and `USD_RED/2` (suffix-encoded color variants emitted by
    the experimental asset-colors feature flag) are also matched

Worse: because the result map is keyed by precision scale only, an entry
like `USD_RED/2 = 500` overwrites the true `USD/2 = 2` value in the
scaling pool. A user holding both `USD/2 = 2` and `USD_RED/2 = 500` on
the same account will see scaling compute conversions against the wrong
amount — silent corruption.

This commit introduces a failing regression test
`TestGetAssetsRejectsSpuriousPrefixMatches` that pins the bug. CI is
intentionally red on this branch.

The fix is in a stacked PR that targets this branch — merging it
flips the test green.

Flagged by CodeRabbit during review of #139.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@gfyrag gfyrag force-pushed the test/asset-scaling-prefix-match-bug branch from ff49c47 to 7b65e3f Compare June 3, 2026 12:10
@gfyrag gfyrag marked this pull request as ready for review June 3, 2026 12:13
@gfyrag gfyrag requested review from Azorlogh and ascandone June 3, 2026 12:22
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.

2 participants