Add and fix unit tests for configuration options.
This commit is contained in:
parent
0bbc388ca6
commit
75058b26b9
@ -51,6 +51,7 @@ Node.prototype.setSyncStrategy = function(strategy) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Node.prototype._loadBitcoinConf = function(config) {
|
Node.prototype._loadBitcoinConf = function(config) {
|
||||||
|
$.checkArgument(config.datadir, 'Please specify "datadir" in configuration options');
|
||||||
var datadir = config.datadir.replace(/^~/, process.env.HOME);
|
var datadir = config.datadir.replace(/^~/, process.env.HOME);
|
||||||
this.bitcoinConfiguration = {};
|
this.bitcoinConfiguration = {};
|
||||||
var file = fs.readFileSync(datadir + '/bitcoin.conf');
|
var file = fs.readFileSync(datadir + '/bitcoin.conf');
|
||||||
@ -66,7 +67,6 @@ Node.prototype._loadBitcoinConf = function(config) {
|
|||||||
|
|
||||||
Node.prototype._loadBitcoind = function(config) {
|
Node.prototype._loadBitcoind = function(config) {
|
||||||
var bitcoindConfig = {};
|
var bitcoindConfig = {};
|
||||||
$.checkArgument(config.datadir, 'Please specify "datadir" in configuration options');
|
|
||||||
bitcoindConfig.datadir = config.datadir;
|
bitcoindConfig.datadir = config.datadir;
|
||||||
bitcoindConfig.testnet = config.testnet;
|
bitcoindConfig.testnet = config.testnet;
|
||||||
|
|
||||||
@ -134,11 +134,15 @@ Node.prototype._loadDB = function(config) {
|
|||||||
|
|
||||||
// Store the additional indexes in a new directory
|
// Store the additional indexes in a new directory
|
||||||
// based on the network configuration and the datadir
|
// based on the network configuration and the datadir
|
||||||
|
$.checkArgument(config.datadir, 'Please specify "datadir" in configuration options');
|
||||||
|
$.checkState(this.network, 'Network property not defined');
|
||||||
var datadir = config.datadir.replace(/^~/, process.env.HOME);
|
var datadir = config.datadir.replace(/^~/, process.env.HOME);
|
||||||
if (this.network === Networks.testnet) {
|
if (this.network === Networks.testnet) {
|
||||||
config.db.path = datadir + '/testnet3/bitcoindjs.db';
|
config.db.path = datadir + '/testnet3/bitcoindjs.db';
|
||||||
} else if (this.network === Networks.livenet) {
|
} else if (this.network === Networks.livenet) {
|
||||||
config.db.path = datadir + '/bitcoindjs.db';
|
config.db.path = datadir + '/bitcoindjs.db';
|
||||||
|
} else {
|
||||||
|
throw new Error('Unknown network: ' + this.network);
|
||||||
}
|
}
|
||||||
config.db.network = this.network;
|
config.db.network = this.network;
|
||||||
|
|
||||||
@ -154,7 +158,7 @@ Node.prototype._loadP2P = function(config) {
|
|||||||
|
|
||||||
// We only want to directly connect via p2p to the trusted bitcoind daemon
|
// We only want to directly connect via p2p to the trusted bitcoind daemon
|
||||||
var port = 8333;
|
var port = 8333;
|
||||||
if (this.bitcoinConfiguration.port) {
|
if (this.bitcoinConfiguration && this.bitcoinConfiguration.port) {
|
||||||
port = this.bitcoinConfiguration.port;
|
port = this.bitcoinConfiguration.port;
|
||||||
} else if (this.network === Networks.testnet) {
|
} else if (this.network === Networks.testnet) {
|
||||||
port = 18333;
|
port = 18333;
|
||||||
|
|||||||
@ -26,9 +26,11 @@ describe('Bitcoind Node', function() {
|
|||||||
describe('#_loadConfiguration', function() {
|
describe('#_loadConfiguration', function() {
|
||||||
it('should call the necessary methods', function() {
|
it('should call the necessary methods', function() {
|
||||||
var node = new Node({});
|
var node = new Node({});
|
||||||
|
node._loadBitcoinConf = sinon.spy();
|
||||||
node._loadBitcoind = sinon.spy();
|
node._loadBitcoind = sinon.spy();
|
||||||
node._loadConfiguration({});
|
node._loadConfiguration({});
|
||||||
node._loadBitcoind.called.should.equal(true);
|
node._loadBitcoind.called.should.equal(true);
|
||||||
|
node._loadBitcoinConf.called.should.equal(true);
|
||||||
BaseNode.prototype._loadConfiguration.called.should.equal(true);
|
BaseNode.prototype._loadConfiguration.called.should.equal(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -182,15 +184,44 @@ describe('Bitcoind Node', function() {
|
|||||||
});
|
});
|
||||||
describe('#_loadDB', function() {
|
describe('#_loadDB', function() {
|
||||||
it('should load the db', function() {
|
it('should load the db', function() {
|
||||||
var DB = function() {};
|
var DB = function(config) {
|
||||||
|
config.path.should.equal(process.env.HOME + '/.bitcoin/bitcoindjs.db');
|
||||||
|
};
|
||||||
var config = {
|
var config = {
|
||||||
DB: DB
|
DB: DB,
|
||||||
|
datadir: '~/.bitcoin'
|
||||||
};
|
};
|
||||||
|
|
||||||
var node = new Node(config);
|
var node = new Node(config);
|
||||||
|
node.network = Networks.livenet;
|
||||||
node._loadDB(config);
|
node._loadDB(config);
|
||||||
node.db.should.be.instanceof(DB);
|
node.db.should.be.instanceof(DB);
|
||||||
});
|
});
|
||||||
|
it('should load the db for testnet', function() {
|
||||||
|
var DB = function(config) {
|
||||||
|
config.path.should.equal(process.env.HOME + '/.bitcoin/testnet3/bitcoindjs.db');
|
||||||
|
};
|
||||||
|
var config = {
|
||||||
|
DB: DB,
|
||||||
|
datadir: '~/.bitcoin'
|
||||||
|
};
|
||||||
|
|
||||||
|
var node = new Node(config);
|
||||||
|
node.network = Networks.testnet;
|
||||||
|
node._loadDB(config);
|
||||||
|
node.db.should.be.instanceof(DB);
|
||||||
|
});
|
||||||
|
it('error with unknown network', function() {
|
||||||
|
var config = {
|
||||||
|
datadir: '~/.bitcoin'
|
||||||
|
};
|
||||||
|
|
||||||
|
var node = new Node(config);
|
||||||
|
node.network = 'not a network';
|
||||||
|
(function() {
|
||||||
|
node._loadDB(config);
|
||||||
|
}).should.throw('Unknown network');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('#_loadP2P', function() {
|
describe('#_loadP2P', function() {
|
||||||
it('should load p2p', function() {
|
it('should load p2p', function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user