In this track: Build, test and reason
Test token decimals
Keep raw integers and display scaling separate.
Changing the ruler should not change the measured quantity.
1 ETH = 1000000000 Gwei = 1000000000000000000 Wei.
Specify the unit model
A token with six decimals displays one token for raw value 1,000,000. A token with eighteen decimals uses a different scaling factor for the same displayed quantity.
Use exact arithmetic
Test integer or exact decimal-string conversions. Floating-point numbers can lose precision before a large raw amount reaches the encoder or assertion.
Exercise invalid precision
A six-decimal parser should reject a value requiring a seventh fractional digit unless the application explicitly defines a rounding policy.
Do not assume metadata always exists
ERC-20 decimals is optional metadata under the standard. An integration must define how missing or unexpected metadata is handled.
Define the test
decimals 6: parse("1") = 1000000
decimals 18: parse("1") = 1000000000000000000
reject unsupported fractional precisionTest plans are framework-neutral unless labeled as complete Solidity or JavaScript. Use a local test environment and no real funds.
Does raw amount 1,000,000 always mean one token?
The display depends on decimals metadata and the intended asset.
Original explanations by EtherTools. Examples are educational and source-linked; this site is independent of the Ethereum Foundation. Our approach.