]> zoso.dev Git - nano-pow.git/commitdiff
Add custom threshold to test page.
authorChris Duncan <chris@zoso.dev>
Mon, 20 Jan 2025 18:51:23 +0000 (10:51 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 20 Jan 2025 18:51:23 +0000 (10:51 -0800)
test.html

index c00e9192fada3a4971f3ace924011316fa5f8037..4e3cc22f75dffec74a3fe5f5ba077655a584104d 100644 (file)
--- a/test.html
+++ b/test.html
@@ -60,7 +60,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        }
                }
 
-               export async function run (size, effort, isOutputShown, isGlForced, isDebug) {
+               export async function run (threshold, size, effort, isOutputShown, isGlForced, isDebug) {
                        if (isGlForced) NanoPow = NanoPowGl
                        document.getElementById('status').innerHTML = `TESTING IN PROGRESS 0/${size}`
                        console.log(`%cNanoPow`, 'color:green', 'Checking validate()')
@@ -90,17 +90,16 @@ SPDX-License-Identifier: GPL-3.0-or-later
                                let work = null
                                const start = performance.now()
                                try {
-                                       work = await NanoPow.search(hash, { threshold: 0, effort, debug: isDebug })
+                                       work = await NanoPow.search(hash, { threshold, effort, debug: isDebug })
                                } catch (err) {
                                        document.getElementById('output').innerHTML += `Error: ${err.message}<br/>`
                                        console.error(err)
+                                       return
                                }
                                const end = performance.now()
-                               // const isValid = (await NanoPow.validate(work, hash, { threshold: 0 })) ? 'VALID' : 'INVALID'
-                               const isValid = 'Valid'
+                               const isValid = (await NanoPow.validate(work, hash, { threshold: 0 })) ? 'VALID' : 'INVALID'
                                times.push(end - start)
                                const msg = `${isValid} [${work}] ${hash} (${end - start} ms)`
-                               // console.log(msg)
                                if (isOutputShown) document.getElementById('output').innerHTML += `${msg}<br/>`
                        }
                        document.getElementById('output').innerHTML += `<hr/>`
@@ -110,11 +109,12 @@ SPDX-License-Identifier: GPL-3.0-or-later
                }
 
                function startValidation (event) {
+                       const threshold = document.getElementById('threshold')
                        const work = document.getElementById('work')
                        const hash = document.getElementById('hash')
                        const validation = document.getElementById('validation')
                        validation.innerText = ''
-                       NanoPow.validate(work.value, hash.value)
+                       NanoPow.validate(work.value, hash.value, { threshold: `0x${+threshold.value}` })
                                .then(result => {
                                        validation.innerText = result
                                                ? 'Valid'
@@ -128,12 +128,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
                document.getElementById('btnStartValidation').addEventListener('click', startValidation)
 
                function startTest (event) {
+                       const threshold = document.getElementById('threshold')
                        const size = document.getElementById('size')
                        const effort = document.getElementById('effort')
                        const isOutputShown = document.getElementById('isOutputShown')
                        const isGlForced = document.getElementById('isGlForced')
                        const isDebug = document.getElementById('isDebug')
-                       run(+size.value, +effort.value, isOutputShown.checked, isGlForced.checked, isDebug.checked)
+                       run(+`0x${threshold.value}`, +size.value, +effort.value, isOutputShown.checked, isGlForced.checked, isDebug.checked)
                }
                document.getElementById('btnStartTest').addEventListener('click', startTest)
        </script>
@@ -149,6 +150,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
        <p>Times below are in milliseconds and are summarized by various averaging methods.</p>
        <p>Level of Effort depends on hardware and does not guarantee faster results.</p>
        <hr />
+       <label for="threshold">Threshold 0x</label>
+       <input id="threshold" type="text" value="FFFFFFF8" />
+       <hr/>
        <label for="work">Work</label>
        <input id="work" type="text" />
        <label for="hash">Hash</label>
@@ -157,7 +161,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
        <span id="validation"></span>
        <hr />
        <label for="size">Test Size</label>
-       <input id="size" type="number" value="1" autofocus />
+       <input id="size" type="number" value="64" autofocus />
        <label for="effort">Effort (1-32)</label>
        <input id="effort" type="number" value="8" min="1" max="32" />
        <span>