Add test on TxProposal

This commit is contained in:
Matias Pando 2015-01-27 18:04:46 -03:00
parent dffdddbace
commit f4f4114865
4 changed files with 172 additions and 5 deletions

View File

@ -713,10 +713,6 @@ Wallet.prototype._onData = function(senderId, data, ts) {
this.updateSyncedTimestamp(ts);
console.log('data.type ', data.type);
console.log('this.id ', this.id);
console.log('data.walletId ', data.walletId);
if (data.type !== 'walletId' && this.id !== data.walletId) {
log.debug('Wallet:' + this.id + ' Received corrupt message:', data)
this.emitAndKeepAlive('corrupt', senderId);

View File

@ -553,6 +553,54 @@ describe('PublicKeyRing model', function() {
w.myCopayerId().should.be.equal(w.getCopayerId(0));
});
it('#_checkKeys should throw error is not complete', function() {
var config = {
networkName: 'livenet',
};
var w2 = new PublicKeyRing(config);
(function() {
return w2._checkKeys();
}).should.throw('dont have required keys');
});
it('#pathForAddress', function() {
var k = getCachedW();
var w = k.w;
var addr = w.generateAddress(true, k.pub);
var path = w.pathForAddress(addr);
path.should.not.be.undefined;
(function() {
return w.pathForAddress('abcd');
}).should.throw('find path for address');
});
it('#copayersForPubkeys', function() {
var k = getCachedW();
var w = k.w;
var addr = w.generateAddress(true, k.pub);
var path = w.pathForAddress(addr);
var paths = [];
paths.push(path);
(function() {
return w.copayersForPubkeys(k.pub, paths);
}).should.throw('Pubkeys not identified');
});
});

View File

@ -728,6 +728,9 @@ describe('TxProposal', function() {
});
describe('micelaneous functions', function() {
it('should report rejectCount', function() {
var txp = dummyProposal();
@ -756,4 +759,5 @@ describe('TxProposal', function() {
});
});

View File

@ -17,7 +17,9 @@ var dummyProposal = new TxProposal({
creator: 1,
createdTs: 1,
builder: {
toObj: sinon.stub().returns({}),
toObj: sinon.stub().returns({
getId: sinon.stub().returns('1234')
}),
},
inputChainPaths: ['m/1'],
});
@ -42,6 +44,66 @@ describe('TxProposals', function() {
should.exist(txps);
txps.network.name.should.equal('livenet');
});
it('should create an instance from an Object using builder', function() {
function dummyBuilder(opts) {
opts = opts || {};
var index = opts.nsig ? opts.nsig - 1 : 1;
var script = SCRIPTSIG[index];
var aIn = {
s: script
};
var tx = {};
tx.ins = opts.noins ? [] : [opts.nosigs ? {} : aIn];
tx.serialize = sinon.stub().returns(new Buffer('1234', 'hex'));
tx.getSize = sinon.stub().returns(1);
tx.getHashType = sinon.stub().returns(opts.hashtype || 1);
tx.getNormalizedHash = sinon.stub().returns('123456');
tx.hashForSignature = sinon.stub().returns(
new Buffer('31103626e162f1cbfab6b95b08c9f6e78aae128523261cb37f8dfd4783cb09a7', 'hex'));
tx.getId = sinon.returns(tx.getNormalizedHash().toString('hex'));
var builder = {};
builder.opts = opts.opts || {};
builder.build = sinon.stub().returns(tx)
builder.toObj = sinon.stub().returns({
iAmBuilderObj: true,
version: 1,
opts: builder.opts,
});
builder.isFullySigned = sinon.stub().returns(false);
builder.vanilla = {
scriptSig: [SCRIPTSIG[1]],
outs: JSON.stringify([{
address: '2NDJbzwzsmRgD2o5HHXPhuq5g6tkKTjYkd6',
amountSatStr: '123',
}]),
};
builder.inputsSigned = 0;
return builder;
};
var txps1 = [];
txps1.push(dummyProposal);
var txps = TxProposals.fromObj({
networkName: 'testnet',
walletId: '123a12',
txps: txps1,
builder: dummyBuilder
});
should.exist(txps);
});
it('should skip Objects with errors', function() {
var txps = TxProposals.fromObj({
networkName: 'livenet',
@ -131,6 +193,63 @@ describe('TxProposals', function() {
}).should.throw('Unknown TXP: c');
});
});
describe('#deletePending', function() {
it('should delete pending proposals', function() {
var txps = new TxProposals();
txps.txps = {
a: {
isPending: sinon.stub().returns(true)
},
b: {
isPending: sinon.stub().returns(false)
},
};
txps.deletePending(2);
txps.getNtxids().should.deep.equal(['b']);
});
});
describe('#getUsedUnspent', function() {
it('should return an empty object', function() {
var txps = new TxProposals();
console.log(txps);
txps.txps = {
a: {
isPending: sinon.stub().returns(false)
},
b: {
isPending: sinon.stub().returns(false)
},
};
var r = txps.getUsedUnspent(2);
Object.keys(r).length.should.equal(0);
});
it('should return an non empty object', function() {
var txps = new TxProposals();
txps.txps = {
a: {
isPending: sinon.stub().returns(true),
builder: {
getSelectedUnspent: sinon.stub().returns([{
txid: 'a1',
vout: '00'
}])
}
},
b: {
isPending: sinon.stub().returns(false)
},
};
var r = txps.getUsedUnspent(2);
Object.keys(r).length.should.equal(1);
});
});
describe('#toObj', function() {
it('should an object', function() {
var txps = TxProposals.fromObj({