bitcore/test/test.util.js

30 lines
850 B
JavaScript
Raw Normal View History

2014-02-21 11:48:27 -08:00
var chai = require('chai');
var bitcore = require('../bitcore');
var coinUtil = bitcore.util;
var should = chai.should();
2013-12-18 16:35:53 -08:00
2014-02-21 11:48:27 -08:00
describe('util', function(){
2013-12-18 16:35:53 -08:00
describe('#parseValue', function(){
it('should convert floating points to satoshis correctly', function(){
function test_value(datum) {
var decimal = datum[0];
var intStr = datum[1];
var bn = coinUtil.parseValue(decimal);
2014-02-21 11:48:27 -08:00
should.exist(bn);
bn.toString().should.equal(intStr);
2013-12-18 16:35:53 -08:00
}
var dataValues=[
[ "0", "0" ],
[ "1.0", "100000000" ],
[ "0.1", "10000000" ],
[ ".1", "10000000" ],
2013-12-18 17:08:52 -08:00
[ "0.0005", "50000" ],
[ ".000000001", "0" ],
[ ".000000009", "0" ],
[ ".00000000000000001", "0" ]
2013-12-18 16:35:53 -08:00
];
dataValues.forEach(function(datum) { test_value(datum); });
});
});
});