]> zoso.dev Git - nano-pow.git/commitdiff
Add edge cases to validate check on testing web page. Add manual validation form.
authorChris Duncan <chris@zoso.dev>
Thu, 16 Jan 2025 03:18:13 +0000 (19:18 -0800)
committerChris Duncan <chris@zoso.dev>
Thu, 16 Jan 2025 03:18:13 +0000 (19:18 -0800)
test.html

index ac527953ec6f98a62d052738e050e078f8b199a4..112a0ebadba31dd90d767eccdbd268e715930239 100644 (file)
--- a/test.html
+++ b/test.html
@@ -73,6 +73,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        console.log(`validate() output for bad nonce is ${expectFalse === false ? 'correct' : 'incorrect'}`)
                        const expectTrue = await NanoPow.validate('47c83266398728cf', '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D')
                        console.log(`validate() output for good nonce is ${expectTrue === true ? 'correct' : 'incorrect'}`)
+                       const expectFalseForVariation = await NanoPow.validate('47c83266398728ce', '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D')
+                       console.log(`validate() output for slightly wrong nonce is ${expectFalseForVariation === false ? 'correct' : 'incorrect'}`)
+                       const expectTrueForCollision = await NanoPow.validate('c5d5d6f7c5d6ccd1', '281e89ac73b1082b464b9c3c1168384f846d39f6df25105f8b4a22915e999117')
+                       console.log(`validate() output for colliding nonce is ${expectTrueForCollision === true ? 'correct' : 'incorrect'}`)
                        const type = (NanoPow === NanoPowGpu) ? 'WebGPU' : (NanoPow === NanoPowGl) ? 'WebGL' : 'unknown API'
 
                        try {
@@ -111,6 +115,24 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        console.log('%cTESTING COMPLETE', 'color:orange;font-weight:bold')
                }
 
+               document.getElementById('validate').addEventListener('click', e => {
+                       console.log(e)
+                       const work = document.getElementById('work')
+                       const hash = document.getElementById('hash')
+                       const validated = document.getElementById('validated')
+                       validated.innerText = ''
+                       NanoPow.validate(work.value, hash.value)
+                               .then(result => {
+                                       validated.innerText = result
+                                               ? 'Valid'
+                                               : 'INVALID'
+                               })
+                               .catch(err => {
+                                       console.error(err)
+                                       validated.innerText = err.message
+                               })
+               })
+
                document.getElementById('go').addEventListener('click', e => {
                        const size = document.getElementById('size')
                        const effort = document.getElementById('effort')
@@ -131,6 +153,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
        <p>Times below are in milliseconds and summarized by various averaging methods.</p>
        <p>Level of Effort depends on hardware and does not guarantee faster results.</p>
        <hr />
+       <label for="work">Work</label>
+       <input id="work" type="text" />
+       <label for="hash">Hash</label>
+       <input id="hash" type="text" />
+       <button id="validate">Validate</button>
+       <span id="validated"></span>
+       <hr />
        <label for="size">Test Size</label>
        <input id="size" type="number" value="64" />
        <label for="effort">Effort (1-16)</label>