Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions e2e/tests/shared/mocked/zcash-blocks.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import type { Page } from "@playwright/test";
import {
BLOCK_3483400,
COINBASE_TX,
} from "../../../../src/services/adapters/ZcashAdapter/fixtures";
import { expect, test } from "../../../fixtures/test";
import { mockZcashRpc, ZCASH, ZCASH_RPC_PATTERN } from "../../../fixtures/zcash";

// Before NU5 (mainnet height 1,687,104) blocks have no Orchard root, tree or block commitments
const PRE_NU5_HEIGHT = 1_000_000;
const PRE_NU5_BLOCK = {
...BLOCK_3483400,
height: PRE_NU5_HEIGHT,
hash: PRE_NU5_HEIGHT.toString(16).padStart(64, "0"),
finalorchardroot: undefined,
blockcommitments: undefined,
trees: { sapling: { size: 123_456 } },
tx: [COINBASE_TX],
};

/**
* Answer one getblock request from the test instead of the shared mock
*/
async function overrideGetBlock(
page: Page,
respond: (params: unknown[]) => { result: unknown } | { error: string } | null,
) {
await page.route(ZCASH_RPC_PATTERN, async (route) => {
const body = JSON.parse(route.request().postData() ?? "{}");
const response = body.method === "getblock" ? respond(body.params ?? []) : null;
if (!response) {
await route.fallback();
return;
}
await route.fulfill({
contentType: "application/json",
body: JSON.stringify(
"error" in response
? { jsonrpc: "2.0", id: body.id, error: { code: -8, message: response.error } }
: { jsonrpc: "2.0", id: body.id, result: response.result },
),
});
});
}

/**
* Hermetic Zcash blocks list and block detail pages, served from mainnet block 3,483,400.
*/
test.describe("Zcash blocks", () => {
test("lists the latest blocks one call per block and pages to older blocks", async ({
page,
}) => {
const calls = await mockZcashRpc(page);

await page.goto(`/#/${ZCASH.networkSlug}/blocks`);

const table = page.locator("table.blocks-table");
await expect(table).toContainText("3,483,400");
await expect(table).toContainText("3,483,391");
await expect(table.locator("tbody tr")).toHaveCount(10);

const summaryHeights = calls
.filter((call) => call.method === "getblock" && call.params[1] === 1)
.map((call) => call.params[0]);
expect(summaryHeights).toContain("3483391");
expect(calls.map((call) => call.method)).not.toContain("getblockhash");

await page.getByRole("button", { name: "Older →" }).click();
await expect(page).toHaveURL(/fromBlock=3483390/);
await expect(table).toContainText("3,483,381");
});

test("shows Zcash-specific block details", async ({ page }) => {
const calls = await mockZcashRpc(page);

await page.goto(`/#/${ZCASH.networkSlug}/block/${ZCASH.tipHeight}`);

await expect(page.locator(".block-number")).toHaveText("#3,483,400");
await expect(page.getByText(BLOCK_3483400.hash)).toBeVisible();
await expect(page.getByText("t1SqwRAAdSig6dE4EBPLonAait219VmkUjP")).toBeVisible();
await expect(page.getByText("2 Sapling")).toBeVisible();
await expect(page.getByText("2 Ironwood")).toBeVisible();
await expect(page.getByTestId("zcash-value-pools")).toContainText("Value Pools After This Block");

await page.getByRole("button", { name: "+ Show More Details" }).click();
await expect(page.getByText(BLOCK_3483400.nonce)).toBeVisible();
await expect(page.getByText("Equihash Solution:")).toBeVisible();
await expect(page.getByText("Ironwood 318,976")).toBeVisible();

// Only the requested block is fetched with full transactions, by height string. The dev
// server runs React StrictMode, which can issue the same request twice.
const verboseBlockCalls = calls.filter(
(call) => call.method === "getblock" && call.params[1] === 2,
);
expect(new Set(verboseBlockCalls.map((call) => call.params[0]))).toEqual(new Set(["3483400"]));
});

test("renders a pre-NU5 block without Orchard fields", async ({ page }) => {
await mockZcashRpc(page);
await overrideGetBlock(page, ([height]) =>
height === String(PRE_NU5_HEIGHT) ? { result: PRE_NU5_BLOCK } : null,
);

await page.goto(`/#/${ZCASH.networkSlug}/block/${PRE_NU5_HEIGHT}`);
await expect(page.locator(".block-number")).toHaveText("#1,000,000");

await page.getByRole("button", { name: "+ Show More Details" }).click();
await expect(page.getByText("Final Sapling Root:")).toBeVisible();
await expect(page.getByText("Sapling 123,456")).toBeVisible();
await expect(page.getByText("Final Orchard Root:")).toHaveCount(0);
await expect(page.getByText("Block Commitments:")).toHaveCount(0);
await expect(page.getByText(/Orchard \d/)).toHaveCount(0);
});

test("pages down to the genesis block", async ({ page }) => {
await mockZcashRpc(page);

await page.goto(`/#/${ZCASH.networkSlug}/blocks?fromBlock=3`);

const table = page.locator("table.blocks-table");
await expect(table.locator("tbody tr")).toHaveCount(4);
await expect(table.locator("tbody tr").last()).toContainText("0");
await expect(page.getByRole("button", { name: "Older →" })).toBeDisabled();
await expect(page.getByRole("button", { name: "← Newer" })).toBeEnabled();
});

test("lists a block that failed to load and retries it", async ({ page }) => {
await mockZcashRpc(page);
const failingHeight = String(ZCASH.tipHeight - 5);
// Fails until the retry (React StrictMode may fetch the page twice in development)
let recovered = false;
await overrideGetBlock(page, ([height]) =>
height === failingHeight && !recovered ? { error: "Block not found" } : null,
);

await page.goto(`/#/${ZCASH.networkSlug}/blocks`);

const table = page.locator("table.blocks-table");
const unavailable = table.getByTestId("zcash-block-unavailable");
// Rows arrive one block at a time, so allow for a slow dev server
await expect(unavailable).toContainText("3,483,395", { timeout: 15_000 });
await expect(table.locator("tbody tr")).toHaveCount(10);

recovered = true;
await unavailable.getByRole("button", { name: "Retry" }).click();
await expect(unavailable).toHaveCount(0);
await expect(table).toContainText("3,483,395");
});
});
6 changes: 6 additions & 0 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ import {
LazyTokenDetails,
LazyTx,
LazyTxs,
LazyZcashBlock,
LazyZcashBlocks,
LazyZcashNetwork,
preloadAllRoutes,
} from "./components/LazyComponents";
Expand Down Expand Up @@ -162,8 +164,12 @@ function AppContent() {
<Route path="tbtc/mempool/:filter" element={<LazyBitcoinTx />} />
{/* Zcash Mainnet routes (must come before :networkId catch-all) */}
<Route path="zec" element={<LazyZcashNetwork />} />
<Route path="zec/blocks" element={<LazyZcashBlocks />} />
<Route path="zec/block/:filter" element={<LazyZcashBlock />} />
{/* Zcash Testnet routes */}
<Route path="tzec" element={<LazyZcashNetwork />} />
<Route path="tzec/blocks" element={<LazyZcashBlocks />} />
<Route path="tzec/block/:filter" element={<LazyZcashBlock />} />
{/* Solana Mainnet routes (must come before :networkId catch-all) */}
<Route path="sol" element={<LazySolanaNetwork />} />
<Route path="sol/slots" element={<LazySolanaSlots />} />
Expand Down
6 changes: 6 additions & 0 deletions src/components/LazyComponents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ const BitcoinMempoolPage = lazy(() => import("./pages/bitcoin/BitcoinMempoolPage

// Lazy load page components - Zcash
const ZcashNetwork = lazy(() => import("./pages/zcash"));
const ZcashBlocksPage = lazy(() => import("./pages/zcash/ZcashBlocksPage"));
const ZcashBlockPage = lazy(() => import("./pages/zcash/ZcashBlockPage"));

// Lazy load page components - Solana
const SolanaNetwork = lazy(() => import("./pages/solana"));
Expand Down Expand Up @@ -68,6 +70,8 @@ export const LazyBitcoinTxs = withSuspense(BitcoinTransactionsPage);
export const LazyBitcoinAddress = withSuspense(BitcoinAddressPage);
export const LazyBitcoinMempool = withSuspense(BitcoinMempoolPage);
export const LazyZcashNetwork = withSuspense(ZcashNetwork);
export const LazyZcashBlocks = withSuspense(ZcashBlocksPage);
export const LazyZcashBlock = withSuspense(ZcashBlockPage);
export const LazySolanaNetwork = withSuspense(SolanaNetwork);
export const LazySolanaSlots = withSuspense(SolanaSlotsPage);
export const LazySolanaSlot = withSuspense(SolanaSlotPage);
Expand Down Expand Up @@ -115,6 +119,8 @@ export function preloadAllRoutes() {
import("./pages/bitcoin/BitcoinMempoolPage");
// Zcash pages
import("./pages/zcash");
import("./pages/zcash/ZcashBlocksPage");
import("./pages/zcash/ZcashBlockPage");
// Solana pages
import("./pages/solana");
import("./pages/solana/SolanaSlotsPage");
Expand Down
10 changes: 6 additions & 4 deletions src/components/common/LoaderWithTimeout.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type React from "react";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { Link } from "react-router-dom";
import OpenScanCubeLoader from "../LoadingLogo";

Expand All @@ -16,8 +17,9 @@ const LoaderWithTimeout: React.FC<LoaderWithTimeoutProps> = ({
size = 60,
timeoutMs = 15000,
onRetry,
timeoutText = "Data is taking longer than expected.",
timeoutText,
}) => {
const { t } = useTranslation("common");
const [timedOut, setTimedOut] = useState(false);

useEffect(() => {
Expand All @@ -40,15 +42,15 @@ const LoaderWithTimeout: React.FC<LoaderWithTimeoutProps> = ({
<circle cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="1.5" />
<path d="M12 6v6l4 2" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" />
</svg>
<p className="loader-timeout-text">{timeoutText}</p>
<p className="loader-timeout-text">{timeoutText ?? t("loaderTimeout.message")}</p>
<div className="loader-timeout-actions">
{onRetry && (
<button type="button" onClick={onRetry} className="button-primary-inline">
Retry
{t("loaderTimeout.retry")}
</button>
)}
<Link to="/" className="button-secondary-inline">
Go Home
{t("errors.goHome")}
</Link>
</div>
</div>
Expand Down
Loading