harden: a token scale above 80 decimal places is refused as unknown (closes #350)
toDecimals() accepted any uint8 scale, but formatUnits() and parseUnits() refuse more than 80 decimal places. A token reporting 81 to 255 made the formatter throw, and the catch in the swap decoder and in the ERC-20 decoder turned that into an undecoded approval screen with nothing saying why. MAX_DECIMALS is now 80, the formatter's own limit, so such a scale is treated exactly like an unknown one: both approval paths show the base-unit amount with the scale stated as unknown. The balance list, the history list and the Send screen use the same check. Model: opus-5-5
This commit was merged in pull request #438.
This commit is contained in:
@@ -184,6 +184,22 @@ describe("decodeCalldata amount", () => {
|
||||
expect(line).not.toMatch(/0\.0000/);
|
||||
});
|
||||
|
||||
// A token added by hand carries whatever its decimals() returned, and a
|
||||
// uint8 reaches 255, but formatUnits() throws above 80. The throw left the
|
||||
// call undecoded rather than refused
|
||||
// (https://git.eeqj.de/sneak/AutistMask/issues/350).
|
||||
test("a token reporting more than 80 decimals shows base units", () => {
|
||||
state.trackedTokens = [
|
||||
{ address: NOVEL_TOKEN, symbol: "NOVEL", decimals: 81 },
|
||||
];
|
||||
expect(
|
||||
amountLine(transferData(FIVE_THOUSAND_AT_SIX), NOVEL_TOKEN),
|
||||
).toBe("5000000000 base units (decimals unknown)");
|
||||
expect(amountLine(approveData(FIVE_THOUSAND_AT_SIX), NOVEL_TOKEN)).toBe(
|
||||
"5000000000 base units (decimals unknown)",
|
||||
);
|
||||
});
|
||||
|
||||
test("an unbounded allowance is still named, with or without a scale", () => {
|
||||
expect(amountLine(approveData(MAX_UINT256), NOVEL_TOKEN)).toBe(
|
||||
"Unlimited",
|
||||
|
||||
Reference in New Issue
Block a user