diff --git a/lib/bcoin/env.js b/lib/bcoin/env.js index af184939..ac638874 100644 --- a/lib/bcoin/env.js +++ b/lib/bcoin/env.js @@ -42,6 +42,11 @@ function Environment(options) { || options.prefix || process.env.HOME + '/.bcoin'; + this.db = options.db; + + if (process.env.BCOIN_DB != null) + this.db = process.env.BCOIN_DB; + this.debugLogs = options.debug; if (process.env.BCOIN_DEBUG != null) diff --git a/lib/bcoin/ldb.js b/lib/bcoin/ldb.js index 236a7470..c6287c47 100644 --- a/lib/bcoin/ldb.js +++ b/lib/bcoin/ldb.js @@ -5,13 +5,12 @@ * https://github.com/indutny/bcoin */ -var db = {}; - module.exports = function(bcoin) { var EventEmitter = require('events').EventEmitter; var utils = bcoin.utils; var network = bcoin.protocol.network; +var db = {}; /** * LDB @@ -55,15 +54,18 @@ function ldb(options) { function getLocation(options) { if (options.location) return options.location; - return bcoin.prefix + '/' + options.name + '-' + network.type + '.db'; + + return bcoin.prefix + + '/' + + options.name + + '-' + + network.type + + '.db'; } function getBackend(backend) { - if (bcoin.isBrowser) - return require('level-js'); - if (typeof backend !== 'string') - backend = process.env.BCOIN_DB; + backend = bcoin.db; if (!backend || backend === 'leveldb') backend = 'leveldown'; @@ -77,6 +79,9 @@ function getBackend(backend) { if (backend === 'bst') return require('./bst'); + if (bcoin.isBrowser) + return require('level-js'); + bcoin.ensurePrefix(); return require(backend); diff --git a/package.json b/package.json index b0e8b92c..33748fb5 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "bin": "./bin/node", "preferGlobal": false, "scripts": { - "test": "rm -rf ~/.bcoin-test && BCOIN_PREFIX=~/.bcoin-test 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/node-test.js b/test/node-test.js index e5d7f5f8..9a3ac59e 100644 --- a/test/node-test.js +++ b/test/node-test.js @@ -1,12 +1,11 @@ var bn = require('bn.js'); -var bcoin = require('../')(); +var bcoin = require('../')({ db: 'memory' }); var constants = bcoin.protocol.constants; var utils = bcoin.utils; var assert = utils.assert; var opcodes = constants.opcodes; describe('Wallet', function() { - process.env.BCOIN_DB = 'bst'; var node = new bcoin.fullnode(); node.on('error', function() {}); @@ -15,7 +14,6 @@ describe('Wallet', function() { }); it('should have wallet', function(cb) { - delete process.env.BCOIN_DB; node.getWallet('primary', function(err, wallet) { if (err) return cb(err); diff --git a/test/wallet-test.js b/test/wallet-test.js index 98bfdd10..b7eda7d1 100644 --- a/test/wallet-test.js +++ b/test/wallet-test.js @@ -1,5 +1,5 @@ var bn = require('bn.js'); -var bcoin = require('../')(); +var bcoin = require('../')({ db: 'memory' }); var constants = bcoin.protocol.constants; var utils = bcoin.utils; var assert = utils.assert; @@ -24,8 +24,11 @@ var dummyInput = { }; describe('Wallet', function() { - var wdb = new bcoin.walletdb(); - wdb.tx.options.verify = true; + var wdb = new bcoin.walletdb({ verify: true }); + + it('should open walletdb', function(cb) { + wdb.open(cb); + }); it('should generate new key and address', function() { var w = bcoin.wallet();