Skip to content

Commit d568194

Browse files
CassioMGclaude
andcommitted
Return the bulk-scan shape from stubScanAssetSafe (fixes swap safe E2E)
The swap flow scans destination tokens via the /scan-asset-bulk endpoint, whose response is { data: { results: { [assetId]: ... } } }. stubScanAssetSafe caught that endpoint (via **/scan-asset**) but returned the single-asset shape, so the recovery hook read results[id] as undefined. Previously that failed open silently; now (correctly) it resolves to UNABLE_TO_SCAN, which made the 'Swap shows no warning when scan confirms tokens are safe' test see a token warning. Have the stub return the bulk shape (keyed by the requested asset_ids) for the bulk endpoint and the single shape otherwise, so a safe scan resolves to SAFE. Verified: blockaid swap E2E (safe/malicious/suspicious/unable) + swap.test.ts pass. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7635667 commit d568194

1 file changed

Lines changed: 26 additions & 18 deletions

File tree

extension/e2e-tests/helpers/stubs.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -548,25 +548,33 @@ export const stubScanAssetSuspicious = async (page: Page | BrowserContext) => {
548548
* This simulates when BlockAid confirms an asset is safe
549549
*/
550550
export const stubScanAssetSafe = async (page: Page | BrowserContext) => {
551+
const benign = {
552+
result_type: "Benign",
553+
malicious_score: "0.0",
554+
attack_types: {},
555+
chain: "stellar",
556+
address: "",
557+
metadata: {
558+
type: "",
559+
},
560+
fees: {},
561+
features: [],
562+
trading_limits: {},
563+
financial_stats: {},
564+
};
551565
await page.route("**/scan-asset**", async (route) => {
552-
const json = {
553-
data: {
554-
result_type: "Benign",
555-
malicious_score: "0.0",
556-
attack_types: {},
557-
chain: "stellar",
558-
address: "",
559-
metadata: {
560-
type: "",
561-
},
562-
fees: {},
563-
features: [],
564-
trading_limits: {},
565-
financial_stats: {},
566-
},
567-
error: null,
568-
};
569-
await route.fulfill({ json });
566+
const url = new URL(route.request().url());
567+
// The swap flow scans via the bulk endpoint, whose response is shaped
568+
// { data: { results: { [assetId]: ... } } } rather than a single result.
569+
if (url.pathname.includes("scan-asset-bulk")) {
570+
const results: Record<string, typeof benign> = {};
571+
url.searchParams.getAll("asset_ids").forEach((id) => {
572+
results[id] = { ...benign, address: id };
573+
});
574+
await route.fulfill({ json: { data: { results }, error: null } });
575+
return;
576+
}
577+
await route.fulfill({ json: { data: benign, error: null } });
570578
});
571579
};
572580

0 commit comments

Comments
 (0)