]> zoso.dev Git - nano-pow.git/commitdiff
Add tests against max value threshold. Fix validator switching between APIs.
authorChris Duncan <chris@zoso.dev>
Wed, 12 Mar 2025 21:06:55 +0000 (14:06 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 12 Mar 2025 21:06:55 +0000 (14:06 -0700)
test.html

index 14c42dab08394ee8724778a3509043e6b42efcce..718aad9d8e16167486479934603db91e173ddfa2 100644 (file)
--- a/test.html
+++ b/test.html
@@ -86,6 +86,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        console.log(`validate() output for good nonce 2 is ${result === true ? 'correct' : 'incorrect'}`)
                        expect.push(result === true)
 
+                       result = await NP.validate('326f310d629a8a98', '204076E3364D16A018754FF67D418AB2FBEB38799FF9A29A1D5F9E34F16BEEEA', { threshold: 0xffffffff, debug: isDebug })
+                       console.log(`validate() output for good max threshold nonce is ${result === true ? 'correct' : 'incorrect'}`)
+                       expect.push(result === true)
+
                        result = await NP.validate('c5d5d6f7c5d6ccd1', '281E89AC73B1082B464B9C3C1168384F846D39F6DF25105F8B4A22915E999117', { debug: isDebug })
                        console.log(`validate() output for colliding nonce is ${result === true ? 'correct' : 'incorrect'}`)
                        expect.push(result === true)
@@ -98,6 +102,10 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        console.log(`validate() output for bad nonce 2 is ${result === false ? 'correct' : 'incorrect'}`)
                        expect.push(result === false)
 
+                       result = await NP.validate('ae238556213c3624', 'BF41D87DA3057FDC6050D2B00C06531F89F4AA6195D7C6C2EAAF15B6E703F8F6', { threshold: 0xffffffff, debug: isDebug })
+                       console.log(`validate() output for bad max threshold nonce is ${result === false ? 'correct' : 'incorrect'}`)
+                       expect.push(result === false)
+
                        result = await NP.validate('47c83266398728ce', '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D', { debug: isDebug })
                        console.log(`validate() output for slightly wrong nonce is ${result === false ? 'correct' : 'incorrect'}`)
                        expect.push(result === false)
@@ -110,6 +118,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
                                console.error(err)
                                return
                        }
+
                        console.log(`%cNanoPow (${type})`, 'color:green', `Calculate proof-of-work for ${size} unique send block hashes`)
                        const times = []
                        for (let i = 0; i < size; i++) {
@@ -138,11 +147,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
 
                function startValidation (event) {
                        const threshold = document.getElementById('threshold')
+                       const isGlForced = document.getElementById('isGlForced')
                        const work = document.getElementById('work')
                        const hash = document.getElementById('hash')
                        const validation = document.getElementById('validation')
                        validation.innerText = '⏳'
                        if (work.value.length === 16 && hash.value.length === 64) {
+                               const NP = isGlForced ? NanoPowGl : NanoPow
                                NP.validate(work.value, hash.value, { threshold: `0x${+threshold.value}` })
                                        .then(result => {
                                                validation.innerText = result