Merge branch 'stress-test' into v5
This commit is contained in:
commit
dd2db492d6
10 changed files with 113 additions and 68 deletions
1
.migrate-stress
Normal file
1
.migrate-stress
Normal file
|
|
@ -0,0 +1 @@
|
|||
{"migrations":[{"title":"001-initial.js"},{"title":"002-bills.js"},{"title":"003-device-events.js"},{"title":"004-transactions-reload.js"},{"title":"005-addCrypto.js"},{"title":"006-add-machine-config.js"},{"title":"007-add-phone.js"},{"title":"008-add-two-way.js"},{"title":"009-update-timestamps.js"},{"title":"010-cached-requests.js"},{"title":"011-transactions-reload-2.js"},{"title":"012-add-hd-path-serial.js"},{"title":"013-add-last-checked.js"},{"title":"014-session-to-tx-id.js"},{"title":"015-paired_devices.js"},{"title":"016-new_cached_requests_table.js"},{"title":"017-user_tokens.js"},{"title":"018-alter_devices.js"},{"title":"019-remove-dispense-counts.js"},{"title":"020-add-server-events.js"},{"title":"021-config-version-id.js"},{"title":"022-add_cash_in_sent.js"},{"title":"023-add-dispenses-to-cash-out.js"},{"title":"024-consolidate-hd.js"},{"title":"025-create_trades.js"},{"title":"026-add_send_confirmed.js"},{"title":"027-tx_errors.js"},{"title":"028-cash_out_actions.js"},{"title":"029-add_valid_to_user_config.js"},{"title":"030-cash-out-provision.js"},{"title":"031-remove_name_from_devices.js"},{"title":"032-create_machine_pings_table.js"},{"title":"033-add_cash_in_fee.js"},{"title":"034-add_cash_out_error_code.js"},{"title":"035-log_bank_notes.js"}],"path":"/Users/josh/projects/lamassu-server/.migrate-stress","pos":35}
|
||||
|
|
@ -1,50 +1,8 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const assert = require('assert')
|
||||
const _ = require('lodash/fp')
|
||||
const applyDefaults = require('../lib/apply-defaults')
|
||||
|
||||
// const db = require('../lib/db')
|
||||
const settingsLoader = require('../lib/settings-loader')
|
||||
const schema = require('../lamassu-schema.json')
|
||||
const newFields = []
|
||||
|
||||
const DEFAULT_CRYPTO = _.first(_.find(['code', 'cryptoCurrencies'], schema.fields).default)
|
||||
|
||||
assert(DEFAULT_CRYPTO)
|
||||
|
||||
Promise.resolve()
|
||||
.then(() => {
|
||||
schema.groups.forEach(group => {
|
||||
return group.fields.forEach(fieldCode => {
|
||||
const field = schema.fields.find(r => r.code === fieldCode)
|
||||
if (!field) throw new Error('No such field: ' + fieldCode)
|
||||
if (_.isNil(field.default)) return
|
||||
if (group.machineScope === 'specific') return
|
||||
|
||||
const crypto = group.cryptoScope === 'specific'
|
||||
? DEFAULT_CRYPTO
|
||||
: 'global'
|
||||
|
||||
return newFields.push({
|
||||
fieldLocator: {
|
||||
fieldScope: {
|
||||
crypto,
|
||||
machine: 'global'
|
||||
},
|
||||
code: fieldCode,
|
||||
fieldType: field.fieldType,
|
||||
fieldClass: field.fieldClass
|
||||
},
|
||||
fieldValue: {
|
||||
fieldType: field.fieldType,
|
||||
value: field.default
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return settingsLoader.save(newFields)
|
||||
})
|
||||
applyDefaults.run()
|
||||
.then(() => {
|
||||
console.log('Success.')
|
||||
process.exit(0)
|
||||
|
|
|
|||
|
|
@ -1,18 +1,13 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
const path = require('path')
|
||||
const migrate = require('migrate')
|
||||
const options = require('../lib/options')
|
||||
|
||||
const migrateDir = path.resolve(__dirname, '..', 'migrations')
|
||||
const migration = migrate.load(options.migrateStatePath, migrateDir)
|
||||
|
||||
migration.up(err => {
|
||||
if (err) {
|
||||
console.error('DB Migration failed: %s', err)
|
||||
process.exit(1)
|
||||
}
|
||||
const migrate = require('../lib/migrate')
|
||||
|
||||
migrate.run()
|
||||
.then(() => {
|
||||
console.log('DB Migration succeeded.')
|
||||
process.exit(0)
|
||||
})
|
||||
.catch(err => {
|
||||
console.error('DB Migration failed: %s', err)
|
||||
process.exit(1)
|
||||
})
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ function fetchData () {
|
|||
{code: 'kraken', display: 'Kraken', class: 'ticker', cryptos: ['BTC', 'ETH', 'LTC', 'DASH', 'ZEC']},
|
||||
{code: 'bitstamp', display: 'Bitstamp', class: 'ticker', cryptos: ['BTC', 'LTC']},
|
||||
{code: 'coinbase', display: 'Coinbase', class: 'ticker', cryptos: ['BTC', 'ETH', 'LTC']},
|
||||
{code: 'mock-ticker', display: 'Mock ticker', class: 'ticker', cryptos: ALL_CRYPTOS},
|
||||
{code: 'bitcoind', display: 'bitcoind', class: 'wallet', cryptos: ['BTC']},
|
||||
{code: 'geth', display: 'geth', class: 'wallet', cryptos: ['ETH']},
|
||||
{code: 'zcashd', display: 'zcashd', class: 'wallet', cryptos: ['ZEC']},
|
||||
|
|
|
|||
48
lib/apply-defaults.js
Normal file
48
lib/apply-defaults.js
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
const assert = require('assert')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const settingsLoader = require('../lib/settings-loader')
|
||||
const schema = require('../lamassu-schema.json')
|
||||
const newFields = []
|
||||
|
||||
const DEFAULT_CRYPTO = _.first(_.find(['code', 'cryptoCurrencies'], schema.fields).default)
|
||||
|
||||
assert(DEFAULT_CRYPTO)
|
||||
|
||||
module.exports = {run}
|
||||
|
||||
function run () {
|
||||
return Promise.resolve()
|
||||
.then(() => {
|
||||
schema.groups.forEach(group => {
|
||||
return group.fields.forEach(fieldCode => {
|
||||
const field = schema.fields.find(r => r.code === fieldCode)
|
||||
if (!field) throw new Error('No such field: ' + fieldCode)
|
||||
if (_.isNil(field.default)) return
|
||||
if (group.machineScope === 'specific') return
|
||||
|
||||
const crypto = group.cryptoScope === 'specific'
|
||||
? DEFAULT_CRYPTO
|
||||
: 'global'
|
||||
|
||||
return newFields.push({
|
||||
fieldLocator: {
|
||||
fieldScope: {
|
||||
crypto,
|
||||
machine: 'global'
|
||||
},
|
||||
code: fieldCode,
|
||||
fieldType: field.fieldType,
|
||||
fieldClass: field.fieldClass
|
||||
},
|
||||
fieldValue: {
|
||||
fieldType: field.fieldType,
|
||||
value: field.default
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return settingsLoader.save(newFields)
|
||||
})
|
||||
}
|
||||
|
|
@ -7,6 +7,6 @@ module.exports = {setup}
|
|||
function setup (dataDir) {
|
||||
const coinRec = coinUtils.getCryptoCurrency('ETH')
|
||||
common.firewall([coinRec.defaultPort])
|
||||
const cmd = `/usr/local/bin/${coinRec.daemon} --datadir "${dataDir}" --cache 500`
|
||||
const cmd = `/usr/local/bin/${coinRec.daemon} --datadir "${dataDir}" --cache 500 --rpc`
|
||||
common.writeSupervisorConfig(coinRec, cmd)
|
||||
}
|
||||
|
|
|
|||
19
lib/migrate.js
Normal file
19
lib/migrate.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
const path = require('path')
|
||||
const migrate = require('migrate')
|
||||
|
||||
const options = require('./options')
|
||||
|
||||
const migrateDir = path.resolve(__dirname, '..', 'migrations')
|
||||
const migration = migrate.load(options.migrateStatePath, migrateDir)
|
||||
|
||||
module.exports = {run}
|
||||
|
||||
function run () {
|
||||
return new Promise((resolve, reject) => {
|
||||
migration.up(err => {
|
||||
if (err) return reject(err)
|
||||
return resolve(0)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -4,21 +4,32 @@ const os = require('os')
|
|||
const _ = require('lodash/fp')
|
||||
const argv = require('minimist')(process.argv.slice(2))
|
||||
|
||||
let serverConfig
|
||||
function load () {
|
||||
if (process.env.LAMASSU_CONFIG) {
|
||||
const configPath = process.env.LAMASSU_CONFIG
|
||||
return JSON.parse(fs.readFileSync(configPath))
|
||||
}
|
||||
|
||||
if (argv.f) {
|
||||
const configPath = argv.f
|
||||
return JSON.parse(fs.readFileSync(configPath))
|
||||
}
|
||||
|
||||
try {
|
||||
const globalConfigPath = path.resolve('/etc', 'lamassu', 'lamassu.json')
|
||||
serverConfig = JSON.parse(fs.readFileSync(globalConfigPath))
|
||||
return JSON.parse(fs.readFileSync(globalConfigPath))
|
||||
} catch (_) {
|
||||
try {
|
||||
const homeConfigPath = path.resolve(os.homedir(), '.lamassu', 'lamassu.json')
|
||||
serverConfig = JSON.parse(fs.readFileSync(homeConfigPath))
|
||||
return JSON.parse(fs.readFileSync(homeConfigPath))
|
||||
} catch (_) {
|
||||
console.error("Couldn't open lamassu.json config file.")
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const serverConfig = load()
|
||||
const defaults = {logLevel: 'info'}
|
||||
const commandLine = {logLevel: argv.logLevel}
|
||||
|
||||
|
|
|
|||
12
lib/plugins/ticker/mock-ticker/mock-ticker.js
Normal file
12
lib/plugins/ticker/mock-ticker/mock-ticker.js
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
const BN = require('../../../bn')
|
||||
|
||||
function ticker (account, fiatCode, cryptoCode) {
|
||||
return Promise.resolve({
|
||||
rates: {
|
||||
ask: BN(105),
|
||||
bid: BN(100)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = {ticker}
|
||||
|
|
@ -6,8 +6,8 @@ const NAME = 'FakeWallet'
|
|||
|
||||
const SECONDS = 1000
|
||||
const PUBLISH_TIME = 2 * SECONDS
|
||||
const AUTHORIZE_TIME = 8 * SECONDS
|
||||
const CONFIRM_TIME = 180 * SECONDS
|
||||
const AUTHORIZE_TIME = PUBLISH_TIME + 6 * SECONDS
|
||||
const CONFIRM_TIME = AUTHORIZE_TIME + 180 * SECONDS
|
||||
|
||||
let t0
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue