Files
universe/e2e/00-health.spec.ts
2026-03-26 22:45:36 -07:00

127 lines
4.6 KiB
TypeScript

import { test, expect } from '@playwright/test'
import {
getUrls, getNetwork, getZooChainId, getLuxChainId,
rpcCall, ethBlockNumber, ethChainId, ethGasPrice,
getNetworkId, isBootstrapped, getNodeVersion,
httpStatus, benchmarkRpc,
} from './helpers'
const urls = getUrls()
const network = getNetwork()
// -- Zoo Chain RPC --------------------------------------------------------
test.describe('Zoo Chain RPC', () => {
test('Zoo returns valid block number', async ({ request }) => {
let block = 0
for (let attempt = 0; attempt < 3; attempt++) {
try {
block = await ethBlockNumber(request, urls.rpcZoo)
break
} catch {
if (attempt < 2) await new Promise(r => setTimeout(r, 1000))
}
}
console.log(` Zoo block: ${block.toLocaleString()}`)
expect(block).toBeGreaterThan(0)
})
test('Zoo returns correct chainId', async ({ request }) => {
const cid = await ethChainId(request, urls.rpcZoo)
const expected = getZooChainId()
console.log(` Zoo chainId: ${cid} (expected ${expected})`)
expect(cid).toBe(expected)
})
test('Zoo returns non-zero gas price', async ({ request }) => {
const gp = await ethGasPrice(request, urls.rpcZoo)
console.log(` Zoo gasPrice: ${Number(gp) / 1e9} gwei`)
expect(gp).toBeGreaterThan(0n)
})
test('Zoo eth_getBalance works', async ({ request }) => {
const result = await rpcCall(request, urls.rpcZoo, 'eth_getBalance', [
'0x0000000000000000000000000000000000000000', 'latest',
])
expect(result).toBeDefined()
})
test('Zoo net_version matches chain ID', async ({ request }) => {
const result = await rpcCall(request, urls.rpcZoo, 'net_version') as string
const expected = getZooChainId()
console.log(` net_version: ${result} (expected ${expected})`)
expect(parseInt(result, 10)).toBe(expected)
})
})
// -- Parent Node Info -----------------------------------------------------
test.describe('Parent Node Info', () => {
test('returns correct Lux network ID', async ({ request }) => {
const nid = await getNetworkId(request, urls.rpcInfo)
console.log(` Lux networkID: ${nid}`)
// mainnet=1, testnet=2, devnet=3
expect(['1', '2', '3']).toContain(nid)
})
test('returns node version containing lux', async ({ request }) => {
try {
const ver = await getNodeVersion(request, urls.rpcInfo)
console.log(` version: ${ver}`)
expect(ver).toBeTruthy()
expect(ver.toLowerCase()).toContain('lux')
} catch (e: unknown) {
const msg = e instanceof Error ? e.message : String(e)
// info.getNodeVersion blocked at gateway (security) — expected behavior
if (msg.includes('-32601') || msg.includes('not allowed') || msg.includes('403') || msg.includes('Method not found')) {
console.log(' info.getNodeVersion blocked at gateway (security) — PASS')
return
}
throw e
}
})
test('C-Chain is bootstrapped', async ({ request }) => {
const bootstrapped = await isBootstrapped(request, urls.rpcInfo, 'C')
expect(bootstrapped).toBe(true)
})
test('P-Chain is bootstrapped', async ({ request }) => {
const bootstrapped = await isBootstrapped(request, urls.rpcInfo, 'P')
expect(bootstrapped).toBe(true)
})
})
// -- Health Endpoint ------------------------------------------------------
test.describe('Health API', () => {
test('parent node reports healthy', async ({ request }) => {
let healthy = false
for (let attempt = 0; attempt < 3; attempt++) {
try {
const res = await request.get(urls.rpcHealth, { ignoreHTTPSErrors: true, timeout: 15_000 })
const json = await res.json()
healthy = json.healthy ?? json.result?.healthy ?? false
if (healthy) break
} catch {
if (attempt < 2) await new Promise(r => setTimeout(r, 1000))
}
}
console.log(` healthy: ${healthy}`)
expect(healthy).toBe(true)
})
})
// -- Zoo RPC Latency Benchmarks -------------------------------------------
test.describe('Zoo RPC Latency', () => {
test('Zoo eth_blockNumber latency (10x)', async ({ request }) => {
const bench = await benchmarkRpc(request, urls.rpcZoo, 'eth_blockNumber')
console.log(` avg=${bench.avg}ms p50=${bench.p50}ms p99=${bench.p99}ms errors=${bench.errors}`)
expect(bench.errors).toBeLessThanOrEqual(5)
expect(bench.avg).toBeLessThan(5000)
})
test('Zoo eth_chainId latency (10x)', async ({ request }) => {
const bench = await benchmarkRpc(request, urls.rpcZoo, 'eth_chainId')
console.log(` avg=${bench.avg}ms p50=${bench.p50}ms p99=${bench.p99}ms errors=${bench.errors}`)
expect(bench.errors).toBeLessThanOrEqual(5)
})
})