Skip to content

fix(assets): read a dotted unit in getByUnit, as fromUnit writes one - #710

Open
jorbuedo wants to merge 1 commit into
IntersectMBO:mainfrom
jorbuedo:slice/assets-dotted-unit
Open

jorbuedo wants to merge 1 commit into
IntersectMBO:mainfrom
jorbuedo:slice/assets-dotted-unit

Conversation

@jorbuedo

@jorbuedo jorbuedo commented Oct 22, 2026 •

Copy link
Copy Markdown

One of the four fixes asked for in the closing comment on
#619 — smallest fix plus its test, nothing else.

fromUnit and getByUnit disagree on a dotted unit, so getByUnit reads 0n for an asset that is there.

The defect

fromUnit accepts both policyId+assetName and policyId.assetName, and has since it was written.
getByUnit and fromRecord sliced at 56 characters unconditionally, so an asset built from a dotted
unit read back as 0n with the same string it was built from.

0n is why this was worth finding: it reads as "this asset is not here" rather than as a parse
failure, so a balance is simply wrong and nothing reports it.

The fix

One splitUnit now serves fromUnit, fromRecord and getByUnit. A dot cannot occur in hex, so
the two spellings stay unambiguous.

Contents

  • packages/evolution/src/Assets.ts — the shared parse.
  • packages/evolution/test/AssetsUnitSpelling.test.ts — both spellings through all three entry
    points, including the round-trip that answered 0n.
  • A patch changeset.

Deliberately left out: the two CIP-21 ordering hunks from the original PR.

Verification

All six CI tasks run locally off ci.yml against this base (lint, type-check, test, build,
check:dts, docgen): green. packages/evolution: 1920 passed, 75 skipped, 0 failed. The new test file fails on this base without the source change, so it does exercise it.
devnet's suite needs Docker and was not run here.

`fromUnit` accepts both `policyId+assetName` and `policyId.assetName`, and has
since it was written. `getByUnit` and `fromRecord` sliced at 56 characters
unconditionally, so an asset built from a dotted unit read back as `0n` with the
same string it was built from.

`0n` is why this was worth finding: it reads as "this asset is not here" rather
than as a parse failure, so a balance is simply wrong and nothing reports it.

One `splitUnit` now serves all three. A dot cannot occur in hex, so the two
spellings stay unambiguous.

This branch has not been deployed

No deployments
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.

1 participant