From bba94d4aaa11a1c4dedb86678926ac1dc572e917 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Sun, 1 May 2016 21:19:25 -0700 Subject: [PATCH] env variables. --- lib/bcoin/env.js | 43 +++++++++++++++++-------------------------- lib/bcoin/ldb.js | 4 ++-- package.json | 2 +- test/aes-test.js | 3 +-- test/block-test.js | 2 +- test/bloom-test.js | 2 +- test/chain-test.js | 6 ++---- test/hd-test.js | 2 +- test/mempool-test.js | 15 ++++++++++++--- test/mnemonic-test.js | 2 +- test/protocol-test.js | 2 +- test/script-test.js | 2 +- test/tx-test.js | 2 +- test/utils-test.js | 2 +- test/wallet-test.js | 14 ++++++++++++-- 15 files changed, 55 insertions(+), 48 deletions(-) diff --git a/lib/bcoin/env.js b/lib/bcoin/env.js index 67606bfd..d3945d23 100644 --- a/lib/bcoin/env.js +++ b/lib/bcoin/env.js @@ -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'); diff --git a/lib/bcoin/ldb.js b/lib/bcoin/ldb.js index ab542969..6bc0c352 100644 --- a/lib/bcoin/ldb.js +++ b/lib/bcoin/ldb.js @@ -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') diff --git a/package.json b/package.json index b1ab7a07..d742d553 100644 --- a/package.json +++ b/package.json @@ -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": [ diff --git a/test/aes-test.js b/test/aes-test.js index 24e42a43..6a8eea9d 100644 --- a/test/aes-test.js +++ b/test/aes-test.js @@ -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'); diff --git a/test/block-test.js b/test/block-test.js index 7dfd32b3..92f8adb6 100644 --- a/test/block-test.js +++ b/test/block-test.js @@ -1,5 +1,5 @@ var bn = require('bn.js'); -var bcoin = require('../')(); +var bcoin = require('../')('main'); var assert = require('assert'); describe('Block', function() { diff --git a/test/bloom-test.js b/test/bloom-test.js index ddcb2b63..9889bb44 100644 --- a/test/bloom-test.js +++ b/test/bloom-test.js @@ -1,4 +1,4 @@ -var bcoin = require('../')(); +var bcoin = require('../')('main'); var assert = require('assert'); describe('Bloom', function() { diff --git a/test/chain-test.js b/test/chain-test.js index 9aceeacf..8bb13922 100644 --- a/test/chain-test.js +++ b/test/chain-test.js @@ -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, diff --git a/test/hd-test.js b/test/hd-test.js index fe50b084..e539922f 100644 --- a/test/hd-test.js +++ b/test/hd-test.js @@ -1,5 +1,5 @@ var bn = require('bn.js'); -var bcoin = require('../')(); +var bcoin = require('../')('main'); var utils = bcoin.utils; var assert = require('assert'); diff --git a/test/mempool-test.js b/test/mempool-test.js index 88797e14..43232c64 100644 --- a/test/mempool-test.js +++ b/test/mempool-test.js @@ -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) { diff --git a/test/mnemonic-test.js b/test/mnemonic-test.js index 92a39a70..fb981870 100644 --- a/test/mnemonic-test.js +++ b/test/mnemonic-test.js @@ -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; diff --git a/test/protocol-test.js b/test/protocol-test.js index 3c320895..8fe57a76 100644 --- a/test/protocol-test.js +++ b/test/protocol-test.js @@ -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; diff --git a/test/script-test.js b/test/script-test.js index a9a71306..ff0aac8e 100644 --- a/test/script-test.js +++ b/test/script-test.js @@ -1,4 +1,4 @@ -var bcoin = require('../')(); +var bcoin = require('../')('main'); var assert = require('assert'); var Script = bcoin.script; var Stack = bcoin.script.stack; diff --git a/test/tx-test.js b/test/tx-test.js index e78ef941..c74d86dc 100644 --- a/test/tx-test.js +++ b/test/tx-test.js @@ -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; diff --git a/test/utils-test.js b/test/utils-test.js index d25606c9..28628822 100644 --- a/test/utils-test.js +++ b/test/utils-test.js @@ -1,5 +1,5 @@ var bn = require('bn.js'); -var bcoin = require('../')(); +var bcoin = require('../')('main'); var assert = require('assert'); var utils = bcoin.utils; diff --git a/test/wallet-test.js b/test/wallet-test.js index 5ac9955e..044aab3a 100644 --- a/test/wallet-test.js +++ b/test/wallet-test.js @@ -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; + }); });