From bcb24962fc196ca73ce8dbae7bb01b81e03813d5 Mon Sep 17 00:00:00 2001 From: Geoffrey Ragot Date: Wed, 3 Jun 2026 14:06:09 +0200 Subject: [PATCH] fix(asset_scaling): match base asset exactly, not as a string prefix Tighten `getAssets` so an entry belongs to the scaling pool iff its key is exactly `baseAsset` or has the form `baseAsset/N`. Drops the spurious matches that the regression test (introduced in the stacked parent PR) pins: - `USDT`, `USDT/2`: unrelated asset, shared prefix - `USD_RED`, `USD_RED/2`: color-suffix-encoded variants from the experimental asset-colors feature flag This flips `TestGetAssetsRejectsSpuriousPrefixMatches` from red to green. Co-Authored-By: Claude Opus 4.7 (1M context) --- internal/interpreter/asset_scaling.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/internal/interpreter/asset_scaling.go b/internal/interpreter/asset_scaling.go index 48c5fd41..b363ae7a 100644 --- a/internal/interpreter/asset_scaling.go +++ b/internal/interpreter/asset_scaling.go @@ -38,13 +38,18 @@ func getAssetScale(asset string) (string, int64) { return asset, 0 } +// getAssets returns, for every precision scale found in `balance`, the amount +// available for `baseAsset`. Match is exact on the base name: `USDT` and +// `USD_RED` are NOT considered scaled forms of `USD`. Only the bare base name +// and its `baseAsset/N` precision variants qualify. func getAssets(balance AccountBalance, baseAsset string) map[int64]*big.Int { result := make(map[int64]*big.Int) for asset, amount := range balance { - if strings.HasPrefix(asset, baseAsset) { - _, scale := getAssetScale(asset) - result[scale] = amount + if asset != baseAsset && !strings.HasPrefix(asset, baseAsset+"/") { + continue } + _, scale := getAssetScale(asset) + result[scale] = amount } return result }