fix: Blockscout and Etherscan lookups are off until the user turns them on (closes #668)
check / check (push) Waiting to run
e2e / e2e-chrome (push) Waiting to run
e2e / e2e-firefox (push) Waiting to run

Out of the box the wallet sent the user's addresses to Blockscout for history
and token lookups. It sent each recipient to Etherscan for its label. Two
settings, "Use Blockscout" and "Check recipients on Etherscan", now gate those
requests. Both are off in a new install and offered unticked on Welcome and in
Settings. While one is off, the screens that relied on it say so in a plain
line. The balance refresh and the Etherscan check read the stored setting. An
open popup takes a change another page saved and draws its screens again. While
"Use Blockscout" is off, no address keeps an untracked token. ENS lookups ask
only the RPC endpoint.

Model: opus-5-5
This commit is contained in:
2026-10-26 02:57:23 +00:00
parent c316d9ee78
commit d02e3aefe0
59 changed files with 2172 additions and 191 deletions
+321
View File
@@ -269,6 +269,65 @@ test("the exact confirmation phrase erases the record and reloads into Welcome (
}
});
// ------------------ Blockscout and Etherscan are sent no user data (#668)
//
// A fresh install sends Blockscout and Etherscan none of the user's data until
// the user turns on "Use Blockscout" or "Check recipients on Etherscan". One
// request is made with the setting off: pressing "Save" beside the Blockscout
// URL asks that URL for `/stats`. It carries no user data.
//
// The route handler in tests/e2e/network.js records every request the
// extension makes in env.routeOpts.requests, from its pages and its background
// worker. Recording starts when launch() in tests/e2e/harness.js installs that
// handler, before the first popup page opens. A request the background worker
// makes while it starts up comes earlier and is not recorded.
//
// Before either setting is changed, these tests drive Home, AddressDetail,
// AddressToken and ConfirmTx, and the background's own balance refresh. Then
// they turn each setting on and watch its requests start. "Use Blockscout" is
// also turned off once and on again, to see a token the user has not tracked
// leave every list. TransactionDetail, which also asks Blockscout, is left to
// the unit tests in tests/blockscoutEtherscanSettings.test.js.
// What the three transaction lists say while Use Blockscout is off. Written
// out here rather than imported, so the assertion does not compare the popup
// with itself.
const HISTORY_OFF =
'No transaction history is shown, because "Use Blockscout" is off in Settings.';
// The requests made so far to Blockscout or Etherscan.
function explorerRequests(env) {
return env.routeOpts.requests.filter(({ url }) => {
const host = new URL(url).hostname;
return host.endsWith("blockscout.com") || host.endsWith("etherscan.io");
});
}
// Waits until the list `listId` shows the line saying "Use Blockscout" is off.
async function waitForHistoryOff(page, listId) {
await page.waitForFunction(
([id, want]) => document.getElementById(id).textContent.trim() === want,
[listId, HISTORY_OFF],
{ timeout: 15000 },
);
}
test("Welcome offers Use Blockscout and Check recipients on Etherscan, both unticked (#668)", async (env) => {
await visible(env.page, "#view-welcome");
for (const id of [
"welcome-use-blockscout",
"welcome-check-recipients-on-etherscan",
]) {
const st = await controlState(env.page, id);
assert(st !== null, "Welcome has no #" + id);
assert(
st.tag === "input" && st.type === "checkbox",
"#" + id + " is a <" + st.tag + " type=" + st.type + ">",
);
assert(st.checked === false, "#" + id + " is ticked on a new install");
}
});
// The address scan that follows creating the wallet is held, so the popup
// reloads while it is in flight. As for the reloads mid-refresh further down,
// the assertion for that is the harness's own: a console.error from the page
@@ -296,6 +355,261 @@ test("wallet creation through the UI reaches the main view, and reloading mid-sc
assert(addrCount > 0, "no addresses rendered in the wallet list");
});
test("with neither setting changed, Home, AddressDetail, AddressToken and ConfirmTx say what is off (#668)", async (env) => {
// Funded, so Send leads to the confirmation screen.
env.routeOpts.ethBalanceWei = toHexWei(FUNDED_ETH_WEI);
try {
await visible(env.page, "#view-main");
await waitForHistoryOff(env.page, "home-tx-list");
await visible(env.page, "#home-tokens-note");
await env.page.waitForFunction(
(want) =>
document
.getElementById("wallet-list")
.textContent.includes(want),
quantity(FUNDED_ETH_WEI),
{ timeout: 60000 },
);
await openAddressDetail(env.page);
await waitForHistoryOff(env.page, "tx-list");
await visible(env.page, "#address-tokens-note");
await env.page.locator('#address-balances [data-token="ETH"]').click();
await visible(env.page, "#view-address-token");
await waitForHistoryOff(env.page, "address-token-tx-list");
await env.page.click("#btn-address-token-back");
await visible(env.page, "#view-address");
await goToConfirm(env.page, {
token: "ETH",
balance: FUNDED_ETH_TEXT + " ETH",
amount: COMFORTABLE_AMOUNT,
});
await waitForEstimate(env.page);
await visible(env.page, "#confirm-etherscan-note");
assert(
!(await env.page.isVisible("#confirm-etherscan-warning")),
"ConfirmTx keeps the Etherscan warning's place while no Etherscan check is made",
);
await backToAddress(env.page);
} finally {
env.routeOpts.ethBalanceWei = null;
}
});
// The background refreshes balances on its alarm, once a minute. It skips a
// refresh when the stored record says one ran in the last 30 seconds, and the
// open popup's own refresh runs every 10. So the popup is closed first. The
// background worker then writes that record back to say no refresh has run, as
// another extension page saving it would.
test("with neither setting changed, nothing has reached Blockscout or Etherscan, the background's refresh included (#668)", async (env) => {
await waitForPersisted(
env.page,
"currentView",
"address",
"before the popup is closed",
);
await env.page.close();
const [worker] = env.ctx.serviceWorkers();
await worker.evaluate(
() =>
new Promise((resolve) => {
chrome.storage.local.get("autistmask", (r) => {
const record = r.autistmask;
record.lastBalanceRefresh = 0;
chrome.storage.local.set({ autistmask: record }, resolve);
});
}),
);
const before = env.routeOpts.requests.length;
const deadline = Date.now() + 75000;
while (
!env.routeOpts.requests
.slice(before)
.some((r) => r.fromWorker && r.method === "POST")
) {
assert(
Date.now() < deadline,
"the background's balance refresh never asked the RPC endpoint",
);
await sleep(250);
}
// Its RPC reads and any Blockscout request start together.
await sleep(3000);
const seen = explorerRequests(env);
assert(
seen.length === 0,
"a fresh install asked Blockscout or Etherscan: " +
JSON.stringify(seen),
);
// The watch saw the popup's own traffic as well as the worker's.
assert(
env.routeOpts.requests.some((r) => !r.fromWorker),
"no request from the popup was recorded",
);
// It reopens on the address screen the test above left it on.
env.page = await openPopup(env.ctx, env.popupUrl);
await visible(env.page, "#view-address");
});
// Ticked from AddressDetail's gear, so Back lands on the screen that said the
// setting is off.
test("turning on Use Blockscout from AddressDetail's gear asks Blockscout for that screen's history on Back, then for the tokens (#668)", async (env) => {
await openAddressDetail(env.page);
await waitForHistoryOff(env.page, "tx-list");
await openSettings(env.page);
await env.page.check("#settings-use-blockscout");
await waitForPersisted(env.page, "useBlockscout", true, "once ticked");
const historyAsked = env.page.waitForRequest(
(r) =>
r.url().includes("blockscout.com") &&
r.url().endsWith("/transactions"),
);
const tokensAsked = env.page.waitForRequest(
(r) => r.url().endsWith("/token-balances"),
{ timeout: 30000 },
);
await env.page.click("#btn-settings-back");
await visible(env.page, "#view-address");
await historyAsked;
await env.page.waitForFunction(
() =>
document
.getElementById("tx-list")
.textContent.includes("No transactions found."),
null,
{ timeout: 15000 },
);
assert(
!(await env.page.isVisible("#address-tokens-note")),
"AddressDetail still says only tracked tokens are listed",
);
await goHome(env.page);
await tokensAsked;
await env.page.waitForFunction(
() =>
document
.getElementById("home-tx-list")
.textContent.includes("No transactions found."),
null,
{ timeout: 15000 },
);
assert(
!(await env.page.isVisible("#home-tokens-note")),
"Home still says only tracked tokens are listed",
);
});
// Unticked from AddressDetail's gear while the address holds the stub token,
// which the user has not tracked and only Blockscout reports. Ticked again at
// the end, so the rest of the run has Blockscout as before.
test("turning off Use Blockscout from AddressDetail's gear takes an untracked token off AddressDetail, Send and Home on Back (#668)", async (env) => {
env.routeOpts.ethBalanceWei = toHexWei(FUNDED_ETH_WEI);
env.routeOpts.seedTokenBalance = true;
const tokenRow = '[data-token="' + STUB_TOKEN.address + '"]';
try {
await settleOnMain(env, { ethWei: FUNDED_ETH_WEI, expectToken: true });
await openAddressDetail(env.page);
await visible(env.page, "#address-balances " + tokenRow);
await openSettings(env.page);
await env.page.uncheck("#settings-use-blockscout");
await waitForPersisted(
env.page,
"useBlockscout",
false,
"once unticked",
);
await env.page.click("#btn-settings-back");
await visible(env.page, "#view-address");
await visible(env.page, "#address-tokens-note");
assert(
(await env.page
.locator("#address-balances " + tokenRow)
.count()) === 0,
"AddressDetail still lists the untracked token",
);
await env.page.click("#btn-send");
await visible(env.page, "#view-send");
await visible(env.page, "#send-tokens-note");
const offered = await env.page.$$eval("#send-token option", (opts) =>
opts.map((opt) => opt.value.toLowerCase()),
);
assert(
!offered.includes(STUB_TOKEN.address),
"Send's dropdown still offers the untracked token",
);
await env.page.click("#btn-send-back");
await visible(env.page, "#view-address");
await goHome(env.page);
await visible(env.page, "#home-tokens-note");
assert(
(await env.page.locator("#wallet-list " + tokenRow).count()) === 0,
"Home still lists the untracked token",
);
} finally {
await openSettings(env.page);
await env.page.check("#settings-use-blockscout");
await waitForPersisted(env.page, "useBlockscout", true, "ticked again");
await env.page.click("#btn-settings-back");
env.routeOpts.ethBalanceWei = null;
env.routeOpts.seedTokenBalance = false;
}
});
// Ticked from ConfirmTx's gear, so Back lands on the screen that said no
// Etherscan check was made. Left on for the rest of the run, so the later
// confirmation screens are driven with the check made.
test("turning on Check recipients on Etherscan from ConfirmTx's gear has ConfirmTx ask Etherscan on Back and show its label (#668)", async (env) => {
env.routeOpts.ethBalanceWei = toHexWei(FUNDED_ETH_WEI);
env.routeOpts.etherscanLabel = "Fake_Phishing668";
try {
await settleOnMain(env, { ethWei: FUNDED_ETH_WEI });
await goToConfirm(env.page, {
token: "ETH",
balance: FUNDED_ETH_TEXT + " ETH",
amount: COMFORTABLE_AMOUNT,
});
await visible(env.page, "#confirm-etherscan-note");
await openSettings(env.page);
await env.page.check("#settings-check-recipients-on-etherscan");
await waitForPersisted(
env.page,
"checkRecipientsOnEtherscan",
true,
"once ticked",
);
const before = env.routeOpts.requests.length;
await env.page.click("#btn-settings-back");
await visible(env.page, "#view-confirm-tx");
await visible(env.page, "#confirm-etherscan-warning", 30000);
assert(
!(await env.page.isVisible("#confirm-etherscan-note")),
"ConfirmTx says no Etherscan check was made, with the check on",
);
const asked = env.routeOpts.requests
.slice(before)
.map((r) => r.url.toLowerCase())
.filter((url) => url.includes("etherscan.io"));
assert(
asked.length === 1 &&
asked[0] ===
"https://etherscan.io/address/" + STUB_COUNTERPARTY,
"ConfirmTx asked Etherscan for " + JSON.stringify(asked),
);
await backToAddress(env.page);
} finally {
env.routeOpts.ethBalanceWei = null;
env.routeOpts.etherscanLabel = null;
}
});
test("add token screen opens from address detail (#150)", async (env) => {
await openAddressDetail(env.page);
await env.page.click("#btn-add-token");
@@ -5258,10 +5572,17 @@ async function main() {
seedReceipt: false,
// Whether eth_getTransactionReceipt fails instead of answering (#315).
failReceiptLookup: false,
// The label Etherscan's page gives an address, when it gives one
// (#668).
etherscanLabel: null,
// Every raw signed transaction handed to eth_sendRawTransaction, in
// order. The dApp transaction round trip asserts against these bytes
// rather than against anything the extension reported about them.
broadcastTransactions: [],
// Every request the extension makes, in order, from when launch()
// installs the route handler, before the first popup page opens
// (#668).
requests: [],
};
let session;