diff --git a/test/basic.js b/test/basic.js index 3e7071a..3b0f6ff 100644 --- a/test/basic.js +++ b/test/basic.js @@ -5,7 +5,6 @@ var Address = require('../Address').class(); var PrivateKey = require('../PrivateKey').class(); var networks = require('../networks'); var KeyModule = require('../Key'); -var coinUtil = require('../util/util'); suite('basic'); @@ -111,19 +110,6 @@ function is_invalid(datum) assert.equal(valid, false); } -function test_value(datum) -{ - if (datum.length != 2) - throw new Error("Bad test"); - - var decimal = datum[0]; - var intStr = datum[1]; - - var bn = coinUtil.parseValue(decimal); - assert.notEqual(bn, undefined); - assert.equal(bn.toString(), intStr); -} - var dataValid = JSON.parse(fs.readFileSync('test/base58_keys_valid.json')); var dataInvalid = JSON.parse(fs.readFileSync('test/base58_keys_invalid.json')); var dataValues = JSON.parse(fs.readFileSync('test/values.json')); @@ -140,9 +126,4 @@ describe('invalid base58 keys', function(){ }); }); -describe('floating point unit conversion to satoshis', function(){ - test('values', function() { - dataValues.forEach(function(datum) { test_value(datum); }); - }); -}); diff --git a/test/util-util.js b/test/util-util.js new file mode 100644 index 0000000..aba0be8 --- /dev/null +++ b/test/util-util.js @@ -0,0 +1,24 @@ +var assert = require('assert'); +var coinUtil = require('../util/util'); + +describe('util/util', function(){ + 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); + assert.notEqual(bn, undefined); + assert.equal(bn.toString(), intStr); + } + var dataValues=[ + [ "0", "0" ], + [ "1.0", "100000000" ], + [ "0.1", "10000000" ], + [ ".1", "10000000" ], + [ "0.0005", "50000" ] + ]; + dataValues.forEach(function(datum) { test_value(datum); }); + }); + }); +});