allow stubbing of unconfirmed utxos
This commit is contained in:
parent
2c9e36a21b
commit
05de23c1b0
|
@ -135,29 +135,28 @@ helpers.toSatoshi = function(btc) {
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers.stubUtxos = function(server, wallet, amounts, cb) {
|
helpers.stubUtxos = function(server, wallet, amounts, cb) {
|
||||||
var amounts = [].concat(amounts);
|
async.mapSeries(_.range(0, amounts.length > 2 ? 2 : 1), function(i, next) {
|
||||||
|
server.createAddress({}, next);
|
||||||
async.mapSeries(_.range(1, Math.ceil(amounts.length / 2) + 1), function(i, next) {
|
|
||||||
server.createAddress({}, function(err, address) {
|
|
||||||
next(err, address);
|
|
||||||
});
|
|
||||||
}, function(err, addresses) {
|
}, function(err, addresses) {
|
||||||
if (err) throw new Error('Could not generate addresses');
|
should.not.exist(err);
|
||||||
|
addresses.should.not.be.empty;
|
||||||
var utxos = _.map(amounts, function(amount, i) {
|
var utxos = _.map([].concat(amounts), function(amount, i) {
|
||||||
var address = addresses[i % addresses.length];
|
var address = addresses[i % addresses.length];
|
||||||
var obj = {
|
var confirmations;
|
||||||
|
if (_.isString(amount) && _.startsWith(amount, 'u')) {
|
||||||
|
amount = parseFloat(amount.substring(1));
|
||||||
|
confirmations = 0;
|
||||||
|
} else {
|
||||||
|
confirmations = Math.floor(Math.random() * 100 + 1);
|
||||||
|
}
|
||||||
|
return {
|
||||||
txid: helpers.randomTXID(),
|
txid: helpers.randomTXID(),
|
||||||
vout: Math.floor(Math.random() * 10 + 1),
|
vout: Math.floor(Math.random() * 10 + 1),
|
||||||
satoshis: helpers.toSatoshi(amount).toString(),
|
satoshis: helpers.toSatoshi(amount).toString(),
|
||||||
scriptPubKey: address.getScriptPubKey(wallet.m).toBuffer().toString('hex'),
|
scriptPubKey: address.getScriptPubKey(wallet.m).toBuffer().toString('hex'),
|
||||||
address: address.address,
|
address: address.address,
|
||||||
confirmations: Math.floor(Math.random() * 100 + 1),
|
confirmations: confirmations,
|
||||||
};
|
};
|
||||||
obj.toObject = function() {
|
|
||||||
return obj;
|
|
||||||
};
|
|
||||||
return obj;
|
|
||||||
});
|
});
|
||||||
blockchainExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, utxos);
|
blockchainExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, utxos);
|
||||||
|
|
||||||
|
@ -1636,19 +1635,7 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should create a tx using confirmed utxos first', function(done) {
|
it('should create a tx using confirmed utxos first', function(done) {
|
||||||
server.createAddress({}, function(err, address) {
|
helpers.stubUtxos(server, wallet, [1.3, 'u0.5', 'u0.1', 1.2], function(utxos) {
|
||||||
var utxos = _.map([1.3, 0.5, 0.1, 1.2], function(amount, i) {
|
|
||||||
return {
|
|
||||||
txid: helpers.randomTXID(),
|
|
||||||
vout: Math.floor((Math.random() * 10) + 1),
|
|
||||||
satoshis: helpers.toSatoshi(amount).toString(),
|
|
||||||
scriptPubKey: address.getScriptPubKey(wallet.m).toBuffer().toString('hex'),
|
|
||||||
address: address.address,
|
|
||||||
confirmations: amount < 1 ? 0 : 1,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
blockchainExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, utxos);
|
|
||||||
|
|
||||||
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 1.5, 'some message', TestData.copayers[0].privKey_1H_0);
|
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 1.5, 'some message', TestData.copayers[0].privKey_1H_0);
|
||||||
server.createTx(txOpts, function(err, tx) {
|
server.createTx(txOpts, function(err, tx) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
|
@ -1661,19 +1648,7 @@ describe('Wallet service', function() {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should use unconfirmed utxos only when no more confirmed utxos are available', function(done) {
|
it('should use unconfirmed utxos only when no more confirmed utxos are available', function(done) {
|
||||||
server.createAddress({}, function(err, address) {
|
helpers.stubUtxos(server, wallet, [1.3, 'u0.5', 'u0.1', 1.2], function(utxos) {
|
||||||
var utxos = _.map([1.3, 0.5, 0.1, 1.2], function(amount, i) {
|
|
||||||
return {
|
|
||||||
txid: helpers.randomTXID(),
|
|
||||||
vout: Math.floor((Math.random() * 10) + 1),
|
|
||||||
satoshis: helpers.toSatoshi(amount).toString(),
|
|
||||||
scriptPubKey: address.getScriptPubKey(wallet.m).toBuffer().toString('hex'),
|
|
||||||
address: address.address,
|
|
||||||
confirmations: amount < 1 ? 0 : 1,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
blockchainExplorer.getUnspentUtxos = sinon.stub().callsArgWith(1, null, utxos);
|
|
||||||
|
|
||||||
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 2.55, 'some message', TestData.copayers[0].privKey_1H_0);
|
var txOpts = helpers.createSimpleProposalOpts('18PzpUFkFZE8zKWUPvfykkTxmB9oMR8qP7', 2.55, 'some message', TestData.copayers[0].privKey_1H_0);
|
||||||
server.createTx(txOpts, function(err, tx) {
|
server.createTx(txOpts, function(err, tx) {
|
||||||
should.not.exist(err);
|
should.not.exist(err);
|
||||||
|
|
Loading…
Reference in New Issue