Merge pull request #10 from braydonf/getblock-tests
Added integration tests for getting blocks.
This commit is contained in:
commit
5cd4f7f090
@ -16,6 +16,10 @@ bitcoind.getBlock(blockHash, function(err, block) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
bitcoind.stop(function(err, result) {
|
||||||
|
// bitcoind is stopped
|
||||||
|
});
|
||||||
|
|
||||||
You can log output from the daemon using:
|
You can log output from the daemon using:
|
||||||
|
|
||||||
``` bash
|
``` bash
|
||||||
|
|||||||
61
integration/index.js
Normal file
61
integration/index.js
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
'use strict';
|
||||||
|
|
||||||
|
// These tests require a fully synced Bitcore Code data directory.
|
||||||
|
// To run the tests: $ mocha -R spec index.js
|
||||||
|
|
||||||
|
var chai = require('chai');
|
||||||
|
var bitcore = require('bitcore');
|
||||||
|
var bitcoind;
|
||||||
|
|
||||||
|
/* jshint unused: false */
|
||||||
|
var should = chai.should();
|
||||||
|
var assert = chai.assert;
|
||||||
|
var sinon = require('sinon');
|
||||||
|
var blockData = require('./livenet-block-data.json');
|
||||||
|
var testBlockData = require('./testnet-block-data.json');
|
||||||
|
|
||||||
|
describe('Basic Functionality', function() {
|
||||||
|
|
||||||
|
before(function(done) {
|
||||||
|
this.timeout(30000);
|
||||||
|
bitcoind = require('../')({
|
||||||
|
directory: '~/.bitcoin',
|
||||||
|
});
|
||||||
|
|
||||||
|
bitcoind.on('error', function(err) {
|
||||||
|
bitcoind.log('error="%s"', err.message);
|
||||||
|
});
|
||||||
|
|
||||||
|
bitcoind.on('open', function(status) {
|
||||||
|
bitcoind.log('status="%s"', status);
|
||||||
|
});
|
||||||
|
|
||||||
|
console.log('Waiting for Bitcoin Core to initialize...');
|
||||||
|
|
||||||
|
bitcoind.on('ready', function() {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
after(function(done) {
|
||||||
|
this.timeout(20000);
|
||||||
|
bitcoind.stop(function(err, result) {
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('will get correct block data', function() {
|
||||||
|
|
||||||
|
blockData.forEach(function(data) {
|
||||||
|
var block = bitcore.Block.fromString(data);
|
||||||
|
it('block ' + block.hash, function(done) {
|
||||||
|
bitcoind.getBlock(block.hash, function(err, response) {
|
||||||
|
assert(response === data, 'incorrect block data for ' + block.hash);
|
||||||
|
done();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
6
integration/livenet-block-data.json
Normal file
6
integration/livenet-block-data.json
Normal file
File diff suppressed because one or more lines are too long
6
integration/testnet-block-data.json
Normal file
6
integration/testnet-block-data.json
Normal file
File diff suppressed because one or more lines are too long
@ -39,8 +39,11 @@
|
|||||||
"tiny": "0.0.10"
|
"tiny": "0.0.10"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"mocha": "~1.16.2",
|
|
||||||
"async": "1.2.1",
|
"async": "1.2.1",
|
||||||
"benchmark": "1.0.0"
|
"benchmark": "1.0.0",
|
||||||
|
"bitcore": "^0.12.12",
|
||||||
|
"chai": "^3.0.0",
|
||||||
|
"mocha": "~1.16.2",
|
||||||
|
"sinon": "^1.15.4"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -672,7 +672,7 @@ start_node_thread(void) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
NAN_METHOD(StopBitcoind) {
|
NAN_METHOD(StopBitcoind) {
|
||||||
fprintf(stderr, "Stopping Bitcoind please wait!");
|
fprintf(stderr, "Stopping Bitcoind please wait!\n");
|
||||||
Isolate* isolate = Isolate::GetCurrent();
|
Isolate* isolate = Isolate::GetCurrent();
|
||||||
HandleScope scope(isolate);
|
HandleScope scope(isolate);
|
||||||
|
|
||||||
@ -716,6 +716,9 @@ async_stop_node(uv_work_t *req) {
|
|||||||
async_node_data *data = static_cast<async_node_data*>(req->data);
|
async_node_data *data = static_cast<async_node_data*>(req->data);
|
||||||
unhook_packets();
|
unhook_packets();
|
||||||
StartShutdown();
|
StartShutdown();
|
||||||
|
while(!shutdown_complete) {
|
||||||
|
usleep(1E6);
|
||||||
|
}
|
||||||
data->result = std::string("bitcoind shutdown.");
|
data->result = std::string("bitcoind shutdown.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user