fix: the recipient warning says what it checked and skips addresses that have received ETH (closes #528)
The transaction count the node reports is what an address has sent, so an address that only receives, such as a savings address, got the "ZERO transaction history" box on every send. The check now also asks the node for the recipient's balance and warns only when both are zero. The box says the address has never sent a transaction and holds no ETH, naming the active network's native token as the contract warning does. Model: opus-5-5
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
// 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"]);
|
||||
});
|
||||
@@ -267,6 +267,13 @@ describe.each([
|
||||
);
|
||||
});
|
||||
|
||||
test("the warning for a recipient that has never sent a transaction", async () => {
|
||||
await confirmSend("0.1");
|
||||
expect(text("confirm-recipient-warning")).toContain(
|
||||
"has never sent a transaction and holds no " + symbol + ".",
|
||||
);
|
||||
});
|
||||
|
||||
// A token reports whatever symbol it likes. One reporting the label the
|
||||
// wallet shows its native token under, on this network or any other, is
|
||||
// a fake, exactly as one reporting `ETH` always was.
|
||||
|
||||
@@ -74,7 +74,7 @@ test("ethers puts the URL in the error message, not in the short message", async
|
||||
test("the recipient checks before a send", async () => {
|
||||
await getFullWarnings(ADDRESS, getProvider(RPC_URL, "mainnet"));
|
||||
expectFailureLoggedWithoutKey("contract check failed");
|
||||
expectFailureLoggedWithoutKey("tx count check failed");
|
||||
expectFailureLoggedWithoutKey("tx count or balance check failed");
|
||||
});
|
||||
|
||||
test("the ENS reverse lookup", async () => {
|
||||
|
||||
Reference in New Issue
Block a user