2018-07-23 09:45:01 +02:00
|
|
|
const { describe, it } = require('mocha')
|
2018-06-25 08:25:12 +02:00
|
|
|
const assert = require('assert')
|
|
|
|
const bcrypto = require('../src/crypto')
|
2014-05-13 08:35:07 +02:00
|
|
|
|
2018-06-25 08:25:12 +02:00
|
|
|
const fixtures = require('./fixtures/crypto')
|
2014-04-08 15:39:22 +02:00
|
|
|
|
2019-04-09 08:09:50 +02:00
|
|
|
describe('crypto', () => {
|
|
|
|
['hash160', 'hash256', 'ripemd160', 'sha1', 'sha256'].forEach(algorithm => {
|
|
|
|
describe(algorithm, () => {
|
|
|
|
fixtures.forEach(f => {
|
2018-06-25 08:37:45 +02:00
|
|
|
const fn = bcrypto[algorithm]
|
|
|
|
const expected = f[algorithm]
|
2014-09-20 03:20:55 +02:00
|
|
|
|
2019-04-09 08:09:50 +02:00
|
|
|
it('returns ' + expected + ' for ' + f.hex, () => {
|
2018-06-25 08:37:45 +02:00
|
|
|
const data = Buffer.from(f.hex, 'hex')
|
|
|
|
const actual = fn(data).toString('hex')
|
2014-09-20 03:20:55 +02:00
|
|
|
|
2015-05-07 03:29:20 +02:00
|
|
|
assert.strictEqual(actual, expected)
|
2014-09-20 03:20:55 +02:00
|
|
|
})
|
2014-05-10 01:55:55 +02:00
|
|
|
})
|
|
|
|
})
|
|
|
|
})
|
2014-04-08 15:39:22 +02:00
|
|
|
})
|