From a1f4d06f273a5966ad5e82c1f3e555f2c1655738 Mon Sep 17 00:00:00 2001 From: Patrick Nagurny Date: Fri, 18 Sep 2015 15:31:09 -0400 Subject: [PATCH] add tests around isSpent --- integration/regtest-node.js | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/integration/regtest-node.js b/integration/regtest-node.js index 18724c15..c22ce171 100644 --- a/integration/regtest-node.js +++ b/integration/regtest-node.js @@ -33,6 +33,8 @@ var testWIF = 'cSdkPxkAjA4HDr5VHgsebAPDEh9Gyub4HK8UJr2DFGGqKKy4K5sG'; var testKey; var client; +var outputForIsSpentTest1; + describe('Node Functionality', function() { var regtest; @@ -264,7 +266,7 @@ describe('Node Functionality', function() { throw err; } results.length.should.equal(1); - unspentOutput = results[0]; + unspentOutput = outputForIsSpentTest1 = results[0]; done(); }); }); @@ -714,5 +716,36 @@ describe('Node Functionality', function() { }); }); + + describe('isSpent', function() { + it('will return true if an input is spent in a confirmed transaction', function(done) { + var result = node.services.bitcoind.isSpent(outputForIsSpentTest1.txid, outputForIsSpentTest1.outputIndex); + result.should.equal(true); + done(); + }); + it('will incorrectly return false for an input that is spent in an unconfirmed transaction', function(done) { + node.services.address.getUnspentOutputs(address, false, function(err, results) { + if (err) { + throw err; + } + + var unspentOutput = results[0]; + + var tx = new Transaction(); + tx.from(unspentOutput); + tx.to(address, unspentOutput.satoshis - 1000); + tx.fee(1000); + tx.sign(testKey); + + node.services.bitcoind.sendTransaction(tx.serialize()); + + setImmediate(function() { + var result = node.services.bitcoind.isSpent(unspentOutput.txid, unspentOutput.outputIndex); + result.should.equal(false); + done(); + }); + }); + }); + }); }); });