diff --git a/src/js/ripple/uint.js b/src/js/ripple/uint.js index 4f2338be..e44f7fbc 100644 --- a/src/js/ripple/uint.js +++ b/src/js/ripple/uint.js @@ -234,7 +234,7 @@ UInt.prototype.parse_number = function (j) { if ("number" === typeof j && j === +j && - j > 0) { + j >= 0) { // XXX Better, faster way to get BigInteger from JS int? this._value = new BigInteger(""+j); } diff --git a/test/uint-test.js b/test/uint-test.js new file mode 100644 index 00000000..9075f51e --- /dev/null +++ b/test/uint-test.js @@ -0,0 +1,25 @@ +var assert = require('assert'); +var utils = require('./testutils'); +var UInt128 = utils.load_module('uint128').UInt128; +var config = require('./testutils').get_config(); + +describe('UInt', function() { + describe('128', function() { + describe('#parse_number', function () { + it('should create 00000000000000000000000000000000 when called with 0', function () { + var val = UInt128.from_number(0); + assert.strictEqual(val.to_hex(), '00000000000000000000000000000000'); + }); + it('should create 00000000000000000000000000000001 when called with 1', function () { + var val = UInt128.from_number(0); + assert.strictEqual(val.to_hex(), '00000000000000000000000000000000'); + }); + it('should create 000000000000000000000000FFFFFFFF when called with 0xFFFFFFFF', function () { + var val = UInt128.from_number(0xFFFFFFFF); + assert.strictEqual(val.to_hex(), '000000000000000000000000FFFFFFFF'); + }); + }); + }); +}); + +// vim:sw=2:sts=2:ts=8:et