bitcore-node icon indicating copy to clipboard operation
bitcore-node copied to clipboard

Configuration defined programmatically does not override default configuration

Open bluemana opened this issue 10 years ago • 1 comments

The BitcoinService run in regtest mode does not keep the configuration passed to the Node constructor when the Bitcore Node starts with clean data and configuration.

Here is a sample test suite to reproduce this issue:

const path = require('path');
const rimraf = require('rimraf');
const lodashLang = require('lodash/lang');
const lodashObject = require('lodash/object');

const BitcoreNode = require('./lib/node');
const BitcoinService = require('./lib/services/bitcoind');

const mocha = require('mocha');
const chai = require('chai');
const should = chai.should();

const DATA_DIR = path.resolve(__dirname, './config_test_data');
const BITCOIND_EXEC_PATH = path.resolve(__dirname, './bin/bitcoind')

mocha.describe('configure Bitcoin node programmatically', function(done) {

  'use strict';

  this.timeout(20000);

  let btcNode;

  mocha.before('initialize test suite', function(done) {
    rimraf(DATA_DIR, function(error) {
      if (!error) {
        done();
      } else {
        throw error;
      }
    });
  });

  mocha.after('stop Bitcore node', function(done) {
    if (btcNode) {
      btcNode.stop(function(error) {
        if (!error) {
          rimraf(DATA_DIR, function(error) {
            if (!error) {
              done();
            } else {
              throw error;
            }
          });
        } else {
          throw error;
        }
      });
    } else {
      done();
    }
  });

  mocha.it('should override default configuration', function(done) {
    let configuration = {
      network: 'regtest',
      datadir: DATA_DIR,
      services: [
        {
          name: 'bitcoind',
          module: BitcoinService,
          config: {
            spawn: {
              datadir: DATA_DIR,
              exec: BITCOIND_EXEC_PATH,
              config: {
                rpchost: 'localhost',
                rpcport: 50001,
                rpcallowip: 'localhost',
                rpcuser: 'user',
                rpcpass: 'pass',
              }
            }
          }
        }
      ]
    };
    btcNode = new BitcoreNode(configuration);
    btcNode.on('error', function(error) {
      throw error;
    });
    btcNode.on('ready', function() {
    });
    btcNode.start(function() {
      let passedConfig = configuration.services[0].config.spawn.config;
      let actualConfig = btcNode.services.bitcoind.spawn.config;
      console.info('Passed configuration: ' + JSON.stringify(passedConfig));
      console.info('Actual configuration: ' + JSON.stringify(actualConfig));
      let expectedConfig = {};
      lodashObject.assign(expectedConfig, actualConfig);
      lodashObject.assign(expectedConfig, passedConfig);
      console.info('Expected configuration: ' + JSON.stringify(expectedConfig));
      lodashLang.isEqual(actualConfig, expectedConfig).should.be.true;
      done();
    });
  });
});

bluemana avatar Aug 21 '16 08:08 bluemana

spawn.config is generated by reading the bitcoin.conf settings. If you want to manually set these, you'll want to use connect instead of spawn, more details at: https://github.com/bitpay/bitcore-node/blob/f6e0783f55f638a8f1ddd136c581bbb8f706ba14/docs/services/bitcoind.md#configuration

braydonf avatar Sep 22 '16 14:09 braydonf