Files
AutistMask/tests/balanceTruncation.test.js
T
sneak fb7c75101f
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run
fix: the balance lists and Home cut amounts to four decimals (closes #757)
The balance lists and Home's ETH line rounded with toFixed(4), so 0.99996
ETH read 1.0000 there and 0.9999 on Send. They now cut the stored decimal
string with truncateAmount(), as the history rows do. balanceLine() takes
the stored balance string instead of a parsed number, and escapes the
quantity cell. The screens that state what is authorized keep the floor
of truncateAmountNeverZero().

Model: opus-5-5
2026-11-10 21:54:45 +00:00

78 lines
2.3 KiB
JavaScript

// The balance lists and Home's ETH line show a balance as the history rows do
// (README.md, Amounts): cut to four decimal places, never rounded up
// (https://git.eeqj.de/sneak/AutistMask/issues/757).
//
// Driven through the real popup over a stored profile on Ethereum Mainnet.
const {
ADDRESS,
bootPopup,
cleanupPopup,
unversionedValidProfile,
} = require("./support/popupBoot");
const { balanceLine } = require("../src/popup/views/helpers");
const USDC = "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48";
afterEach(() => {
cleanupPopup();
});
// The quantity cell of a balance row.
function quantity(row) {
return row.match(/<span>([^<]*)<\/span><\/span>/)[1];
}
// The popup on Home over one address holding `eth` ETH and `usdc` USDC.
function bootHolding(eth, usdc) {
const profile = unversionedValidProfile({
trackedTokens: [{ address: USDC, symbol: "USDC", decimals: 6 }],
});
profile.wallets[0].addresses[0] = {
address: ADDRESS,
balance: eth,
tokenBalances: [
{ address: USDC, symbol: "USDC", decimals: 6, balance: usdc },
],
};
return bootPopup(profile);
}
// The balance row for `token` in Home's wallet list.
function homeRow(page, token) {
return page
.node("wallet-list")
.innerHTML.split("<div ")
.find((row) => row.includes('data-token="' + token + '"'));
}
describe("balanceLine", () => {
test("cuts 0.99996 to 0.9999, never rounding it up to 1.0000", () => {
expect(quantity(balanceLine("ETH", "0.99996", null, "ETH"))).toBe(
"0.9999",
);
});
test("cuts 0.00004 to 0.0000", () => {
expect(quantity(balanceLine("USDC", "0.00004", null, USDC))).toBe(
"0.0000",
);
});
});
describe("Home", () => {
test("the ETH line and the balance list read 0.99996 ETH as 0.9999", async () => {
const page = await bootHolding("0.99996", "0.00004");
expect(page.visibleViews()).toEqual(["main"]);
expect(page.text("total-value")).toBe("0.9999 ETH");
expect(quantity(homeRow(page, "ETH"))).toBe("0.9999");
});
test("the balance list reads 0.00004 USDC as 0.0000", async () => {
const page = await bootHolding("0.99996", "0.00004");
expect(quantity(homeRow(page, USDC.toLowerCase()))).toBe("0.0000");
});
});