test.js 821 B

12345678910111213141516171819202122232425262728
  1. var test = require('tape')
  2. var crypto = require('./browser')
  3. var Buffer = require('safe-buffer').Buffer
  4. test('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. })
  15. test('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. })