From f441c90d400571cc08731e9c3e32139a7d23622b Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 12 Jan 2025 14:45:03 -0800 Subject: [PATCH] Add test for NanoPow smart class selection. --- test.html | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/test.html b/test.html index 21777b9..320ec3e 100644 --- a/test.html +++ b/test.html @@ -59,12 +59,37 @@ SPDX-License-Identifier: GPL-3.0-or-later console.log(`Geometric Mean: ${geometric} ms`) } - console.log(`%cNanoWebGpu`, 'color:green', 'Testing validation function') - const expectFalse = await NanoPowGpu.validate('0000000000000000', '0000000000000000000000000000000000000000000000000000000000000000') + console.log(`%cNanoPow`, 'color:green', 'Testing validation function') + const expectFalse = await NanoPow.validate('0000000000000000', '0000000000000000000000000000000000000000000000000000000000000000') console.log(`validate() output for bad nonce is ${expectFalse === false ? 'correct' : 'incorrect'}`) - const expectTrue = await NanoPowGpu.validate('47c83266398728cf', '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D') + const expectTrue = await NanoPow.validate('47c83266398728cf', '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D') console.log(`validate() output for good nonce is ${expectTrue === true ? 'correct' : 'incorrect'}`) + console.log(`%cNanoPow `, 'color:green', `Calculate proof-of-work for ${COUNT} unique send block hashes`) + times = [] + document.getElementById('output').innerHTML += `Now testing: NanoPow
` + for (let i = 0; i < COUNT; i++) { + const hash = random() + let work = null + let isValid = null + const start = performance.now() + try { + work = await NanoPow.search(hash) + isValid = (await NanoPow.validate(work, hash)) ? 'VALID' : 'INVALID' + } catch (err) { + document.getElementById('output').innerHTML += `Error: ${err.message}
` + console.error(err) + } + const end = performance.now() + times.push(end - start) + const msg = `${isValid} [${work}] ${hash} (${end - start} ms)` + console.log(msg) + document.getElementById('output').innerHTML += `${msg}
` + } + document.getElementById('output').innerHTML += `-----
` + document.getElementById('summary').innerHTML += `NanoPow
${JSON.stringify(average(times), null, '\t')}
` + print(times) + console.log(`%cNanoPowGpu `, 'color:green', `Calculate proof-of-work for ${COUNT} unique send block hashes`) times = [] document.getElementById('output').innerHTML += `Now testing: NanoPowGpu
` -- 2.34.1