The deploy manifest's contract_hash is the Odra contract *package* hash, which cspr.live indexes at /contract-package/<hex>. We were linking /contract/<hex>, which 404s for these (that route expects a per-version contract hash), so clicking a contract link did not open the block explorer. Verified via the cspr.live API: /contract-packages/<hex> resolves, /contracts/<hex> does not. Fixes contract links across the On-Chain tab, footer, and Explorer search. Deploy-tx and account links were already correct.
102 lines
4.3 KiB
TypeScript
102 lines
4.3 KiB
TypeScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
import {
|
|
loadChainManifest,
|
|
contractExplorerUrl,
|
|
accountExplorerUrl,
|
|
} from "../lib/services/chain_manifest.js";
|
|
import { Ledger } from "../lib/ledger/index.js";
|
|
import { ExplorerService } from "../lib/services/explorer.js";
|
|
import { ServerState } from "../api/state.js";
|
|
|
|
test("chain manifest: loads the real Casper Testnet deployment", () => {
|
|
const m = loadChainManifest();
|
|
assert.equal(m.chain, "casper-test");
|
|
assert.equal(m.mode, "live");
|
|
assert.ok(m.contract_count >= 14, "expected the full deployed contract set");
|
|
assert.equal(m.contracts.length, m.contract_count);
|
|
assert.ok(m.explorer.startsWith("https://"), "explorer base must be an absolute URL");
|
|
});
|
|
|
|
test("chain manifest: every contract gets a resolvable cspr.live link", () => {
|
|
const m = loadChainManifest();
|
|
for (const c of m.contracts) {
|
|
assert.ok(c.name.length > 0);
|
|
assert.match(c.contract_hash, /^hash-[0-9a-f]{64}$/, `bad hash for ${c.name}`);
|
|
// The explorer URL must use the raw hex, with the CLType `hash-` prefix stripped.
|
|
const hex = c.contract_hash.replace(/^hash-/, "");
|
|
assert.equal(c.explorer_url, `${m.explorer}/contract-package/${hex}`);
|
|
assert.ok(!c.explorer_url.includes("hash-"), "explorer URL must not keep the hash- prefix");
|
|
}
|
|
});
|
|
|
|
test("chain manifest: deployer account links to its cspr.live page", () => {
|
|
const m = loadChainManifest();
|
|
assert.match(m.deployer_public_key, /^0[12][0-9a-f]+$/);
|
|
assert.equal(m.deployer_url, `${m.explorer}/account/${m.deployer_public_key}`);
|
|
});
|
|
|
|
test("chain manifest: url builders normalise a trailing slash on the base", () => {
|
|
assert.equal(
|
|
contractExplorerUrl("https://x.io/", "hash-abcdef"),
|
|
"https://x.io/contract-package/abcdef",
|
|
);
|
|
assert.equal(
|
|
accountExplorerUrl("https://x.io", "01ff"),
|
|
"https://x.io/account/01ff",
|
|
);
|
|
});
|
|
|
|
test("chain manifest: exposes real install deploy transactions with cspr.live links", () => {
|
|
const m = loadChainManifest();
|
|
assert.ok(m.transaction_count > 0, "expected real deploy transactions");
|
|
assert.equal(m.transactions.length, m.transaction_count);
|
|
for (const tx of m.transactions) {
|
|
assert.match(tx.deploy_hash, /^[0-9a-f]{64}$/, "deploy hash must be a 32-byte hex");
|
|
assert.equal(tx.deploy_url, `${m.explorer}/deploy/${tx.deploy_hash}`);
|
|
assert.ok(tx.block_height > 0);
|
|
}
|
|
});
|
|
|
|
test("chain manifest: every contract links to its real install deploy tx", () => {
|
|
const m = loadChainManifest();
|
|
const known = new Set(m.transactions.map((t) => t.deploy_hash));
|
|
for (const c of m.contracts) {
|
|
assert.ok(c.deploy_hash, `${c.name} should map to an install deploy`);
|
|
assert.ok(known.has(c.deploy_hash!), "contract deploy hash must exist in the tx log");
|
|
assert.equal(c.deploy_url, `${m.explorer}/deploy/${c.deploy_hash}`);
|
|
}
|
|
});
|
|
|
|
test("chain manifest: repeated loads return a cached, stable manifest", () => {
|
|
assert.deepEqual(loadChainManifest(), loadChainManifest());
|
|
});
|
|
|
|
test("parity: ServerState.chainManifest() backs the /v1/chain + /api/chain routes", () => {
|
|
const s = new ServerState();
|
|
const m = s.chainManifest();
|
|
assert.equal(m.chain, "casper-test");
|
|
assert.ok(m.contracts.length >= 14);
|
|
assert.ok(m.transaction_count > 0);
|
|
assert.deepEqual(m, loadChainManifest());
|
|
});
|
|
|
|
test("explorer: resolves a deployed contract by name with a cspr.live link", () => {
|
|
const results = new ExplorerService(new Ledger()).search("AgentRegistry");
|
|
const contract = results.find((r) => r.kind === "contract");
|
|
assert.ok(contract, "AgentRegistry should resolve as an on-chain contract");
|
|
assert.ok(contract.url?.startsWith("https://testnet.cspr.live/contract-package/"));
|
|
assert.ok(!contract.url?.includes("hash-"));
|
|
});
|
|
|
|
test("explorer: resolves a deployed contract by its on-chain hash", () => {
|
|
const { contracts, explorer } = loadChainManifest();
|
|
const target = contracts[0];
|
|
assert.ok(target, "manifest must have at least one contract");
|
|
const results = new ExplorerService(new Ledger()).search(target.contract_hash);
|
|
const hit = results.find((r) => r.kind === "contract" && r.id === target.contract_hash);
|
|
assert.ok(hit, "a full contract hash should resolve to its contract");
|
|
assert.equal(hit.url, `${explorer}/contract-package/${target.contract_hash.replace(/^hash-/, "")}`);
|
|
});
|