forked from ethereumjs/ethereumjs-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ethereumjs#29 from fgimenez/data-dir-test
Initial test structure and data dir creation test
- Loading branch information
Showing
8 changed files
with
95 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
const levelup = require('levelup') | ||
const leveldown = require('leveldown') | ||
|
||
class DBManager { | ||
constructor (config) { | ||
this._config = config | ||
this._logger = config.logger | ||
|
||
this._initializeDatadir() | ||
|
||
// TODO: Store chain data in an appropriate sub folder (e.g. 'chaindata/ropsten/') | ||
this._blockchainDB = levelup(this._config.datadir, { db: leveldown }) | ||
} | ||
|
||
blockchainDB () { | ||
return this._blockchainDB | ||
} | ||
|
||
// From: https://stackoverflow.com/a/40686853 | ||
// replace if there is an easier solution | ||
_mkDirByPathSync (targetDir, {isRelativeToScript = false} = {}) { | ||
const sep = path.sep | ||
const initDir = path.isAbsolute(targetDir) ? sep : '' | ||
const baseDir = isRelativeToScript ? __dirname : '.' | ||
|
||
targetDir.split(sep).reduce((parentDir, childDir) => { | ||
const curDir = path.resolve(baseDir, parentDir, childDir) | ||
if (!fs.existsSync(curDir)) { | ||
try { | ||
fs.mkdirSync(curDir) | ||
} catch (err) { | ||
throw err | ||
} | ||
} | ||
return curDir | ||
}, initDir) | ||
} | ||
|
||
_initializeDatadir () { | ||
if (!fs.existsSync(this._config.datadir)) { | ||
this._mkDirByPathSync(this._config.datadir) | ||
} | ||
this._logger.info(`Initialized data directory: ${this._config.datadir}`) | ||
} | ||
} | ||
|
||
module.exports = DBManager |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
const fs = require('fs') | ||
const tape = require('tape') | ||
const tmp = require('tmp') | ||
const DBManager = require('../lib/chain/DBManager.js') | ||
const Logger = require('./mocks/Logger.js') | ||
|
||
tape('[DB]: Database functions', function (t) { | ||
const config = {} | ||
config.logger = Logger | ||
|
||
t.test('should test data dir creation', function (st) { | ||
const tmpdir = tmp.dirSync() | ||
config.datadir = `${tmpdir.name}/chaindb` | ||
|
||
new DBManager(config) // eslint-disable-line no-new | ||
|
||
st.ok(fs.existsSync(config.datadir), 'data dir exists') | ||
|
||
st.end() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1 @@ | ||
// Remove this test once first test is established, | ||
// just for test setup, linting test,... | ||
// Replace with references to separate test files | ||
// see other ethereumjs repos for reference | ||
const tape = require('tape') | ||
|
||
tape('[CL]: Test --debug command line option', function (t) { | ||
t.test('should test empty command line option', function (st) { | ||
st.equal(true, true, 'output should default to INFO log level') | ||
st.end() | ||
}) | ||
}) | ||
require('./db-manager.js') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let Logger = {} | ||
|
||
Logger.info = function () {} | ||
|
||
module.exports = Logger |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
let NetworkManager = {} | ||
|
||
NetworkManager.startNetworking = function () {} | ||
|
||
module.exports = NetworkManager |