Merge pull request #405 from braydonf/add-regtest

Switch to use enableRegtest from bitcore-lib
This commit is contained in:
Gabe Gattis 2016-02-08 12:21:33 -05:00
commit ae8221ffb3
8 changed files with 45 additions and 73 deletions

View File

@ -71,19 +71,7 @@ Node.prototype._setNetwork = function(config) {
if (config.network === 'testnet') { if (config.network === 'testnet') {
this.network = Networks.get('testnet'); this.network = Networks.get('testnet');
} else if (config.network === 'regtest') { } else if (config.network === 'regtest') {
Networks.remove(Networks.testnet); Networks.enableRegtest();
Networks.add({
name: 'regtest',
alias: 'regtest',
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,
xpubkey: 0x043587cf,
xprivkey: 0x04358394,
networkMagic: 0xfabfb5da,
port: 18444,
dnsSeeds: [ ]
});
this.network = Networks.get('regtest'); this.network = Networks.get('regtest');
} else { } else {
this.network = Networks.defaultNetwork; this.network = Networks.defaultNetwork;

View File

@ -121,13 +121,14 @@ AddressService.prototype._setMempoolIndexPath = function() {
AddressService.prototype._getDBPathFor = function(dbname) { AddressService.prototype._getDBPathFor = function(dbname) {
$.checkState(this.node.datadir, 'Node is expected to have a "datadir" property'); $.checkState(this.node.datadir, 'Node is expected to have a "datadir" property');
var path; var path;
var regtest = Networks.get('regtest');
if (this.node.network === Networks.livenet) { if (this.node.network === Networks.livenet) {
path = this.node.datadir + '/' + dbname; path = this.node.datadir + '/' + dbname;
} else if (this.node.network === Networks.testnet) { } else if (this.node.network === Networks.testnet) {
path = this.node.datadir + '/testnet3/' + dbname; if (this.node.network.regtestEnabled) {
} else if (this.node.network === regtest) { path = this.node.datadir + '/regtest/' + dbname;
path = this.node.datadir + '/regtest/' + dbname; } else {
path = this.node.datadir + '/testnet3/' + dbname;
}
} else { } else {
throw new Error('Unknown network: ' + this.network); throw new Error('Unknown network: ' + this.network);
} }

View File

@ -154,9 +154,14 @@ Bitcoin.prototype.start = function(callback) {
this._loadConfiguration(); this._loadConfiguration();
var networkName = this.node.network.name;
if (this.node.network.regtestEnabled) {
networkName = 'regtest';
}
bindings.start({ bindings.start({
datadir: this.node.datadir, datadir: this.node.datadir,
network: this.node.network.name network: networkName
}, function(err) { }, function(err) {
if(err) { if(err) {
return callback(err); return callback(err);

View File

@ -89,13 +89,14 @@ DB.DEFAULT_MAX_OPEN_FILES = 200;
*/ */
DB.prototype._setDataPath = function() { DB.prototype._setDataPath = function() {
$.checkState(this.node.datadir, 'Node is expected to have a "datadir" property'); $.checkState(this.node.datadir, 'Node is expected to have a "datadir" property');
var regtest = Networks.get('regtest');
if (this.node.network === Networks.livenet) { if (this.node.network === Networks.livenet) {
this.dataPath = this.node.datadir + '/bitcore-node.db'; this.dataPath = this.node.datadir + '/bitcore-node.db';
} else if (this.node.network === Networks.testnet) { } else if (this.node.network === Networks.testnet) {
this.dataPath = this.node.datadir + '/testnet3/bitcore-node.db'; if (this.node.network.regtestEnabled) {
} else if (this.node.network === regtest) { this.dataPath = this.node.datadir + '/regtest/bitcore-node.db';
this.dataPath = this.node.datadir + '/regtest/bitcore-node.db'; } else {
this.dataPath = this.node.datadir + '/testnet3/bitcore-node.db';
}
} else { } else {
throw new Error('Unknown network: ' + this.network); throw new Error('Unknown network: ' + this.network);
} }

View File

@ -48,7 +48,7 @@
"dependencies": { "dependencies": {
"async": "^1.3.0", "async": "^1.3.0",
"bindings": "^1.2.1", "bindings": "^1.2.1",
"bitcore-lib": "^0.13.7", "bitcore-lib": "^0.13.13",
"body-parser": "^1.13.3", "body-parser": "^1.13.3",
"colors": "^1.1.2", "colors": "^1.1.2",
"commander": "^2.8.1", "commander": "^2.8.1",

View File

@ -21,29 +21,9 @@ describe('Bitcore Node', function() {
Node.prototype._loadConfiguration = sinon.spy(); Node.prototype._loadConfiguration = sinon.spy();
Node.prototype._initialize = sinon.spy(); Node.prototype._initialize = sinon.spy();
}); });
after(function() { after(function() {
var regtest = Networks.get('regtest'); Networks.disableRegtest();
if (regtest) {
Networks.remove(regtest);
}
// restore testnet
Networks.add({
name: 'testnet',
alias: 'testnet',
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,
xpubkey: 0x043587cf,
xprivkey: 0x04358394,
networkMagic: 0x0b110907,
port: 18333,
dnsSeeds: [
'testnet-seed.bitcoin.petertodd.org',
'testnet-seed.bluematt.me',
'testnet-seed.alexykot.me',
'testnet-seed.bitcoin.schildbach.de'
],
});
}); });
describe('@constructor', function() { describe('@constructor', function() {

View File

@ -271,19 +271,7 @@ describe('Address Service', function() {
}); });
it('should load the db with regtest', function() { it('should load the db with regtest', function() {
// Switch to use regtest // Switch to use regtest
Networks.remove(Networks.testnet); Networks.enableRegtest();
Networks.add({
name: 'regtest',
alias: 'regtest',
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,
xpubkey: 0x043587cf,
xprivkey: 0x04358394,
networkMagic: 0xfabfb5da,
port: 18444,
dnsSeeds: [ ]
});
var regtest = Networks.get('regtest'); var regtest = Networks.get('regtest');
var testnode = { var testnode = {
network: regtest, network: regtest,
@ -299,7 +287,7 @@ describe('Address Service', function() {
node: testnode node: testnode
}); });
am.mempoolIndexPath.should.equal(process.env.HOME + '/.bitcoin/regtest/bitcore-addressmempool.db'); am.mempoolIndexPath.should.equal(process.env.HOME + '/.bitcoin/regtest/bitcore-addressmempool.db');
Networks.remove(regtest); Networks.disableRegtest();
}); });
}); });
@ -735,6 +723,7 @@ describe('Address Service', function() {
describe('#createInputsStream', function() { describe('#createInputsStream', function() {
it('transform stream from buffer into object', function(done) { it('transform stream from buffer into object', function(done) {
var testnode = { var testnode = {
network: Networks.livenet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -777,6 +766,7 @@ describe('Address Service', function() {
it('will stream all keys', function() { it('will stream all keys', function() {
var streamStub = sinon.stub().returns({}); var streamStub = sinon.stub().returns({});
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -808,6 +798,7 @@ describe('Address Service', function() {
it('will stream keys based on a range of block heights', function() { it('will stream keys based on a range of block heights', function() {
var streamStub = sinon.stub().returns({}); var streamStub = sinon.stub().returns({});
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -1144,6 +1135,7 @@ describe('Address Service', function() {
describe('#createOutputsStream', function() { describe('#createOutputsStream', function() {
it('transform stream from buffer into object', function(done) { it('transform stream from buffer into object', function(done) {
var testnode = { var testnode = {
network: Networks.livenet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -1188,6 +1180,7 @@ describe('Address Service', function() {
it('will stream all keys', function() { it('will stream all keys', function() {
var streamStub = sinon.stub().returns({}); var streamStub = sinon.stub().returns({});
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -1219,6 +1212,7 @@ describe('Address Service', function() {
it('will stream keys based on a range of block heights', function() { it('will stream keys based on a range of block heights', function() {
var streamStub = sinon.stub().returns({}); var streamStub = sinon.stub().returns({});
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2030,6 +2024,7 @@ describe('Address Service', function() {
}); });
it('will handle error from _getAddressConfirmedSummary', function(done) { it('will handle error from _getAddressConfirmedSummary', function(done) {
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2052,6 +2047,7 @@ describe('Address Service', function() {
}); });
it('will handle error from _getAddressMempoolSummary', function(done) { it('will handle error from _getAddressMempoolSummary', function(done) {
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2075,6 +2071,7 @@ describe('Address Service', function() {
}); });
it('will pass cache and summary between functions correctly', function(done) { it('will pass cache and summary between functions correctly', function(done) {
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2108,6 +2105,7 @@ describe('Address Service', function() {
}); });
it('will log if there is a slow query', function(done) { it('will log if there is a slow query', function(done) {
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2139,6 +2137,7 @@ describe('Address Service', function() {
describe('#_getAddressConfirmedSummary', function() { describe('#_getAddressConfirmedSummary', function() {
it('will pass arguments correctly', function(done) { it('will pass arguments correctly', function(done) {
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2177,6 +2176,7 @@ describe('Address Service', function() {
}); });
it('will pass error correctly (inputs)', function(done) { it('will pass error correctly (inputs)', function(done) {
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2200,6 +2200,7 @@ describe('Address Service', function() {
}); });
it('will pass error correctly (outputs)', function(done) { it('will pass error correctly (outputs)', function(done) {
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2229,6 +2230,7 @@ describe('Address Service', function() {
var streamStub = new stream.Readable(); var streamStub = new stream.Readable();
streamStub._read = function() { /* do nothing */ }; streamStub._read = function() { /* do nothing */ };
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2265,6 +2267,7 @@ describe('Address Service', function() {
var streamStub = new stream.Readable(); var streamStub = new stream.Readable();
streamStub._read = function() { /* do nothing */ }; streamStub._read = function() { /* do nothing */ };
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2296,6 +2299,7 @@ describe('Address Service', function() {
var streamStub = new stream.Readable(); var streamStub = new stream.Readable();
streamStub._read = function() { /* do nothing */ }; streamStub._read = function() { /* do nothing */ };
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub(), on: sinon.stub(),
@ -2350,6 +2354,7 @@ describe('Address Service', function() {
var streamStub = new stream.Readable(); var streamStub = new stream.Readable();
streamStub._read = function() { /* do nothing */ }; streamStub._read = function() { /* do nothing */ };
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2386,6 +2391,7 @@ describe('Address Service', function() {
describe('#_setAndSortTxidsFromAppearanceIds', function() { describe('#_setAndSortTxidsFromAppearanceIds', function() {
it('will sort correctly', function(done) { it('will sort correctly', function(done) {
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2432,6 +2438,7 @@ describe('Address Service', function() {
describe('#_getAddressMempoolSummary', function() { describe('#_getAddressMempoolSummary', function() {
it('skip if options not enabled', function(done) { it('skip if options not enabled', function(done) {
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2460,6 +2467,7 @@ describe('Address Service', function() {
}); });
it('include all txids and balance from inputs and outputs', function(done) { it('include all txids and balance from inputs and outputs', function(done) {
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()
@ -2560,6 +2568,7 @@ describe('Address Service', function() {
unconfirmedBalance: 500000 unconfirmedBalance: 500000
}; };
var testnode = { var testnode = {
network: Networks.testnet,
services: { services: {
bitcoind: { bitcoind: {
on: sinon.stub() on: sinon.stub()

View File

@ -77,19 +77,7 @@ describe('DB Service', function() {
}); });
it('should load the db with regtest', function() { it('should load the db with regtest', function() {
// Switch to use regtest // Switch to use regtest
// Networks.remove(Networks.testnet); Networks.enableRegtest();
Networks.add({
name: 'regtest',
alias: 'regtest',
pubkeyhash: 0x6f,
privatekey: 0xef,
scripthash: 0xc4,
xpubkey: 0x043587cf,
xprivkey: 0x04358394,
networkMagic: 0xfabfb5da,
port: 18444,
dnsSeeds: [ ]
});
var regtest = Networks.get('regtest'); var regtest = Networks.get('regtest');
var config = { var config = {
node: { node: {
@ -100,7 +88,7 @@ describe('DB Service', function() {
}; };
var db = new DB(config); var db = new DB(config);
db.dataPath.should.equal(process.env.HOME + '/.bitcoin/regtest/bitcore-node.db'); db.dataPath.should.equal(process.env.HOME + '/.bitcoin/regtest/bitcore-node.db');
Networks.remove(regtest); Networks.disableRegtest();
}); });
}); });