Adds BI.toPaddedBuffer and toBuffer
This commit is contained in:
parent
596b31b1e1
commit
d8883e8d32
8 changed files with 131 additions and 26 deletions
test
46
test/bigi.js
Normal file
46
test/bigi.js
Normal file
|
@ -0,0 +1,46 @@
|
|||
var assert = require('assert')
|
||||
var BigInteger = require('../').BigInteger
|
||||
|
||||
var fixtures = require('./fixtures/bigi')
|
||||
|
||||
describe('BigInteger', function() {
|
||||
describe('fromBuffer/fromHex', function() {
|
||||
it('should match the test vectors', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
assert.deepEqual(BigInteger.fromHex(f.hex).toString(), f.dec)
|
||||
assert.deepEqual(BigInteger.fromHex(f.hexPadded).toString(), f.dec)
|
||||
})
|
||||
})
|
||||
|
||||
fixtures.invalid.forEach(function(f) {
|
||||
it('throws on ' + f.description, function() {
|
||||
assert.throws(function() {
|
||||
BigInteger.fromHex(f.string)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('toBuffer/toHex', function() {
|
||||
it('should match the test vectors', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
var actualHex = new BigInteger(f.dec).toHex()
|
||||
|
||||
assert.equal(actualHex, f.hex)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('toPaddedBuffer', function() {
|
||||
it('should match the test vectors', function() {
|
||||
fixtures.valid.forEach(function(f) {
|
||||
var actualBuf = new BigInteger(f.dec).toPaddedBuffer(32)
|
||||
|
||||
assert.equal(actualBuf.length, 32)
|
||||
assert.equal(actualBuf.toString('hex'), f.hexPadded)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
module.exports = BigInteger
|
Loading…
Add table
Add a link
Reference in a new issue