add wallet.id to debug logs

This commit is contained in:
Matias Alejo Garcia 2014-10-07 18:33:55 -03:00
commit 622c3da68c
10 changed files with 299 additions and 160 deletions

View file

@ -83,12 +83,12 @@ describe('PayPro (in Wallet) model', function() {
c.networkName = walletConfig.networkName;
c.version = '0.0.1';
c.network = sinon.stub();
c.network.setHexNonce = sinon.stub();
c.network.setHexNonces = sinon.stub();
c.network.getHexNonce = sinon.stub();
c.network.getHexNonces = sinon.stub();
c.network.send = sinon.stub();
c.network = sinon.stub();
c.network.setHexNonce = sinon.stub();
c.network.setHexNonces = sinon.stub();
c.network.getHexNonce = sinon.stub();
c.network.getHexNonces = sinon.stub();
c.network.send = sinon.stub();
return new Wallet(c);
@ -130,7 +130,15 @@ describe('PayPro (in Wallet) model', function() {
cachedW2obj = cachedW2.toObj();
cachedW2obj.opts.reconnectDelay = 100;
}
var w = Wallet.fromObj(cachedW2obj, cachedW2.storage, cachedW2.network, cachedW2.blockchain);
Wallet._newAsync = sinon.stub().returns(new Network(walletConfig.network));
Wallet._newInsight = sinon.stub().returns(new Blockchain(walletConfig.blockchain));
var w = Wallet.fromObj(cachedW2obj, {
storage: cachedW2.storage,
blockchainOpts: {},
networkOpts: {},
});
return w;
};
@ -745,7 +753,10 @@ describe('PayPro (in Wallet) model', function() {
uri = address.split(/\s+/)[1];
}
w.createPaymentTx({ uri: uri, memo: commentText }, function(err, ntxid, merchantData) {
w.createPaymentTx({
uri: uri,
memo: commentText
}, function(err, ntxid, merchantData) {
should.equal(err, null);
if (w.isShared()) {
should.exist(ntxid);
@ -767,7 +778,10 @@ describe('PayPro (in Wallet) model', function() {
should.exist(w);
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
var commentText = 'Hello, server. I\'d like to make a payment.';
w.createPaymentTx({ uri: address, memo: commentText }, function(err, ntxid, merchantData) {
w.createPaymentTx({
uri: address,
memo: commentText
}, function(err, ntxid, merchantData) {
should.equal(err, null);
if (w.isShared()) {
should.exist(ntxid);
@ -788,7 +802,10 @@ describe('PayPro (in Wallet) model', function() {
should.exist(w);
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
var commentText = 'Hello, server. I\'d like to make a payment.';
w.createPaymentTx({ uri: address, memo: commentText }, function(err, ntxid, merchantData) {
w.createPaymentTx({
uri: address,
memo: commentText
}, function(err, ntxid, merchantData) {
should.equal(err, null);
should.exist(ntxid);
should.exist(merchantData);
@ -825,7 +842,10 @@ describe('PayPro (in Wallet) model', function() {
should.exist(w);
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
var commentText = 'Hello, server. I\'d like to make a payment.';
w.createPaymentTx({ uri: address, memo: commentText }, function(err, ntxid, merchantData) {
w.createPaymentTx({
uri: address,
memo: commentText
}, function(err, ntxid, merchantData) {
should.equal(err, null);
should.exist(ntxid);
should.exist(merchantData);
@ -853,7 +873,10 @@ describe('PayPro (in Wallet) model', function() {
should.exist(w);
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
var commentText = 'Hello, server. I\'d like to make a payment.';
w.createPaymentTx({ uri: address, memo: commentText }, function(err, ntxid, merchantData) {
w.createPaymentTx({
uri: address,
memo: commentText
}, function(err, ntxid, merchantData) {
should.equal(err, null);
should.exist(ntxid);
should.exist(merchantData);
@ -880,7 +903,10 @@ describe('PayPro (in Wallet) model', function() {
should.exist(w);
var address = 'bitcoin:2NBzZdFBoQymDgfzH2Pmnthser1E71MmU47?amount=0.00003&r=' + server.uri + '/request';
var commentText = 'Hello, server. I\'d like to make a payment.';
w.createPaymentTx({ uri: address, memo: commentText }, function(err, ntxid, merchantData) {
w.createPaymentTx({
uri: address,
memo: commentText
}, function(err, ntxid, merchantData) {
should.equal(err, null);
should.exist(ntxid);
should.exist(merchantData);

View file

@ -27,8 +27,23 @@ var walletConfig = {
reconnectDelay: 100,
networkName: 'testnet',
storage: requireMock('FakeLocalStorage').storageParams,
// network layer config
networkOpts: {
testnet: {
url: 'https://test-insight.bitpay.com:443',
transports: ['polling'],
},
livenet: {
url: 'https://insight.bitpay.com:443',
transports: ['polling'],
},
},
};
walletConfig.blockchainOpts = walletConfig.networkOpts;
var getNewEpk = function() {
return new PrivateKey({
networkName: walletConfig.networkName,
@ -81,11 +96,19 @@ describe('Wallet model', function() {
var storage = new Storage(walletConfig.storage);
storage._setPassphrase('xxx');
var network = new Network(walletConfig.network);
var blockchain = new Blockchain(walletConfig.blockchain);
c.blockchain = new Blockchain(walletConfig.blockchain);
c.storage = storage;
c.network = network;
c.blockchain = blockchain;
c.network = sinon.stub();
c.network.setHexNonce = sinon.stub();
c.network.setHexNonces = sinon.stub();
c.network.getHexNonce = sinon.stub();
c.network.getHexNonces = sinon.stub();
c.network.peerFromCopayer = sinon.stub().returns('xxxx');
c.network.send = sinon.stub();
c.addressBook = {
'2NFR2kzH9NUdp8vsXTB4wWQtTtzhpKxsyoJ': {
@ -105,7 +128,6 @@ describe('Wallet model', function() {
c.networkName = walletConfig.networkName;
c.version = '0.0.1';
return new Wallet(c);
}
@ -117,7 +139,14 @@ describe('Wallet model', function() {
cachedWobj = cachedW.toObj();
cachedWobj.opts.reconnectDelay = 100;
}
var w = Wallet.fromObj(cachedWobj, cachedW.storage, cachedW.network, cachedW.blockchain);
Wallet._newAsync = sinon.stub().returns(new Network(walletConfig.network));
Wallet._newInsight = sinon.stub().returns(new Blockchain(walletConfig.blockchain));
var w = Wallet.fromObj(cachedWobj, {
storage: cachedW.storage,
blockchainOpts: {},
networkOpts: {},
});
return w;
};
@ -183,10 +212,18 @@ describe('Wallet model', function() {
cachedW2obj = cachedW2.toObj();
cachedW2obj.opts.reconnectDelay = 100;
}
var w = Wallet.fromObj(cachedW2obj, cachedW2.storage, cachedW2.network, cachedW2.blockchain);
Wallet._newAsync = sinon.stub().returns(new Network(walletConfig.network));
Wallet._newInsight = sinon.stub().returns(new Blockchain(walletConfig.blockchain));
var w = Wallet.fromObj(cachedW2obj, {
storage: cachedW2.storage,
blockchainOpts: {},
networkOpts: {},
});
return w;
};
it('#create, fail for network', function() {
var w = cachedCreateW2();
@ -343,10 +380,11 @@ describe('Wallet model', function() {
var s = new Storage(walletConfig.storage);
s._setPassphrase('xxx');
var w2 = Wallet.fromObj(o,
s,
new Network(walletConfig.network),
new Blockchain(walletConfig.blockchain));
var w2 = Wallet.fromObj(o, {
storage: s,
blockchainOpts: {},
networkOpts: {},
});
should.exist(w2);
w2.publicKeyRing.requiredCopayers.should.equal(w.publicKeyRing.requiredCopayers);
should.exist(w2.publicKeyRing.getCopayerId);
@ -613,8 +651,10 @@ describe('Wallet model', function() {
var newId = '00bacacafe';
it('handle new connections', function(done) {
var w = createW();
w.sendWalletId = sinon.stub();
w.on('connect', function(id) {
id.should.equal(newId);
id.should.equal('xxxx');
done();
});
w._onConnect(newId);
@ -1849,7 +1889,12 @@ describe('Wallet model', function() {
var blockchain = new Blockchain(walletConfig.blockchain);
it('Import backup using old copayerIndex', function() {
var w = Wallet.fromObj(JSON.parse(o), storage, network, blockchain);
var w = Wallet.fromObj(JSON.parse(o), {
storage: storage,
blockchainOpts: {},
networkOpts: {},
});
should.exist(w);
w.id.should.equal("dbfe10c3fae71cea");
@ -1860,7 +1905,12 @@ describe('Wallet model', function() {
});
it('#fromObj, skipping fields', function() {
var w = Wallet.fromObj(JSON.parse(o), storage, network, blockchain, ['publicKeyRing']);
var w = Wallet.fromObj(JSON.parse(o), {
storage: storage,
networkOpts: {},
blockchainOpts: {},
skipFields: ['publicKeyRing'],
});
should.exist(w);
w.id.should.equal("dbfe10c3fae71cea");
@ -1876,7 +1926,11 @@ describe('Wallet model', function() {
var o = '{"opts":{"id":"dbfe10c3fae71cea","spendUnconfirmed":1,"requiredCopayers":3,"totalCopayers":5,"version":"0.0.5"},"networkNonce":"0000000000000001","networkNonces":[],"publicKeyRing":{"walletId":"dbfe10c3fae71cea","networkName":"testnet","requiredCopayers":3,"totalCopayers":5,"indexes":{"changeIndex":0,"receiveIndex":0},"copayersBackup":[],"copayersExtPubKeys":["tpubD6NzVbkrYhZ4YGK8ZhZ8WVeBXNAAoTYjjpw9twCPiNGrGQYFktP3iVQkKmZNiFnUcAFMJRxJVJF6Nq9MDv2kiRceExJaHFbxUCGUiRhmy97","tpubD6NzVbkrYhZ4YKGDJkzWdQsQV3AcFemaQKiwNhV4RL8FHnBFvinidGdQtP8RKj3h34E65RkdtxjrggZYqsEwJ8RhhN2zz9VrjLnrnwbXYNc","tpubD6NzVbkrYhZ4YkDiewjb32Pp3Sz9WK2jpp37KnL7RCrHAyPpnLfgdfRnTdpn6DTWmPS7niywfgWiT42aJb1J6CjWVNmkgsMCxuw7j9DaGKB","tpubD6NzVbkrYhZ4XEtUAz4UUTWbprewbLTaMhR8NUvSJUEAh4Sidxr6rRPFdqqVRR73btKf13wUjds2i8vVCNo8sbKrAnyoTr3o5Y6QSbboQjk","tpubD6NzVbkrYhZ4Yj9AAt6xUVuGPVd8jXCrEE6V2wp7U3PFh8jYYvVad31b4VUXEYXzSnkco4fktu8r4icBsB2t3pCR3WnhVLedY2hxGcPFLKD"],"nicknameFor":{}},"txProposals":{"txps":[],"walletId":"dbfe10c3fae71cea","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPeoHLg3tY75z4xLeEe8MqAXLNcRA6J6UTRvHV8VZTXznt9eoTmSk1fwSrwZtMhY3XkNsceJ14h6sCXHSWinRqMSSbY8tfhHi","networkName":"testnet"},"addressBook":{}}';
var o2 = '{"opts":{"id":"dbfe10c3fae71cea","spendUnconfirmed":1,"requiredCopayers":3,"totalCopayers":5,"version":"0.0.5","networkName":"testnet"},"networkNonce":"0000000000000001","networkNonces":[],"publicKeyRing":{"walletId":"dbfe10c3fae71cea","networkName":"testnet","requiredCopayers":3,"totalCopayers":5,"indexes":[{"copayerIndex":2147483647,"changeIndex":0,"receiveIndex":0},{"copayerIndex":0,"changeIndex":0,"receiveIndex":0},{"copayerIndex":1,"changeIndex":0,"receiveIndex":0},{"copayerIndex":2,"changeIndex":0,"receiveIndex":0},{"copayerIndex":3,"changeIndex":0,"receiveIndex":0},{"copayerIndex":4,"changeIndex":0,"receiveIndex":0}],"copayersBackup":[],"copayersExtPubKeys":["tpubD6NzVbkrYhZ4YGK8ZhZ8WVeBXNAAoTYjjpw9twCPiNGrGQYFktP3iVQkKmZNiFnUcAFMJRxJVJF6Nq9MDv2kiRceExJaHFbxUCGUiRhmy97","tpubD6NzVbkrYhZ4YKGDJkzWdQsQV3AcFemaQKiwNhV4RL8FHnBFvinidGdQtP8RKj3h34E65RkdtxjrggZYqsEwJ8RhhN2zz9VrjLnrnwbXYNc","tpubD6NzVbkrYhZ4YkDiewjb32Pp3Sz9WK2jpp37KnL7RCrHAyPpnLfgdfRnTdpn6DTWmPS7niywfgWiT42aJb1J6CjWVNmkgsMCxuw7j9DaGKB","tpubD6NzVbkrYhZ4XEtUAz4UUTWbprewbLTaMhR8NUvSJUEAh4Sidxr6rRPFdqqVRR73btKf13wUjds2i8vVCNo8sbKrAnyoTr3o5Y6QSbboQjk","tpubD6NzVbkrYhZ4Yj9AAt6xUVuGPVd8jXCrEE6V2wp7U3PFh8jYYvVad31b4VUXEYXzSnkco4fktu8r4icBsB2t3pCR3WnhVLedY2hxGcPFLKD"],"nicknameFor":{}},"txProposals":{"txps":[],"walletId":"dbfe10c3fae71cea","networkName":"testnet"},"privateKey":{"extendedPrivateKeyString":"tprv8ZgxMBicQKsPeoHLg3tY75z4xLeEe8MqAXLNcRA6J6UTRvHV8VZTXznt9eoTmSk1fwSrwZtMhY3XkNsceJ14h6sCXHSWinRqMSSbY8tfhHi","networkName":"testnet"},"addressBook":{}}';
var w = Wallet.fromObj(JSON.parse(o), storage, network, blockchain);
var w = Wallet.fromObj(JSON.parse(o), {
storage: storage,
networkOpts: {},
blockchainOpts: {},
});
should.exist(w);
w.id.should.equal("dbfe10c3fae71cea");
@ -1889,18 +1943,25 @@ describe('Wallet model', function() {
});
describe('#read', function() {
var storage, network, blockchain;
var s = function() {};
var storage = new s();
var network = new Network(walletConfig.network);
var blockchain = new Blockchain(walletConfig.blockchain);
storage.setPassword = sinon.stub();
beforeEach(function() {
var s = function() {};
storage = new s();
network = new Network(walletConfig.network);
blockchain = new Blockchain(walletConfig.blockchain);
storage.setPassword = sinon.stub();
});
it('should fail to read an unexisting wallet', function(done) {
storage.getFirst = sinon.stub().yields(null);
Wallet.read('123', storage, network, blockchain, [], function(err, w) {
Wallet.read('123', {
storage: storage,
networkOpts: {},
blockchainOpts: {},
}, function(err, w) {
err.toString().should.contain('WNOTFOUND');
done();
});
@ -1910,7 +1971,11 @@ describe('Wallet model', function() {
storage.getFirst = sinon.stub().yields(null, '{hola:1}');
Wallet.read('123', storage, network, blockchain, [], function(err, w) {
Wallet.read('123', {
storage: storage,
networkOpts: {},
blockchainOpts: {},
}, function(err, w) {
err.toString().should.contain('WERROR');
done();
});
@ -1918,7 +1983,11 @@ describe('Wallet model', function() {
it('should read a wallet', function(done) {
storage.getFirst = sinon.stub().yields(null, JSON.parse(o));
Wallet.read('123', storage, network, blockchain, [], function(err, w) {
Wallet.read('123', {
storage: storage,
networkOpts: {},
blockchainOpts: {},
}, function(err, w) {
should.not.exist(err);
done();
});
@ -1926,7 +1995,11 @@ describe('Wallet model', function() {
it('should be able to import unencrypted legacy wallet TxProposal: v0', function(done) {
storage.getFirst = sinon.stub().yields(null, JSON.parse(legacyO));
Wallet.read('123', storage, network, blockchain, [], function(err, w) {
Wallet.read('123', {
storage: storage,
networkOpts: {},
blockchainOpts: {},
}, function(err, w) {
should.exist(w);
w.id.should.equal('55d4bd062d32f90a');
should.exist(w.publicKeyRing.getCopayerId);
@ -1939,7 +2012,11 @@ describe('Wallet model', function() {
it('should be able to import simple 1-of-1 encrypted legacy testnet wallet', function(done) {
storage.getFirst = sinon.stub().yields(null, JSON.parse(legacy1));
Wallet.read('123', storage, network, blockchain, [], function(err, w) {
Wallet.read('123', {
storage: storage,
networkOpts: {},
blockchainOpts: {},
}, function(err, w) {
should.exist(w);
w.isReady().should.equal(true);
var wo = w.toObj();

View file

@ -6,7 +6,6 @@ var chai = chai || require('chai');
var should = chai.should();
var FakeNetwork = requireMock('FakeNetwork');
var FakeBlockchain = requireMock('FakeBlockchain');
var FakeStorage = function FakeStorage() {};
var Identity = copay.Identity;
@ -338,7 +337,8 @@ describe('Identity model', function() {
};
it('should yield bad network error', function(done) {
var net = iden.networks['testnet'];
var net = sinon.stub();
net.greet = sinon.stub();
net.cleanUp = sinon.stub();
net.start = sinon.stub().yields(null);
@ -348,6 +348,8 @@ describe('Identity model', function() {
networkName: 'aWeirdNetworkName',
opts: {},
});
Identity._newAsync = function() { return net; };
opts.privHex = undefined;
iden.joinWallet(opts, function(err, w) {
err.should.equal('badNetwork');
@ -358,7 +360,7 @@ describe('Identity model', function() {
it('should yield to join error', function(done) {
opts.privHex = undefined;
var net = iden.networks['testnet'];
var net = sinon.stub();
net.greet = sinon.stub();
net.cleanUp = sinon.stub();
net.start = sinon.stub().yields(null);
@ -369,6 +371,8 @@ describe('Identity model', function() {
type: 'walletId',
networkName: iden.networkName,
});
Identity._newAsync = function() { return net; };
iden.joinWallet(opts, function(err, w) {
err.should.equal('joinError');
done();
@ -378,7 +382,7 @@ describe('Identity model', function() {
it('should call network.start / create', function(done) {
opts.privHex = undefined;
var net = iden.networks['testnet'];
var net = sinon.stub();
net.cleanUp = sinon.spy();
net.greet = sinon.spy();
net.start = sinon.stub().yields(null);
@ -390,6 +394,7 @@ describe('Identity model', function() {
networkName: 'testnet',
opts: {},
});
Identity._newAsync = function() { return net; };
var w = sinon.stub();
w.sendWalletReady = sinon.spy();
@ -407,7 +412,7 @@ describe('Identity model', function() {
it('should return walletFull', function(done) {
opts.privHex = undefined;
var net = iden.networks['testnet'];
var net = sinon.stub();
net.cleanUp = sinon.spy();
net.greet = sinon.spy();
net.start = sinon.stub().yields(null);
@ -419,6 +424,7 @@ describe('Identity model', function() {
networkName: 'testnet',
opts: {},
});
Identity._newAsync = function() { return net; };
iden.createWallet = sinon.stub().yields(null, null);
iden.joinWallet(opts, function(err, w) {
err.should.equal('walletFull');
@ -428,7 +434,10 @@ describe('Identity model', function() {
it('should accept a priv key a input', function() {
opts.privHex = 'tprv8ZgxMBicQKsPf7MCvCjnhnr4uiR2Z2gyNC27vgd9KUu98F9mM1tbaRrWMyddVju36GxLbeyntuSadBAttriwGGMWUkRgVmUUCg5nFioGZsd';
var net = iden.networks['testnet'];
var net = sinon.stub();
Identity._newAsync = function() { return net; };
net.on = sinon.stub();
net.cleanUp = sinon.spy();
net.start = sinon.spy();
iden.joinWallet(opts, function(err, w) {
@ -437,9 +446,11 @@ describe('Identity model', function() {
});
it('should call network.start with private key', function() {
opts.privHex = undefined;
var net = iden.networks['testnet'];
var net = sinon.stub();
net.cleanUp = sinon.spy();
net.on = sinon.stub();
net.start = sinon.spy();
Identity._newAsync = function() { return net; };
iden.joinWallet(opts, function(err, w) {
net.start.getCall(0).args[0].privkey.length.should.equal(64); //privkey is hex of private key buffer
});