test(asset_scaling): pin getAssets prefix-match bug (failing)#141
test(asset_scaling): pin getAssets prefix-match bug (failing)#141gfyrag wants to merge 1 commit into
Conversation
WalkthroughThis PR adds a targeted test case ChangesAsset Prefix Matching Test
🎯 2 (Simple) | ⏱️ ~8 minutes
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
`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>
ff49c47 to
7b65e3f
Compare
Summary
Failing regression test demonstrating a pre-existing bug in
internal/interpreter/asset_scaling.go::getAssets. CI is intentionallyred on this branch — see the stacked fix PR below.
getAssets(balance, baseAsset)usesstrings.HasPrefix(asset, baseAsset)to gather scaled variants of an asset. The match is too loose:
USD?USDUSD/2USDTUSDT/2USD_RED(color-suffix-encoded)USD_RED/2Because the result map is keyed by precision scale only, an entry
like
USD_RED/2 = 500silently overwrites the trueUSD/2 = 2valuein 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
maingetAssetsto exact base +base/NmatchMerging the fix flips the test green.
Test plan
TestGetAssetsRejectsSpuriousPrefixMatchesfails locally withsub-test failures for
USDTandUSD_REDprefix pollution.🤖 Generated with Claude Code