// The balance lists, Home's ETH line and Send's current balance 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>/)[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("
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"); }); }); describe("Send", () => { test("the current balance reads 0.00004 USDC as 0.0000", async () => { const page = await bootHolding("0.99996", "0.00004"); await page.click("btn-main-send"); // USDC chosen in the dropdown, as the user does. const dropdown = page.node("send-token"); dropdown.value = USDC; for (const fn of dropdown.listeners.change) await fn(); expect(page.visibleViews()).toEqual(["send"]); expect(page.text("send-balance")).toBe("Current balance: 0.0000 USDC"); }); });