nip13: add minePow function

This commit is contained in:
Alex Gleason
2023-09-10 13:40:57 -05:00
committed by fiatjaf_
parent 13bc2ad5a8
commit 6db8b94275
2 changed files with 51 additions and 1 deletions

View File

@@ -1,7 +1,21 @@
import { getPow } from './nip13.ts'
import { getPow, minePow } from './nip13.ts'
test('identifies proof-of-work difficulty', async () => {
const id = '000006d8c378af1779d2feebc7603a125d99eca0ccf1085959b307f64e5dd358'
const difficulty = getPow(id)
expect(difficulty).toEqual(21)
})
test('mines POW for an event', async () => {
const difficulty = 10
const event = minePow({
kind: 1,
tags: [],
content: 'Hello, world!',
created_at: 0,
pubkey: '79c2cae114ea28a981e7559b4fe7854a473521a8d22a66bbab9fa248eb820ff6',
}, difficulty)
expect(getPow(event.id)).toBeGreaterThanOrEqual(difficulty)
})