|
1 | 1 | var assert = require('assert') |
2 | 2 | var convert = require('../src/convert') |
3 | 3 |
|
4 | | -describe('convert', function() { |
5 | | - describe('byte array and word array conversions', function(){ |
6 | | - var bytes, wordArray |
7 | | - |
8 | | - beforeEach(function(){ |
9 | | - bytes = [ |
10 | | - 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, |
11 | | - 153, 235, 246, 240, 251, 80, 235, 184, 143, 24 |
12 | | - ] |
13 | | - wordArray = { |
14 | | - words: [1659439025, 1556031445, 1112775147, -151979184, -340226280], |
15 | | - sigBytes: 20 |
16 | | - } |
17 | | - }) |
| 4 | +var fixtures = require('./fixtures/convert') |
18 | 5 |
|
19 | | - describe('bytesToWords', function() { |
20 | | - it('works', function() { |
21 | | - assert.deepEqual(convert.bytesToWordArray(bytes), wordArray) |
22 | | - }) |
23 | | - }) |
| 6 | +describe('convert', function() { |
| 7 | + describe('bufferToWordArray', function() { |
| 8 | + fixtures.valid.forEach(function(f) { |
| 9 | + it('converts ' + f.hex + ' correctly', function() { |
| 10 | + var buffer = new Buffer(f.hex, 'hex') |
| 11 | + var result = convert.bufferToWordArray(buffer) |
24 | 12 |
|
25 | | - describe('bytesToWords', function() { |
26 | | - it('works', function() { |
27 | | - assert.deepEqual(convert.wordArrayToBytes(wordArray), bytes) |
| 13 | + assert.deepEqual(result, f.wordArray) |
28 | 14 | }) |
29 | 15 | }) |
30 | 16 | }) |
31 | 17 |
|
32 | | - describe('reverseEndian', function() { |
33 | | - it('works', function() { |
34 | | - var bigEndian = "6a4062273ac4f9ea4ffca52d9fd102b08f6c32faa0a4d1318e3a7b2e437bb9c7" |
35 | | - var littleEdian = "c7b97b432e7b3a8e31d1a4a0fa326c8fb002d19f2da5fc4feaf9c43a2762406a" |
36 | | - assert.deepEqual(convert.reverseEndian(bigEndian), littleEdian) |
37 | | - assert.deepEqual(convert.reverseEndian(littleEdian), bigEndian) |
| 18 | + describe('wordArrayToBuffer', function() { |
| 19 | + fixtures.valid.forEach(function(f) { |
| 20 | + it('converts to ' + f.hex + ' correctly', function() { |
| 21 | + var resultHex = convert.wordArrayToBuffer(f.wordArray).toString('hex') |
| 22 | + |
| 23 | + assert.deepEqual(resultHex, f.hex) |
| 24 | + }) |
38 | 25 | }) |
39 | 26 | }) |
40 | 27 | }) |
0 commit comments