diff --git a/.github/workflows/test-and-deploy.yml b/.github/workflows/test-and-deploy.yml index 93055a0f..ab9921a8 100644 --- a/.github/workflows/test-and-deploy.yml +++ b/.github/workflows/test-and-deploy.yml @@ -30,7 +30,12 @@ jobs: timeout-minutes: 60 runs-on: ubuntu-latest container: - image: mcr.microsoft.com/playwright:v1.30.0-focal + image: mcr.microsoft.com/playwright:v1.37.0-focal + strategy: + fail-fast: false + matrix: + shardIndex: [1,2,3,4,5,6,7,8,9,10] + shardTotal: [10] steps: - name: Checkout uses: actions/checkout@v3 @@ -48,7 +53,7 @@ jobs: - name: Start app run: npm run start:test & - name: Run Playwright Tests - run: npx playwright test + run: npx playwright test --shard=${{ matrix.shardIndex }}/${{ matrix.shardTotal }} - name: Upload test screenshots artifact uses: actions/upload-artifact@v3 if: always() @@ -60,7 +65,7 @@ jobs: uses: actions/upload-artifact@v3 if: always() with: - name: test-report + name: test-blob-reports path: test/report/ retention-days: 14 test-report: @@ -84,8 +89,10 @@ jobs: - name: Download test report artifact uses: actions/download-artifact@master with: - name: test-report - path: test/report + name: test-blob-reports + path: test/blob-reports + - name: Merge blob reports into HTML report + run: npx playwright merge-reports --config playwright.merge-reports.config.ts ./test/blob-reports - name: Upload Argos screenshots continue-on-error: true env: diff --git a/package-lock.json b/package-lock.json index ee2f6dad..dc074c56 100644 --- a/package-lock.json +++ b/package-lock.json @@ -43,7 +43,7 @@ "devDependencies": { "@argos-ci/cli": "^0.4.4", "@emotion/eslint-plugin": "^11.10.0", - "@playwright/test": "^1.30.0", + "@playwright/test": "^1.37.0", "@polkadot/api": "^10.1.4", "@polkadot/apps-config": "^0.124.1", "@subsquid/archive-registry": "^2.1.9", @@ -4591,19 +4591,22 @@ "dev": true }, "node_modules/@playwright/test": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.30.0.tgz", - "integrity": "sha512-SVxkQw1xvn/Wk/EvBnqWIq6NLo1AppwbYOjNLmyU0R1RoQ3rLEBtmjTnElcnz8VEtn11fptj1ECxK0tgURhajw==", + "version": "1.37.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.37.0.tgz", + "integrity": "sha512-181WBLk4SRUyH1Q96VZl7BP6HcK0b7lbdeKisn3N/vnjitk+9HbdlFz/L5fey05vxaAhldIDnzo8KUoy8S3mmQ==", "dev": true, "dependencies": { "@types/node": "*", - "playwright-core": "1.30.0" + "playwright-core": "1.37.0" }, "bin": { "playwright": "cli.js" }, "engines": { - "node": ">=14" + "node": ">=16" + }, + "optionalDependencies": { + "fsevents": "2.3.2" } }, "node_modules/@pmmmwh/react-refresh-webpack-plugin": { @@ -21137,15 +21140,15 @@ } }, "node_modules/playwright-core": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.30.0.tgz", - "integrity": "sha512-7AnRmTCf+GVYhHbLJsGUtskWTE33SwMZkybJ0v6rqR1boxq2x36U7p1vDRV7HO2IwTZgmycracLxPEJI49wu4g==", + "version": "1.37.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.37.0.tgz", + "integrity": "sha512-1c46jhTH/myQw6sesrcuHVtLoSNfJv8Pfy9t3rs6subY7kARv0HRw5PpyfPYPpPtQvBOmgbE6K+qgYUpj81LAA==", "dev": true, "bin": { - "playwright": "cli.js" + "playwright-core": "cli.js" }, "engines": { - "node": ">=14" + "node": ">=16" } }, "node_modules/pnglib": { @@ -30197,13 +30200,14 @@ "dev": true }, "@playwright/test": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.30.0.tgz", - "integrity": "sha512-SVxkQw1xvn/Wk/EvBnqWIq6NLo1AppwbYOjNLmyU0R1RoQ3rLEBtmjTnElcnz8VEtn11fptj1ECxK0tgURhajw==", + "version": "1.37.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.37.0.tgz", + "integrity": "sha512-181WBLk4SRUyH1Q96VZl7BP6HcK0b7lbdeKisn3N/vnjitk+9HbdlFz/L5fey05vxaAhldIDnzo8KUoy8S3mmQ==", "dev": true, "requires": { "@types/node": "*", - "playwright-core": "1.30.0" + "fsevents": "2.3.2", + "playwright-core": "1.37.0" } }, "@pmmmwh/react-refresh-webpack-plugin": { @@ -42318,9 +42322,9 @@ } }, "playwright-core": { - "version": "1.30.0", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.30.0.tgz", - "integrity": "sha512-7AnRmTCf+GVYhHbLJsGUtskWTE33SwMZkybJ0v6rqR1boxq2x36U7p1vDRV7HO2IwTZgmycracLxPEJI49wu4g==", + "version": "1.37.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.37.0.tgz", + "integrity": "sha512-1c46jhTH/myQw6sesrcuHVtLoSNfJv8Pfy9t3rs6subY7kARv0HRw5PpyfPYPpPtQvBOmgbE6K+qgYUpj81LAA==", "dev": true }, "pnglib": { diff --git a/package.json b/package.json index 232cbc3c..f805b9ba 100644 --- a/package.json +++ b/package.json @@ -70,7 +70,7 @@ "devDependencies": { "@argos-ci/cli": "^0.4.4", "@emotion/eslint-plugin": "^11.10.0", - "@playwright/test": "^1.30.0", + "@playwright/test": "^1.37.0", "@polkadot/api": "^10.1.4", "@polkadot/apps-config": "^0.124.1", "@subsquid/archive-registry": "^2.1.9", diff --git a/playwright.config.ts b/playwright.config.ts index 6e6f289d..7e2f290e 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -31,10 +31,14 @@ const config: Config = { workers: 1, /* Reporter to use. See https://playwright.dev/docs/test-reporters */ reporter: [ - ["html", { - outputFolder: "./test/report", + process.env.CI ? ["blob", { + outputDir: "./test/report", open: "never" - }] + }] : + ["html", { + outputFolder: "./test/report", + open: "never" + }] ], /* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */ use: { diff --git a/playwright.merge-reports.config.ts b/playwright.merge-reports.config.ts new file mode 100644 index 00000000..e7af5ad0 --- /dev/null +++ b/playwright.merge-reports.config.ts @@ -0,0 +1,8 @@ +export default { + reporter: [ + ["html", { + outputFolder: "./test/report", + open: "never" + }] + ] +}; diff --git a/scripts/update-networks/config/squids.ts b/scripts/update-networks/config/squids.ts index 5ac9da6b..1e1e17c4 100644 --- a/scripts/update-networks/config/squids.ts +++ b/scripts/update-networks/config/squids.ts @@ -1,7 +1,6 @@ -export const squidTypes = ["archive", "balances", "explorer", "main", "main-identites", "stats"] as const; +export const squidTypes = ["archive", "explorer", "main", "identites", "stats"] as const; export const squidUrlTemplates: Record string> = { - balances: (network: string) => `https://squid.subsquid.io/${network}-balances/graphql`, explorer: (network: string) => `https://squid.subsquid.io/gs-explorer-${network}/graphql`, main: (network: string) => `https://squid.subsquid.io/gs-main-${network}/graphql`, stats: (network: string) => `https://squid.subsquid.io/gs-stats-${network}/graphql` @@ -9,6 +8,9 @@ export const squidUrlTemplates: Record string> = { export const forceSquidUrl: Record>> = { "kusama": { - "main-identites": "https://squid.subsquid.io/gs-main-kusama/graphql" + "identites": "https://squid.subsquid.io/gs-main-kusama/graphql" + }, + "polkadot": { + "identites": "https://squid.subsquid.io/gs-main-polkadot/graphql" }, }; diff --git a/src/components/DataViewerValueParsed.tsx b/src/components/DataViewerValueParsed.tsx index 60ee010e..50dbac91 100644 --- a/src/components/DataViewerValueParsed.tsx +++ b/src/components/DataViewerValueParsed.tsx @@ -10,6 +10,7 @@ import { RuntimeSpec } from "../model/runtimeSpec"; // found in https://github.com/polkadot-js/apps/blob/59c2badf87c29fd8cb5b7dfcc045c3ce451a54bc/packages/react-params/src/Param/findComponent.ts#L51 const ADDRESS_TYPES = ["AccountId", "AccountId20", "AccountId32", "Address", "LookupSource", "MultiAddress"]; +const ADDRESS_KINDS = ["Id", "AccountId"]; const valueTableStyle = css` width: fit-content; @@ -119,8 +120,8 @@ type MaybeAccountLinkValueProps = { const AccountValue = (props: MaybeAccountLinkValueProps) => { const {network, value, valueMetadata, runtimeSpec} = props; - if (valueMetadata.type === "MultiAddress") { - if (value.__kind === "Id") { + if (typeof value === "object") { + if (ADDRESS_KINDS.includes(value.__kind)) { return { }} runtimeSpec={runtimeSpec} />; - } else { - return ( - - ); } + + return ( + + ); } return ( diff --git a/src/components/balances/BalancesTable.tsx b/src/components/balances/BalancesTable.tsx index 3f090542..3a0921f3 100644 --- a/src/components/balances/BalancesTable.tsx +++ b/src/components/balances/BalancesTable.tsx @@ -88,8 +88,8 @@ function BalancesTable(props: BalancesTableProps) { - - {balance.updatedAt} + + {balance.updatedAtBlock} } /> diff --git a/src/model/accountBalance.ts b/src/model/accountBalance.ts index 53bd51bb..2b3c953c 100644 --- a/src/model/accountBalance.ts +++ b/src/model/accountBalance.ts @@ -6,7 +6,7 @@ export type Balance = { free: Decimal; reserved: Decimal; total: Decimal; - updatedAt?: number; + updatedAtBlock?: number; } export type AccountBalance = { diff --git a/src/model/balance.ts b/src/model/balance.ts index 32b1153c..48b8dd7d 100644 --- a/src/model/balance.ts +++ b/src/model/balance.ts @@ -7,6 +7,6 @@ export type Balance = { free: Decimal; reserved: Decimal; total: Decimal; - updatedAt?: number; + updatedAtBlock?: number; runtimeSpec: RuntimeSpec; } diff --git a/src/model/explorer-squid/explorerSquidAccountBalance.ts b/src/model/explorer-squid/explorerSquidAccountBalance.ts deleted file mode 100644 index ae38ef63..00000000 --- a/src/model/explorer-squid/explorerSquidAccountBalance.ts +++ /dev/null @@ -1,7 +0,0 @@ -export type BalancesSquidBalance = { - id: string; - free: string; - reserved: string; - total: string; - updatedAt?: number; -} diff --git a/src/model/stats-squid/statsSquidAccountBalance.ts b/src/model/stats-squid/statsSquidAccountBalance.ts new file mode 100644 index 00000000..93cdb792 --- /dev/null +++ b/src/model/stats-squid/statsSquidAccountBalance.ts @@ -0,0 +1,7 @@ +export type StatsSquidAccountBalance = { + id: string; + free: string; + reserved: string; + total: string; + updatedAtBlock?: number; +} diff --git a/src/networks.json b/src/networks.json index b55d56d2..6224dad0 100644 --- a/src/networks.json +++ b/src/networks.json @@ -296,10 +296,9 @@ "symbol": "KSM", "squids": { "archive": "https://kusama.explorer.subsquid.io/graphql", - "balances": "https://squid.subsquid.io/kusama-balances/graphql", "explorer": "https://squid.subsquid.io/gs-explorer-kusama/graphql", "main": "https://squid.subsquid.io/gs-main-kusama/graphql", - "main-identites": "https://squid.subsquid.io/gs-main-kusama/graphql", + "identites": "https://squid.subsquid.io/gs-main-kusama/graphql", "stats": "https://squid.subsquid.io/gs-stats-kusama/graphql" }, "coinGeckoId": "kusama" @@ -369,25 +368,11 @@ "symbol": "MOVR", "squids": { "archive": "https://moonriver.explorer.subsquid.io/graphql", - "balances": "https://squid.subsquid.io/moonriver-balances/graphql", "explorer": "https://squid.subsquid.io/gs-explorer-moonriver/graphql", "main": "https://squid.subsquid.io/gs-main-moonriver/graphql" }, "coinGeckoId": "moonriver" }, - { - "name": "opal", - "displayName": "Opal", - "icon": "/assets/network-icons/opal.png", - "color": "#40bcff", - "website": "https://docs.unique.network/unique-and-quartz-wiki/build/get-started/testnet-and-mainnet#opal-testnet", - "prefix": 42, - "decimals": 18, - "symbol": "OPL", - "squids": { - "archive": "https://archive.unique.network/opal/explorer/graphql" - } - }, { "name": "peaq", "displayName": "peaq", @@ -447,29 +432,13 @@ "symbol": "DOT", "squids": { "archive": "https://polkadot.explorer.subsquid.io/graphql", - "balances": "https://squid.subsquid.io/polkadot-balances/graphql", "explorer": "https://squid.subsquid.io/gs-explorer-polkadot/graphql", "main": "https://squid.subsquid.io/gs-main-polkadot/graphql", + "identites": "https://squid.subsquid.io/gs-main-polkadot/graphql", "stats": "https://squid.subsquid.io/gs-stats-polkadot/graphql" }, "coinGeckoId": "polkadot" }, - { - "name": "quartz", - "displayName": "Quartz", - "icon": "/assets/network-icons/quartz.png", - "color": "#ff4d6a", - "website": "https://unique.network/quartz/", - "parachainId": 2095, - "relayChain": "kusama", - "prefix": 255, - "decimals": 18, - "symbol": "QTZ", - "squids": { - "archive": "https://archive.unique.network/quartz/explorer/graphql" - }, - "coinGeckoId": "quartz" - }, { "name": "robonomics", "displayName": "Robonomics", @@ -554,7 +523,6 @@ "name": "statemint", "displayName": "Statemint", "icon": "/assets/network-icons/statemint.png", - "color": "#86e62a", "website": "https://www.parity.io/", "parachainId": 1000, "relayChain": "polkadot", @@ -598,22 +566,6 @@ "archive": "https://t0rn.explorer.subsquid.io/graphql" } }, - { - "name": "unique", - "displayName": "Unique", - "icon": "/assets/network-icons/unique.png", - "color": "#40bcff", - "website": "https://unique.network/", - "parachainId": 2037, - "relayChain": "polkadot", - "prefix": 7391, - "decimals": 18, - "symbol": "UNQ", - "squids": { - "archive": "https://archive.unique.network/unique/explorer/graphql" - }, - "coinGeckoId": "unique-network" - }, { "name": "vara", "displayName": "Vara", @@ -640,4 +592,4 @@ }, "coinGeckoId": "xxcoin" } -] \ No newline at end of file +] diff --git a/src/screens/network.tsx b/src/screens/network.tsx index c9dd242a..55855592 100644 --- a/src/screens/network.tsx +++ b/src/screens/network.tsx @@ -115,7 +115,7 @@ export const NetworkPage = () => { } - {hasSupport(network.name, "balances-squid") && + {hasSupport(network.name, "stats-squid") && { @@ -28,7 +28,7 @@ export async function getAccount(network: string, address: string): Promise( + const response = await fetchIdentitiesSquid<{identity: MainSquidIdentity|null}>( networkName, `query ($id: String!) { identity: identityById(id: $id) { diff --git a/src/services/balancesService.ts b/src/services/balancesService.ts index 1762dc0c..758ad4cb 100644 --- a/src/services/balancesService.ts +++ b/src/services/balancesService.ts @@ -1,7 +1,7 @@ import Decimal from "decimal.js"; import { AccountBalance } from "../model/accountBalance"; import { Balance } from "../model/balance"; -import { BalancesSquidBalance } from "../model/explorer-squid/explorerSquidAccountBalance"; +import { StatsSquidAccountBalance } from "../model/stats-squid/statsSquidAccountBalance"; import { ItemsConnection } from "../model/itemsConnection"; import { PaginationOptions } from "../model/paginationOptions"; @@ -10,7 +10,7 @@ import { extractConnectionItems } from "../utils/extractConnectionItems"; import { encodeAddress } from "../utils/formatAddress"; import { rawAmountToDecimal } from "../utils/number"; -import { fetchBalancesSquid } from "./fetchService"; +import { fetchStatsSquid } from "./fetchService"; import { getNetwork, getNetworks, hasSupport } from "./networksService"; @@ -25,10 +25,10 @@ export async function getBalances( order: BalancesOrder = "total_DESC", pagination: PaginationOptions, ) { - if (hasSupport(network, "balances-squid")) { + if (hasSupport(network, "stats-squid")) { const after = pagination.offset === 0 ? null : pagination.offset.toString(); - const response = await fetchBalancesSquid<{accountsConnection: ItemsConnection}>( + const response = await fetchStatsSquid<{accountsConnection: ItemsConnection}>( network, `query ($first: Int!, $after: String, $filter: AccountWhereInput, $order: [AccountOrderByInput!]!) { accountsConnection(first: $first, after: $after, where: $filter, orderBy: $order) { @@ -38,7 +38,7 @@ export async function getBalances( free reserved total - updatedAt + updatedAtBlock } } pageInfo { @@ -58,7 +58,7 @@ export async function getBalances( } ); - const items = extractConnectionItems(response.accountsConnection, pagination, unifyBalancesSquidBalance, network); + const items = extractConnectionItems(response.accountsConnection, pagination, unifyStatsSquidAccountBalance, network); const balances = await addRuntimeSpecs(network, items, () => "latest"); return balances; @@ -81,7 +81,7 @@ export async function getAccountBalances(address: string) { const accountBalances = networks.map((network) => ({ id: `${address}_${network.name}`, network, - balanceSupported: !!hasSupport(network.name, "balances-squid"), + balanceSupported: !!hasSupport(network.name, "stats-squid"), })); const response = await Promise.allSettled(networks.map(async (network, index) => { @@ -92,14 +92,14 @@ export async function getAccountBalances(address: string) { accountBalance.encodedAddress = encodedAddress; if (accountBalance.balanceSupported) { - const response = await fetchBalancesSquid<{balance?: BalancesSquidBalance}>(network.name, ` + const response = await fetchStatsSquid<{balance?: StatsSquidAccountBalance}>(network.name, ` query ($address: String!) { balance: accountById(id: $address) { id free reserved total - updatedAt + updatedAtBlock } } `, { @@ -107,7 +107,7 @@ export async function getAccountBalances(address: string) { }); accountBalance.balance = response.balance - ? unifyBalancesSquidBalance(response.balance, network.name) + ? unifyStatsSquidAccountBalance(response.balance, network.name) : { id: address, total: new Decimal(0), @@ -130,7 +130,7 @@ export async function getAccountBalances(address: string) { /*** PRIVATE ***/ -function unifyBalancesSquidBalance(balance: BalancesSquidBalance, networkName: string): Omit { +function unifyStatsSquidAccountBalance(balance: StatsSquidAccountBalance, networkName: string): Omit { const network = getNetwork(networkName); return { @@ -138,6 +138,6 @@ function unifyBalancesSquidBalance(balance: BalancesSquidBalance, networkName: s free: rawAmountToDecimal(network, balance.free), reserved: rawAmountToDecimal(network, balance.reserved), total: rawAmountToDecimal(network, balance.total), - updatedAt: balance.updatedAt + updatedAtBlock: balance.updatedAtBlock }; } diff --git a/src/services/fetchService.ts b/src/services/fetchService.ts index a147b8ca..e11a9136 100644 --- a/src/services/fetchService.ts +++ b/src/services/fetchService.ts @@ -1,5 +1,5 @@ import { fetchGraphql } from "../utils/fetchGraphql"; -import { getArchive, getBalancesSquid, getExplorerSquid, getStatsSquid, getMainSquid, getMainIdentitesSquid } from "./networksService"; +import { getArchive, getExplorerSquid, getStatsSquid, getMainSquid, getIdentitesSquid } from "./networksService"; export async function fetchArchive(network: string, query: string, variables: object = {}) { const archiveUrl = getArchive(network); @@ -21,16 +21,6 @@ export function fetchExplorerSquid(network: string, query: string, vari return fetchGraphql(squidUrl, query, variables); } -export function fetchBalancesSquid(network: string, query: string, variables: object = {}) { - const squidUrl = getBalancesSquid(network); - - if (!squidUrl) { - throw new Error(`Balances squid for network '${network}' not found`); - } - - return fetchGraphql(squidUrl, query, variables); -} - export function fetchMainSquid(network: string, query: string, variables: object = {}) { const squidUrl = getMainSquid(network); @@ -41,11 +31,11 @@ export function fetchMainSquid(network: string, query: string, variable return fetchGraphql(squidUrl, query, variables); } -export function fetchMainIdentitiesSquid(network: string, query: string, variables: object = {}) { - const squidUrl = getMainIdentitesSquid(network); +export function fetchIdentitiesSquid(network: string, query: string, variables: object = {}) { + const squidUrl = getIdentitesSquid(network); if (!squidUrl) { - throw new Error(`Main (identities) squid for network '${network}' not found`); + throw new Error(`Identities squid for network '${network}' not found`); } return fetchGraphql(squidUrl, query, variables); diff --git a/src/services/networksService.ts b/src/services/networksService.ts index b4adcca6..3eba9705 100644 --- a/src/services/networksService.ts +++ b/src/services/networksService.ts @@ -6,10 +6,6 @@ export function getArchive(network: string) { return getNetwork(network).squids["archive"]; } -export function getBalancesSquid(network: string) { - return getNetwork(network).squids["balances"]; -} - export function getExplorerSquid(network: string) { return getNetwork(network).squids["explorer"]; } @@ -18,8 +14,8 @@ export function getMainSquid(network: string) { return getNetwork(network).squids["main"]; } -export function getMainIdentitesSquid(network: string) { - return getNetwork(network).squids["main-identites"]; +export function getIdentitesSquid(network: string) { + return getNetwork(network).squids["identites"]; } export function getStatsSquid(network: string) { @@ -43,13 +39,12 @@ export function getNetwork(name: string, throwIfNotFound = true) { return network; } -export function hasSupport(network: string, feature: "archive"|"balances-squid"|"explorer-squid"|"main-squid"|"main-identities-squid"|"stats-squid") { +export function hasSupport(network: string, feature: "archive"|"explorer-squid"|"main-squid"|"identities-squid"|"stats-squid") { switch(feature) { case "archive": return !!getArchive(network); - case "balances-squid": return !!getBalancesSquid(network); case "explorer-squid": return !!getExplorerSquid(network); case "main-squid": return !!getMainSquid(network); - case "main-identities-squid": return !!getMainIdentitesSquid(network); + case "identities-squid": return !!getIdentitesSquid(network); case "stats-squid": return !!getStatsSquid(network); } } diff --git a/src/utils/balance.ts b/src/utils/balance.ts index c5d9e830..c98c23b8 100644 --- a/src/utils/balance.ts +++ b/src/utils/balance.ts @@ -3,7 +3,7 @@ import { AccountBalance, Balance } from "../model/accountBalance"; import { UsdRates } from "../model/usdRates"; import { uniq } from "./uniq"; -export function balanceSum(balances: AccountBalance[]|undefined, type: keyof Omit) { +export function balanceSum(balances: AccountBalance[]|undefined, type: keyof Omit) { if (uniq((balances || []).map(it => it.network.symbol)).length > 0) { throw new Error("Cannot sum balances of different symbols"); } @@ -13,7 +13,7 @@ export function balanceSum(balances: AccountBalance[]|undefined, type: keyof Omi )); } -export function usdBalanceSum(balances: AccountBalance[]|undefined, type: keyof Omit, usdRates: UsdRates|undefined) { +export function usdBalanceSum(balances: AccountBalance[]|undefined, type: keyof Omit, usdRates: UsdRates|undefined) { console.log(balances); console.log(usdRates); return Decimal.sum(new Decimal(0), ...(balances || []).map(it => diff --git a/test/e2e/account.fixture.json b/test/e2e/account.fixture.json index 2590befb..fc0fba20 100644 --- a/test/e2e/account.fixture.json +++ b/test/e2e/account.fixture.json @@ -16,7 +16,7 @@ "free": "87402905689471", "reserved": "1252580000000", "total": "88655485689471", - "updatedAt": 14688400 + "updatedAtBlock": 14688400 } } }, @@ -35,7 +35,7 @@ "free": "1036706567490360", "reserved": "10000000000000", "total": "1046706567490360", - "updatedAt": 15120699 + "updatedAtBlock": 15120699 } } }, @@ -44,19 +44,6 @@ "free": ["1,036.7066 KSM", "$35,299.86"], "reserved": ["10 KSM", "$340.5"] } - }, - { - "network": "moonriver", - "response": { - "data": { - "balance": null - } - }, - "display": { - "total": ["0 MOVR"], - "free": ["0 MOVR"], - "reserved": ["0 MOVR"] - } } ], "usdRates": { diff --git a/test/e2e/account.spec.ts b/test/e2e/account.spec.ts index 8b788437..251f5649 100644 --- a/test/e2e/account.spec.ts +++ b/test/e2e/account.spec.ts @@ -1,3 +1,8 @@ +import { Request } from "@playwright/test"; + +import { encodeAddress } from "../../src/utils/formatAddress"; +import { getNetwork } from "../../src/services/networksService"; + import { clearCapturedPageEvents, waitForPageEvent } from "../utils/events"; import { mockRequest } from "../utils/mockRequest"; import { navigate } from "../utils/navigate"; @@ -6,6 +11,24 @@ import { test, expect } from "../utils/test"; import fixtures from "./account.fixture.json"; +function isAccountBalanceQuery(request: Request, networkName?: string, address?: string) { + const network = networkName ? getNetwork(networkName) : undefined; + + if (!request.url().match(`gs-stats-${network?.name || ""}`)) { + return false; + } + + if (!request.postDataJSON()?.query.match("accountById")) { + return false; + } + + if (network && address && request.postDataJSON()?.variables?.address !== encodeAddress(address, network.prefix)) { + return false; + } + + return true; +} + test.describe("Account detail page", () => { const address = "0xa69484f2b10ec2f1dea19394423d576f91c6b5ab2315b389f4e108bcf0aa2840"; @@ -13,7 +36,7 @@ test.describe("Account detail page", () => { test.beforeEach(async ({ page }) => { await page.route("**/*", (route, request) => { for (const balanceFixture of fixtures.balances) { - if (request.url().match(`${balanceFixture.network}-balances`)) { + if (isAccountBalanceQuery(request, balanceFixture.network, address)) { return route.fulfill({ status: 200, body: JSON.stringify(balanceFixture.response) @@ -75,7 +98,7 @@ test.describe("Account detail page", () => { test("shows portfolio not found message if no account balances found", async ({ page, takeScreenshot }) => { await page.route("**/*", (route, request) => { - if (request.url().match(/[a-z]+-balances/)) { + if (isAccountBalanceQuery(request)) { return route.fulfill({ status: 200, body: JSON.stringify({ @@ -122,7 +145,7 @@ test.describe("Account detail page", () => { test("shows error message if account balances fetch fails", async ({ page, takeScreenshot }) => { await page.route("**/*", (route, request) => { - if (request.url().match("kusama-balances")) { + if (isAccountBalanceQuery(request, "kusama")) { return route.fulfill({ status: 200, body: JSON.stringify({ @@ -191,7 +214,7 @@ test.describe("Account detail page", () => { const id = "0x123456789"; await page.route("**/*", (route, request) => { - if (request.url().match(/[a-z]+-balances/)) { + if (isAccountBalanceQuery(request)) { return route.fulfill({ status: 200, body: JSON.stringify({ diff --git a/test/utils/screenshot.ts b/test/utils/screenshot.ts index aba80560..73b97c9e 100644 --- a/test/utils/screenshot.ts +++ b/test/utils/screenshot.ts @@ -7,7 +7,7 @@ const hideSelectors = [ ]; export async function screenshot(page: Page, element: Locator|undefined, path: string) { - page.evaluate((hideSelectors) => { + await page.evaluate((hideSelectors) => { const topBar = document.querySelector("[data-test=top-bar"); if (topBar) { topBar.style.position = "relative"; @@ -29,7 +29,7 @@ export async function screenshot(page: Page, element: Locator|undefined, path: s ? await element.screenshot({path, animations: "disabled"}) : await page.screenshot({path, fullPage: true, animations: "disabled"}); - page.evaluate((hideSelectors) => { + await page.evaluate((hideSelectors) => { const topBar = document.querySelector("[data-test=top-bar"); if (topBar) { topBar.style.position = "";