79 lines
6.1 KiB
JavaScript
79 lines
6.1 KiB
JavaScript
// node --test tools/observer/vendor-share.test.mjs
|
|
// Fabricated rows: one known-finished case (two reporting workers, every blue block mapped) and one known-failed
|
|
// case (a vote key no reporting machine owns lands in "unknown"; a stale upload is left out; a 0 MH/s worker counts 0).
|
|
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { compute, parseStatus, parseVoteKeys, parseCardsLine, vendorOfWorker, cardOfWorker, VENDORS } from './vendor-share.mjs';
|
|
|
|
const NOW = Date.parse('2026-10-06T08:00:00Z');
|
|
const status = (label, mhs, ageS = 20) => `${(NOW / 1000 - ageS).toFixed(3)} STATUS '${label}' [worker]: 20212s jobs=137109 accepted=16053 rejected=0 fee=152 mismatched=0 extra=1059 rate=0.79 blocks/s hash=113.81 MH/s wall (114.08 MH/s inside jobs) now=${mhs.toFixed(2)} MH/s wall (113.92 MH/s inside jobs, 204 jobs, seed walk 0 calls) template_age=0.80s synced=true idle=0.2% (last 30s: 0.0%) queued=1 restarts=0 faults=0 identities=2 accepted_by_identity=8044/8009`;
|
|
const K1 = 'a'.repeat(64), K2 = 'b'.repeat(64), K3 = 'c'.repeat(64), K4 = 'd'.repeat(64), KX = 'e'.repeat(64);
|
|
const cards = {
|
|
'1ccfe586': parseCardsLine('1791271300 cards: NVIDIA GeForce RTX 5090 [discrete, mining] | AMD Radeon(TM) Graphics [integrated, off]'),
|
|
'ae432dc7': parseCardsLine('1791271259 cards: NVIDIA GeForce RTX 5090 [discrete, mining] | AMD Radeon(TM) Graphics [integrated, off] | AMD Radeon RX 9070 XT [discrete, mining]'),
|
|
'37ba0461': parseCardsLine('1791271315 cards: Intel(R) UHD Graphics [integrated, mining]'),
|
|
'd937c69d': parseCardsLine('1791271752 cards: Apple M5 Max [apple, off]'),
|
|
};
|
|
|
|
test('the parsers read the app\'s own line shapes', () => {
|
|
const s = parseStatus(status('nvidia-1ccfe586-1', 113.87));
|
|
assert.equal(s.label, 'nvidia-1ccfe586-1'); assert.equal(s.nowMhs, 113.87);
|
|
assert.equal(parseStatus('1791270154.425 identity 8 \'nvidia-ae432dc7-1-8\' vote_key_hash=' + K1), null);
|
|
assert.deepEqual(parseVoteKeys(`x\n1 identity 1 'a' vote_key_hash=${K1} pubkey=ff\n2 identity 2 'a' vote_key_hash=${K2}\n3 identity 1 'a' vote_key_hash=${K1}`), [K1, K2]);
|
|
assert.deepEqual(cards['ae432dc7'], ['NVIDIA GeForce RTX 5090', 'AMD Radeon(TM) Graphics', 'AMD Radeon RX 9070 XT']);
|
|
assert.equal(vendorOfWorker('miner-amd-ae432dc7-3', cards['ae432dc7']), 'amd');
|
|
assert.equal(cardOfWorker('miner-amd-ae432dc7-3', cards['ae432dc7']), 'AMD Radeon RX 9070 XT');
|
|
assert.equal(vendorOfWorker('miner-other-37ba0461-1', cards['37ba0461']), 'intel');
|
|
assert.equal(vendorOfWorker('miner-other-37ba0461-1', undefined), 'unknown');
|
|
assert.equal(vendorOfWorker('miner-mac-d937c69d-1', cards['d937c69d']), 'apple');
|
|
});
|
|
|
|
test('known-finished: two workers, every blue block mapped, both readings agree on the vendor order', () => {
|
|
const workers = [
|
|
{ label: 'miner-nvidia-1ccfe586-1', machine: 'DESKTOP-1ccfe586', received_at: NOW - 30_000, status: status('nvidia-1ccfe586-1', 113.87), keys: [K1, K2] },
|
|
{ label: 'miner-amd-ae432dc7-3', machine: 'DESKTOP-ae432dc7', received_at: NOW - 45_000, status: status('amd-ae432dc7-3', 19.09), keys: [K3] },
|
|
];
|
|
const blocks = [{ vote_key_hash: K1, blue: 45 }, { vote_key_hash: K2, blue: 40 }, { vote_key_hash: K3, blue: 15 }];
|
|
const v = compute({ workers, machineCards: cards, blocks, networkHps: 133e6, nowMs: NOW, hpsSource: 'test' });
|
|
assert.equal(v.fleet_reported.total_mhs, 132.96);
|
|
assert.equal(v.fleet_reported.by_vendor.nvidia.mhs, 113.87);
|
|
assert.equal(v.fleet_reported.by_vendor.amd.mhs, 19.09);
|
|
assert.equal(v.fleet_reported.workers, 2); assert.equal(v.fleet_reported.machines, 2);
|
|
assert.equal(v.chain_attributed.blue_blocks_total, 100);
|
|
assert.equal(v.chain_attributed.by_vendor.nvidia.share, 0.85);
|
|
assert.equal(v.chain_attributed.by_vendor.nvidia.mhs, 113.05);
|
|
assert.equal(v.chain_attributed.by_vendor.amd.share, 0.15);
|
|
assert.equal(v.chain_attributed.by_vendor.unknown.blue_blocks, 0);
|
|
assert.equal(v.coverage, 1);
|
|
assert.deepEqual(Object.keys(v.by_vendor), VENDORS);
|
|
assert.equal(v.fleet_reported.rows[1].card, 'AMD Radeon RX 9070 XT');
|
|
});
|
|
|
|
test('known-failed: a vote key no reporting machine owns lands in unknown; a stale upload is left out; 0 MH/s counts 0', () => {
|
|
const workers = [
|
|
{ label: 'miner-nvidia-1ccfe586-1', machine: 'DESKTOP-1ccfe586', received_at: NOW - 30_000, status: status('nvidia-1ccfe586-1', 113.87), keys: [K1, K2] },
|
|
// the Mac paused 40 minutes ago: its upload is outside the window and must not count, but its keys still map
|
|
{ label: 'miner-mac-d937c69d-1', machine: 'MacBook-Pro-d937c69d', received_at: NOW - 40 * 60_000, status: status('mac-d937c69d-1', 27.9, 2400), keys: [K4] },
|
|
// a worker whose newest STATUS line says 0 (the watchdog's zero case)
|
|
{ label: 'miner-other-37ba0461-1', machine: 'DESKTOP-37ba0461', received_at: NOW - 10_000, status: status('other-37ba0461-1', 0), keys: [] },
|
|
];
|
|
const blocks = [{ vote_key_hash: K1, blue: 50 }, { vote_key_hash: K2, blue: 30 }, { vote_key_hash: KX, blue: 20 }, { vote_key_hash: K4, blue: 0 }];
|
|
const v = compute({ workers, machineCards: cards, blocks, networkHps: 200e6, nowMs: NOW });
|
|
assert.equal(v.fleet_reported.workers, 2, 'the stale Mac upload is out');
|
|
assert.equal(v.fleet_reported.by_vendor.apple.mhs, 0);
|
|
assert.equal(v.fleet_reported.by_vendor.intel.mhs, 0);
|
|
assert.equal(v.fleet_reported.by_vendor.intel.workers, 1);
|
|
assert.equal(v.fleet_reported.total_mhs, 113.87);
|
|
assert.equal(v.chain_attributed.by_vendor.unknown.blue_blocks, 20);
|
|
assert.equal(v.chain_attributed.by_vendor.unknown.share, 0.2);
|
|
assert.equal(v.chain_attributed.by_vendor.unknown.mhs, 40);
|
|
assert.deepEqual(v.chain_attributed.unknown_miner_ids, [KX.slice(0, 8)]);
|
|
assert.equal(v.chain_attributed.by_vendor.apple.blue_blocks, 0, 'a key with no blue blocks adds nothing');
|
|
assert.equal(v.chain_attributed.mapped_keys, 3, 'the paused Mac\'s key is still in the map');
|
|
assert.equal(v.coverage, 0.8);
|
|
// no network estimate: shares stand, MH/s is null
|
|
const w = compute({ workers, machineCards: cards, blocks, networkHps: null, nowMs: NOW });
|
|
assert.equal(w.chain_attributed.by_vendor.nvidia.share, 0.8);
|
|
assert.equal(w.chain_attributed.by_vendor.nvidia.mhs, null);
|
|
assert.equal(w.network_hps, null);
|
|
});
|