// The confirmation screen's warning for a recipient that has never sent a // transaction (https://git.eeqj.de/sneak/AutistMask/issues/528). // // The node's transaction count for an address is the number of transactions // it has sent, so an address that only ever receives, such as a savings // address or an exchange deposit address, has a count of zero. The warning // used to fire on that count alone. It now also needs a zero balance: ETH an // address received stays in its balance until it sends a transaction. "use strict"; const { getFullWarnings } = require("../src/shared/addressWarnings"); global.fetch = jest.fn(async () => { throw new Error("tests must not perform network requests"); }); const RECIPIENT = "0x" + "b".repeat(40); // The warning types getFullWarnings() returns for RECIPIENT when the node // reports it as a regular address with `txCount` sent transactions and a // balance of `balance` wei. async function warningTypes(txCount, balance) { const provider = { getCode: async () => "0x", getTransactionCount: async () => txCount, getBalance: async () => balance, }; const warnings = await getFullWarnings(RECIPIENT, provider); return warnings.map((w) => w.type); } test("a recipient that has received 0.5 ETH and never sent a transaction gets no warning", async () => { expect(await warningTypes(0, 500000000000000000n)).toEqual([]); }); test("a recipient that has never sent a transaction and holds no ETH gets the warning", async () => { expect(await warningTypes(0, 0n)).toEqual(["new-address"]); });