Files
Matt Hess 733ecd2681 Migrate all JS tests to Rust: 9-crate workspace, 703 tests, 0 JS remaining
Add root Cargo workspace with 9 crates: salvium-crypto (extended),
  salvium-types, salvium-consensus, salvium-wallet, salvium-tx,
  salvium-rpc, salvium-miner (extended), salvium-cli, salvium-multisig.

  New modules: chain_state, block_weight, alt_chain, validation,
  offline signing, stake lifecycle, wallet sync/query/encryption/utxo,
  randomx utilities, and full multisig crate with CARROT support.

  Delete 188 JS test/helper/debug files; archive integration test
  scripts to test/legacy-js/ for live testnet use. Testnet integration
  tests (transfer, stake, burn, convert, sweep) remain as #[ignore]-
  gated Rust tests runnable with --ignored against a live daemon.
2026-02-17 23:09:35 +00:00

59 lines
1.7 KiB
JavaScript

/**
* Test Worker Initialization Time
*/
import { Worker, isMainThread, parentPort, workerData } from 'worker_threads';
import { fileURLToPath } from 'url';
if (!isMainThread) {
const { workerId } = workerData;
const startTime = Date.now();
parentPort.postMessage({ type: 'started', workerId });
// Import the module
const { randomx_init_cache, randomx_create_vm } = await import('../src/randomx/vendor/index.js');
parentPort.postMessage({ type: 'imported', workerId, time: Date.now() - startTime });
// Initialize cache
const seedHash = new TextEncoder().encode('test seed');
const cache = randomx_init_cache(seedHash);
parentPort.postMessage({ type: 'cache_ready', workerId, time: Date.now() - startTime });
// Create VM
const vm = randomx_create_vm(cache);
parentPort.postMessage({ type: 'vm_ready', workerId, time: Date.now() - startTime });
// Do one hash
const hash = vm.calculate_hash(new Uint8Array(76));
parentPort.postMessage({ type: 'hashed', workerId, time: Date.now() - startTime });
parentPort.postMessage({ type: 'done', workerId, totalTime: Date.now() - startTime });
} else {
async function main() {
console.log('Worker Initialization Test');
console.log('==========================\n');
const workerPath = fileURLToPath(import.meta.url);
const worker = new Worker(workerPath, {
workerData: { workerId: 0 }
});
worker.on('message', (msg) => {
console.log(`[${msg.type}] Worker ${msg.workerId}: ${msg.time || msg.totalTime || ''}ms`);
if (msg.type === 'done') {
worker.terminate();
console.log('\nDone!');
}
});
worker.on('error', (err) => {
console.error('Worker error:', err);
});
}
main().catch(console.error);
}