if (NanoPow && Logger) {
document.getElementById('btnStartTest').disabled = false
- document.getElementById('status').innerHTML = `READY`
+ document.getElementById('status').textContent = `READY`
}
const logger = new Logger()
duration = end - start
const valid = (result.hash === hash && check.hash === hash && check.valid === '1')
- document.getElementById('output').textContent += `${valid ? 'VALID' : 'INVALID'} (${duration} ms)\n${JSON.stringify(result, ' ', 2)}\n`
if (!valid) {
logger.log(hash, result, check)
throw new Error(`invalid result\nblock hash: ${hash}\nwork: ${work}`)
* @param {string} api
*/
async function selfCheck (api) {
- document.getElementById('status').innerHTML = `RUNNING SELF-CHECK`
+ document.getElementById('status').textContent = `RUNNING SELF-CHECK`
logger.log(`%cNanoPow`, 'color:green', 'Checking validation against known values')
const options = { api, debug: true }
// Generate once on load to compile shaders and initialize buffers
result = await NanoPow.work_generate(hash, options)
logger.log(result)
} catch (err) {
- document.getElementById('output').innerHTML += `Error: ${err.message}<br/>${err.cause}<br/>${err.stack}`
console.error(err)
return
}
}
if (!expect.every(result => result)) {
- document.getElementById('status').innerHTML = `FAILED TO VALIDATE KNOWN VALUES`
- document.getElementById('output').innerHTML += `Error: Failed to validate known values<br/>`
+ document.getElementById('status').textContent = `FAILED TO VALIDATE KNOWN VALUES, CHECK CONSOLE`
throw new Error(`Validation is not working`)
}
}
await selfCheck(api)
Cache.clear()
logger.log(`%cNanoPow ${type}`, 'color:green', `Calculate truncated harmonic mean of the truncated arithmetic rate of generating proof-of-work for ${size} samples over ${runs} test runs.`)
+ const output = document.getElementById('output').appendChild(document.createElement('pre'))
const rates = []
for (let i = 0; i < runs; i++) {
- await new Promise(r => setTimeout(r))
const times = []
for (let j = 0; j < size; j++) {
- document.getElementById('status').innerHTML = `TESTING IN PROGRESS. THIS MAY TAKE A LONG TIME. ${j}/${size} ${i}/${runs}<br/>`
+ document.getElementById('status').textContent = `TESTING IN PROGRESS. THIS MAY TAKE A LONG TIME. ${j}/${size} ${i}/${runs}`
try {
const duration = await sequenceGenerateValidate(api, difficulty, effort)
times.push(duration)
} catch (err) {
- document.getElementById('output').innerHTML += `Error: ${err.message}<br/>`
+ output.textContent += `Error: ${err.message}\n`
console.error(err)
return
}
const result = Object.values(avg)[0]
const { truncatedRate } = result
rates.push(truncatedRate)
- document.getElementById('summary').innerHTML += `Test run ${i + 1} score: ${truncatedRate} wps<br/>`
- document.getElementById('output').innerHTML += `${JSON.stringify(avg, null, '\t')}<br/>`
+ document.getElementById('summary').textContent += `Test run ${i + 1} score: ${truncatedRate} wps\n`
+ output.textContent += `${JSON.stringify(avg, null, '\t')}\n`
}
const results = stats(rates)
const { truncatedHarmonic } = results
logger.log(rates)
logger.log(results)
- document.getElementById('output').innerHTML += `<hr/>`
- document.getElementById('summary').innerHTML += `Final work-per-second: ${truncatedHarmonic}<br/>`
- document.getElementById('status').innerHTML = `TESTING COMPLETE<br/>`
+ output.after(document.createElement('hr'))
+ document.getElementById('summary').textContent += `Final work-per-second: ${truncatedHarmonic}\n`
+ document.getElementById('status').textContent = `TESTING COMPLETE`
logger.log('%TESTING COMPLETE', 'color:orange;font-weight:bold')
}
<pre id="summary"></pre>
<hr />
<h4>Output</h4>
- <pre id="output"></pre>
+ <div id="output"></div>
</body>
</html>