Files
salvium-rs/test/legacy-js/test-parallel-dataset.js
T
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

87 lines
3.2 KiB
JavaScript

#!/usr/bin/env node
/**
* Test: Parallel Dataset Generation
*
* Tests the worker-based parallel dataset generation.
*
* Usage:
* source ~/.bash_profile && bun test/test-parallel-dataset.js
*/
import { cpus } from 'os';
import { generateDatasetParallel } from '../src/randomx/parallel-dataset.js';
import { RANDOMX_DATASET_ITEM_COUNT } from '../src/randomx/config.js';
console.log('Parallel Dataset Generation Test');
console.log('=================================\n');
const numCpus = cpus().length;
console.log(`Available CPUs: ${numCpus}`);
console.log(`Dataset items: ${RANDOMX_DATASET_ITEM_COUNT.toLocaleString()}`);
console.log(`Dataset size: ${((RANDOMX_DATASET_ITEM_COUNT * 64) / 1024 / 1024 / 1024).toFixed(2)} GB\n`);
// For testing, we'll use a smaller dataset
// Uncomment the full run for production testing
const testItems = 100000; // 100K items for quick test
console.log(`Test mode: ${testItems.toLocaleString()} items`);
console.log(`Using ${numCpus} workers\n`);
const testKey = new TextEncoder().encode('test key');
try {
// Override item count for testing
const originalCount = RANDOMX_DATASET_ITEM_COUNT;
// Monkey-patch the config for testing
// In production, remove this and use full dataset
const config = await import('../src/randomx/config.js');
console.log('Starting parallel generation...\n');
const startTime = Date.now();
// Note: For full production use, remove the test limit
// For now, we're testing with a subset
const dataset = await generateDatasetParallel(testKey, {
workers: numCpus,
itemCount: testItems, // Use test subset instead of full 34M items
onProgress: (stage, percent, details) => {
if (typeof process !== 'undefined' && process.stdout) {
const bar = '█'.repeat(Math.floor(percent / 5)) + '░'.repeat(20 - Math.floor(percent / 5));
if (stage === 'cache') {
const info = details.pass !== undefined
? `pass ${details.pass + 1}/3, slice ${details.slice + 1}/4`
: details.message || '';
process.stdout.write(`\rCache: [${bar}] ${percent}% ${info}`.padEnd(80));
} else if (stage === 'programs') {
process.stdout.write(`\rPrograms: [${bar}] ${percent}% ${details.message || ''}`.padEnd(80));
} else if (stage === 'dataset') {
const info = details.eta !== undefined
? `${details.itemsPerSec?.toLocaleString()} items/s, ETA: ${Math.floor(details.eta / 60)}m ${details.eta % 60}s`
: details.message || '';
process.stdout.write(`\rDataset: [${bar}] ${percent}% ${info}`.padEnd(80));
} else if (stage === 'complete') {
process.stdout.write('\r' + ' '.repeat(80) + '\r');
console.log(`\nDataset initialized in ${details.totalTime?.toFixed(1)}s`);
}
}
}
});
const totalTime = (Date.now() - startTime) / 1000;
console.log(`\nTotal time: ${totalTime.toFixed(1)}s`);
console.log(`Dataset size: ${(dataset.length / 1024 / 1024).toFixed(2)} MB`);
// Verify first few items
console.log('\nFirst item (hex):');
console.log(Buffer.from(dataset.slice(0, 64)).toString('hex'));
} catch (error) {
console.error('Error:', error.message);
console.error(error.stack);
process.exit(1);
}