From: Chris Duncan Date: Wed, 12 Mar 2025 21:06:55 +0000 (-0700) Subject: Add tests against max value threshold. Fix validator switching between APIs. X-Git-Tag: v3.1.0~9^2~10 X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=df328d5f5036ebd5255b35247cbe32c6fb522c4f;p=nano-pow.git Add tests against max value threshold. Fix validator switching between APIs. --- diff --git a/test.html b/test.html index 14c42da..718aad9 100644 --- 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