env variables.

This commit is contained in:
Christopher Jeffrey 2016-05-01 21:19:25 -07:00
parent 703c9aec3c
commit bba94d4aaa
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
15 changed files with 55 additions and 48 deletions

View File

@ -125,23 +125,26 @@ function Environment(options) {
(typeof process !== 'undefined' && process.browser)
|| typeof window !== 'undefined';
this.prefix = process.env.BCOIN_PREFIX
|| options.prefix
this.prefix = options.prefix
|| process.env.BCOIN_PREFIX
|| process.env.HOME + '/.bcoin';
this.db = options.db;
if (process.env.BCOIN_DB != null)
this.db = process.env.BCOIN_DB;
this.networkType = options.network
|| process.env.BCOIN_NETWORK
|| 'main';
this.db = options.db || process.env.BCOIN_DB;
this.debugLogs = options.debug;
this.debugFile = options.debugFile;
this.profile = options.profile;
this.useWorkers = options.useWorkers;
this.maxWorkers = options.maxWorkers;
this.workerTimeout = options.workerTimeout;
if (process.env.BCOIN_DEBUG != null)
if (this.debugLogs == null && process.env.BCOIN_DEBUG != null)
this.debugLogs = +process.env.BCOIN_DEBUG === 1;
this.debugFile = options.debugFile;
if (process.env.BCOIN_DEBUGFILE != null) {
if (this.debugFile == null && process.env.BCOIN_DEBUGFILE != null) {
if (process.env.BCOIN_DEBUGFILE === '0'
|| process.env.BCOIN_DEBUGFILE === '1') {
this.debugFile = +process.env.BCOIN_DEBUGFILE !== 0;
@ -153,30 +156,18 @@ function Environment(options) {
if (this.debugFile && typeof this.debugFile !== 'string')
this.debugFile = this.prefix + '/debug.log'
this.profile = options.profile;
if (process.env.BCOIN_PROFILE != null)
if (this.profile == null && process.env.BCOIN_PROFILE != null)
this.profile = +process.env.BCOIN_PROFILE === 1;
this.useWorkers = options.useWorkers;
if (process.env.BCOIN_USE_WORKERS != null)
if (this.useWorkers == null && process.env.BCOIN_USE_WORKERS != null)
this.useWorkers = +process.env.BCOIN_USE_WORKERS === 1;
this.useWorkers = options.maxWorkers;
if (process.env.BCOIN_MAX_WORKERS != null)
if (this.maxWorkers == null && process.env.BCOIN_MAX_WORKERS != null)
this.maxWorkers = +process.env.BCOIN_MAX_WORKERS;
this.workerTimeout = options.workerTimeout;
if (process.env.BCOIN_WORKER_TIMEOUT != null)
if (this.workerTime == null && process.env.BCOIN_WORKER_TIMEOUT != null)
this.workerTimeout = +process.env.BCOIN_WORKER_TIMEOUT;
this.networkType = process.env.BCOIN_NETWORK
|| options.network
|| 'main';
this.bn = require('bn.js');
this.utils = require('./utils');
this.locker = require('./locker');

View File

@ -51,7 +51,7 @@ function ldb(options) {
// For LMDB if we decide to use it:
sync: options.sync || false,
mapSize: options.mapSize || 150 * (1024 << 20),
mapSize: options.mapSize || 300 * (1024 << 20),
writeMap: options.writeMap || false,
db: getBackend(options.db)
@ -74,7 +74,7 @@ function getLocation(options) {
}
function getBackend(backend) {
if (typeof backend !== 'string')
if (!backend)
backend = bcoin.db;
if (!backend || backend === 'leveldb')

View File

@ -9,7 +9,7 @@
},
"preferGlobal": false,
"scripts": {
"test": "BCOIN_NETWORK=main mocha --reporter spec test/*-test.js"
"test": "mocha --reporter spec test/*-test.js"
},
"repository": "git://github.com/bcoin-org/bcoin.git",
"keywords": [

View File

@ -1,6 +1,5 @@
var bn = require('bn.js');
var bcoin = require('../')();
var utils = bcoin.utils;
var utils = require('../lib/bcoin/utils');
var assert = require('assert');
var aes = require('../lib/bcoin/aes');
var crypto = require('crypto');

View File

@ -1,5 +1,5 @@
var bn = require('bn.js');
var bcoin = require('../')();
var bcoin = require('../')('main');
var assert = require('assert');
describe('Block', function() {

View File

@ -1,4 +1,4 @@
var bcoin = require('../')();
var bcoin = require('../')('main');
var assert = require('assert');
describe('Bloom', function() {

View File

@ -1,7 +1,5 @@
var bn = require('bn.js');
delete process.env.BCOIN_NETWORK;
var bcoin = require('../')({ network: 'regtest', db: 'memory' });
process.env.BCOIN_NETWORK = 'main';
var bcoin = require('../')('regtest');
var constants = bcoin.protocol.constants;
var utils = bcoin.utils;
var assert = require('assert');
@ -13,7 +11,7 @@ describe('Chain', function() {
var chain, wallet, miner;
var competingTip, oldTip, ch1, ch2, cb1, cb2;
chain = new bcoin.chain();
chain = new bcoin.chain({ name: 'chain-test', db: 'memory' });
wallet = new bcoin.wallet();
miner = new bcoin.miner({
chain: chain,

View File

@ -1,5 +1,5 @@
var bn = require('bn.js');
var bcoin = require('../')();
var bcoin = require('../')('main');
var utils = bcoin.utils;
var assert = require('assert');

View File

@ -1,13 +1,22 @@
var bn = require('bn.js');
var bcoin = require('../')();
var bcoin = require('../')('main');
var constants = bcoin.protocol.constants;
var utils = bcoin.utils;
var assert = require('assert');
var opcodes = constants.opcodes;
describe('Mempool', function() {
var chain = new bcoin.chain({ db: 'memory' });
var mempool = new bcoin.mempool({ chain: chain, db: 'memory' });
var chain = new bcoin.chain({
name: 'mp-chain',
db: 'memory'
});
var mempool = new bcoin.mempool({
chain: chain,
name: 'mempool-test',
db: 'memory'
});
mempool.on('error', function() {});
it('should open mempool', function(cb) {

View File

@ -1,5 +1,5 @@
var bn = require('bn.js');
var bcoin = require('../')();
var bcoin = require('../')('main');
var utils = bcoin.utils;
var assert = require('assert');
var mnemonic1 = require('./data/mnemonic1').english;

View File

@ -1,4 +1,4 @@
var bcoin = require('../')();
var bcoin = require('../')('main');
var assert = require('assert');
var constants = bcoin.protocol.constants;
var network = bcoin.protocol.network;

View File

@ -1,4 +1,4 @@
var bcoin = require('../')();
var bcoin = require('../')('main');
var assert = require('assert');
var Script = bcoin.script;
var Stack = bcoin.script.stack;

View File

@ -1,5 +1,5 @@
var bn = require('bn.js');
var bcoin = require('../')();
var bcoin = require('../')('main');
var assert = require('assert');
var utils = bcoin.utils;
var constants = bcoin.protocol.constants;

View File

@ -1,5 +1,5 @@
var bn = require('bn.js');
var bcoin = require('../')();
var bcoin = require('../')('main');
var assert = require('assert');
var utils = bcoin.utils;

View File

@ -1,6 +1,7 @@
var bn = require('bn.js');
var bcoin = require('../').env();
var bcoin = require('../')('main');
var constants = bcoin.protocol.constants;
var network = bcoin.protocol.network;
var utils = bcoin.utils;
var assert = require('assert');
@ -24,9 +25,14 @@ var dummyInput = {
};
describe('Wallet', function() {
var wdb = new bcoin.walletdb({ db: 'memory', verify: true });
var wdb = new bcoin.walletdb({
name: 'wallet-test',
db: 'memory',
verify: true
});
it('should open walletdb', function(cb) {
constants.tx.COINBASE_MATURITY = 0;
wdb.open(cb);
});
@ -554,4 +560,8 @@ describe('Wallet', function() {
it('should verify 2-of-3 witnessscripthash tx with bullshit nesting', function(cb) {
multisig(true, true, cb);
});
it('should cleanup', function(cb) {
constants.tx.COINBASE_MATURITY = 100;
});
});