fix karma

This commit is contained in:
Matias Alejo Garcia 2014-11-25 13:21:00 -03:00
parent 3706b00724
commit a759d801b4
4 changed files with 53 additions and 66 deletions

View File

@ -2168,8 +2168,8 @@ Wallet.prototype.removeTxWithSpentInputs = function(cb) {
* spend * spend
* *
* @desc Spends coins from the wallet * @desc Spends coins from the wallet
* Create a Transaction Proposal and broadcast it or send it * Create a Transaction Proposal and send it
* to copayers * to copayers (broadcast it in a 1-x wallet)
* @param {object} opts * @param {object} opts
* @param {string} opts.toAddress address to send coins * @param {string} opts.toAddress address to send coins
* @param {number} opts.amountSat amount in satoshis * @param {number} opts.amountSat amount in satoshis
@ -2231,6 +2231,7 @@ Wallet.prototype.spend = function(opts, cb) {
log.debug('TXP Added: ', ntxid); log.debug('TXP Added: ', ntxid);
console.log('[Wallet.js.2233]'); //TODO
self.sendIndexes(); self.sendIndexes();
// Needs only one signature? Broadcast it! // Needs only one signature? Broadcast it!
if (!self.requiresMultipleSignatures()) { if (!self.requiresMultipleSignatures()) {

View File

@ -56,7 +56,6 @@ module.exports = function(config) {
'js/init.js', 'js/init.js',
'test/mocks/FakeBlockchainSocket.js', 'test/mocks/FakeBlockchainSocket.js',
'test/mocks/FakePayProServer.js',
'test/mocha.conf.js', 'test/mocha.conf.js',

View File

@ -10,17 +10,23 @@ var util = bitcore.util;
var networks = bitcore.networks; var networks = bitcore.networks;
var FakeBuilder = requireMock('FakeBuilder'); var FakeBuilder = requireMock('FakeBuilder');
var TxProposal = copay.TxProposal; var TxProposal = copay.TxProposal;
var Buffer = bitcore.Buffer;
var dummyProposal = function() { return new TxProposal({
creator: 'creator',
createdTs: 1,
builder: new FakeBuilder(),
inputChainPaths: ['m/1'],
})};
var someKeys = ["03b39d61dc9a504b13ae480049c140dcffa23a6cc9c09d12d6d1f332fee5e18ca5", "022929f515c5cf967474322468c3bd945bb6f281225b2c884b465680ef3052c07e"]; var someKeys = ["03b39d61dc9a504b13ae480049c140dcffa23a6cc9c09d12d6d1f332fee5e18ca5", "022929f515c5cf967474322468c3bd945bb6f281225b2c884b465680ef3052c07e"];
describe('TxProposal', function() { describe('TxProposal', function() {
function dummyProposal() {
return new TxProposal({
creator: 'creator',
createdTs: 1,
builder: new FakeBuilder(),
inputChainPaths: ['m/1'],
})
};
describe('new', function() { describe('new', function() {
it('should fail to create an instance with wrong arguments', function() { it('should fail to create an instance with wrong arguments', function() {
@ -351,13 +357,13 @@ describe('TxProposal', function() {
txp.addMerchantData(md); txp.addMerchantData(md);
}).should.throw('expired'); }).should.throw('expired');
}); });
it('OK Expired but sent', function() { it('OK Expired but sent', function() {
md.expires = 2; md.expires = 2;
txp.sentTs = 1; txp.sentTs = 1;
txp.addMerchantData(md); txp.addMerchantData(md);
}); });
}); });
describe('#merge', function() { describe('#merge', function() {

View File

@ -12,12 +12,16 @@ saveAs = function(blob, filename) {
}; };
}; };
var startServer = require('../../mocks/FakePayProServer');
describe("Unit: Controllers", function() { describe("Unit: Controllers", function() {
config.plugins.LocalStorage = true; config.plugins.LocalStorage = true;
config.plugins.GoogleDrive = null; config.plugins.GoogleDrive = null;
var anAddr = 'mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy';
var anAmount = 1000;
var aComment = 'hola';
var invalidForm = { var invalidForm = {
$invalid: true $invalid: true
}; };
@ -69,24 +73,30 @@ describe("Unit: Controllers", function() {
w.getTransactionHistory = sinon.stub().yields(null); w.getTransactionHistory = sinon.stub().yields(null);
w.getNetworkName = sinon.stub().returns('testnet'); w.getNetworkName = sinon.stub().returns('testnet');
w.createTx = sinon.stub().yields(null); w.spend = sinon.stub().yields(null);
w.sendTx = sinon.stub().yields(null); w.sendTxProposal = sinon.stub();
w.broadcastTx = sinon.stub().yields(null);
w.requiresMultipleSignatures = sinon.stub().returns(true); w.requiresMultipleSignatures = sinon.stub().returns(true);
w.getTxProposals = sinon.stub().returns([1, 2, 3]); w.getTxProposals = sinon.stub().returns([1, 2, 3]);
w.getPendingTxProposals = sinon.stub().returns({ w.getPendingTxProposals = sinon.stub().returns({
txs : [{ isPending : true }], txs: [{
isPending: true
}],
pendingForUs: 1 pendingForUs: 1
}); });
w.getId = sinon.stub().returns(1234); w.getId = sinon.stub().returns(1234);
w.on = sinon.stub().yields({'e': 'errmsg', 'loading': false}); w.on = sinon.stub().yields({
'e': 'errmsg',
'loading': false
});
w.getBalance = sinon.stub().returns(10000); w.getBalance = sinon.stub().returns(10000);
w.publicKeyRing = sinon.stub().yields(null); w.publicKeyRing = sinon.stub().yields(null);
w.publicKeyRing.nicknameForCopayer = sinon.stub().returns('nickcopayer'); w.publicKeyRing.nicknameForCopayer = sinon.stub().returns('nickcopayer');
w.updateFocusedTimestamp = sinon.stub().returns(1415804323); w.updateFocusedTimestamp = sinon.stub().returns(1415804323);
w.getAddressesInfo = sinon.stub().returns([ w.getAddressesInfo = sinon.stub().returns([{
{ addressStr: "2MxvwvfshZxw4SkkaJZ8NDKLyepa9HLMKtu", addressStr: "2MxvwvfshZxw4SkkaJZ8NDKLyepa9HLMKtu",
isChange: false } isChange: false
]); }]);
var iden = {}; var iden = {};
iden.deleteWallet = sinon.stub().yields(null); iden.deleteWallet = sinon.stub().yields(null);
@ -240,31 +250,35 @@ describe("Unit: Controllers", function() {
}); });
it('should create a transaction proposal with given values', function() { it('should create a transaction proposal with given values', function() {
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); sendForm.address.$setViewValue(anAddr);
sendForm.amount.$setViewValue(1000); sendForm.amount.$setViewValue(anAmount);
sendForm.comment.$setViewValue(aComment);
scope.loadTxs = sinon.spy(); scope.loadTxs = sinon.spy();
var w = scope.wallet; var w = scope.wallet;
scope.submitForm(sendForm); scope.submitForm(sendForm);
sinon.assert.callCount(w.createTx, 1); sinon.assert.callCount(w.spend, 1);
sinon.assert.callCount(w.sendTx, 0); sinon.assert.callCount(w.broadcastTx, 0);
sinon.assert.callCount(scope.loadTxs, 1); sinon.assert.callCount(scope.loadTxs, 1);
w.createTx.getCall(0).args[0].should.equal('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); var spendArgs = w.spend.getCall(0).args[0];
w.createTx.getCall(0).args[1].should.equal(1000 * scope.wallet.settings.unitToSatoshi); spendArgs.toAddress.should.equal(anAddr);
(typeof w.createTx.getCall(0).args[2]).should.equal('undefined'); spendArgs.amountSat.should.equal(anAmount * scope.wallet.settings.unitToSatoshi);
spendArgs.comment.should.equal(aComment);
}); });
it('should handle big values in 100 BTC', function() { it('should handle big values in 100 BTC', function() {
var old = scope.wallet.settings.unitToSatoshi; var old = scope.wallet.settings.unitToSatoshi;
scope.wallet.settings.unitToSatoshi = 100000000;; scope.wallet.settings.unitToSatoshi = 100000000;;
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); sendForm.address.$setViewValue(anAddr);
sendForm.amount.$setViewValue(100); sendForm.amount.$setViewValue(100);
sendForm.address.$setViewValue(anAddr);
scope.loadTxs = sinon.spy(); scope.loadTxs = sinon.spy();
scope.submitForm(sendForm); scope.submitForm(sendForm);
var w = scope.wallet; var w = scope.wallet;
w.createTx.getCall(0).args[1].should.equal(100 * scope.wallet.settings.unitToSatoshi); w.spend.getCall(0).args[0].amountSat.should.equal(100 * scope.wallet.settings.unitToSatoshi);
scope.wallet.settings.unitToSatoshi = old; scope.wallet.settings.unitToSatoshi = old;
}); });
@ -276,11 +290,11 @@ describe("Unit: Controllers", function() {
var old = $rootScope.wallet.settings.unitToSatoshi; var old = $rootScope.wallet.settings.unitToSatoshi;
$rootScope.wallet.settings.unitToSatoshi = 100000000;; $rootScope.wallet.settings.unitToSatoshi = 100000000;;
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy'); sendForm.address.$setViewValue(anAddr);
sendForm.amount.$setViewValue(5000); sendForm.amount.$setViewValue(5000);
scope.submitForm(sendForm); scope.submitForm(sendForm);
w.createTx.getCall(0).args[1].should.equal(5000 * $rootScope.wallet.settings.unitToSatoshi); w.spend.getCall(0).args[0].amountSat.should.equal(5000 * $rootScope.wallet.settings.unitToSatoshi);
$rootScope.wallet.settings.unitToSatoshi = old; $rootScope.wallet.settings.unitToSatoshi = old;
})); }));
@ -300,39 +314,6 @@ describe("Unit: Controllers", function() {
done(); done();
}); });
}); });
it('should create and send a transaction proposal', function() {
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
sendForm.amount.$setViewValue(1000);
scope.loadTxs = sinon.spy();
var w = scope.wallet;
w.requiresMultipleSignatures = sinon.stub().returns(false);
w.totalCopayers = w.requiredCopayers = 1;
scope.submitForm(sendForm);
sinon.assert.callCount(w.createTx, 1);
sinon.assert.callCount(w.sendTx, 1);
sinon.assert.callCount(scope.loadTxs, 1);
});
it('should not send txp when there is an error at creation', function() {
sendForm.address.$setViewValue('mkfTyEk7tfgV611Z4ESwDDSZwhsZdbMpVy');
sendForm.amount.$setViewValue(1000);
scope.wallet.totalCopayers = scope.wallet.requiredCopayers = 1;
scope.loadTxs = sinon.spy();
var w = scope.wallet;
w.createTx.yields('error');
w.isShared = sinon.stub().returns(false);
scope.submitForm(sendForm);
sinon.assert.callCount(w.createTx, 1);
sinon.assert.callCount(w.sendTx, 0);
sinon.assert.callCount(scope.loadTxs, 1);
});
}); });
describe("Unit: Version Controller", function() { describe("Unit: Version Controller", function() {