mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #2351 from matiaspando/increaseCoverage86
Increase coverage to 86%
This commit is contained in:
commit
e0f7f5f991
|
@ -265,7 +265,7 @@ Wallet.prototype.seedCopayer = function(pubKey) {
|
|||
* Processes the data using {@link HDParams#fromList} and merges it with the
|
||||
* {@link Wallet#publicKeyRing}.
|
||||
*
|
||||
* @param {Object} data - the data recived, {@see HDParams#fromList}
|
||||
* @param {Object} data - the data received, {@see HDParams#fromList}
|
||||
*/
|
||||
Wallet.prototype._doOnIndexes = function(indexes, fromTxProposal) {
|
||||
preconditions.checkArgument(indexes);
|
||||
|
@ -403,7 +403,7 @@ Wallet.prototype._getPubkeyToCopayerMap = function(txp) {
|
|||
|
||||
/**
|
||||
* @desc
|
||||
* Asyncchronously check with the blockchain if a given transaction was sent.
|
||||
* Asynchronously check with the blockchain if a given transaction was sent.
|
||||
*
|
||||
* @param {string} ntxid - the transaction proposal
|
||||
* @param {transactionCallback} cb
|
||||
|
@ -411,7 +411,9 @@ Wallet.prototype._getPubkeyToCopayerMap = function(txp) {
|
|||
Wallet.prototype._checkIfTxIsSent = function(ntxid, cb) {
|
||||
var txp = this.txProposals.get(ntxid);
|
||||
var tx = txp.builder.build();
|
||||
var txHex = tx.serialize().toString('hex');
|
||||
|
||||
//not used anymore
|
||||
//var txHex = tx.serialize().toString('hex');
|
||||
|
||||
|
||||
//Use calcHash NOT getHash which could be cached.
|
||||
|
|
|
@ -17,7 +17,9 @@ describe('HDParams model', function() {
|
|||
should.exist(is);
|
||||
is.length.should.equal(3);
|
||||
|
||||
var cosigners = is.map(function(i) { return i.copayerIndex; });
|
||||
var cosigners = is.map(function(i) {
|
||||
return i.copayerIndex;
|
||||
});
|
||||
cosigners.indexOf(HDPath.SHARED_INDEX).should.not.equal(-1);
|
||||
cosigners.indexOf(0).should.not.equal(-1);
|
||||
cosigners.indexOf(1).should.not.equal(-1);
|
||||
|
@ -36,7 +38,7 @@ describe('HDParams model', function() {
|
|||
is2.length.should.equal(4);
|
||||
});
|
||||
|
||||
it('show be able to store and read', function() {
|
||||
it('should be able to store and read', function() {
|
||||
var i = new HDParams();
|
||||
i.copayerIndex = 1;
|
||||
var changeN = 2;
|
||||
|
@ -58,13 +60,22 @@ describe('HDParams model', function() {
|
|||
i2.getReceiveIndex().should.equal(addressN);
|
||||
});
|
||||
|
||||
it('should throw an error', function() {
|
||||
var data = new HDParams();
|
||||
(function() {
|
||||
HDParams.fromObj(data);
|
||||
}).should.throw('BADDATA');
|
||||
|
||||
});
|
||||
|
||||
|
||||
it('should count generation indexes', function() {
|
||||
var j = new HDParams();
|
||||
j.copayerIndex = 1;
|
||||
for (var i = 0; i < 3; i++)
|
||||
j.increment(true);
|
||||
j.increment(true);
|
||||
for (var i = 0; i < 2; i++)
|
||||
j.increment(false);
|
||||
j.increment(false);
|
||||
|
||||
j.changeIndex.should.equal(3);
|
||||
j.receiveIndex.should.equal(2);
|
||||
|
@ -75,9 +86,9 @@ describe('HDParams model', function() {
|
|||
j.copayerIndex = 1;
|
||||
|
||||
for (var i = 0; i < 15; i++)
|
||||
j.increment(true);
|
||||
j.increment(true);
|
||||
for (var i = 0; i < 7; i++)
|
||||
j.increment(false);
|
||||
j.increment(false);
|
||||
var j2 = new HDParams({
|
||||
copayerIndex: j.copayerIndex,
|
||||
});
|
||||
|
@ -89,11 +100,44 @@ describe('HDParams model', function() {
|
|||
});
|
||||
|
||||
it('#merge should fail with different copayerIndex index', function() {
|
||||
var j1 = new HDParams({ walletId: '1234', copayerIndex: 2 });
|
||||
var j2 = new HDParams({ walletId: '1234', copayerIndex: 3 });
|
||||
var j1 = new HDParams({
|
||||
walletId: '1234',
|
||||
copayerIndex: 2
|
||||
});
|
||||
var j2 = new HDParams({
|
||||
walletId: '1234',
|
||||
copayerIndex: 3
|
||||
});
|
||||
|
||||
var merge = function() { j2.merge(j1); };
|
||||
var merge = function() {
|
||||
j2.merge(j1);
|
||||
};
|
||||
merge.should.throw(Error);
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
describe('#checkRange', function() {
|
||||
it('should throw an error', function() {
|
||||
var hd = new HDParams();
|
||||
|
||||
(function() {
|
||||
hd.checkRange(60, true);
|
||||
}).should.throw('Out of bounds');
|
||||
|
||||
});
|
||||
it('should throw an error', function() {
|
||||
var hd = new HDParams();
|
||||
|
||||
(function() {
|
||||
hd.checkRange(60, false);
|
||||
}).should.throw('Out of bounds');
|
||||
|
||||
});
|
||||
it('should not throw an error', function() {
|
||||
var hd = new HDParams();
|
||||
hd.checkRange(0, false);
|
||||
hd.checkRange(0, true);
|
||||
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1137,8 +1137,6 @@ describe('Identity model', function() {
|
|||
kdf: sinon.stub().returns('passphrase'),
|
||||
decrypt: sinon.stub().returns('{"walletId":123}'),
|
||||
};
|
||||
|
||||
|
||||
opts = {
|
||||
email: 'test@test.com',
|
||||
password: '123',
|
||||
|
@ -1263,9 +1261,12 @@ describe('Identity model', function() {
|
|||
expect(iden._checkVersion()).to.be.undefined;
|
||||
expect(iden._checkVersion('0.0.0')).to.be.undefined;
|
||||
(function() {
|
||||
console.log('b', iden._checkVersion('9.9.9'));
|
||||
iden._checkVersion('9.9.9');
|
||||
}).should.throw('Major difference');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
|
|
@ -23,6 +23,27 @@ describe('PrivateKey model', function() {
|
|||
should.exist(w.bip.derive);
|
||||
});
|
||||
|
||||
it('should return the extended public key', function() {
|
||||
var w = new PrivateKey(pkConfig);
|
||||
var pubk1 = w.getExtendedPublicKeyString();
|
||||
should.exist(pubk1);
|
||||
});
|
||||
|
||||
it('should return the private key', function() {
|
||||
var w = new PrivateKey(pkConfig);
|
||||
var pk1 = w.getIdKey();
|
||||
should.exist(pk1);
|
||||
var pk2 = w.getIdKey();
|
||||
should.exist(pk2);
|
||||
pk1.should.be.equal(pk2);
|
||||
});
|
||||
|
||||
it('should return the Hierarchical key', function() {
|
||||
var w = new PrivateKey(pkConfig);
|
||||
var hk = w._getHK();
|
||||
should.exist(hk);
|
||||
});
|
||||
|
||||
it('should derive priv keys', function() {
|
||||
var pk = new PrivateKey(pkConfig);
|
||||
for (var j = false; !j; j = true) {
|
||||
|
|
|
@ -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.skip('#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');
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
|
|
@ -173,6 +173,29 @@ describe('RateService model', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return an error', function() {
|
||||
var rs = new RateService();
|
||||
rs.isAvailable = sinon.stub().returns(true);
|
||||
var today = Date.now();
|
||||
var yesterday = today - 24 * 3600;
|
||||
var getHistoricalRateStub = sinon.stub(rs, 'getHistoricRate');
|
||||
getHistoricalRateStub.withArgs('XXX', today).yields('Not found', null);
|
||||
|
||||
|
||||
var params = [{
|
||||
satoshis: 0,
|
||||
code: 'XXX',
|
||||
date: today,
|
||||
expected: '0.00'
|
||||
}];
|
||||
_.each(params, function(p) {
|
||||
rs.toFiatHistoric(p.satoshis, p.code, p.date, function(err, rate) {
|
||||
err.should.equal('Not found');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#getHistoricRate', function() {
|
||||
|
@ -203,6 +226,7 @@ describe('RateService model', function() {
|
|||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error', function() {
|
||||
var yesterday = moment().subtract(1, 'day');
|
||||
var reqStub = sinon.stub();
|
||||
|
@ -265,6 +289,30 @@ describe('RateService model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
it('should return a value', function() {
|
||||
var yesterday = moment().subtract(1, 'day');
|
||||
var reqStub = sinon.stub();
|
||||
|
||||
var statusIn = {
|
||||
statusCode: 200
|
||||
};
|
||||
|
||||
var rateIn = {
|
||||
rate: 50
|
||||
};
|
||||
reqStub.get = sinon.stub().yields(null, statusIn, rateIn);
|
||||
|
||||
var rs = new RateService({
|
||||
request: reqStub
|
||||
});
|
||||
rs.isAvailable = sinon.stub().returns(true);
|
||||
|
||||
var dates = [yesterday, yesterday];
|
||||
rs.getHistoricRates('USD', dates, function(err, status, rate) {
|
||||
status[0].rate.should.equal(50);
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error', function() {
|
||||
var yesterday = moment().subtract(1, 'day');
|
||||
var reqStub = sinon.stub();
|
||||
|
@ -356,6 +404,26 @@ describe('RateService model', function() {
|
|||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#whenAvailable is available', function() {
|
||||
it('should return callback ', function() {
|
||||
var rs = new RateService();
|
||||
rs.isAvailable = sinon.stub().returns(true);
|
||||
rs.whenAvailable(function() {});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#whenAvailable is not available', function() {
|
||||
it('should queue the callback ', function() {
|
||||
|
||||
var rs = new RateService();
|
||||
var count = rs._queued.length;
|
||||
rs.isAvailable = sinon.stub().returns(false);
|
||||
rs.whenAvailable(function() {});
|
||||
rs._queued.length.should.be.equal(count + 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#singleton', function() {
|
||||
it('should create only one instance', function() {
|
||||
var rs = RateService.singleton();
|
||||
|
|
|
@ -49,7 +49,7 @@ describe('TxProposal', function() {
|
|||
function dummyBuilder(opts) {
|
||||
opts = opts || {};
|
||||
|
||||
var index = opts.nsig ? opts.nsig - 1 : 1;
|
||||
var index = opts.nsig ? opts.nsig - 1 : 1;
|
||||
var script = SCRIPTSIG[index];
|
||||
|
||||
var aIn = {
|
||||
|
@ -85,7 +85,7 @@ describe('TxProposal', function() {
|
|||
amountSatStr: '123',
|
||||
}]),
|
||||
};
|
||||
builder.inputsSigned =0;
|
||||
builder.inputsSigned = 0;
|
||||
|
||||
return builder;
|
||||
};
|
||||
|
@ -231,6 +231,28 @@ describe('TxProposal', function() {
|
|||
|
||||
});
|
||||
|
||||
describe('#getSeen', function() {
|
||||
it('should set txid and timestamp', function() {
|
||||
var txp = new TxProposal({
|
||||
creator: 1,
|
||||
createdTs: 1,
|
||||
builder: new dummyBuilder(),
|
||||
inputChainPaths: ['m/1'],
|
||||
});
|
||||
var ts = txp.getSeen('pepe');
|
||||
expect(ts).to.be.undefined;
|
||||
|
||||
txp.setSeen('pepe');
|
||||
|
||||
ts = txp.getSeen('pepe');
|
||||
expect(ts).to.be.not.undefined;
|
||||
|
||||
txp.setSeen('pepe');
|
||||
var ts2 = txp.getSeen('pepe');
|
||||
ts.should.be.equal(ts2);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('#setSent', function() {
|
||||
it('should set txid and timestamp', function() {
|
||||
|
@ -326,6 +348,10 @@ describe('TxProposal', function() {
|
|||
}
|
||||
Buffer.isBuffer(info.script.getBuffer()).should.equal(true);
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
it('#getSignersPubKeys', function() {
|
||||
var txp = dummyProposal();
|
||||
var pubkeys = txp.getSignersPubKeys();
|
||||
|
@ -348,7 +374,7 @@ describe('TxProposal', function() {
|
|||
describe('#addSignature', function() {
|
||||
it('should add signatures maintaing pubkeys order', function() {
|
||||
var txp = dummyProposal({
|
||||
nsig:1
|
||||
nsig: 1
|
||||
});
|
||||
txp.getSignersPubKeys()[0].length.should.equal(1);
|
||||
|
||||
|
@ -362,31 +388,41 @@ describe('TxProposal', function() {
|
|||
});
|
||||
it('should add signatures to incomplete txs ', function() {
|
||||
var txp = dummyProposal({
|
||||
nsig:1
|
||||
nsig: 1
|
||||
});
|
||||
txp.addSignature('pepe', [SIG1]);
|
||||
txp.builder.inputsSigned.should.be.equal(0);
|
||||
});
|
||||
|
||||
it('should not add signatures to complete txs ', function() {
|
||||
var txp = dummyProposal({
|
||||
nsig: 1
|
||||
});
|
||||
|
||||
txp.builder.isFullySigned = sinon.stub.returns(true);
|
||||
var r = txp.addSignature('pepe', [SIG1]);
|
||||
r.should.be.false;
|
||||
});
|
||||
|
||||
it('should fail with invalid signatures', function() {
|
||||
var txp = dummyProposal({
|
||||
nsig:1
|
||||
nsig: 1
|
||||
});
|
||||
txp.getSignersPubKeys()[0].length.should.equal(1);
|
||||
|
||||
(function(){
|
||||
(function() {
|
||||
txp.addSignature('pepe', ['002030a77c9613d6ee010717c1abc494668d877e3fa0ae4c520f65cc3b308754c98c02205219d387bcb291bd44805b9468439e4168b02a6a180cdbcc24d84d71d696c1ae01']);
|
||||
}).should.throw('BADSIG');
|
||||
});
|
||||
|
||||
it('should fail adding the same signature twice', function() {
|
||||
var txp = dummyProposal({
|
||||
nsig:1
|
||||
nsig: 1
|
||||
});
|
||||
txp.getSignersPubKeys()[0].length.should.equal(1);
|
||||
|
||||
txp.addSignature('pepe', [SIG1]);
|
||||
(function(){
|
||||
(function() {
|
||||
txp.addSignature('pepe', [SIG1]);
|
||||
}).should.throw('BADSIG');
|
||||
});
|
||||
|
@ -533,7 +569,7 @@ describe('TxProposal', function() {
|
|||
it('with less signatures', function() {
|
||||
var txp = dummyProposal();
|
||||
var txp1Sig = dummyProposal({
|
||||
nsig:1
|
||||
nsig: 1
|
||||
});
|
||||
var backup = txp.builder.vanilla.scriptSig[0];
|
||||
var hasChanged = txp.merge(txp);
|
||||
|
@ -693,7 +729,19 @@ describe('TxProposal', function() {
|
|||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
describe('micelaneous functions', function() {
|
||||
it('should sign previously reject tx', function() {
|
||||
var txp = dummyProposal();
|
||||
txp.rejectCount().should.equal(0);
|
||||
txp.setRejected(['juan'])
|
||||
txp.rejectCount().should.equal(1);
|
||||
txp._setSigned('juan');
|
||||
txp.rejectCount().should.equal(0);
|
||||
|
||||
});
|
||||
it('should report rejectCount', function() {
|
||||
var txp = dummyProposal();
|
||||
txp.rejectCount().should.equal(0);
|
||||
|
@ -721,4 +769,5 @@ describe('TxProposal', function() {
|
|||
});
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
|
|
@ -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,61 @@ 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();
|
||||
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({
|
||||
|
|
439
test/Wallet.js
439
test/Wallet.js
|
@ -212,7 +212,6 @@ describe('Wallet model', function() {
|
|||
status.should.equal(Wallet.TX_PROPOSAL_SENT);
|
||||
|
||||
w.network.send.calledOnce.should.equal(true);
|
||||
console.log(w.network.send.getCall(0).args[1]);
|
||||
w.network.send.getCall(0).args[1].type.should.equal("txProposal");
|
||||
should.exist(w.network.send.getCall(0).args[1].indexes);
|
||||
should.exist(w.network.send.getCall(0).args[1].txProposal);
|
||||
|
@ -521,6 +520,18 @@ describe('Wallet model', function() {
|
|||
|
||||
});
|
||||
|
||||
it('should call emitAndKeepAlive', function() {
|
||||
var data = {
|
||||
type: "typeUnknown",
|
||||
walletId: '00001111'
|
||||
};
|
||||
|
||||
var spy = sinon.spy(w, 'emitAndKeepAlive');
|
||||
w._onData(sender, data, ts);
|
||||
sinon.assert.callCount(spy, 1);
|
||||
});
|
||||
|
||||
|
||||
it('should call sendWalletReady', function() {
|
||||
var data = {
|
||||
type: "walletId",
|
||||
|
@ -532,6 +543,109 @@ describe('Wallet model', function() {
|
|||
sinon.assert.callCount(spy, 1);
|
||||
});
|
||||
|
||||
it('should call sendPublicKeyRing', function() {
|
||||
var data = {
|
||||
type: "walletReady",
|
||||
walletId: w.id
|
||||
};
|
||||
|
||||
var spy = sinon.spy(w, 'sendPublicKeyRing');
|
||||
w._onData(sender, data, ts);
|
||||
sinon.assert.callCount(spy, 1);
|
||||
});
|
||||
|
||||
it('should call _onPublicKeyRing', function() {
|
||||
var data = {
|
||||
type: "publicKeyRing",
|
||||
walletId: w.id,
|
||||
publicKeyRing: {
|
||||
networkName: 'testnet',
|
||||
requiredCopayers: 3,
|
||||
totalCopayers: 3,
|
||||
indexes: [],
|
||||
nicknameFor: 'NickName',
|
||||
copayersExtPubKeys: [],
|
||||
}
|
||||
};
|
||||
|
||||
var spy = sinon.spy(w, '_onPublicKeyRing');
|
||||
w._onData(sender, data, ts);
|
||||
sinon.assert.callCount(spy, 1);
|
||||
});
|
||||
|
||||
it('should call _onReject', function() {
|
||||
var data = {
|
||||
type: "reject",
|
||||
walletId: w.id,
|
||||
ntxid: '12345',
|
||||
};
|
||||
|
||||
//todo: add a txp
|
||||
|
||||
var spy = sinon.spy(w, '_onReject');
|
||||
w._onData(sender, data, ts);
|
||||
sinon.assert.callCount(spy, 1);
|
||||
});
|
||||
|
||||
it('should call _onSeen', function() {
|
||||
var data = {
|
||||
type: "seen",
|
||||
walletId: w.id,
|
||||
ntxid: '12345',
|
||||
};
|
||||
|
||||
var spy = sinon.spy(w, '_onSeen');
|
||||
w._onData(sender, data, ts);
|
||||
sinon.assert.callCount(spy, 1);
|
||||
});
|
||||
|
||||
it('should call _onTxProposal', function() {
|
||||
var data = {
|
||||
type: "txProposal",
|
||||
walletId: w.id,
|
||||
ntxid: '12345',
|
||||
txProposal: '0001'
|
||||
};
|
||||
|
||||
var spy = sinon.spy(w, '_onTxProposal');
|
||||
w._onData(sender, data, ts);
|
||||
sinon.assert.callCount(spy, 1);
|
||||
});
|
||||
|
||||
it('should call _onSignature', function() {
|
||||
var data = {
|
||||
type: "signature",
|
||||
walletId: w.id,
|
||||
};
|
||||
|
||||
var spy = sinon.spy(w, '_onSignature');
|
||||
w._onData(sender, data, ts);
|
||||
sinon.assert.callCount(spy, 1);
|
||||
});
|
||||
|
||||
|
||||
it('should call _onIndexes', function() {
|
||||
var data = {
|
||||
type: "indexes",
|
||||
walletId: w.id,
|
||||
indexes: []
|
||||
};
|
||||
var spy = sinon.spy(w, '_onIndexes');
|
||||
w._onData(sender, data, ts);
|
||||
sinon.assert.callCount(spy, 1);
|
||||
});
|
||||
|
||||
it('should call _onAddressBook', function() {
|
||||
var data = {
|
||||
type: "addressbook",
|
||||
walletId: w.id,
|
||||
};
|
||||
var spy = sinon.spy(w, '_onAddressBook');
|
||||
w._onData(sender, data, ts);
|
||||
sinon.assert.callCount(spy, 1);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
@ -989,6 +1103,98 @@ describe('Wallet model', function() {
|
|||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
describe('#_updateTxProposalSent', function() {
|
||||
it('should call setSent', function(done) {
|
||||
var w = createW2(null, 1);
|
||||
var txp = {
|
||||
getId: sinon.stub().returns('1'),
|
||||
setSent: sinon.stub()
|
||||
};
|
||||
|
||||
w._checkIfTxIsSent = sinon.stub().yields(null, '2');
|
||||
|
||||
w._updateTxProposalSent(txp);
|
||||
txp.setSent.calledOnce.should.be.true;
|
||||
done();
|
||||
});
|
||||
it('should not call setSent', function(done) {
|
||||
var w = createW2(null, 1);
|
||||
var txp = {
|
||||
getId: sinon.stub().returns('1'),
|
||||
setSent: sinon.stub()
|
||||
};
|
||||
|
||||
w._checkIfTxIsSent = sinon.stub().yields(null, null);
|
||||
|
||||
w._updateTxProposalSent(txp);
|
||||
txp.setSent.calledOnce.should.be.false;
|
||||
done();
|
||||
});
|
||||
|
||||
it('should not call setSent case 2', function(done) {
|
||||
var w = createW2(null, 1);
|
||||
var txp = {
|
||||
getId: sinon.stub().returns('1'),
|
||||
setSent: sinon.stub()
|
||||
};
|
||||
|
||||
w._checkIfTxIsSent = sinon.stub().yields('error', null);
|
||||
|
||||
w._updateTxProposalSent(txp, function(err) {
|
||||
err.should.be.equal('error');
|
||||
txp.setSent.calledOnce.should.be.false;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('#_doOnIndexes', function() {
|
||||
it('should call subscribeToAddresses', function() {
|
||||
var w = createW2(null, 1);
|
||||
var utxo = createUTXO(w);
|
||||
var now = Date.now();
|
||||
var txp = w._createTxProposal(PP.outs[0].address, PP.outs[0].amountSatStr, 'hola', utxo);
|
||||
var indexes = [{
|
||||
index: 1
|
||||
}];
|
||||
w.subscribeToAddresses = sinon.stub().returns();
|
||||
w.emitAndKeepAlive = sinon.stub().returns();
|
||||
w.publicKeyRing.mergeIndexes = sinon.stub().returns(true);
|
||||
w.clearUnspentCache = sinon.stub();
|
||||
|
||||
w._doOnIndexes(indexes, false);
|
||||
w.clearUnspentCache.calledOnce.should.be.true;
|
||||
w.subscribeToAddresses.calledOnce.should.be.true;
|
||||
w.emitAndKeepAlive.calledOnce.should.be.true;
|
||||
});
|
||||
|
||||
it('should call subscribeToAddresses case 2', function() {
|
||||
var w = createW2(null, 1);
|
||||
var utxo = createUTXO(w);
|
||||
var now = Date.now();
|
||||
var txp = w._createTxProposal(PP.outs[0].address, PP.outs[0].amountSatStr, 'hola', utxo);
|
||||
var indexes = [{
|
||||
index: 1
|
||||
}];
|
||||
w.subscribeToAddresses = sinon.stub().returns();
|
||||
w.emitAndKeepAlive = sinon.stub().returns();
|
||||
w.publicKeyRing.mergeIndexes = sinon.stub().returns(true);
|
||||
w.clearUnspentCache = sinon.stub();
|
||||
|
||||
w._doOnIndexes(indexes, true);
|
||||
w.clearUnspentCache.calledOnce.should.be.false;
|
||||
w.subscribeToAddresses.calledOnce.should.be.true;
|
||||
w.emitAndKeepAlive.calledOnce.should.be.true;
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
describe('#issueTx', function() {
|
||||
it('should broadcast a TX', function(done) {
|
||||
var w = createW2(null, 1);
|
||||
|
@ -1061,6 +1267,80 @@ describe('Wallet model', function() {
|
|||
});
|
||||
|
||||
|
||||
describe('#_processTxProposalPayPro', function() {
|
||||
it('should return without error', function(done) {
|
||||
var w = cachedCreateW2();
|
||||
|
||||
var utxos = [{
|
||||
txid: 'txid0',
|
||||
vout: 'vout1',
|
||||
}, {
|
||||
txid: 'txid0',
|
||||
vout: 'vout2',
|
||||
}];
|
||||
|
||||
var txp = {
|
||||
ntxid: 'txid1',
|
||||
isPending: true,
|
||||
builder: {
|
||||
utxos: [utxos[0]],
|
||||
},
|
||||
paymentProtocolURL: null
|
||||
};
|
||||
txp.addMerchantData = sinon.spy();
|
||||
w.getTxProposals = sinon.stub().returns([txp]);
|
||||
w.blockchain.getUnspent = sinon.stub().yields(null, utxos);
|
||||
|
||||
w._processTxProposalPayPro(txp, function(err) {
|
||||
should.not.exist(err);
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
it('should call addMerchantData', function(done) {
|
||||
var w = cachedCreateW2();
|
||||
|
||||
var utxos = [{
|
||||
txid: 'txid0',
|
||||
vout: 'vout1',
|
||||
}, {
|
||||
txid: 'txid0',
|
||||
vout: 'vout2',
|
||||
}];
|
||||
|
||||
var txp = {
|
||||
ntxid: 'txid1',
|
||||
isPending: true,
|
||||
builder: {
|
||||
utxos: [utxos[0]],
|
||||
},
|
||||
paymentProtocolURL: 'http://mydomain.com'
|
||||
};
|
||||
txp.addMerchantData = sinon.spy();
|
||||
w.getTxProposals = sinon.stub().returns([txp]);
|
||||
w.blockchain.getUnspent = sinon.stub().yields(null, utxos);
|
||||
|
||||
sinon.stub(w, 'fetchPaymentRequest').yields(null, {
|
||||
outs: [{
|
||||
address: 'n2Wz7KjyzBJVaNMBN88Lj1YUHMDZSAGeMV',
|
||||
amountSatStr: '123400',
|
||||
}],
|
||||
request_url: 'url',
|
||||
pr: {
|
||||
signature: '123',
|
||||
},
|
||||
total: '123400',
|
||||
});
|
||||
|
||||
w._processTxProposalPayPro(txp, function(err) {
|
||||
should.not.exist(err);
|
||||
|
||||
txp.addMerchantData.calledOnce.should.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#fetchPaymentRequest', function() {
|
||||
it('should fetch a payment request', function(done) {
|
||||
var w = cachedCreateW2();
|
||||
|
@ -1282,6 +1562,26 @@ describe('Wallet model', function() {
|
|||
});
|
||||
|
||||
|
||||
describe('#getStorageKey', function() {
|
||||
it('should return storage key', function() {
|
||||
var w = cachedCreateW2();
|
||||
var r = w.getStorageKey();
|
||||
r.should.not.be.undefined;
|
||||
});
|
||||
});
|
||||
|
||||
describe('#seedCopayer', function() {
|
||||
it('should set copayerId', function() {
|
||||
var w = cachedCreateW2();
|
||||
w.seedCopayer('abcd');
|
||||
w.seededCopayerId.should.be.equal('abcd');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
describe('#_sendToPeers', function() {
|
||||
it('should call this.network.send', function() {
|
||||
|
@ -1535,6 +1835,41 @@ describe('Wallet model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
|
||||
describe('#changeSettings', function() {
|
||||
it('should call emitAndKeepAlive', function() {
|
||||
var w = cachedCreateW2();
|
||||
w.emitAndKeepAlive = sinon.spy();
|
||||
var settings = {
|
||||
unitName: 'bits',
|
||||
unitToSatoshi: 100,
|
||||
alternativeName: 'US Dollar',
|
||||
alternativeIsoCode: 'USD',
|
||||
};
|
||||
w.changeSettings(settings);
|
||||
w.emitAndKeepAlive.calledOnce.should.equal(true);
|
||||
w.emitAndKeepAlive.getCall(0).args[0].should.equal('settingsUpdated');
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('#_onNoMessages', function() {
|
||||
it('should call sendWalletReady', function() {
|
||||
var w = cachedCreateW2();
|
||||
w.sendWalletReady = sinon.spy();
|
||||
w._onNoMessages();
|
||||
w.sendWalletReady.calledOnce.should.equal(true);
|
||||
});
|
||||
it('should not call sendWalletReady', function() {
|
||||
var w = cachedCreateW2();
|
||||
w.sendWalletReady = sinon.spy();
|
||||
w.isComplete = sinon.stub().returns(false);
|
||||
w._onNoMessages();
|
||||
w.sendWalletReady.calledOnce.should.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('#netStart', function() {
|
||||
it('should call Network.start', function() {
|
||||
var w = cachedCreateW2();
|
||||
|
@ -1574,7 +1909,7 @@ describe('Wallet model', function() {
|
|||
inputChainPaths: ['/m/1'],
|
||||
};
|
||||
var map = w._getPubkeyToCopayerMap(txp);
|
||||
console.log('[Wallet.js.1526:map:]', map); //TODO
|
||||
//console.log('[Wallet.js.1526:map:]', map); //TODO
|
||||
Object.keys(map).length.should.equal(1);
|
||||
map['123'].should.equal('juan');
|
||||
stub.restore();
|
||||
|
@ -1885,6 +2220,47 @@ describe('Wallet model', function() {
|
|||
});
|
||||
|
||||
|
||||
|
||||
|
||||
describe('_processIncomingNewTxProposal', function(done) {
|
||||
it('should return an error', function(done) {
|
||||
var w = cachedCreateW2();
|
||||
var txp = {
|
||||
getId: sinon.stub().returns('1')
|
||||
};
|
||||
|
||||
w._processTxProposalPayPro = sinon.stub().yields('error');
|
||||
w._processIncomingNewTxProposal(txp, function(err) {
|
||||
err.should.be.equal('error');
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should call _updateTxProposalSent', function(done) {
|
||||
var w = cachedCreateW2();
|
||||
var tx = {
|
||||
isComplete: sinon.stub().returns(true)
|
||||
};
|
||||
|
||||
var txp = {
|
||||
getId: sinon.stub().returns('1'),
|
||||
builder: {
|
||||
build: sinon.stub().returns(tx)
|
||||
},
|
||||
getSent: sinon.stub().returns(false)
|
||||
};
|
||||
|
||||
w._updateTxProposalSent = sinon.stub().returns();
|
||||
w._processTxProposalPayPro = sinon.stub().yields(null);
|
||||
w._processIncomingNewTxProposal(txp, function(err) {
|
||||
expect(err).to.be.undefined;
|
||||
w._updateTxProposalSent.calledOnce.should.be.true;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
describe('_onSignature', function() {
|
||||
var w, data, txp;
|
||||
beforeEach(function() {
|
||||
|
@ -1919,6 +2295,35 @@ describe('Wallet model', function() {
|
|||
});
|
||||
|
||||
|
||||
describe('_checkIfTxIsSent', function() {
|
||||
it('should call the blockchain ', function(done) {
|
||||
var w = cachedCreateW2();
|
||||
var utxo = createUTXO(w);
|
||||
var txp = w._createTxProposal(PP.outs[0].address, PP.outs[0].amountSatStr, 'hola', utxo);
|
||||
var ntxid = w.txProposals.add(txp);
|
||||
sinon.stub(w.blockchain, 'broadcast').yields(null, 1234);
|
||||
var data = {
|
||||
ntxid: ntxid,
|
||||
signatures: [1],
|
||||
}
|
||||
sinon.stub(w.txProposals, 'get').returns(txp);
|
||||
sinon.stub(txp, '_addSignatureAndVerify').returns();
|
||||
|
||||
sinon.stub(w.blockchain, 'getTransaction').yields(null, null);
|
||||
|
||||
|
||||
w.on('txProposalEvent', function(e) {
|
||||
e.type.should.equal(Wallet.TX_SIGNED);
|
||||
w._checkIfTxIsSent(txp, function() {
|
||||
w.blockchain.getTransaction.called.should.equal(true);
|
||||
done();
|
||||
});
|
||||
})
|
||||
w._onSignature('senderID', data);
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe('_onReject', function() {
|
||||
it('should do nothing on unknown tx', function() {
|
||||
var w = cachedCreateW();
|
||||
|
@ -1973,6 +2378,36 @@ describe('Wallet model', function() {
|
|||
});
|
||||
|
||||
|
||||
|
||||
describe('_setTxProposalSeen', function() {
|
||||
it('should call sendSeen', function() {
|
||||
var w = cachedCreateW();
|
||||
|
||||
var txp = {
|
||||
getSeen: sinon.stub().returns(false),
|
||||
setSeen: sinon.stub(),
|
||||
getId: sinon.stub().returns('1'),
|
||||
};
|
||||
|
||||
var spy1 = sinon.spy(w, 'sendSeen');
|
||||
w._setTxProposalSeen(txp);
|
||||
spy1.called.should.equal(true);
|
||||
});
|
||||
it('should not call sendSeen', function() {
|
||||
var w = cachedCreateW();
|
||||
|
||||
var txp = {
|
||||
getSeen: sinon.stub().returns(true),
|
||||
setSeen: sinon.stub(),
|
||||
getId: sinon.stub().returns('1'),
|
||||
};
|
||||
|
||||
var spy1 = sinon.spy(w, 'sendSeen');
|
||||
w._setTxProposalSeen(txp);
|
||||
spy1.called.should.equal(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('_onSeen', function() {
|
||||
it('should do nothing on unknown tx', function() {
|
||||
var w = cachedCreateW();
|
||||
|
|
|
@ -429,4 +429,76 @@ describe('Insight model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
describe.skip('#request', function() {
|
||||
it('should check request', function(done) {
|
||||
var blockchain = new Insight(FAKE_OPTS);
|
||||
blockchain.request('hola', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe.skip('#requestPost', function() {
|
||||
it('should check requestPost', function(done) {
|
||||
var blockchain = new Insight(FAKE_OPTS);
|
||||
blockchain.requestPost('hola', 'myData', function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#broadcast', function() {
|
||||
it('should check broadcast', function(done) {
|
||||
var blockchain = new Insight(FAKE_OPTS);
|
||||
blockchain.requestPost = sinon.stub().yields({
|
||||
error: 'error',
|
||||
status: 500
|
||||
});
|
||||
blockchain.broadcast('myTX', function(err) {
|
||||
err.should.not.be.undefined;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getTransactions', function() {
|
||||
it('should check getTransactions', function(done) {
|
||||
var blockchain = new Insight(FAKE_OPTS);
|
||||
blockchain.requestPost = sinon.stub().yields({
|
||||
error: 'error',
|
||||
status: 500
|
||||
});
|
||||
blockchain.getTransactions(['addr1'], 'to', 'from', function(err) {
|
||||
err.should.not.be.undefined;
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should check getTransactions using to and from as numbers', function(done) {
|
||||
var blockchain = new Insight(FAKE_OPTS);
|
||||
blockchain.requestPost = sinon.stub().yields({
|
||||
error: 'error',
|
||||
status: 500
|
||||
});
|
||||
blockchain.getTransactions(['addr1'], 1, 10, function(err) {
|
||||
err.should.not.be.undefined;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('#getUnspent', function() {
|
||||
it('should check getUnspent with error response', function(done) {
|
||||
var blockchain = new Insight(FAKE_OPTS);
|
||||
blockchain.requestPost = sinon.stub().yields({
|
||||
error: 'error',
|
||||
status: 500
|
||||
});
|
||||
blockchain.getUnspent(['addr1'], function(err) {
|
||||
err.should.not.be.undefined;
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
|
|
|
@ -433,7 +433,6 @@ describe('Network / Async', function() {
|
|||
|
||||
var lockIds = ['abc001', 'abc002'];
|
||||
n.lockIncommingConnections(lockIds);
|
||||
console.log(n.allowedCopayerIds);
|
||||
Object.keys(n.allowedCopayerIds).length.should.be.equal(2);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue