Precondition check for TxProposals#deleteOne

This commit is contained in:
Ivan Socolsky 2014-08-28 11:03:47 -03:00
commit a07ffee068
2 changed files with 16 additions and 3 deletions

View file

@ -45,9 +45,7 @@ TxProposals.prototype.getNtxids = function() {
}; };
TxProposals.prototype.deleteOne = function(ntxid) { TxProposals.prototype.deleteOne = function(ntxid) {
var txp = this.txps[ntxid]; preconditions.checkState(this.txps[ntxid], 'Unknown TXP: ' + ntxid);
if (!txp)
throw new Error('Unknown TXP: ' + ntxid);
delete this.txps[ntxid]; delete this.txps[ntxid];
}; };

View file

@ -65,6 +65,21 @@ describe('TxProposals', function() {
txps.getNtxids().should.deep.equal(['a','b']); txps.getNtxids().should.deep.equal(['a','b']);
}); });
}); });
describe.only('#deleteOne', function() {
it('should delete specified ntxid', function() {
var txps = new TxProposals();
txps.txps = {a:1, b:2};
txps.deleteOne('a');
txps.getNtxids().should.deep.equal(['b']);
});
it('should fail on non-existent ntxid', function() {
var txps = new TxProposals();
txps.txps = {a:1, b:2};
(function () {
txps.deleteOne('c');
}).should.throw('Unknown TXP: c');
});
});
describe('#toObj', function() { describe('#toObj', function() {
it('should an object', function() { it('should an object', function() {
var txps = TxProposals.fromObj({ var txps = TxProposals.fromObj({