Add validation and tests for spendUnconfirmed = false
This commit is contained in:
parent
4d6e9f8a6d
commit
26c829f6de
4 changed files with 47 additions and 7 deletions
|
|
@ -89,7 +89,7 @@ var defaultConfig = {
|
||||||
wallet: {
|
wallet: {
|
||||||
requiredCopayers: 2,
|
requiredCopayers: 2,
|
||||||
totalCopayers: 3,
|
totalCopayers: 3,
|
||||||
spendUnconfirmed: 1,
|
spendUnconfirmed: true,
|
||||||
verbose: 1,
|
verbose: 1,
|
||||||
reconnectDelay: 5000,
|
reconnectDelay: 5000,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -647,7 +647,8 @@ Wallet.prototype.getUnspent = function(cb) {
|
||||||
|
|
||||||
for (var i in unspentList) {
|
for (var i in unspentList) {
|
||||||
var u = unspentList[i];
|
var u = unspentList[i];
|
||||||
if (!uu[u.txid + ',' + u.vout])
|
var name = u.txid + ',' + u.vout;
|
||||||
|
if (!uu[name] && (self.spendUnconfirmed || u.confirmations >= 1))
|
||||||
safeUnspendList.push(u);
|
safeUnspendList.push(u);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,20 @@ FakeBlockchain.prototype.getUnspent = function(addresses, cb) {
|
||||||
}]);
|
}]);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
FakeBlockchain.prototype.getUnspent2 = function(addresses, cb) {
|
||||||
|
if (!addresses || !addresses.length) return cb(null, []);
|
||||||
|
return cb(null, this.u || [{
|
||||||
|
'address': 'mji7zocy8QzYywQakwWf99w9bCT6orY1C1',
|
||||||
|
'txid': '0be0fb4579911be829e3077202e1ab47fcc12cf3ab8f8487ccceae768e1f95fa',
|
||||||
|
'vout': 0,
|
||||||
|
'ts': 1402323949,
|
||||||
|
'scriptPubKey': '21032ca453c1d9a93b7de8cf3d44d7bb8d52a45dbdf8fff63f69de4e51b740bb1da3ac',
|
||||||
|
'amount': 25.0001,
|
||||||
|
'confirmations': 1,
|
||||||
|
'confirmationsFromCache': false
|
||||||
|
}]);
|
||||||
|
};
|
||||||
|
|
||||||
FakeBlockchain.prototype.sendRawTransaction = function(rawtx, cb) {
|
FakeBlockchain.prototype.sendRawTransaction = function(rawtx, cb) {
|
||||||
var txid = '0be0fb4579911be829e3077202e1ab47fcc12cf3ab8f8487ccceae768e1f95fa';
|
var txid = '0be0fb4579911be829e3077202e1ab47fcc12cf3ab8f8487ccceae768e1f95fa';
|
||||||
return cb(txid);
|
return cb(txid);
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ describe('Wallet model', function() {
|
||||||
var config = {
|
var config = {
|
||||||
requiredCopayers: 3,
|
requiredCopayers: 3,
|
||||||
totalCopayers: 5,
|
totalCopayers: 5,
|
||||||
spendUnconfirmed: 1,
|
spendUnconfirmed: true,
|
||||||
reconnectDelay: 100,
|
reconnectDelay: 100,
|
||||||
networkName: 'testnet',
|
networkName: 'testnet',
|
||||||
};
|
};
|
||||||
|
|
@ -42,9 +42,9 @@ describe('Wallet model', function() {
|
||||||
w.getNetworkName().should.equal('testnet');
|
w.getNetworkName().should.equal('testnet');
|
||||||
});
|
});
|
||||||
|
|
||||||
var createW = function(netKey, N) {
|
var createW = function(netKey, N, conf) {
|
||||||
|
|
||||||
var c = JSON.parse(JSON.stringify(config));
|
var c = JSON.parse(JSON.stringify(conf || config));
|
||||||
if (!N) N = c.totalCopayers;
|
if (!N) N = c.totalCopayers;
|
||||||
|
|
||||||
if (netKey) c.netKey = netKey;
|
if (netKey) c.netKey = netKey;
|
||||||
|
|
@ -122,10 +122,10 @@ describe('Wallet model', function() {
|
||||||
"confirmations": 7
|
"confirmations": 7
|
||||||
}];
|
}];
|
||||||
|
|
||||||
var createW2 = function(privateKeys, N) {
|
var createW2 = function(privateKeys, N, conf) {
|
||||||
if (!N) N = 3;
|
if (!N) N = 3;
|
||||||
var netKey = 'T0FbU2JLby0=';
|
var netKey = 'T0FbU2JLby0=';
|
||||||
var w = createW(netKey, N);
|
var w = createW(netKey, N, conf);
|
||||||
should.exist(w);
|
should.exist(w);
|
||||||
|
|
||||||
var pkr = w.publicKeyRing;
|
var pkr = w.publicKeyRing;
|
||||||
|
|
@ -467,6 +467,31 @@ describe('Wallet model', function() {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('#getUnspent should honor spendUnconfirmed = false', function(done) {
|
||||||
|
var conf = JSON.parse(JSON.stringify(config));
|
||||||
|
conf.spendUnconfirmed = false;
|
||||||
|
var w = createW2(null, null, conf);
|
||||||
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||||
|
balance.should.equal(2500010000);
|
||||||
|
safeBalance.should.equal(0);
|
||||||
|
balanceByAddr.mji7zocy8QzYywQakwWf99w9bCT6orY1C1.should.equal(2500010000);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('#getUnspent and spendUnconfirmed should count transactions with 1 confirmations', function(done) {
|
||||||
|
var conf = JSON.parse(JSON.stringify(config));
|
||||||
|
conf.spendUnconfirmed = false;
|
||||||
|
var w = createW2(null, null, conf);
|
||||||
|
w.blockchain.getUnspent = w.blockchain.getUnspent2;
|
||||||
|
w.getBalance(function(err, balance, balanceByAddr, safeBalance) {
|
||||||
|
balance.should.equal(2500010000);
|
||||||
|
safeBalance.should.equal(2500010000);
|
||||||
|
balanceByAddr.mji7zocy8QzYywQakwWf99w9bCT6orY1C1.should.equal(2500010000);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
var roundErrorChecks = [{
|
var roundErrorChecks = [{
|
||||||
unspent: [1.0001],
|
unspent: [1.0001],
|
||||||
balance: 100010000
|
balance: 100010000
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue