|
| 1 | +import { expect } from "earljs"; |
| 2 | + |
| 3 | +import { explorerApiUrls } from "../ethereum-viewer/src/explorer/networks"; |
| 4 | +import { apiUrlToWebsite } from "../ethereum-viewer/src/explorer/apiUrlToWebsite"; |
| 5 | +import { ethViewerCommands } from "../vscode-host/src/deth/commands/ethViewerCommands"; |
| 6 | +import { givenUrl } from "../vscode-host/src/test/test-utils"; |
| 7 | +import { toDethNet } from "./bookmarklet"; |
| 8 | + |
| 9 | +describe(`bookmarklet: ${toDethNet.name}`, () => { |
| 10 | + const websiteUrls = Object.values(explorerApiUrls).map( |
| 11 | + (url) => |
| 12 | + apiUrlToWebsite(url) + |
| 13 | + "/address/0x0000000000000000000000000000000000000000" |
| 14 | + ); |
| 15 | + |
| 16 | + it("returns hostname ending with deth.net", () => { |
| 17 | + const urls = websiteUrls.map(toDethNet); |
| 18 | + for (const actual of urls) { |
| 19 | + expect(actual).toEqual(expect.stringMatching(/\.deth\.net\//)); |
| 20 | + } |
| 21 | + }); |
| 22 | + |
| 23 | + it("preserves contract address", () => { |
| 24 | + const urls = websiteUrls.map(toDethNet); |
| 25 | + for (const actual of urls) { |
| 26 | + expect(actual).toEqual(expect.stringMatching(/address\/0x[0-9a-f]{40}/)); |
| 27 | + } |
| 28 | + |
| 29 | + const address = `0x${Math.floor( |
| 30 | + Math.random() * 10 ** Math.floor(Math.log10(Number.MAX_SAFE_INTEGER)) |
| 31 | + )}`.padEnd(42, "0"); |
| 32 | + |
| 33 | + expect(toDethNet(`https://etherscan.io/address/${address}`)).toEqual( |
| 34 | + `https://etherscan.deth.net/address/${address}` |
| 35 | + ); |
| 36 | + }); |
| 37 | + |
| 38 | + it("preserves explorer api name for all explorers", () => { |
| 39 | + for (const apiName of Object.keys(explorerApiUrls)) { |
| 40 | + const websiteUrl = |
| 41 | + apiUrlToWebsite( |
| 42 | + explorerApiUrls[apiName as keyof typeof explorerApiUrls] |
| 43 | + ) + "/address/0x0000000000000000000000000000000000000000"; |
| 44 | + |
| 45 | + const ecvUrl = toDethNet(websiteUrl); |
| 46 | + |
| 47 | + givenUrl(ecvUrl); |
| 48 | + expect(ethViewerCommands.getApiName()).toEqual(apiName); |
| 49 | + } |
| 50 | + }); |
| 51 | +}); |
0 commit comments