UNPKG

821 BJavaScriptView Raw
1var test = require('tape')
2var crypto = require('./browser')
3var Buffer = require('safe-buffer').Buffer
4test('sync', function (t) {
5 t.test('first', function (t) {
6 const buf = Buffer.alloc(10)
7 const before = buf.toString('hex')
8 crypto.randomFillSync(buf, 5, 5)
9 const after = buf.toString('hex')
10 t.notEqual(before, after)
11 t.equal(before.slice(0, 10), after.slice(0, 10))
12 t.end()
13 })
14})
15test('async', function (t) {
16 t.test('first', function (t) {
17 const buf = Buffer.alloc(10)
18 const before = buf.toString('hex')
19 crypto.randomFill(buf, 5, 5, function (err, bufa) {
20 t.error(err)
21 const after = bufa.toString('hex')
22 t.notEqual(before, after)
23 t.equal(before.slice(0, 10), after.slice(0, 10))
24 t.ok(buf === bufa, 'same buffer')
25 t.end()
26 })
27 })
28})