Repository navigation
Conversation
solidsnakedev
left a comment
There was a problem hiding this comment.
Thanks, the shared split fixes it, and undotted input reads back the same as before everywhere.
One change before merge: fromUnit now also accepts the joined spelling, policyId followed by assetName with no dot, which main rejected with a PolicyId ParseError. That's a good change, but please say so in the changeset and in the fromUnit JSDoc, and update the "First 56 chars are policyId" comment in fromRecord.
One more of the same kind, if you want it here: a unit in uppercase hex still reads back as 0n, because getByUnit compares it against lowercase hex. Main does the same. Lowercasing both halves in splitUnit fixes it, and a follow-up PR is fine too.
`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 shared parse also lowercases both halves, for the same symptom from the same cause: `Bytes.fromHex` takes either case, so `fromUnit` built an asset from an uppercase unit that `getByUnit` answered `0n` for, because it compares against `PolicyId.toHex`, which emits lowercase. `getUnits` still emits the canonical lowercase spelling. One `splitUnit` now serves all three. A dot cannot occur in hex, so the two spellings stay unambiguous. This widens what `fromUnit` accepts, which the changeset and its doc comment now say: a dotless unit longer than 56 characters splits at 56, where before the whole string was read as the policy id and rejected with a `PolicyId` parse error -- for the very spelling `getUnits` emits.
ef66c72 to
450705e
Compare
|
Both in, including the one you offered. Rebased onto
Done. The changeset now carries it as its own paragraph, marked as the one input this widens: a dotless unit longer than 56 characters splits at 56, where before the whole string was read as the policy id and rejected with a
Taken here, since it is the same sentence of behaviour as the dotted case — a unit that built an asset must read that asset back, and a spelling is a spelling. Reproduced first: Gate, after a clean |
One of the four fixes asked for in the closing comment on
#619 — smallest fix plus its test, nothing else.
The defect
fromUnitaccepts bothpolicyId+assetNameandpolicyId.assetName, and has since it was written.getByUnitandfromRecordsliced at 56 characters unconditionally, so an asset built from a dottedunit read back as
0nwith the same string it was built from.0nis why this was worth finding: it reads as "this asset is not here" rather than as a parsefailure, so a balance is simply wrong and nothing reports it.
The fix
One
splitUnitnow servesfromUnit,fromRecordandgetByUnit. A dot cannot occur in hex, sothe two spellings stay unambiguous.
Contents
packages/evolution/src/Assets.ts— the shared parse.packages/evolution/test/AssetsUnitSpelling.test.ts— both spellings through all three entrypoints, including the round-trip that answered
0n.Deliberately left out: the two CIP-21 ordering hunks from the original PR.
Verification
All six CI tasks run locally off
ci.ymlagainst 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.