Some checks failed
check / check (push) Has been cancelled
Prices are fetched for the top 25 tokens only, so an address can hold real
assets this build has no price for. The address total summed the priced
holdings and printed the result as the total, so an address holding nothing
but unpriced ERC-20s was reported as worth $0.00 — wrong in the direction
that matters, and on the address-removal confirmation it sat directly under
"This address holds a balance."
getAddressValue() returns { usd, partial }: the value of the priced holdings,
and whether an unpriced holding was left out of it. Worth zero and worth an
unknown amount stay separate facts, as an absent holders_count stays separate
from a count of zero. formatAddressTotal() is the one rendering of that pair,
so no screen can word it differently:
- nothing knowable (testnet, before the first fetch): no total line
- everything priced: "Total: $5,500.00"
- part priced: "Total: $3,000.00 plus unpriced tokens"
- nothing priced: "Total: unpriced tokens only"
A partial total is kept rather than suppressed: the figure is the ETH and
priced tokens the user does hold and is correct as far as it goes, so it is
named as a floor instead of being thrown away. What is never printed is a
figure covering no holdings at all.
All four call sites read it — the Home summary line, the Home wallet list,
AddressDetail and the removal confirmation — and getWalletValue() and
getTotalValue() carry partial up so a future consumer cannot lose it.
The per-token balance lines are unchanged: a token with no price shows its
quantity and a blank USD column.
tests/addressValue.test.js covers the only-unpriced, genuinely-zero and
fully-priced cases at the helper, at its formatter, and through both call
sites that return their markup as a string. Written first and watched fail
on the unfixed helper: the Home wallet list gave "$0.00" and the removal
confirmation "Total: $0.00" for an address holding 5000 unpriced tokens.
159 lines
6.6 KiB
JavaScript
159 lines
6.6 KiB
JavaScript
// Tests for the copy on the address-removal confirmation (issue #162).
|
|
//
|
|
// The screen's whole job is to warn before a destructive-looking action, so
|
|
// the copy is the substance and is tested as such. Two things it must not
|
|
// get wrong: what it takes to get the address back — the app refuses both
|
|
// obvious routes — and what counts as holding something, which is any
|
|
// ERC-20 as well as ETH, at any size, including a balance that rounds to
|
|
// zero at the four decimals the balance lines render. The DOM behaviour
|
|
// around them is driven against the real popup by tests/e2e/run.js.
|
|
|
|
// helpers.js pulls in state.js, which reads chrome.storage.local at load.
|
|
globalThis.chrome = {
|
|
storage: { local: { get: async () => ({}), set: async () => {} } },
|
|
};
|
|
|
|
const { addressHoldsFunds } = require("../src/popup/views/helpers");
|
|
const {
|
|
recoveryPathText,
|
|
balanceWarningHtml,
|
|
} = require("../src/popup/views/deleteAddress");
|
|
const { prices, clearPrices } = require("../src/shared/prices");
|
|
|
|
const USDC = "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48";
|
|
|
|
const EMPTY = { address: "0x1", balance: "0.0000", tokenBalances: [] };
|
|
const ETH_ONLY = { address: "0x1", balance: "1.5", tokenBalances: [] };
|
|
const DUST = { address: "0x1", balance: "0.00001", tokenBalances: [] };
|
|
const TOKEN_ONLY = {
|
|
address: "0x1",
|
|
balance: "0.0000",
|
|
tokenBalances: [{ address: USDC, symbol: "USDC", balance: "2500.0" }],
|
|
};
|
|
const ZERO_TOKEN = {
|
|
address: "0x1",
|
|
balance: "0",
|
|
tokenBalances: [{ address: USDC, symbol: "USDC", balance: "0" }],
|
|
};
|
|
|
|
afterEach(() => {
|
|
clearPrices();
|
|
});
|
|
|
|
describe("what the screen says it takes to get the address back", () => {
|
|
// The screen used to promise the address "can be brought back at any
|
|
// time by importing this wallet's recovery phrase again". That import is
|
|
// refused as a duplicate for as long as the wallet is present, which it
|
|
// always is here — a wallet never gives up its last address.
|
|
test("it does not promise a re-import while the wallet is here", () => {
|
|
const text = recoveryPathText({ type: "hd" });
|
|
expect(text).not.toMatch(/at any time/);
|
|
expect(text).toContain("is refused while this wallet is still here");
|
|
});
|
|
|
|
test("it names deleting the whole wallet as the route back", () => {
|
|
expect(recoveryPathText({ type: "hd" })).toContain(
|
|
"delete the whole wallet in Settings",
|
|
);
|
|
});
|
|
|
|
// The scan after a re-import finds used addresses only, so an address
|
|
// that never saw a transaction does not come back at all. Saying so is
|
|
// the difference between a warning and a false reassurance.
|
|
test("it states the limit: only on-chain activity is found", () => {
|
|
const text = recoveryPathText({ type: "hd" });
|
|
expect(text).toContain("only finds addresses that have on-chain");
|
|
expect(text).toContain("never been used is not found by it");
|
|
});
|
|
|
|
// The screen is offered on xprv wallets too, and an xprv wallet holds no
|
|
// recovery phrase — telling its owner to import one would send them
|
|
// looking for words that do not exist.
|
|
test("an xprv wallet is told about its extended private key", () => {
|
|
const text = recoveryPathText({ type: "xprv" });
|
|
expect(text).toContain("extended private key");
|
|
expect(text).not.toContain("recovery phrase");
|
|
});
|
|
|
|
test("an HD wallet is told about its recovery phrase", () => {
|
|
const text = recoveryPathText({ type: "hd" });
|
|
expect(text).toContain("recovery phrase");
|
|
expect(text).not.toContain("extended private key");
|
|
});
|
|
});
|
|
|
|
describe("whether an address holds anything", () => {
|
|
test("ETH counts", () => {
|
|
expect(addressHoldsFunds(ETH_ONLY)).toBe(true);
|
|
});
|
|
|
|
// The case that decides the screen: no ETH at all, and $2500 of a
|
|
// stablecoin sitting at the address.
|
|
test("an ERC-20 balance counts even with no ETH", () => {
|
|
expect(addressHoldsFunds(TOKEN_ONLY)).toBe(true);
|
|
});
|
|
|
|
// 0.00001 ETH renders as "0.0000" at four decimals. It is still money.
|
|
test("an ETH balance below the displayed precision counts", () => {
|
|
expect(addressHoldsFunds(DUST)).toBe(true);
|
|
});
|
|
|
|
test("an address holding nothing does not", () => {
|
|
expect(addressHoldsFunds(EMPTY)).toBe(false);
|
|
expect(addressHoldsFunds(ZERO_TOKEN)).toBe(false);
|
|
});
|
|
|
|
test("a missing address or missing fields do not", () => {
|
|
expect(addressHoldsFunds(undefined)).toBe(false);
|
|
expect(addressHoldsFunds({ address: "0x1" })).toBe(false);
|
|
});
|
|
});
|
|
|
|
describe("the balance warning on the removal confirmation", () => {
|
|
test("an address holding nothing gets a blank line, not a warning", () => {
|
|
expect(balanceWarningHtml(EMPTY)).toBe(" ");
|
|
expect(balanceWarningHtml(ZERO_TOKEN)).toBe(" ");
|
|
});
|
|
|
|
test("an ERC-20-only address is warned about, and its token listed", () => {
|
|
const html = balanceWarningHtml(TOKEN_ONLY);
|
|
expect(html).toContain("This address holds a balance.");
|
|
expect(html).toContain("does not move or spend anything");
|
|
expect(html).toContain("USDC");
|
|
expect(html).toContain("2500.0000");
|
|
});
|
|
|
|
// The rendered line says 0.0000 for this address — that is the display
|
|
// format, shared with Home and AddressDetail — and the warning is shown
|
|
// all the same, because the balance is not zero.
|
|
test("an ETH balance that renders as 0.0000 is warned about", () => {
|
|
const html = balanceWarningHtml(DUST);
|
|
expect(html).toContain("This address holds a balance.");
|
|
expect(html).toContain("<span>0.0000</span>");
|
|
});
|
|
|
|
// The sentence must not assert an amount, because any amount it could
|
|
// assert has been rounded: "This address holds 0.0000 ETH." is what the
|
|
// rounded form produces for an address that holds real money.
|
|
test("the warning sentence asserts no rounded amount", () => {
|
|
for (const addr of [DUST, ETH_ONLY, TOKEN_ONLY]) {
|
|
expect(balanceWarningHtml(addr)).not.toMatch(
|
|
/holds [\d.]+ (ETH|USDC)/,
|
|
);
|
|
}
|
|
});
|
|
|
|
test("the USD total is shown when prices are known", () => {
|
|
prices.ETH = 2000;
|
|
prices.USDC = 1;
|
|
expect(balanceWarningHtml(TOKEN_ONLY)).toContain("Total: $2,500.00");
|
|
expect(balanceWarningHtml(ETH_ONLY)).toContain("Total: $3,000.00");
|
|
});
|
|
|
|
// getAddressValue() reports no value on testnet and before the first
|
|
// price fetch. A "Total: $0.00" there would be a lie about the holdings.
|
|
test("no USD total is shown when prices are not known", () => {
|
|
expect(balanceWarningHtml(TOKEN_ONLY)).not.toContain("Total:");
|
|
});
|
|
});
|