mirror of https://github.com/BTCPrivate/copay.git
Merge pull request #1927 from matiu/bug/wallet2
Add more tests to Wallet.js
This commit is contained in:
commit
baa4cc0a24
|
@ -76,6 +76,7 @@ PublicKeyRing.prototype.resetCache = function() {
|
|||
* as a parameter
|
||||
*/
|
||||
PublicKeyRing.trim = function(data) {
|
||||
preconditions.checkArgument(data);
|
||||
var opts = {};
|
||||
['walletId', 'networkName', 'requiredCopayers', 'totalCopayers',
|
||||
'indexes', 'nicknameFor', 'copayersExtPubKeys'
|
||||
|
@ -698,6 +699,7 @@ PublicKeyRing.prototype.getRedeemScriptMap = function(paths) {
|
|||
*/
|
||||
|
||||
PublicKeyRing.prototype._checkInPKR = function(inPKR, ignoreId) {
|
||||
preconditions.checkArgument(_.isObject(inPKR));
|
||||
|
||||
if (!ignoreId && this.walletId !== inPKR.walletId)
|
||||
throw new Error('inPKR walletId mismatch');
|
||||
|
@ -786,8 +788,8 @@ PublicKeyRing.prototype.mergeIndexes = function(indexes) {
|
|||
* @return {boolean} true if the internal state has changed
|
||||
*/
|
||||
PublicKeyRing.prototype.merge = function(inPKR, ignoreId) {
|
||||
this._checkInPKR(inPKR, ignoreId);
|
||||
|
||||
this._checkInPKR(inPKR, ignoreId);
|
||||
var hasChanged = false;
|
||||
hasChanged |= this.mergeIndexes(inPKR.indexes);
|
||||
hasChanged |= this._mergePubkeys(inPKR);
|
||||
|
|
|
@ -327,8 +327,7 @@ Wallet.prototype._onPublicKeyRing = function(senderId, data) {
|
|||
try {
|
||||
hasChanged = this.publicKeyRing.merge(inPKR, true);
|
||||
} catch (e) {
|
||||
log.debug('Wallet:' + this.id + '## WALLET ERROR', e);
|
||||
this.emitAndKeepAlive('connectionError', e.message);
|
||||
log.warn('Wallet:' + this.id, e);
|
||||
return;
|
||||
}
|
||||
if (hasChanged) {
|
||||
|
|
|
@ -1616,6 +1616,56 @@ describe('Wallet model', function() {
|
|||
});
|
||||
});
|
||||
|
||||
|
||||
describe('_onPublicKeyRing', function() {
|
||||
var w, data, txp, pkr;
|
||||
beforeEach(function() {
|
||||
w = cachedCreateW();
|
||||
pkr = '{"walletId":"0a903a2eb33793d1","networkName":"testnet","requiredCopayers":2,"totalCopayers":2,"indexes":[{"copayerIndex":2147483647,"changeIndex":0,"receiveIndex":1},{"copayerIndex":0,"changeIndex":39,"receiveIndex":0},{"copayerIndex":1,"changeIndex":102,"receiveIndex":39}],"copayersExtPubKeys":["tpubD9peJo88ArhgmJNqRkQmhHt4zAGTYVowsHrDj385xyXyMy4RhWZpV5Qx2mMDUVzpbAD5V9jci5D7cZaHhjLYP8gEkngmTKtSF4Y7V3qkAsy","tpubD8udwzKWwNUgoE2WG7LYsXKf5m1eRtJ1Etp43vnoxViFmrmZ1ND2CkdqGyQtuidcN1CiqdBUvbKegbdsMQaj5VLY2hbA4LEnLDrqkgSzikz"],"nicknameFor":{"03338b105850c7126f1f5b0439b357765b17ead8eed15bcdfdbd28d0e3915b696f":"5@queparece","0286b376d65cc4af0de5932fb8299cbef2ca9ed37ec9fdb0edfd4e9cb74eac45da":"4@queparece"}}';
|
||||
});
|
||||
|
||||
it('should fail wrong nr copayers PublicKeyRing', function() {
|
||||
var spy = sinon.spy(console, 'warn');
|
||||
w._onPublicKeyRing('sender', {
|
||||
publicKeyRing: JSON.parse(pkr),
|
||||
});
|
||||
spy.getCall(0).args[1].toString().should.contain('mismatch');
|
||||
spy.restore();
|
||||
});
|
||||
it('should receive and send PKR', function() {
|
||||
var obj = JSON.parse(pkr);
|
||||
|
||||
sinon.stub(w.network, 'send').returns();
|
||||
|
||||
obj.requiredCopayers = 3;
|
||||
obj.totalCopayers = 5;
|
||||
w._onPublicKeyRing('sender', {
|
||||
publicKeyRing: obj,
|
||||
});
|
||||
w.network.send.calledOnce.should.equal(true);
|
||||
should.not.exist(w.network.send.getCall(0).args[0])
|
||||
var o = w.network.send.getCall(0).args[1];
|
||||
_.isObject(o).should.equal(true);
|
||||
o.type.should.equal('publicKeyRing');
|
||||
});
|
||||
it('should lock incomming connections', function() {
|
||||
var obj = JSON.parse(pkr);
|
||||
sinon.stub(w.network, 'send').returns();
|
||||
sinon.stub(w.network, 'lockIncommingConnections').returns();
|
||||
|
||||
obj.requiredCopayers = 3;
|
||||
obj.totalCopayers = 5;
|
||||
var s = sinon.stub(w.publicKeyRing, 'isComplete');
|
||||
s.returns(true);
|
||||
|
||||
w._onPublicKeyRing('sender', {
|
||||
publicKeyRing: obj,
|
||||
});
|
||||
w.network.send.calledOnce.should.equal(false); // wasComplete
|
||||
w.network.lockIncommingConnections.calledOnce.should.equal(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('_onTxProposal', function() {
|
||||
var w, data, txp;
|
||||
beforeEach(function() {
|
||||
|
|
Loading…
Reference in New Issue