"nano-pow/utils": "https://unpkg.com/nano-pow@5.2.2/dist/utils/index.js"
},
"scopes": {
- "/": {
- "nano-pow": "./dist/index.js",
- "nano-pow/utils": "./dist/utils/index.js"
+ "/test/": {
+ "nano-pow": "../dist/index.js",
+ "nano-pow/utils": "../dist/utils/index.js"
}
}
}
return gl?.drawingBufferHeight < gl?.drawingBufferWidth ? gl?.drawingBufferHeight : gl?.drawingBufferWidth
})(new OffscreenCanvas(0, 0))
- function random () {
+ function random() {
const bytes = crypto.getRandomValues(new Uint8Array(32))
return [...bytes].map(b => b.toString(16).padStart(2, '0')).join('')
}
* @param {string} type
* @param {number} effort
*/
- function average (times, type, effort) {
+ function average(times, type, effort) {
const averages = stats(times)
const title = type === 'WebGPU'
? `NanoPow (${type}) | Effort: ${effort} | Dispatch: ${(effort << 8) << 1} | Threads: ${64 * (effort << 8) << 1}`
* @param {string} difficulty
* @param {number} effort
*/
- async function sequenceGenerateValidate (api, difficulty, effort) {
+ async function sequenceGenerateValidate(api, difficulty, effort) {
let start = 0, end = 0, duration = 0, result = null, check = false
const options = { api, difficulty, effort, debug: true }
const hash = random()
* @param {string} name
* @param {boolean} test
*/
- function check (name, test) {
+ function check(name, test) {
if (typeof test !== 'boolean') {
throw 'invalid test'
}
/**
* @param {string} api
*/
- async function selfCheck (api) {
+ async function selfCheck(api) {
if (selfChecked[api]) return
document.getElementById('status').textContent = `RUNNING SELF-CHECK: ${api.toUpperCase()}`
logger.log(`%cNanoPow`, 'color:green', 'Checking validation against known values')
const expect = []
let result
- // PASS
- result = await NanoPow.work_validate('47c83266398728cf', '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D', options)
- logger.log(result)
- result = result.valid_all === '1'
- logger.log(`work_validate() output for good nonce 1 is ${result === true ? 'correct' : 'incorrect'}`)
- expect.push(result)
+ // PASS
+ result = await NanoPow.work_validate('47c83266398728cf', '92BA74A7D6DC7557F3EDA95ADC6341D51AC777A0A6FF0688A5C492AB2B2CB40D', options)
+ logger.log(result)
+ result = result.valid_all === '1'
+ logger.log(`work_validate() output for good nonce 1 is ${result === true ? 'correct' : 'incorrect'}`)
+ expect.push(result)
- result = await NanoPow.work_validate('4a8fb104eebbd336', '8797585D56B8AEA3A62899C31FC088F9BE849BA8298A88E94F6E3112D4E55D01', options)
- logger.log(result)
- result = result.valid_all === '1'
- logger.log(`work_validate() output for good nonce 2 is ${result === true ? 'correct' : 'incorrect'}`)
- expect.push(result)
+ result = await NanoPow.work_validate('4a8fb104eebbd336', '8797585D56B8AEA3A62899C31FC088F9BE849BA8298A88E94F6E3112D4E55D01', options)
+ logger.log(result)
+ result = result.valid_all === '1'
+ logger.log(`work_validate() output for good nonce 2 is ${result === true ? 'correct' : 'incorrect'}`)
+ expect.push(result)
- result = await NanoPow.work_validate('c5d5d6f7c5d6ccd1', '281E89AC73B1082B464B9C3C1168384F846D39F6DF25105F8B4A22915E999117', options)
- logger.log(result)
- result = result.valid_all === '1'
- logger.log(`work_validate() output for colliding nonce is ${result === true ? 'correct' : 'incorrect'}`)
- expect.push(result)
+ result = await NanoPow.work_validate('c5d5d6f7c5d6ccd1', '281E89AC73B1082B464B9C3C1168384F846D39F6DF25105F8B4A22915E999117', options)
+ logger.log(result)
+ result = result.valid_all === '1'
+ logger.log(`work_validate() output for colliding nonce is ${result === true ? 'correct' : 'incorrect'}`)
+ expect.push(result)
- result = await NanoPow.work_validate('6866c1ac3831a891', '7069D9CD1E85D6204301D254B0927F06ACC794C9EA5DF70EA5578458FB597090', { ...options, difficulty: 0xfffffe0000000000n })
- logger.log(result)
- result = result.valid === '1' && result.valid_all === '0' && result.valid_receive === '1'
- logger.log(`work_validate() output for good receive difficulty nonce is ${result === true ? 'correct' : 'incorrect'}`)
- expect.push(result)
+ result = await NanoPow.work_validate('6866c1ac3831a891', '7069D9CD1E85D6204301D254B0927F06ACC794C9EA5DF70EA5578458FB597090', { ...options, difficulty: 0xfffffe0000000000n })
+ logger.log(result)
+ result = result.valid === '1' && result.valid_all === '0' && result.valid_receive === '1'
+ logger.log(`work_validate() output for good receive difficulty nonce is ${result === true ? 'correct' : 'incorrect'}`)
+ expect.push(result)
- // XFAIL
- result = await NanoPow.work_validate('0000000000000000', '0000000000000000000000000000000000000000000000000000000000000000', options)
- logger.log(result)
- result = result.valid_all === '0'
- logger.log(`work_validate() output for bad nonce 1 is ${result === true ? 'correct' : 'incorrect'}`)
- expect.push(result)
+ // XFAIL
+ result = await NanoPow.work_validate('0000000000000000', '0000000000000000000000000000000000000000000000000000000000000000', options)
+ logger.log(result)
+ result = result.valid_all === '0'
+ logger.log(`work_validate() output for bad nonce 1 is ${result === true ? 'correct' : 'incorrect'}`)
+ expect.push(result)
- result = await NanoPow.work_validate('c5d5d6f7c5d6ccd1', 'BA1E946BA3D778C2F30A83D44D2132CC6EEF010D8D06FF10A8ABD0100D8FB47E', options)
- logger.log(result)
- result = result.valid_all === '0'
- logger.log(`work_validate() output for bad nonce 2 is ${result === true ? 'correct' : 'incorrect'}`)
- expect.push(result)
+ result = await NanoPow.work_validate('c5d5d6f7c5d6ccd1', 'BA1E946BA3D778C2F30A83D44D2132CC6EEF010D8D06FF10A8ABD0100D8FB47E', options)
+ logger.log(result)
+ result = result.valid_all === '0'
+ logger.log(`work_validate() output for bad nonce 2 is ${result === true ? 'correct' : 'incorrect'}`)
+ expect.push(result)
- result = await NanoPow.work_validate('ae238556213c3624', 'BF41D87DA3057FDC6050D2B00C06531F89F4AA6195D7C6C2EAAF15B6E703F8F6', { ...options, difficulty: 0xfffffff800000001n })
- logger.log(result)
- result = result.error === 'Invalid difficulty fffffff800000001'
- logger.log(`work_validate() output for bad difficulty beyond max is ${result === true ? 'correct' : 'incorrect'}`)
- expect.push(result)
+ result = await NanoPow.work_validate('ae238556213c3624', 'BF41D87DA3057FDC6050D2B00C06531F89F4AA6195D7C6C2EAAF15B6E703F8F6', { ...options, difficulty: 0xfffffff800000001n })
+ logger.log(result)
+ result = result.error === 'Invalid difficulty fffffff800000001'
+ logger.log(`work_validate() output for bad difficulty beyond max is ${result === true ? 'correct' : 'incorrect'}`)
+ expect.push(result)
- result = await NanoPow.work_validate('29a9ae0236990e2e', '32721F4BD2AFB6F6A08D41CD0DF3C0D9C0B5294F68D0D12422F52B28F0800B5F', options)
- logger.log(result)
- result = result.valid_all === '0'
- logger.log(`work_validate() output for slightly wrong nonce is ${result === true ? 'correct' : 'incorrect'}`)
- expect.push(result)
+ result = await NanoPow.work_validate('29a9ae0236990e2e', '32721F4BD2AFB6F6A08D41CD0DF3C0D9C0B5294F68D0D12422F52B28F0800B5F', options)
+ logger.log(result)
+ result = result.valid_all === '0'
+ logger.log(`work_validate() output for slightly wrong nonce is ${result === true ? 'correct' : 'incorrect'}`)
+ expect.push(result)
- result = await NanoPow.work_validate('7d903b18d03f9820', '39C57C28F904DFE4012288FFF64CE80C0F42601023A9C82108E8F7B2D186C150', { ...options, difficulty: 0xfffffe0000000000n })
- logger.log(result)
- result = result.valid === '0' && result.valid_all === '0' && result.valid_receive === '0'
- logger.log(`work_validate() output for bad receive difficulty nonce is ${result === true ? 'correct' : 'incorrect'}`)
- expect.push(result)
+ result = await NanoPow.work_validate('7d903b18d03f9820', '39C57C28F904DFE4012288FFF64CE80C0F42601023A9C82108E8F7B2D186C150', { ...options, difficulty: 0xfffffe0000000000n })
+ logger.log(result)
+ result = result.valid === '0' && result.valid_all === '0' && result.valid_receive === '0'
+ logger.log(`work_validate() output for bad receive difficulty nonce is ${result === true ? 'correct' : 'incorrect'}`)
+ expect.push(result)
const prefixes = [
'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
'0Xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
'0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff',
- ' 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn ',
+ ' 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn ',
' ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffn ',
'fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'
]
* @param {number} size
* @param {number} runs
*/
- async function test (api, difficulty, effort, size, runs) {
+ async function test(api, difficulty, effort, size, runs) {
logger.isEnabled = true
const type = api
api = type.toLowerCase()
/**
* @param {InputEvent} event
*/
- function startValidation (event) {
+ function startValidation(event) {
const difficulty = document.getElementById('difficulty')?.value
const work = document.getElementById('work')?.value
const hash = document.getElementById('hash')?.value
/**
* @param {InputEvent} event
*/
- function startTest (event) {
+ function startTest(event) {
event.target.disabled = true
const api = document.getElementById('api')
const difficulty = document.getElementById('difficulty')