Added more test to Wallet

This commit is contained in:
Matias Pando 2015-01-19 18:32:34 -03:00
parent fc824a1c11
commit bf82fa0760
2 changed files with 222 additions and 0 deletions

View File

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

View File

@ -521,6 +521,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 +544,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);
});
});
@ -1061,6 +1176,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();
@ -1535,6 +1724,35 @@ 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);
});
});
describe('#netStart', function() {
it('should call Network.start', function() {
var w = cachedCreateW2();