Skip to content

Commit b528c85

Browse files
author
Braydon Fuller
committed
test: add additional mempool related utxo tests
1 parent 8f9af82 commit b528c85

File tree

1 file changed

+174
-0
lines changed

1 file changed

+174
-0
lines changed

test/services/bitcoind.unit.js

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2433,6 +2433,180 @@ describe('Bitcoin Service', function() {
24332433
done();
24342434
});
24352435
});
2436+
it('three confirmed utxos -> one utxo after mempool', function(done) {
2437+
var deltas = [
2438+
{
2439+
txid: 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce',
2440+
satoshis: -7679241,
2441+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2442+
index: 0,
2443+
timestamp: 1461342707725,
2444+
prevtxid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2445+
prevout: 0
2446+
},
2447+
{
2448+
txid: 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce',
2449+
satoshis: -7679241,
2450+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2451+
index: 0,
2452+
timestamp: 1461342707725,
2453+
prevtxid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2454+
prevout: 1
2455+
},
2456+
{
2457+
txid: 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce',
2458+
satoshis: -7679241,
2459+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2460+
index: 1,
2461+
timestamp: 1461342707725,
2462+
prevtxid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2463+
prevout: 2
2464+
},
2465+
{
2466+
txid: 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce',
2467+
satoshis: 100000,
2468+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2469+
index: 1,
2470+
script: '76a914809dc14496f99b6deb722cf46d89d22f4beb8efd88ac',
2471+
timestamp: 1461342833133
2472+
}
2473+
];
2474+
var bitcoind = new BitcoinService(baseConfig);
2475+
var confirmedUtxos = [
2476+
{
2477+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2478+
txid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2479+
outputIndex: 0,
2480+
script: '76a914f399b4b8894f1153b96fce29f05e6e116eb4c21788ac',
2481+
satoshis: 7679241,
2482+
height: 207111
2483+
},
2484+
{
2485+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2486+
txid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2487+
outputIndex: 1,
2488+
script: '76a914f399b4b8894f1153b96fce29f05e6e116eb4c21788ac',
2489+
satoshis: 7679241,
2490+
height: 207111
2491+
},
2492+
{
2493+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2494+
txid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2495+
outputIndex: 2,
2496+
script: '76a914f399b4b8894f1153b96fce29f05e6e116eb4c21788ac',
2497+
satoshis: 7679241,
2498+
height: 207111
2499+
}
2500+
];
2501+
bitcoind.nodes.push({
2502+
client: {
2503+
getAddressUtxos: sinon.stub().callsArgWith(1, null, {
2504+
result: confirmedUtxos
2505+
}),
2506+
getAddressMempool: sinon.stub().callsArgWith(1, null, {
2507+
result: deltas
2508+
})
2509+
}
2510+
});
2511+
var options = {
2512+
queryMempool: true
2513+
};
2514+
var address = '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo';
2515+
bitcoind.getAddressUnspentOutputs(address, options, function(err, utxos) {
2516+
if (err) {
2517+
return done(err);
2518+
}
2519+
utxos.length.should.equal(1);
2520+
done();
2521+
});
2522+
});
2523+
it('spending utxos in the mempool', function(done) {
2524+
var deltas = [
2525+
{
2526+
txid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2527+
satoshis: 7679241,
2528+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2529+
index: 0,
2530+
timestamp: 1461342707724
2531+
},
2532+
{
2533+
txid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2534+
satoshis: 7679241,
2535+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2536+
index: 1,
2537+
timestamp: 1461342707724
2538+
},
2539+
{
2540+
txid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2541+
satoshis: 7679241,
2542+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2543+
timestamp: 1461342707724,
2544+
index: 2,
2545+
},
2546+
{
2547+
txid: 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce',
2548+
satoshis: -7679241,
2549+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2550+
index: 0,
2551+
timestamp: 1461342707725,
2552+
prevtxid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2553+
prevout: 0
2554+
},
2555+
{
2556+
txid: 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce',
2557+
satoshis: -7679241,
2558+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2559+
index: 0,
2560+
timestamp: 1461342707725,
2561+
prevtxid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2562+
prevout: 1
2563+
},
2564+
{
2565+
txid: 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce',
2566+
satoshis: -7679241,
2567+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2568+
index: 1,
2569+
timestamp: 1461342707725,
2570+
prevtxid: '46f24e0c274fc07708b781963576c4c5d5625d926dbb0a17fa865dcd9fe58ea0',
2571+
prevout: 2
2572+
},
2573+
{
2574+
txid: 'e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce',
2575+
satoshis: 100000,
2576+
address: '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo',
2577+
index: 1,
2578+
timestamp: 1461342833133
2579+
}
2580+
];
2581+
var bitcoind = new BitcoinService(baseConfig);
2582+
var confirmedUtxos = [];
2583+
bitcoind.nodes.push({
2584+
client: {
2585+
getAddressUtxos: sinon.stub().callsArgWith(1, null, {
2586+
result: confirmedUtxos
2587+
}),
2588+
getAddressMempool: sinon.stub().callsArgWith(1, null, {
2589+
result: deltas
2590+
})
2591+
}
2592+
});
2593+
var options = {
2594+
queryMempool: true
2595+
};
2596+
var address = '1Cj4UZWnGWAJH1CweTMgPLQMn26WRMfXmo';
2597+
bitcoind.getAddressUnspentOutputs(address, options, function(err, utxos) {
2598+
if (err) {
2599+
return done(err);
2600+
}
2601+
utxos.length.should.equal(1);
2602+
utxos[0].address.should.equal(address);
2603+
utxos[0].txid.should.equal('e9dcf22807db77ac0276b03cc2d3a8b03c4837db8ac6650501ef45af1c807cce');
2604+
utxos[0].outputIndex.should.equal(1);
2605+
utxos[0].script.should.equal('76a914809dc14496f99b6deb722cf46d89d22f4beb8efd88ac');
2606+
utxos[0].timestamp.should.equal(1461342833133);
2607+
done();
2608+
});
2609+
});
24362610
it('will update with mempool results spending zero value output (likely never to happen)', function(done) {
24372611
var deltas = [
24382612
{

0 commit comments

Comments
 (0)