Added checkState for positive integer in Output satoshis
This commit is contained in:
parent
3005e19cbf
commit
bcd4efb724
@ -7,6 +7,7 @@ var bufferUtil = require('../util/buffer');
|
|||||||
var JSUtil = require('../util/js');
|
var JSUtil = require('../util/js');
|
||||||
var BufferWriter = require('../encoding/bufferwriter');
|
var BufferWriter = require('../encoding/bufferwriter');
|
||||||
var Script = require('../script');
|
var Script = require('../script');
|
||||||
|
var $ = require('../util/preconditions');
|
||||||
|
|
||||||
function Output(params) {
|
function Output(params) {
|
||||||
if (!(this instanceof Output)) {
|
if (!(this instanceof Output)) {
|
||||||
@ -50,6 +51,10 @@ Object.defineProperty(Output.prototype, 'satoshis', {
|
|||||||
this._satoshisBN = BN.fromNumber(num);
|
this._satoshisBN = BN.fromNumber(num);
|
||||||
this._satoshis = num;
|
this._satoshis = num;
|
||||||
}
|
}
|
||||||
|
$.checkState(
|
||||||
|
JSUtil.isPositiveInteger(this._satoshis),
|
||||||
|
'Output satoshis is not a positive integer'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -30,6 +30,52 @@ describe('Output', function() {
|
|||||||
newOutput.satoshis.should.equal(100);
|
newOutput.satoshis.should.equal(100);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('can be assigned a satoshi amount with a string', function() {
|
||||||
|
var newOutput = new Output({
|
||||||
|
satoshis: '100',
|
||||||
|
script: Script.empty()
|
||||||
|
});
|
||||||
|
newOutput.satoshis.should.equal(100);
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('will error if output is not a positive integer', function() {
|
||||||
|
it('-100', function() {
|
||||||
|
(function() {
|
||||||
|
var newOutput = new Output({
|
||||||
|
satoshis: -100,
|
||||||
|
script: Script.empty()
|
||||||
|
});
|
||||||
|
}).should.throw('Output satoshis is not a positive integer');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('1.1', function() {
|
||||||
|
(function() {
|
||||||
|
var newOutput = new Output({
|
||||||
|
satoshis: 1.1,
|
||||||
|
script: Script.empty()
|
||||||
|
});
|
||||||
|
}).should.throw('Output satoshis is not a positive integer');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('NaN', function() {
|
||||||
|
(function() {
|
||||||
|
var newOutput = new Output({
|
||||||
|
satoshis: NaN,
|
||||||
|
script: Script.empty()
|
||||||
|
});
|
||||||
|
}).should.throw('Output satoshis is not a positive integer');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Infinity', function() {
|
||||||
|
(function() {
|
||||||
|
var newOutput = new Output({
|
||||||
|
satoshis: Infinity,
|
||||||
|
script: Script.empty()
|
||||||
|
});
|
||||||
|
}).should.throw('Output satoshis is not a positive integer');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var expectEqualOutputs = function(a, b) {
|
var expectEqualOutputs = function(a, b) {
|
||||||
a.satoshis.should.equal(b.satoshis);
|
a.satoshis.should.equal(b.satoshis);
|
||||||
a.script.toString().should.equal(b.script.toString());
|
a.script.toString().should.equal(b.script.toString());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user