diff --git a/package.json b/package.json index 45454ab..5d74f0b 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "insight-api", "description": "A Bitcoin blockchain REST and web socket API service for Bitcore Node.", - "version": "5.0.0-beta.4", + "version": "5.0.0-beta.5", "repository": "git://github.com/bitpay/insight-api.git", "bugs": { "url": "https://github.com/bitpay/insight-api/issues" diff --git a/perf/perf.js b/perf/perf.js index 8521bc9..0fb7df4 100644 --- a/perf/perf.js +++ b/perf/perf.js @@ -162,7 +162,9 @@ var startBitcoind = function(count, callback) { }); console.log(count + ' bitcoind\'s started at pid(s): ' + pids); - callback(); + async.retry({ interval: 1000, times: 1000 }, function(next) { + rpc1.getInfo(next); + }, callback); }); }; @@ -399,21 +401,12 @@ describe('Address Performance', function() { startBitcoind(bitcoinDataDirs.length, next); }, function(next) { - setTimeout(function() { - buildInitialChain(next); - }, 8000); + buildInitialChain(next); }, function(next) { startBitcore(next); } - ], function(err) { - - if (err) { - return done(err); - } - - setTimeout(done, 2000); - }); + ], done); }); diff --git a/regtest/address.js b/regtest/address.js index d49215b..c36f164 100644 --- a/regtest/address.js +++ b/regtest/address.js @@ -14,6 +14,7 @@ var Transaction = bitcore.Transaction; var rpc1Address; var rpc2Address; +var blocksGenerated = 0; var rpcConfig = { protocol: 'http', @@ -39,7 +40,7 @@ var bitcoin = { server: 1, rpcuser: 'local', rpcpassword: 'localtest', - //printtoconsole: 1 + //printtoconsole: 1, rpcport: 58332, }, datadir: null, @@ -91,6 +92,76 @@ var bitcore = { process: null }; +var request = function(httpOpts, callback) { + + var request = http.request(httpOpts, function(res) { + + if (res.statusCode !== 200 && res.statusCode !== 201) { + return callback('Error from bitcore-node webserver: ' + res.statusCode); + } + + var resError; + var resData = ''; + + res.on('error', function(e) { + resError = e; + }); + + res.on('data', function(data) { + resData += data; + }); + + res.on('end', function() { + + if (resError) { + return callback(resError); + } + var data = JSON.parse(resData); + callback(null, data); + + }); + + }); + + request.on('error', function(err) { + callback(err); + }); + + if (httpOpts.body) { + request.write(httpOpts.body); + } else { + request.write(''); + } + request.end(); +}; + +var waitForBlocksGenerated = function(callback) { + + var httpOpts = { + hostname: 'localhost', + port: 53001, + path: '/api/status', + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }; + + async.retry({ interval: 1000, times: 100 }, function(next) { + + request(httpOpts, function(err, data) { + if (err) { + return next(err); + } + if (data.info.blocks < blocksGenerated) { + return next(data); + } + next(); + }); + + }, callback); +}; + var startBitcoind = function(count, callback) { var listenCount = 0; @@ -159,7 +230,18 @@ var startBitcoind = function(count, callback) { }); console.log(count + ' bitcoind\'s started at pid(s): ' + pids); - callback(); + + async.retry({ interval: 1000, times: 1000 }, function(next) { + rpc1.getInfo(function(err, res) { + if (err) { + return next(err); + } + // there is a bit of time even after the rpc server comes online that the rpc server is not truly ready + setTimeout(function(err) { + next(); + }, 1000); + }); + }, callback); }); }; @@ -183,7 +265,7 @@ var buildInitialChain = function(callback) { async.waterfall([ function(next) { console.log('checking to see if bitcoind\'s are connected to each other.'); - rpc1.getinfo(function(err, res) { + rpc1.getInfo(function(err, res) { if (err || res.result.connections !== 1) { next(err || new Error('bitcoind\'s not connected to each other.')); } @@ -192,6 +274,7 @@ var buildInitialChain = function(callback) { }, function(next) { console.log('generating 101 blocks'); + blocksGenerated += 101; rpc1.generate(101, next); }, function(res, next) { @@ -210,7 +293,8 @@ var buildInitialChain = function(callback) { }, function(res, next) { console.log('TXID: ' + res.result); - console.log('generating 6 blocks'); + console.log('generating 7 blocks'); + blocksGenerated += 7; rpc1.generate(7, next); }, function(res, next) { @@ -236,6 +320,7 @@ var buildInitialChain = function(callback) { txid = res.result; console.log('sending from rpc2Address TXID: ', res); console.log('generating 6 blocks'); + blocksGenerated += 6; rpc2.generate(6, next); } ], function(err) { @@ -285,12 +370,11 @@ var startBitcore = function(callback) { }); - callback(); + waitForBlocksGenerated(callback); }); }); - }; describe('Address', function() { @@ -304,21 +388,12 @@ describe('Address', function() { startBitcoind(2, next); }, function(next) { - setTimeout(function() { - buildInitialChain(next); - }, 8000); + buildInitialChain(next); }, function(next) { - setTimeout(function() { - startBitcore(next); - }, 8000); + startBitcore(next); } - ], function(err) { - if (err) { - return done(err); - } - setTimeout(done, 2000); - }); + ], done); }); @@ -332,127 +407,86 @@ describe('Address', function() { it('should get address info correctly: /addr/:addr', function(done) { + var httpOpts = { + hostname: 'localhost', + port: 53001, + path: 'http://localhost:53001/api/addr/' + rpc2Address, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }; - var request = http.request('http://localhost:53001/api/addr/' + rpc2Address, function(res) { + request(httpOpts, function(err, data) { - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - console.log(data); - expect(data.balance).to.equal(0); - expect(data.totalSent).to.equal(25); - done(); - }); + console.log(data); + expect(data.balance).to.equal(0); + expect(data.totalSent).to.equal(25); + done(); }); - request.write(''); - request.end(); + }); it('should get a utxo: /addr/:addr/utxo', function(done) { - var request = http.request('http://localhost:53001/api/addr/' + rpc1Address + '/utxo', function(res) { + var httpOpts = { + hostname: 'localhost', + port: 53001, + path: 'http://localhost:53001/api/addr/' + rpc1Address + '/utxo', + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }; - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + request(httpOpts, function(err, data) { + + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - console.log(data); - expect(data.length).equal(1); - expect(data[0].amount).equal(20); - expect(data[0].satoshis).equal(2000000000); - expect(data[0].confirmations).equal(6); - done(); - }); + console.log(data); + expect(data.length).equal(1); + expect(data[0].amount).equal(20); + expect(data[0].satoshis).equal(2000000000); + expect(data[0].confirmations).equal(6); + done(); }); - request.write(''); - request.end(); - }); it('should get multi-address utxos: /addrs/:addrs/utxo', function(done) { - var request = http.request('http://localhost:53001/api/addrs/' + rpc2Address + ',' + rpc1Address + '/utxo', function(res) { + var httpOpts = { + hostname: 'localhost', + port: 53001, + path: 'http://localhost:53001/api/addrs/' + rpc2Address + ',' + rpc1Address + '/utxo', + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }; - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + request(httpOpts, function(err, data) { + + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - console.log(data); - expect(data.length).to.equal(1); - expect(data[0].amount).to.equal(20); - expect(data[0].satoshis).to.equal(2000000000); - done(); - }); + console.log(data); + expect(data.length).to.equal(1); + expect(data[0].amount).to.equal(20); + expect(data[0].satoshis).to.equal(2000000000); + done(); }); - request.write(''); - request.end(); - }); it('should post a utxo: /addrs/:addrs/utxo', function(done) { @@ -466,50 +500,27 @@ describe('Address', function() { port: 53001, path: '/api/addrs/utxo', method: 'POST', + body: body, headers: { 'Content-Type': 'application/json', 'Content-Length': body.length - } + }, }; - var request = http.request(httpOpts, function(res) { + request(httpOpts, function(err, data) { - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - console.log(data); - expect(data.length).to.equal(1); - expect(data[0].amount).to.equal(20); - expect(data[0].satoshis).to.equal(2000000000); - done(); - }); + console.log(data); + expect(data.length).to.equal(1); + expect(data[0].amount).to.equal(20); + expect(data[0].satoshis).to.equal(2000000000); + done(); }); - request.write(body); - request.end(); - }); it('should get txs for a set of addresses: /addrs/:addrs/txs', function(done) { @@ -521,44 +532,20 @@ describe('Address', function() { method: 'GET' }; - var request = http.request(httpOpts, function(res) { + request(httpOpts, function(err, data) { - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - console.log(resData); - expect(data.items.length).to.equal(3); - expect(data.from).to.equal(0); - expect(data.to).to.equal(3); - done(); - }); + console.log(data); + expect(data.items.length).to.equal(3); + expect(data.from).to.equal(0); + expect(data.to).to.equal(3); + done(); }); - request.write(''); - request.end(); - }); it('should post txs for a set of addresses: /addrs/txs', function(done) { @@ -572,49 +559,26 @@ describe('Address', function() { port: 53001, path: '/api/addrs/txs', method: 'POST', + body: body, headers: { 'Content-Type': 'application/json' } }; - var request = http.request(httpOpts, function(res) { + request(httpOpts, function(err, data) { - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - console.log(resData); - expect(data.items.length).to.equal(3); - expect(data.from).to.equal(0); - expect(data.to).to.equal(3); - done(); - }); + console.log(data); + expect(data.items.length).to.equal(3); + expect(data.from).to.equal(0); + expect(data.to).to.equal(3); + done(); }); - request.write(body); - request.end(); - }); it('should get totalReceived for an address: /addr/:addr/totalReceived', function(done) { @@ -629,45 +593,21 @@ describe('Address', function() { } }; - var request = http.request(httpOpts, function(res) { + request(httpOpts, function(err, data) { - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - - if (error) { - return; - } - - var data = JSON.parse(resData); - expect(data).to.equal(2000000000); - done(); - }); + var data = JSON.parse(data); + expect(data).to.equal(2000000000); + done(); }); - request.write(''); - request.end(); - }); + it('should get totalSent for an address: /addr/:addr/totalSent', function(done) { var httpOpts = { @@ -680,41 +620,17 @@ describe('Address', function() { } }; - var request = http.request(httpOpts, function(res) { + request(httpOpts, function(err, data) { - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - expect(data).to.equal(0); - done(); - }); - + var data = JSON.parse(data); + expect(data).to.equal(0); + done(); }); - request.write(''); - request.end(); - }); it('should get unconfirmedBalance for an address: /addr/:addr/unconfirmedBalance', function(done) { @@ -729,94 +645,55 @@ describe('Address', function() { } }; - var request = http.request(httpOpts, function(res) { + request(httpOpts, function(err, data) { - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - expect(data).to.equal(0); - done(); - }); - + var data = JSON.parse(data); + expect(data).to.equal(0); + done(); }); - request.write(''); - request.end(); - }); it('should index addresses correctly', function(done) { // if we send a tx that has an address in both the input and the output, does it index correctly? - var txid; - var pk1; - var tx; + var txid; + var pk1; + var tx; + var utxo; + async.waterfall([ function(next) { - rpc1.listUnspent(function(err, res) { - - if (err) { - return next(err); - } - - next(null, res.result[0]); - - }); + rpc1.listUnspent(next); }, - function(utxo, next) { - rpc1.dumpPrivKey(utxo.address, function(err, res) { - if (err) { - return next(err); - } - var pk = new PrivateKey(res.result); - pk1 = new PrivateKey('testnet'); - var change = new PrivateKey('testnet'); - var changeAddress = change.toAddress(); - var from = { - txId: utxo.txid, - address: utxo.address, - script: utxo.scriptPubKey, - satoshis: utxo.amount * 1e8, - outputIndex: utxo.vout - }; - tx = new Transaction().from(from).to(pk1.toAddress(), 2500000000).change(changeAddress).sign(pk); - - rpc2.sendRawTransaction(tx.serialize(), function(err, res) { - if (err) { - return next(err); - } - txid = res.result; - console.log(txid); - next(); - }); - }); + function(res, next) { + utxo = res.result[0]; + rpc1.dumpPrivKey(utxo.address, next); }, - function(next) { - rpc2.generate(1, function() { - setTimeout(next, 2000); - }); + function(res, next) { + var pk = new PrivateKey(res.result); + pk1 = new PrivateKey('testnet'); + var change = new PrivateKey('testnet'); + var changeAddress = change.toAddress(); + var from = { + txId: utxo.txid, + address: utxo.address, + script: utxo.scriptPubKey, + satoshis: utxo.amount * 1e8, + outputIndex: utxo.vout + }; + tx = new Transaction().from(from).to(pk1.toAddress(), 2500000000).change(changeAddress).sign(pk); + rpc2.sendRawTransaction(tx.serialize(), next); }, - function(next) { + function(res, next) { + txid = res.result; + blocksGenerated += 1; + rpc2.generate(1, next); + }, + function(res, next) { var tx2 = new Transaction().from({ txId: txid, satoshis: 2500000000, @@ -824,64 +701,45 @@ describe('Address', function() { script: tx.outputs[0].script.toHex(), address: pk1.toAddress() }).to(pk1.toAddress(), 2500000000 - 1000).sign(pk1); - rpc2.sendRawTransaction(tx2.serialize(), function(err, res) { - if (err) { - return next(err); - } - txid = res.result; - console.log(txid); - next(); + rpc2.sendRawTransaction(tx2.serialize(), next); + }, + function(res, next) { + txid = res.result; + blocksGenerated += 1; + rpc2.generate(1, next); + }, + function(res, next) { + waitForBlocksGenerated(next); + }, - }); - }, - function(next) { - rpc2.generate(1, function() { - setTimeout(next, 2000); - }); - }, ], function(err) { - if (err) { + + if (err) { + return done(err); + } + + var httpOpts = { + hostname: 'localhost', + port: 53001, + path: 'http://localhost:53001/api/addr/' + pk1.toAddress(), + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }; + + request(httpOpts, function(err, data) { + + if(err) { return done(err); } - var request = http.request('http://localhost:53001/api/addr/' + pk1.toAddress(), function(res) { - - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); - } - - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - console.log(data); - expect(data.transactions.length).to.equal(2); - done(); - }); - - }); - request.write(''); - request.end(); + console.log(data); + expect(data.transactions.length).to.equal(2); + done(); + }); }); }); }); - - diff --git a/regtest/transaction.js b/regtest/transaction.js index 4747bcf..450ba6b 100644 --- a/regtest/transaction.js +++ b/regtest/transaction.js @@ -14,6 +14,7 @@ var rpc2Address; var tx1; var tx2; var block; +var blocksGenerated = 0; var rpcConfig = { protocol: 'http', @@ -91,6 +92,76 @@ var bitcore = { process: null }; +var request = function(httpOpts, callback) { + + var request = http.request(httpOpts, function(res) { + + if (res.statusCode !== 200 && res.statusCode !== 201) { + return callback('Error from bitcore-node webserver: ' + res.statusCode); + } + + var resError; + var resData = ''; + + res.on('error', function(e) { + resError = e; + }); + + res.on('data', function(data) { + resData += data; + }); + + res.on('end', function() { + + if (resError) { + return callback(resError); + } + var data = JSON.parse(resData); + callback(null, data); + + }); + + }); + + request.on('error', function(err) { + callback(err); + }); + + if (httpOpts.body) { + request.write(httpOpts.body); + } else { + request.write(''); + } + request.end(); +}; + +var waitForBlocksGenerated = function(callback) { + + var httpOpts = { + hostname: 'localhost', + port: 53001, + path: '/api/status', + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }; + + async.retry({ interval: 1000, times: 100 }, function(next) { + + request(httpOpts, function(err, data) { + if (err) { + return next(err); + } + if (data.info.blocks < blocksGenerated) { + return next(data); + } + next(); + }); + + }, callback); +}; + var startBitcoind = function(count, callback) { var listenCount = 0; @@ -159,7 +230,19 @@ var startBitcoind = function(count, callback) { }); console.log(count + ' bitcoind\'s started at pid(s): ' + pids); - callback(); + + async.retry({ interval: 1000, times: 1000 }, function(next) { + rpc1.getInfo(function(err, res) { + if (err) { + return next(err); + } + // there is a bit of time even after the rpc server comes online that the rpc server is not truly ready + setTimeout(function(err) { + next(); + }, 1000); + }); + }, callback); + }); }; @@ -192,6 +275,7 @@ var buildInitialChain = function(callback) { }, function(next) { console.log('generating 101 blocks'); + blocksGenerated += 101; rpc1.generate(101, next); }, function(res, next) { @@ -212,6 +296,7 @@ var buildInitialChain = function(callback) { tx1 = res.result; console.log('TXID: ' + res.result); console.log('generating 6 blocks'); + blocksGenerated += 6; rpc1.generate(7, next); }, function(res, next) { @@ -238,6 +323,7 @@ var buildInitialChain = function(callback) { tx2 = res.result; console.log('sending from rpc2Address TXID: ', res); console.log('generating 6 blocks'); + blocksGenerated += 6; rpc2.generate(6, next); } ], function(err) { @@ -287,7 +373,7 @@ var startBitcore = function(callback) { }); - callback(); + waitForBlocksGenerated(callback); }); }); @@ -306,14 +392,10 @@ describe('Transaction', function() { startBitcoind(2, next); }, function(next) { - setTimeout(function() { - buildInitialChain(next); - }, 8000); + buildInitialChain(next); }, function(next) { - setTimeout(function() { - startBitcore(next); - }, 6000); + startBitcore(next); } ], function(err) { if (err) { @@ -332,115 +414,76 @@ describe('Transaction', function() { it('should get a transaction: /tx/:txid', function(done) { - var request = http.request('http://localhost:53001/api/tx/' + tx1, function(res) { + var httpOpts = { + hostname: 'localhost', + port: 53001, + path: 'http://localhost:53001/api/tx/' + tx1, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }; - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + request(httpOpts, function(err, data) { + + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - expect(data.txid).to.equal(tx1); - done(); - }); + expect(data.txid).to.equal(tx1); + done(); }); - request.write(''); - request.end(); }); it('should get transactions: /txs', function(done) { - var request = http.request('http://localhost:53001/api/txs?block=' + block, function(res) { + var httpOpts = { + hostname: 'localhost', + port: 53001, + path: 'http://localhost:53001/api/txs?block=' + block, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }; - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + request(httpOpts, function(err, data) { + + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - console.log(resData); - expect(data.txs.length).to.equal(1); - done(); - }); + console.log(data); + expect(data.txs.length).to.equal(1); + done(); }); - request.write(''); - request.end(); }); it('should get a raw transactions: /rawtx/:txid', function(done) { - var request = http.request('http://localhost:53001/api/rawtx/' + tx2, function(res) { + var httpOpts = { + hostname: 'localhost', + port: 53001, + path: 'http://localhost:53001/api/rawtx/' + tx2, + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }; - var error; - if (res.statusCode !== 200 && res.statusCode !== 201) { - if (error) { - return; - } - return done('Error from bitcore-node webserver: ' + res.statusCode); + request(httpOpts, function(err, data) { + + if(err) { + return done(err); } - var resError; - var resData = ''; - - res.on('error', function(e) { - resError = e; - }); - - res.on('data', function(data) { - resData += data; - }); - - res.on('end', function() { - if (error) { - return; - } - var data = JSON.parse(resData); - console.log(resData); - expect(data.rawtx).to.not.be.null; - done(); - }); + console.log(data); + expect(data.rawtx).to.not.be.null; + done(); }); - request.write(''); - request.end(); }); }); diff --git a/test/status.js b/test/status.js index 269bc94..3a05ec0 100644 --- a/test/status.js +++ b/test/status.js @@ -30,8 +30,8 @@ describe('Status', function() { var node = { services: { - header: { getInfo: sinon.stub().callsArgWith(0, null, info) }, block: { + getInfo: sinon.stub().callsArgWith(0, null, info), getTip: sinon.stub().returns({ hash: outSetInfo.bestblock }), getBestBlockHash: sinon.stub().callsArgWith(0, null, outSetInfo.bestblock), } @@ -115,8 +115,8 @@ describe('Status', function() { it('should have correct data', function(done) { var node = { services: { - header: { getInfo: sinon.stub() }, block: { + getInfo: sinon.stub(), isSynced: sinon.stub().callsArgWith(0, null, true), syncPercentage: sinon.stub().callsArgWith(0, null, 100), getTip: sinon.stub().returns({ height: 500000, hash: 'aa' })