Refactored TxProposal#getSent & tests

This commit is contained in:
Ivan Socolsky 2014-10-07 12:17:27 -03:00
commit 807e7754a3
2 changed files with 40 additions and 6 deletions

View file

@ -255,8 +255,8 @@ TxProposal.prototype.setSent = function(sentTxid) {
this.sentTs = Date.now();
};
TxProposal.prototype.getSent = function(sentTxid) {
return !!this.sentTxid;
TxProposal.prototype.getSent = function() {
return this.sentTs;
}
TxProposal.prototype._allSignatures = function() {

View file

@ -112,7 +112,11 @@ describe('TxProposal', function() {
});
it('sets force opts', function() {
var b = new FakeBuilder();
b.opts={juan:1, pepe:1, fee:1000};
b.opts = {
juan: 1,
pepe: 1,
fee: 1000
};
var txp;
var o = {
creator: 1,
@ -121,9 +125,16 @@ describe('TxProposal', function() {
inputChainPaths: ['m/1'],
};
(function() {
txp = TxProposal.fromObj(o,{pepe:100});
txp = TxProposal.fromObj(o, {
pepe: 100
});
}).should.throw('Invalid tx proposal: no ins');
o.builderObj.opts.should.deep.equal({juan:1, pepe:100, feeSat:undefined, fee:undefined});
o.builderObj.opts.should.deep.equal({
juan: 1,
pepe: 100,
feeSat: undefined,
fee: undefined
});
});
});
@ -131,13 +142,36 @@ describe('TxProposal', function() {
describe('#setSent', function() {
it('should set txid and timestamp', function() {
var now = Date.now();
var txp = dummyProposal;
var txp = new TxProposal({
creator: 1,
createdTs: 1,
builder: new FakeBuilder(),
inputChainPaths: ['m/1'],
});
txp.setSent('3a42');
txp.sentTs.should.gte(now);
txp.sentTxid.should.equal('3a42');
});
});
describe('#getSent', function() {
it('should get sent timestamp', function() {
var now = Date.now();
var txp = new TxProposal({
creator: 1,
createdTs: 1,
builder: new FakeBuilder(),
inputChainPaths: ['m/1'],
});
var sentTs = txp.getSent();
should.not.exist(sentTs);
txp.setSent('3a42');
sentTs = txp.getSent();
sentTs.should.gte(now);
});
});
describe('Signature verification', function() {
var validScriptSig = new bitcore.Script(FakeBuilder.VALID_SCRIPTSIG_BUF);