Added native RandomX integration check
This commit is contained in:
@@ -2,8 +2,9 @@ import test from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
import { Pool, type PoolConfig } from 'pg';
|
||||
import { generateKeyPairSync, randomUUID, sign } from 'node:crypto';
|
||||
import { mkdtemp, rm, writeFile, mkdir, readFile } from 'node:fs/promises';
|
||||
import { join } from 'node:path';
|
||||
import { access, mkdtemp, rm, writeFile, mkdir, readFile } from 'node:fs/promises';
|
||||
import { constants } from 'node:fs';
|
||||
import { join, resolve } from 'node:path';
|
||||
import { tmpdir } from 'node:os';
|
||||
import { spawn } from 'node:child_process';
|
||||
import { execFile } from 'node:child_process';
|
||||
@@ -30,6 +31,7 @@ import { keccak } from 'hash-wasm';
|
||||
import type { CanonicalInboxPage } from '../../server/market/canonical-inbox.ts';
|
||||
import { CanonicalObserver } from '../../server/market/canonical-observer.ts';
|
||||
import { Ledger } from '../../server/testnet/ledger.ts';
|
||||
import { RandomX } from '../../server/testnet/randomx.ts';
|
||||
import { GENESIS_TIME, makeTemplate, miningBlob, mintId, transition } from '../../server/testnet/consensus.ts';
|
||||
import { deriveStats } from '../../shared/enrichment.ts';
|
||||
import { blockClaimMessage, type NftStateView, type TestnetBlock } from '../../shared/testnet.ts';
|
||||
@@ -577,6 +579,35 @@ test('gated adapter consumes actual validated local Ledger connect and reorg pag
|
||||
await observer.audit();
|
||||
});
|
||||
|
||||
test('observer consumes a block independently validated with the native RandomX engine', { timeout: 120000 }, async t => {
|
||||
const binary = resolve(process.env.RANDOMX_BINARY ?? join(process.cwd(), 'native', 'build', 'wikideck-randomx'));
|
||||
try { await access(binary, constants.X_OK); }
|
||||
catch (error) {
|
||||
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') throw error;
|
||||
t.skip(`Native RandomX binary absent: ${binary}`); return;
|
||||
}
|
||||
const dir = await mkdtemp(join(tmpdir(), 'wikideck-pg-real-randomx-'));
|
||||
const engine = new RandomX({ binary }), ledger = await Ledger.open(dir, engine), f = await fixture(t);
|
||||
const observer = await PostgresCustody.open(f.runtime, { ...options, disposableSaleRehearsal: true });
|
||||
t.after(async () => { await observer.close(); ledger.close(); engine.close(); await rm(dir, { recursive: true, force: true }); });
|
||||
const template = makeTemplate([], {}, seller.actor, seller.publicKey, [], fixtureArticle(55000), fixtureStats(), GENESIS_TIME + 30);
|
||||
const header = structuredClone(template.header);
|
||||
let mined: Awaited<ReturnType<typeof engine.mine>> = null;
|
||||
for (let batch = 0; batch < 16 && !mined; batch++) {
|
||||
mined = await engine.mine(header.key, miningBlob(header), header.target, 32, 64);
|
||||
if (!mined) header.nonce += 64;
|
||||
}
|
||||
assert.ok(mined, 'Native RandomX fixture mining exceeded bounded attempts');
|
||||
header.nonce = mined.nonce;
|
||||
const blockHash = sha256(miningBlob(header));
|
||||
const block: TestnetBlock = { ...header, hash: blockHash, tokenId: mintId(header), powHash: mined.hash,
|
||||
signature: seller.sign(blockClaimMessage(blockHash)), transactions: [] };
|
||||
await ledger.submit(block); // Ledger independently recalculates and validates native RandomX.
|
||||
const page = await observer.observeLedgerCanonicalEvents(ledger);
|
||||
assert.equal(page.cursor, 1); assert.equal(page.height, 1); assert.equal(page.tip, block.hash);
|
||||
await observer.audit();
|
||||
});
|
||||
|
||||
test('scheduled observer bounds catch-up, stops cleanly, and resumes its durable cursor after restart', async t => {
|
||||
const dir = await mkdtemp(join(tmpdir(), 'wikideck-pg-observer-runner-'));
|
||||
const pow = new EasyFixturePow(), ledger = await Ledger.open(dir, pow), f = await fixture(t);
|
||||
|
||||
Reference in New Issue
Block a user