mirror of https://github.com/BTCPrivate/copay.git
Test fixed and added error checks
This commit is contained in:
parent
0712300580
commit
c7590c2d33
|
@ -2550,13 +2550,10 @@ Wallet.prototype.isComplete = function() {
|
||||||
Wallet.prototype.getTransactionHistoryCsv = function(cb) {
|
Wallet.prototype.getTransactionHistoryCsv = function(cb) {
|
||||||
var self = this;
|
var self = this;
|
||||||
self.getTransactionHistory(function(err, res) {
|
self.getTransactionHistory(function(err, res) {
|
||||||
|
preconditions.checkState(res);
|
||||||
if (err) {
|
if (err) {
|
||||||
log.debug(err);
|
log.warn(err);
|
||||||
return cb('ERROR');
|
return cb(new Error('TXHISTORY: ' + err.toString()));
|
||||||
}
|
|
||||||
|
|
||||||
if (!res) {
|
|
||||||
return cb('ERROR');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var unit = self.settings.unitName;
|
var unit = self.settings.unitName;
|
||||||
|
@ -2573,7 +2570,7 @@ Wallet.prototype.getTransactionHistoryCsv = function(cb) {
|
||||||
|
|
||||||
data.forEach(function(it, index) {
|
data.forEach(function(it, index) {
|
||||||
if (!it) {
|
if (!it) {
|
||||||
return cb('ERROR');
|
return cb(new Error('TXHISTORY: The item is null'));
|
||||||
}
|
}
|
||||||
var dataString = formatDate(it.minedTs || it.sentTs) + ',' + it.amount + ',' + it.action + ',' + formatString(it.addressTo) + ',' + formatString(it.comment);
|
var dataString = formatDate(it.minedTs || it.sentTs) + ',' + it.amount + ',' + it.action + ',' + formatString(it.addressTo) + ',' + formatString(it.comment);
|
||||||
if (self.isShared() && it.actionList) {
|
if (self.isShared() && it.actionList) {
|
||||||
|
@ -2589,7 +2586,7 @@ Wallet.prototype.getTransactionHistoryCsv = function(cb) {
|
||||||
function formatDate(date) {
|
function formatDate(date) {
|
||||||
var dateObj = new Date(date);
|
var dateObj = new Date(date);
|
||||||
if (!dateObj) {
|
if (!dateObj) {
|
||||||
log.error('Error formating a date');
|
log.warn('Error formating a date');
|
||||||
return 'DateError'
|
return 'DateError'
|
||||||
}
|
}
|
||||||
if (!dateObj.toJSON()) {
|
if (!dateObj.toJSON()) {
|
||||||
|
|
|
@ -2391,14 +2391,6 @@ describe('Wallet model', function() {
|
||||||
items: txs,
|
items: txs,
|
||||||
totalItems: txs.length,
|
totalItems: txs.length,
|
||||||
});
|
});
|
||||||
w.getAddressesInfo = sinon.stub().returns([{
|
|
||||||
addressStr: 'addr_in_1'
|
|
||||||
}, {
|
|
||||||
addressStr: 'addr_in_2'
|
|
||||||
}, {
|
|
||||||
addressStr: 'change',
|
|
||||||
isChange: true,
|
|
||||||
}]);
|
|
||||||
|
|
||||||
w.addressBook = {
|
w.addressBook = {
|
||||||
'addr_out_1': {
|
'addr_out_1': {
|
||||||
|
@ -2441,14 +2433,6 @@ describe('Wallet model', function() {
|
||||||
items: txs,
|
items: txs,
|
||||||
totalItems: txs.length,
|
totalItems: txs.length,
|
||||||
});
|
});
|
||||||
w.getAddressesInfo = sinon.stub().returns([{
|
|
||||||
addressStr: 'addr_in_1'
|
|
||||||
}, {
|
|
||||||
addressStr: 'addr_in_2'
|
|
||||||
}, {
|
|
||||||
addressStr: 'change',
|
|
||||||
isChange: true,
|
|
||||||
}]);
|
|
||||||
|
|
||||||
w.txProposals.txps = [{
|
w.txProposals.txps = [{
|
||||||
sentTxid: 'id0',
|
sentTxid: 'id0',
|
||||||
|
@ -2490,37 +2474,37 @@ describe('Wallet model', function() {
|
||||||
var w = cachedCreateW2();
|
var w = cachedCreateW2();
|
||||||
var txs = [{
|
var txs = [{
|
||||||
vin: [{
|
vin: [{
|
||||||
addr: 'addr_in_1',
|
addr: 'in_1',
|
||||||
valueSat: 1000
|
valueSat: 1000
|
||||||
}],
|
}],
|
||||||
vout: [{
|
vout: [{
|
||||||
scriptPubKey: {
|
scriptPubKey: {
|
||||||
addresses: ['addr_out_1'],
|
addresses: ['out_1'],
|
||||||
},
|
},
|
||||||
value: '0.00000900',
|
value: '0.00000900',
|
||||||
}],
|
}],
|
||||||
fees: 0.00000100
|
fees: 0.00000100
|
||||||
}, {
|
}, {
|
||||||
vin: [{
|
vin: [{
|
||||||
addr: 'addr_in_2',
|
addr: 'in_2',
|
||||||
valueSat: 2000
|
valueSat: 2000
|
||||||
}],
|
}],
|
||||||
vout: [{
|
vout: [{
|
||||||
scriptPubKey: {
|
scriptPubKey: {
|
||||||
addresses: ['addr_out_2'],
|
addresses: ['out_2'],
|
||||||
},
|
},
|
||||||
value: '0.00001900',
|
value: '0.00001900',
|
||||||
}],
|
}],
|
||||||
fees: 0.00000100
|
fees: 0.00000100
|
||||||
}, {
|
}, {
|
||||||
vin: [{
|
vin: [{
|
||||||
addr: 'addr_in_1',
|
addr: 'in_3',
|
||||||
valueSat: 3000
|
valueSat: 3000
|
||||||
|
|
||||||
}],
|
}],
|
||||||
vout: [{
|
vout: [{
|
||||||
scriptPubKey: {
|
scriptPubKey: {
|
||||||
addresses: ['addr_out_2'],
|
addresses: ['out_3'],
|
||||||
},
|
},
|
||||||
value: '0.00002900',
|
value: '0.00002900',
|
||||||
|
|
||||||
|
@ -2532,15 +2516,22 @@ describe('Wallet model', function() {
|
||||||
items: txs,
|
items: txs,
|
||||||
totalItems: txs.length,
|
totalItems: txs.length,
|
||||||
});
|
});
|
||||||
w.getAddressesInfo = sinon.stub().returns([{
|
|
||||||
addressStr: 'addr_in_1'
|
sinon.stub(w, 'getAddresses').returns(['in_1', 'in_2', 'in_3', 'out_1', 'out_2', 'out_3']);
|
||||||
}, {
|
var s = sinon.stub(w.publicKeyRing, 'addressIsOwn');
|
||||||
addressStr: 'addr_out_2'
|
s.withArgs('in_1').returns(true);
|
||||||
}]);
|
s.withArgs('out_1').returns(false);
|
||||||
|
|
||||||
|
s.withArgs('in_2').returns(false);
|
||||||
|
s.withArgs('out_2').returns(true);
|
||||||
|
|
||||||
|
s.withArgs('in_3').returns(true);
|
||||||
|
s.withArgs('out_3').returns(true);
|
||||||
|
|
||||||
|
|
||||||
w.getTransactionHistoryCsv(function(data) {
|
w.getTransactionHistoryCsv(function(data) {
|
||||||
data.should.exist;
|
data.should.exist;
|
||||||
data.should.equal('data:text/csv;charset=utf-8,Date,Amount(bits),Action,AddressTo,Comment,Signers\n,9,sent,"addr_out_1",\n,19,received,,\n,29,moved,"addr_out_2",\n');
|
data.should.equal('data:text/csv;charset=utf-8,Date,Amount(bits),Action,AddressTo,Comment,Signers\n,9,sent,"out_1",\n,0,moved,"out_2",\n,29,sent,"out_3",\n');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue