2022-10-18 13:48:27 +00:00
|
|
|
import { Bytes, Hash, Hashes, Hex } from '../dist/index.js'
|
2022-10-13 20:06:51 +00:00
|
|
|
import { Precomputed } from './values.js'
|
|
|
|
|
|
|
|
describe('Hash', () => {
|
|
|
|
for (const type of Object.keys(Hashes)) {
|
|
|
|
describe(type, () => {
|
|
|
|
const values = Precomputed.Hash[type]
|
|
|
|
for (const [input, output] of Object.entries(values)) {
|
2022-10-14 11:31:52 +00:00
|
|
|
it(`Should hash "${input}" to "${output.slice(0, 8)}..."`, async () => {
|
2022-10-14 15:32:05 +00:00
|
|
|
const hashed = await Hash.hash(input, Hashes[type])
|
2022-10-13 20:06:51 +00:00
|
|
|
chai.expect(hashed).to.equal(output)
|
|
|
|
})
|
2022-10-14 11:31:52 +00:00
|
|
|
|
|
|
|
it(`Should hash "${input}" to "${output.slice(0, 8)}..." as buffer`, async () => {
|
|
|
|
const outputBuffer = Hex.decode(output)
|
|
|
|
const inputBuffer = Bytes.encode(input)
|
2022-10-14 15:32:05 +00:00
|
|
|
const hashed = await Hash.hash(inputBuffer, Hashes[type])
|
2022-10-14 11:31:52 +00:00
|
|
|
chai.expect(hashed).to.deep.equal(outputBuffer)
|
|
|
|
})
|
2022-10-13 20:06:51 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
})
|