Precondition check for TxProposals#deleteOne
This commit is contained in:
parent
25064829e0
commit
a07ffee068
2 changed files with 16 additions and 3 deletions
|
|
@ -45,9 +45,7 @@ TxProposals.prototype.getNtxids = function() {
|
|||
};
|
||||
|
||||
TxProposals.prototype.deleteOne = function(ntxid) {
|
||||
var txp = this.txps[ntxid];
|
||||
if (!txp)
|
||||
throw new Error('Unknown TXP: ' + ntxid);
|
||||
preconditions.checkState(this.txps[ntxid], 'Unknown TXP: ' + ntxid);
|
||||
delete this.txps[ntxid];
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -65,6 +65,21 @@ describe('TxProposals', function() {
|
|||
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() {
|
||||
it('should an object', function() {
|
||||
var txps = TxProposals.fromObj({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue