]> zoso.dev Git - nano-pow.git/commitdiff
Add test for NanoPow smart class selection.
authorChris Duncan <chris@zoso.dev>
Sun, 12 Jan 2025 22:45:03 +0000 (14:45 -0800)
committerChris Duncan <chris@zoso.dev>
Sun, 12 Jan 2025 22:45:03 +0000 (14:45 -0800)
test.html

index 21777b90918b9967a4a35ef3d43272a5e6cc0e82..320ec3ed54ab3064b605b9af0ac6a7e7988fe662 100644 (file)
--- 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<br/>`
+               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}<br/>`
+                               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}<br/>`
+               }
+               document.getElementById('output').innerHTML += `-----<br/>`
+               document.getElementById('summary').innerHTML += `NanoPow<br/>${JSON.stringify(average(times), null, '\t')}<br/>`
+               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<br/>`