fix: Blockscout and Etherscan lookups are off until the user turns them on (closes #668)
Out of the box the wallet sent the user's addresses to Blockscout for history and token lookups, and each recipient to Etherscan for its label. Two settings, "Use Blockscout" and "Check recipients on Etherscan", now gate those requests where they are made. Both are off in a new profile and offered unticked on Welcome and in Settings. While one is off, the screens that relied on it say so in a plain line naming the setting. README and the user guide say what is contacted by default and what each setting adds. Unit tests show each request skipped while its setting is off and made while it is on; the Chrome suite watches every request from a fresh install, then turns each setting on. Model: opus-5-5
This commit is contained in:
@@ -269,6 +269,55 @@ test("the exact confirmation phrase erases the record and reloads into Welcome (
|
||||
}
|
||||
});
|
||||
|
||||
// ------------------ Blockscout and Etherscan are asked nothing (#668)
|
||||
//
|
||||
// A fresh install asks neither Blockscout nor Etherscan anything until the
|
||||
// user turns on "Use Blockscout" or "Check recipients on Etherscan". The route
|
||||
// handler in tests/e2e/network.js records every request the extension makes,
|
||||
// from its pages and its background worker, from the moment the browser
|
||||
// starts, in env.routeOpts.requests. These tests drive every screen that
|
||||
// would ask either service, and the background's own balance refresh, before
|
||||
// either setting is changed, then turn each on and watch its requests start.
|
||||
|
||||
// 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` says what Use Blockscout being off leaves out.
|
||||
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 +345,180 @@ 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, and skips a
|
||||
// refresh when the stored record says one ran in the last 30 seconds, which
|
||||
// the open popup's own refresh does every 10. So the popup is closed, and that
|
||||
// record is written back to say no refresh has run, from the background
|
||||
// worker, 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");
|
||||
});
|
||||
|
||||
test("turning on Use Blockscout in Settings asks Blockscout for the history and the tokens (#668)", async (env) => {
|
||||
await openSettings(env.page);
|
||||
await env.page.check("#settings-use-blockscout");
|
||||
await waitForPersisted(env.page, "useBlockscout", true, "once ticked");
|
||||
const asked = Promise.all([
|
||||
env.page.waitForRequest(
|
||||
(r) =>
|
||||
r.url().includes("blockscout.com") &&
|
||||
r.url().endsWith("/transactions"),
|
||||
),
|
||||
env.page.waitForRequest((r) => r.url().endsWith("/token-balances"), {
|
||||
timeout: 30000,
|
||||
}),
|
||||
]);
|
||||
await env.page.click("#btn-settings-back");
|
||||
await goHome(env.page);
|
||||
await asked;
|
||||
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",
|
||||
);
|
||||
});
|
||||
|
||||
// Left on for the rest of the run, as the check was always made before #668.
|
||||
test("turning on Check recipients on Etherscan in Settings has ConfirmTx ask Etherscan and show its label (#668)", async (env) => {
|
||||
env.routeOpts.ethBalanceWei = toHexWei(FUNDED_ETH_WEI);
|
||||
env.routeOpts.etherscanLabel = "Fake_Phishing668";
|
||||
try {
|
||||
await openSettings(env.page);
|
||||
await env.page.check("#settings-check-recipients-on-etherscan");
|
||||
await waitForPersisted(
|
||||
env.page,
|
||||
"checkRecipientsOnEtherscan",
|
||||
true,
|
||||
"once ticked",
|
||||
);
|
||||
await env.page.click("#btn-settings-back");
|
||||
await settleOnMain(env, { ethWei: FUNDED_ETH_WEI });
|
||||
|
||||
const before = env.routeOpts.requests.length;
|
||||
await goToConfirm(env.page, {
|
||||
token: "ETH",
|
||||
balance: FUNDED_ETH_TEXT + " ETH",
|
||||
amount: COMFORTABLE_AMOUNT,
|
||||
});
|
||||
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 +5481,16 @@ 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, from the browser's start, in
|
||||
// order (#668).
|
||||
requests: [],
|
||||
};
|
||||
|
||||
let session;
|
||||
|
||||
Reference in New Issue
Block a user