mirror of https://github.com/BTCPrivate/copay.git
add tests
This commit is contained in:
parent
4931c9d618
commit
e11ac3e956
|
@ -66,11 +66,13 @@ TxProposal.prototype._check = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposal.prototype.rejectCount = function() {
|
TxProposal.prototype.rejectCount = function() {
|
||||||
return Object.keys(this.rejectedBy);
|
return Object.keys(this.rejectedBy).length;
|
||||||
};
|
};
|
||||||
|
|
||||||
TxProposal.prototype.isPending = function(maxRejectCount) {
|
TxProposal.prototype.isPending = function(maxRejectCount) {
|
||||||
if (this.rejectCount() < maxRejectCount || p.sentTxid)
|
preconditions.checkArgument(typeof maxRejectCount != 'undefined');
|
||||||
|
|
||||||
|
if (this.rejectCount() > maxRejectCount || this.sentTxid)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -139,6 +139,7 @@ describe('TxProposal', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
describe('#setSent', function() {
|
describe('#setSent', function() {
|
||||||
it('should set txid and timestamp', function() {
|
it('should set txid and timestamp', function() {
|
||||||
var now = Date.now();
|
var now = Date.now();
|
||||||
|
@ -430,4 +431,33 @@ describe('TxProposal', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('micelaneous functions', function() {
|
||||||
|
it('should report rejectCount', function() {
|
||||||
|
var txp = dummyProposal;
|
||||||
|
txp.rejectCount().should.equal(0);
|
||||||
|
txp.setRejected(['juan'])
|
||||||
|
txp.rejectCount().should.equal(1);
|
||||||
|
});
|
||||||
|
it('should report isPending 1', function() {
|
||||||
|
var txp = dummyProposal;
|
||||||
|
txp.rejectedBy=[];
|
||||||
|
txp.sentTxid=1;
|
||||||
|
txp.isPending(3).should.equal(false);
|
||||||
|
});
|
||||||
|
it('should report isPending 2', function() {
|
||||||
|
var txp = dummyProposal;
|
||||||
|
txp.rejectedBy=[];
|
||||||
|
txp.sentTxid=null;
|
||||||
|
txp.isPending(3).should.equal(true);
|
||||||
|
});
|
||||||
|
it('should report isPending 3', function() {
|
||||||
|
var txp = dummyProposal;
|
||||||
|
txp.rejectedBy=[1,2,3,4];
|
||||||
|
txp.sentTxid=null;
|
||||||
|
txp.isPending(3).should.equal(false);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -358,7 +358,7 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it.only('#maxRejectCount', function() {
|
it('#maxRejectCount', function() {
|
||||||
var w = cachedCreateW();
|
var w = cachedCreateW();
|
||||||
w.maxRejectCount().should.equal(2);
|
w.maxRejectCount().should.equal(2);
|
||||||
});
|
});
|
||||||
|
@ -372,6 +372,8 @@ describe('Wallet model', function() {
|
||||||
w.purgeTxProposals(1);
|
w.purgeTxProposals(1);
|
||||||
spy1.callCount.should.equal(1);
|
spy1.callCount.should.equal(1);
|
||||||
spy2.callCount.should.equal(0);
|
spy2.callCount.should.equal(0);
|
||||||
|
spy1.restore();
|
||||||
|
spy2.restore();
|
||||||
});
|
});
|
||||||
it('should delete pending', function() {
|
it('should delete pending', function() {
|
||||||
var w = cachedCreateW();
|
var w = cachedCreateW();
|
||||||
|
@ -380,12 +382,15 @@ describe('Wallet model', function() {
|
||||||
w.purgeTxProposals();
|
w.purgeTxProposals();
|
||||||
spy1.callCount.should.equal(0);
|
spy1.callCount.should.equal(0);
|
||||||
spy2.callCount.should.equal(1);
|
spy2.callCount.should.equal(1);
|
||||||
|
spy1.restore();
|
||||||
|
spy2.restore();
|
||||||
});
|
});
|
||||||
it('should count deletions', function() {
|
it('should count deletions', function() {
|
||||||
var w = cachedCreateW();
|
var w = cachedCreateW();
|
||||||
var s = sinon.stub(w.txProposals, 'length').returns(10);
|
var s = sinon.stub(w.txProposals, 'length').returns(10);
|
||||||
var n = w.purgeTxProposals();
|
var n = w.purgeTxProposals();
|
||||||
n.should.equal(0);
|
n.should.equal(0);
|
||||||
|
s.restore();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue