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
|
* Processes the data using {@link HDParams#fromList} and merges it with the
|
||||||
* {@link Wallet#publicKeyRing}.
|
* {@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) {
|
Wallet.prototype._doOnIndexes = function(indexes, fromTxProposal) {
|
||||||
preconditions.checkArgument(indexes);
|
preconditions.checkArgument(indexes);
|
||||||
|
@ -403,7 +403,7 @@ Wallet.prototype._getPubkeyToCopayerMap = function(txp) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @desc
|
* @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 {string} ntxid - the transaction proposal
|
||||||
* @param {transactionCallback} cb
|
* @param {transactionCallback} cb
|
||||||
|
@ -411,7 +411,9 @@ Wallet.prototype._getPubkeyToCopayerMap = function(txp) {
|
||||||
Wallet.prototype._checkIfTxIsSent = function(ntxid, cb) {
|
Wallet.prototype._checkIfTxIsSent = function(ntxid, cb) {
|
||||||
var txp = this.txProposals.get(ntxid);
|
var txp = this.txProposals.get(ntxid);
|
||||||
var tx = txp.builder.build();
|
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.
|
//Use calcHash NOT getHash which could be cached.
|
||||||
|
|
|
@ -17,7 +17,9 @@ describe('HDParams model', function() {
|
||||||
should.exist(is);
|
should.exist(is);
|
||||||
is.length.should.equal(3);
|
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(HDPath.SHARED_INDEX).should.not.equal(-1);
|
||||||
cosigners.indexOf(0).should.not.equal(-1);
|
cosigners.indexOf(0).should.not.equal(-1);
|
||||||
cosigners.indexOf(1).should.not.equal(-1);
|
cosigners.indexOf(1).should.not.equal(-1);
|
||||||
|
@ -36,7 +38,7 @@ describe('HDParams model', function() {
|
||||||
is2.length.should.equal(4);
|
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();
|
var i = new HDParams();
|
||||||
i.copayerIndex = 1;
|
i.copayerIndex = 1;
|
||||||
var changeN = 2;
|
var changeN = 2;
|
||||||
|
@ -58,13 +60,22 @@ describe('HDParams model', function() {
|
||||||
i2.getReceiveIndex().should.equal(addressN);
|
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() {
|
it('should count generation indexes', function() {
|
||||||
var j = new HDParams();
|
var j = new HDParams();
|
||||||
j.copayerIndex = 1;
|
j.copayerIndex = 1;
|
||||||
for (var i = 0; i < 3; i++)
|
for (var i = 0; i < 3; i++)
|
||||||
j.increment(true);
|
j.increment(true);
|
||||||
for (var i = 0; i < 2; i++)
|
for (var i = 0; i < 2; i++)
|
||||||
j.increment(false);
|
j.increment(false);
|
||||||
|
|
||||||
j.changeIndex.should.equal(3);
|
j.changeIndex.should.equal(3);
|
||||||
j.receiveIndex.should.equal(2);
|
j.receiveIndex.should.equal(2);
|
||||||
|
@ -75,9 +86,9 @@ describe('HDParams model', function() {
|
||||||
j.copayerIndex = 1;
|
j.copayerIndex = 1;
|
||||||
|
|
||||||
for (var i = 0; i < 15; i++)
|
for (var i = 0; i < 15; i++)
|
||||||
j.increment(true);
|
j.increment(true);
|
||||||
for (var i = 0; i < 7; i++)
|
for (var i = 0; i < 7; i++)
|
||||||
j.increment(false);
|
j.increment(false);
|
||||||
var j2 = new HDParams({
|
var j2 = new HDParams({
|
||||||
copayerIndex: j.copayerIndex,
|
copayerIndex: j.copayerIndex,
|
||||||
});
|
});
|
||||||
|
@ -89,11 +100,44 @@ describe('HDParams model', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('#merge should fail with different copayerIndex index', function() {
|
it('#merge should fail with different copayerIndex index', function() {
|
||||||
var j1 = new HDParams({ walletId: '1234', copayerIndex: 2 });
|
var j1 = new HDParams({
|
||||||
var j2 = new HDParams({ walletId: '1234', copayerIndex: 3 });
|
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);
|
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'),
|
kdf: sinon.stub().returns('passphrase'),
|
||||||
decrypt: sinon.stub().returns('{"walletId":123}'),
|
decrypt: sinon.stub().returns('{"walletId":123}'),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
opts = {
|
opts = {
|
||||||
email: 'test@test.com',
|
email: 'test@test.com',
|
||||||
password: '123',
|
password: '123',
|
||||||
|
@ -1263,9 +1261,12 @@ describe('Identity model', function() {
|
||||||
expect(iden._checkVersion()).to.be.undefined;
|
expect(iden._checkVersion()).to.be.undefined;
|
||||||
expect(iden._checkVersion('0.0.0')).to.be.undefined;
|
expect(iden._checkVersion('0.0.0')).to.be.undefined;
|
||||||
(function() {
|
(function() {
|
||||||
console.log('b', iden._checkVersion('9.9.9'));
|
iden._checkVersion('9.9.9');
|
||||||
}).should.throw('Major difference');
|
}).should.throw('Major difference');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -23,6 +23,27 @@ describe('PrivateKey model', function() {
|
||||||
should.exist(w.bip.derive);
|
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() {
|
it('should derive priv keys', function() {
|
||||||
var pk = new PrivateKey(pkConfig);
|
var pk = new PrivateKey(pkConfig);
|
||||||
for (var j = false; !j; j = true) {
|
for (var j = false; !j; j = true) {
|
||||||
|
|
|
@ -553,6 +553,54 @@ describe('PublicKeyRing model', function() {
|
||||||
w.myCopayerId().should.be.equal(w.getCopayerId(0));
|
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() {
|
describe('#getHistoricRate', function() {
|
||||||
|
@ -203,6 +226,7 @@ describe('RateService model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return error', function() {
|
it('should return error', function() {
|
||||||
var yesterday = moment().subtract(1, 'day');
|
var yesterday = moment().subtract(1, 'day');
|
||||||
var reqStub = sinon.stub();
|
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() {
|
it('should return error', function() {
|
||||||
var yesterday = moment().subtract(1, 'day');
|
var yesterday = moment().subtract(1, 'day');
|
||||||
var reqStub = sinon.stub();
|
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() {
|
describe('#singleton', function() {
|
||||||
it('should create only one instance', function() {
|
it('should create only one instance', function() {
|
||||||
var rs = RateService.singleton();
|
var rs = RateService.singleton();
|
||||||
|
|
|
@ -29,7 +29,7 @@ describe('TxProposal', function() {
|
||||||
/* decoded redeemscript
|
/* decoded redeemscript
|
||||||
*
|
*
|
||||||
"asm" : "3 03197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d 0380a29968851f93af55e581c43d9ef9294577a439a3ca9fc2bc47d1ca2b3e9127 0392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed03 03a94351fecc4328bb683bf93a1aa67378374904eac5980c7966723a51897c56e3 03e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e4 5 OP_CHECKMULTISIG",
|
"asm" : "3 03197599f6e209cefef07da2fddc6fe47715a70162c531ffff8e611cef23dfb70d 0380a29968851f93af55e581c43d9ef9294577a439a3ca9fc2bc47d1ca2b3e9127 0392dccb2ed470a45984811d6402fdca613c175f8f3e4eb8e2306e8ccd7d0aed03 03a94351fecc4328bb683bf93a1aa67378374904eac5980c7966723a51897c56e3 03e085eb6fa1f20b2722c16161144314070a2c316a9cae2489fd52ce5f63fff6e4 5 OP_CHECKMULTISIG",
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// 1,2 signatures 3-5!
|
// 1,2 signatures 3-5!
|
||||||
var SCRIPTSIG = _.map([
|
var SCRIPTSIG = _.map([
|
||||||
|
@ -44,12 +44,12 @@ describe('TxProposal', function() {
|
||||||
|
|
||||||
|
|
||||||
// 3-5
|
// 3-5
|
||||||
|
|
||||||
|
|
||||||
function dummyBuilder(opts) {
|
function dummyBuilder(opts) {
|
||||||
opts = opts || {};
|
opts = opts || {};
|
||||||
|
|
||||||
var index = opts.nsig ? opts.nsig - 1 : 1;
|
var index = opts.nsig ? opts.nsig - 1 : 1;
|
||||||
var script = SCRIPTSIG[index];
|
var script = SCRIPTSIG[index];
|
||||||
|
|
||||||
var aIn = {
|
var aIn = {
|
||||||
|
@ -85,7 +85,7 @@ describe('TxProposal', function() {
|
||||||
amountSatStr: '123',
|
amountSatStr: '123',
|
||||||
}]),
|
}]),
|
||||||
};
|
};
|
||||||
builder.inputsSigned =0;
|
builder.inputsSigned = 0;
|
||||||
|
|
||||||
return builder;
|
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() {
|
describe('#setSent', function() {
|
||||||
it('should set txid and timestamp', function() {
|
it('should set txid and timestamp', function() {
|
||||||
|
@ -326,6 +348,10 @@ describe('TxProposal', function() {
|
||||||
}
|
}
|
||||||
Buffer.isBuffer(info.script.getBuffer()).should.equal(true);
|
Buffer.isBuffer(info.script.getBuffer()).should.equal(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
it('#getSignersPubKeys', function() {
|
it('#getSignersPubKeys', function() {
|
||||||
var txp = dummyProposal();
|
var txp = dummyProposal();
|
||||||
var pubkeys = txp.getSignersPubKeys();
|
var pubkeys = txp.getSignersPubKeys();
|
||||||
|
@ -345,10 +371,10 @@ describe('TxProposal', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#addSignature', function() {
|
describe('#addSignature', function() {
|
||||||
it('should add signatures maintaing pubkeys order', function() {
|
it('should add signatures maintaing pubkeys order', function() {
|
||||||
var txp = dummyProposal({
|
var txp = dummyProposal({
|
||||||
nsig:1
|
nsig: 1
|
||||||
});
|
});
|
||||||
txp.getSignersPubKeys()[0].length.should.equal(1);
|
txp.getSignersPubKeys()[0].length.should.equal(1);
|
||||||
|
|
||||||
|
@ -362,31 +388,41 @@ describe('TxProposal', function() {
|
||||||
});
|
});
|
||||||
it('should add signatures to incomplete txs ', function() {
|
it('should add signatures to incomplete txs ', function() {
|
||||||
var txp = dummyProposal({
|
var txp = dummyProposal({
|
||||||
nsig:1
|
nsig: 1
|
||||||
});
|
});
|
||||||
txp.addSignature('pepe', [SIG1]);
|
txp.addSignature('pepe', [SIG1]);
|
||||||
txp.builder.inputsSigned.should.be.equal(0);
|
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() {
|
it('should fail with invalid signatures', function() {
|
||||||
var txp = dummyProposal({
|
var txp = dummyProposal({
|
||||||
nsig:1
|
nsig: 1
|
||||||
});
|
});
|
||||||
txp.getSignersPubKeys()[0].length.should.equal(1);
|
txp.getSignersPubKeys()[0].length.should.equal(1);
|
||||||
|
|
||||||
(function(){
|
(function() {
|
||||||
txp.addSignature('pepe', ['002030a77c9613d6ee010717c1abc494668d877e3fa0ae4c520f65cc3b308754c98c02205219d387bcb291bd44805b9468439e4168b02a6a180cdbcc24d84d71d696c1ae01']);
|
txp.addSignature('pepe', ['002030a77c9613d6ee010717c1abc494668d877e3fa0ae4c520f65cc3b308754c98c02205219d387bcb291bd44805b9468439e4168b02a6a180cdbcc24d84d71d696c1ae01']);
|
||||||
}).should.throw('BADSIG');
|
}).should.throw('BADSIG');
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fail adding the same signature twice', function() {
|
it('should fail adding the same signature twice', function() {
|
||||||
var txp = dummyProposal({
|
var txp = dummyProposal({
|
||||||
nsig:1
|
nsig: 1
|
||||||
});
|
});
|
||||||
txp.getSignersPubKeys()[0].length.should.equal(1);
|
txp.getSignersPubKeys()[0].length.should.equal(1);
|
||||||
|
|
||||||
txp.addSignature('pepe', [SIG1]);
|
txp.addSignature('pepe', [SIG1]);
|
||||||
(function(){
|
(function() {
|
||||||
txp.addSignature('pepe', [SIG1]);
|
txp.addSignature('pepe', [SIG1]);
|
||||||
}).should.throw('BADSIG');
|
}).should.throw('BADSIG');
|
||||||
});
|
});
|
||||||
|
@ -533,7 +569,7 @@ describe('TxProposal', function() {
|
||||||
it('with less signatures', function() {
|
it('with less signatures', function() {
|
||||||
var txp = dummyProposal();
|
var txp = dummyProposal();
|
||||||
var txp1Sig = dummyProposal({
|
var txp1Sig = dummyProposal({
|
||||||
nsig:1
|
nsig: 1
|
||||||
});
|
});
|
||||||
var backup = txp.builder.vanilla.scriptSig[0];
|
var backup = txp.builder.vanilla.scriptSig[0];
|
||||||
var hasChanged = txp.merge(txp);
|
var hasChanged = txp.merge(txp);
|
||||||
|
@ -693,7 +729,19 @@ describe('TxProposal', function() {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
describe('micelaneous functions', 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() {
|
it('should report rejectCount', function() {
|
||||||
var txp = dummyProposal();
|
var txp = dummyProposal();
|
||||||
txp.rejectCount().should.equal(0);
|
txp.rejectCount().should.equal(0);
|
||||||
|
@ -721,4 +769,5 @@ describe('TxProposal', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -17,7 +17,9 @@ var dummyProposal = new TxProposal({
|
||||||
creator: 1,
|
creator: 1,
|
||||||
createdTs: 1,
|
createdTs: 1,
|
||||||
builder: {
|
builder: {
|
||||||
toObj: sinon.stub().returns({}),
|
toObj: sinon.stub().returns({
|
||||||
|
getId: sinon.stub().returns('1234')
|
||||||
|
}),
|
||||||
},
|
},
|
||||||
inputChainPaths: ['m/1'],
|
inputChainPaths: ['m/1'],
|
||||||
});
|
});
|
||||||
|
@ -42,6 +44,66 @@ describe('TxProposals', function() {
|
||||||
should.exist(txps);
|
should.exist(txps);
|
||||||
txps.network.name.should.equal('livenet');
|
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() {
|
it('should skip Objects with errors', function() {
|
||||||
var txps = TxProposals.fromObj({
|
var txps = TxProposals.fromObj({
|
||||||
networkName: 'livenet',
|
networkName: 'livenet',
|
||||||
|
@ -131,6 +193,61 @@ describe('TxProposals', function() {
|
||||||
}).should.throw('Unknown TXP: c');
|
}).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() {
|
describe('#toObj', function() {
|
||||||
it('should an object', function() {
|
it('should an object', function() {
|
||||||
var txps = TxProposals.fromObj({
|
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);
|
status.should.equal(Wallet.TX_PROPOSAL_SENT);
|
||||||
|
|
||||||
w.network.send.calledOnce.should.equal(true);
|
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");
|
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].indexes);
|
||||||
should.exist(w.network.send.getCall(0).args[1].txProposal);
|
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() {
|
it('should call sendWalletReady', function() {
|
||||||
var data = {
|
var data = {
|
||||||
type: "walletId",
|
type: "walletId",
|
||||||
|
@ -532,6 +543,109 @@ describe('Wallet model', function() {
|
||||||
sinon.assert.callCount(spy, 1);
|
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() {
|
describe('#issueTx', function() {
|
||||||
it('should broadcast a TX', function(done) {
|
it('should broadcast a TX', function(done) {
|
||||||
var w = createW2(null, 1);
|
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() {
|
describe('#fetchPaymentRequest', function() {
|
||||||
it('should fetch a payment request', function(done) {
|
it('should fetch a payment request', function(done) {
|
||||||
var w = cachedCreateW2();
|
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() {
|
describe('#_sendToPeers', function() {
|
||||||
it('should call this.network.send', 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() {
|
describe('#netStart', function() {
|
||||||
it('should call Network.start', function() {
|
it('should call Network.start', function() {
|
||||||
var w = cachedCreateW2();
|
var w = cachedCreateW2();
|
||||||
|
@ -1574,7 +1909,7 @@ describe('Wallet model', function() {
|
||||||
inputChainPaths: ['/m/1'],
|
inputChainPaths: ['/m/1'],
|
||||||
};
|
};
|
||||||
var map = w._getPubkeyToCopayerMap(txp);
|
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);
|
Object.keys(map).length.should.equal(1);
|
||||||
map['123'].should.equal('juan');
|
map['123'].should.equal('juan');
|
||||||
stub.restore();
|
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() {
|
describe('_onSignature', function() {
|
||||||
var w, data, txp;
|
var w, data, txp;
|
||||||
beforeEach(function() {
|
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() {
|
describe('_onReject', function() {
|
||||||
it('should do nothing on unknown tx', function() {
|
it('should do nothing on unknown tx', function() {
|
||||||
var w = cachedCreateW();
|
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() {
|
describe('_onSeen', function() {
|
||||||
it('should do nothing on unknown tx', function() {
|
it('should do nothing on unknown tx', function() {
|
||||||
var w = cachedCreateW();
|
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'];
|
var lockIds = ['abc001', 'abc002'];
|
||||||
n.lockIncommingConnections(lockIds);
|
n.lockIncommingConnections(lockIds);
|
||||||
console.log(n.allowedCopayerIds);
|
|
||||||
Object.keys(n.allowedCopayerIds).length.should.be.equal(2);
|
Object.keys(n.allowedCopayerIds).length.should.be.equal(2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue