Skip to content

Commit

Permalink
add more tests for toArrayLike
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Aug 9, 2019
1 parent c080ed7 commit 791750a
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,16 @@ describe('BN.js/Utils', function () {
describe('.toBuffer', function () {
it('should return proper Buffer', function () {
var n = new BN(0x123456);
assert.deepEqual(n.toBuffer('be', 5).toString('hex'), '0000123456');
assert.equal(n.toBuffer('be', 5).toString('hex'), '0000123456');
assert.deepEqual(n.toBuffer('le', 5).toString('hex'), '5634120000');

var s = '211e1566be78319bb949470577c2d4ac7e800a90d5104379478d8039451a8efe';
for (var i = 1; i <= s.length; i++) {
var slice = (i % 2 === 0 ? '' : '0') + s.slice(0, i);
var bn = new BN(slice, 16);
assert.equal(bn.toBuffer('be').toString('hex'), slice);
assert.equal(bn.toBuffer('le').toString('hex'), Buffer.from(slice, 'hex').reverse().toString('hex'));
}
});
});

Expand Down

0 comments on commit 791750a

Please sign in to comment.