Merge pull request #528 from csrapr/fix/coinatmradar-fix-7.5
Fix/coinatmradar fix 7.5 - error 400 request response fix
This commit is contained in:
commit
b1d6c5c7a5
5 changed files with 4965 additions and 28 deletions
|
|
@ -24,7 +24,6 @@ module.exports = { update }
|
|||
function mapCoin (rates, deviceId, settings, cryptoCode) {
|
||||
const config = settings.config
|
||||
const buildedRates = plugins(settings, deviceId).buildRates(rates)[cryptoCode] || { cashIn: null, cashOut: null }
|
||||
|
||||
const commissions = configManager.getCommissions(cryptoCode, deviceId, config)
|
||||
const coinAtmRadar = configManager.getCoinAtmRadar(config)
|
||||
|
||||
|
|
@ -64,28 +63,17 @@ function mapMachine (rates, settings, machineRow) {
|
|||
|
||||
const coinAtmRadar = configManager.getCoinAtmRadar(config)
|
||||
const triggers = configManager.getTriggers(config)
|
||||
const triggerCashLimit = complianceTriggers.getCashLimit(triggers)
|
||||
const locale = configManager.getLocale(deviceId, config)
|
||||
const cashOutConfig = configManager.getCashOut(deviceId, config)
|
||||
const cashOutEnabled = cashOutConfig.active ? cashOutConfig.active : false
|
||||
|
||||
const lastOnline = machineRow.last_online.toISOString()
|
||||
const status = machineRow.stale ? 'online' : 'offline'
|
||||
const showSupportedCryptocurrencies = coinAtmRadar.supportedCryptocurrencies
|
||||
const showSupportedFiat = coinAtmRadar.supportedFiat
|
||||
const showSupportedBuySellDirection = coinAtmRadar.supportedBuySellDirection
|
||||
const showLimitsAndVerification = coinAtmRadar.limitsAndVerification
|
||||
|
||||
const cashLimit = showLimitsAndVerification ? ( triggerCashLimit || Infinity ) : null
|
||||
|
||||
const cashLimit = showLimitsAndVerification ? ( complianceTriggers.getCashLimit(triggers)?.threshold || Infinity ) : null
|
||||
const cryptoCurrencies = locale.cryptoCurrencies
|
||||
const cashInEnabled = showSupportedBuySellDirection ? true : null
|
||||
const cashOutEnabled = showSupportedBuySellDirection ? cashOutConfig.active : null
|
||||
const fiat = showSupportedFiat ? locale.fiatCurrency : null
|
||||
const identification = mapIdentification(config)
|
||||
const coins = showSupportedCryptocurrencies ?
|
||||
_.map(_.partial(mapCoin, [rates, deviceId, settings]), cryptoCurrencies)
|
||||
: null
|
||||
|
||||
const coins = _.map(_.partial(mapCoin, [rates, deviceId, settings]), cryptoCurrencies)
|
||||
return {
|
||||
machineId: deviceId,
|
||||
address: {
|
||||
|
|
@ -102,14 +90,14 @@ function mapMachine (rates, settings, machineRow) {
|
|||
},
|
||||
status,
|
||||
lastOnline,
|
||||
cashIn: cashInEnabled,
|
||||
cashIn: true,
|
||||
cashOut: cashOutEnabled,
|
||||
manufacturer: 'lamassu',
|
||||
cashInTxLimit: cashLimit,
|
||||
cashOutTxLimit: cashLimit,
|
||||
cashInDailyLimit: cashLimit,
|
||||
cashOutDailyLimit: cashLimit,
|
||||
fiatCurrency: fiat,
|
||||
fiatCurrency: locale.fiatCurrency,
|
||||
identification,
|
||||
coins
|
||||
}
|
||||
|
|
@ -120,7 +108,6 @@ function getMachines (rates, settings) {
|
|||
where display=TRUE and
|
||||
paired=TRUE
|
||||
order by created`
|
||||
|
||||
return db.any(sql, [STALE_INTERVAL])
|
||||
.then(_.map(_.partial(mapMachine, [rates, settings])))
|
||||
}
|
||||
|
|
@ -140,9 +127,7 @@ function sendRadar (data) {
|
|||
maxContentLength: MAX_CONTENT_LENGTH
|
||||
}
|
||||
|
||||
console.log('%j', data)
|
||||
|
||||
return axios(config)
|
||||
return axios.default(config)
|
||||
.then(r => console.log(r.status))
|
||||
}
|
||||
|
||||
|
|
|
|||
259
lib/coinatmradar/test/coinatmradar.test.js
Normal file
259
lib/coinatmradar/test/coinatmradar.test.js
Normal file
|
|
@ -0,0 +1,259 @@
|
|||
const yup = require('yup')
|
||||
const BigNumber = require('../../../lib/bn')
|
||||
const car = require('../coinatmradar')
|
||||
const db = require('../../db')
|
||||
|
||||
jest.mock('../../db')
|
||||
|
||||
afterEach(() => {
|
||||
// https://stackoverflow.com/questions/58151010/difference-between-resetallmocks-resetmodules-resetmoduleregistry-restoreallm
|
||||
jest.restoreAllMocks()
|
||||
})
|
||||
|
||||
const settings = {
|
||||
config: {
|
||||
wallets_BTC_coin: 'BTC',
|
||||
wallets_BTC_wallet: 'mock-wallet',
|
||||
wallets_BTC_ticker: 'kraken',
|
||||
wallets_BTC_exchange: 'mock-exchange',
|
||||
wallets_BTC_zeroConf: 'all-zero-conf',
|
||||
locale_id: '1983951f-6c73-4308-ae6e-f6f56dfa5e11',
|
||||
locale_country: 'US',
|
||||
locale_fiatCurrency: 'USD',
|
||||
locale_languages: ['en-US'],
|
||||
locale_cryptoCurrencies: ['BTC', 'ETH', 'LTC', 'DASH', 'ZEC', 'BCH'],
|
||||
commissions_minimumTx: 1,
|
||||
commissions_fixedFee: 2,
|
||||
commissions_cashOut: 11,
|
||||
commissions_cashIn: 11,
|
||||
commissions_id: '960bb192-db37-40eb-9b59-2c2c78620de6',
|
||||
wallets_ETH_active: true,
|
||||
wallets_ETH_ticker: 'bitstamp',
|
||||
wallets_ETH_wallet: 'mock-wallet',
|
||||
wallets_ETH_exchange: 'mock-exchange',
|
||||
wallets_ETH_zeroConf: 'mock-zero-conf',
|
||||
wallets_LTC_active: true,
|
||||
wallets_LTC_ticker: 'kraken',
|
||||
wallets_LTC_wallet: 'mock-wallet',
|
||||
wallets_LTC_exchange: 'mock-exchange',
|
||||
wallets_LTC_zeroConf: 'mock-zero-conf',
|
||||
wallets_DASH_active: true,
|
||||
wallets_DASH_ticker: 'coinbase',
|
||||
wallets_DASH_wallet: 'mock-wallet',
|
||||
wallets_DASH_exchange: 'mock-exchange',
|
||||
wallets_DASH_zeroConf: 'mock-zero-conf',
|
||||
wallets_ZEC_active: true,
|
||||
wallets_ZEC_ticker: 'coinbase',
|
||||
wallets_ZEC_wallet: 'mock-wallet',
|
||||
wallets_ZEC_exchange: 'mock-exchange',
|
||||
wallets_ZEC_zeroConf: 'mock-zero-conf',
|
||||
wallets_BCH_active: true,
|
||||
wallets_BCH_ticker: 'bitpay',
|
||||
wallets_BCH_wallet: 'mock-wallet',
|
||||
wallets_BCH_exchange: 'mock-exchange',
|
||||
wallets_BCH_zeroConf: 'mock-zero-conf',
|
||||
cashOut_7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4_zeroConfLimit: 50,
|
||||
cashOut_7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4_bottom: 20,
|
||||
cashOut_7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4_top: 5,
|
||||
cashOut_7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4_active: true,
|
||||
cashOut_f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05_zeroConfLimit: 200,
|
||||
cashOut_f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05_bottom: 20,
|
||||
cashOut_f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05_top: 5,
|
||||
cashOut_f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05_active: true,
|
||||
notifications_email_active: false,
|
||||
notifications_sms_active: true,
|
||||
notifications_email_errors: false,
|
||||
notifications_sms_errors: true,
|
||||
coinAtmRadar_active: true,
|
||||
coinAtmRadar_commissions: true,
|
||||
coinAtmRadar_limitsAndVerification: true,
|
||||
triggers: [
|
||||
{
|
||||
requirement: 'suspend',
|
||||
suspensionDays: 1,
|
||||
threshold: 123,
|
||||
id: '9c3b5af8-b1d1-4125-b169-0e913b33894c',
|
||||
direction: 'both',
|
||||
triggerType: 'txAmount'
|
||||
},
|
||||
{
|
||||
requirement: 'sms',
|
||||
threshold: 999,
|
||||
thresholdDays: 1,
|
||||
id: 'b0e1e6a8-be1b-4e43-ac5f-3e4951e86f8b',
|
||||
direction: 'both',
|
||||
triggerType: 'txVelocity'
|
||||
},
|
||||
{
|
||||
requirement: 'sms',
|
||||
threshold: 888,
|
||||
thresholdDays: 1,
|
||||
id: '6ac38fe6-172c-48a4-8a7f-605213cbd600',
|
||||
direction: 'both',
|
||||
triggerType: 'txVolume'
|
||||
}
|
||||
],
|
||||
notifications_sms_transactions: true,
|
||||
notifications_highValueTransaction: 50
|
||||
},
|
||||
accounts: {}
|
||||
}
|
||||
|
||||
const rates = [
|
||||
{
|
||||
rates: {
|
||||
ask: BigNumber(19164.3),
|
||||
bid: BigNumber(19164.2)
|
||||
},
|
||||
timestamp: +new Date()
|
||||
},
|
||||
{
|
||||
rates: {
|
||||
ask: BigNumber(594.54),
|
||||
bid: BigNumber(594.09)
|
||||
},
|
||||
timestamp: +new Date()
|
||||
},
|
||||
{
|
||||
rates: {
|
||||
ask: BigNumber(84.38),
|
||||
bid: BigNumber(84.37)
|
||||
},
|
||||
timestamp: +new Date()
|
||||
},
|
||||
{
|
||||
rates: {
|
||||
ask: BigNumber(102.8),
|
||||
bid: BigNumber(101.64)
|
||||
},
|
||||
timestamp: +new Date()
|
||||
},
|
||||
{
|
||||
rates: {
|
||||
ask: BigNumber(74.91),
|
||||
bid: BigNumber(74.12)
|
||||
},
|
||||
timestamp: +new Date()
|
||||
},
|
||||
{
|
||||
rates: {
|
||||
ask: BigNumber(284.4),
|
||||
bid: BigNumber(284.4)
|
||||
},
|
||||
timestamp: +new Date()
|
||||
}
|
||||
]
|
||||
|
||||
const dbResponse = [
|
||||
{
|
||||
device_id:
|
||||
'mock7e531a2666987aa27b9917ca17df7998f72771c57fdb21c90bc033999edd17e4',
|
||||
last_online: new Date('2020-11-16T13:11:03.169Z'),
|
||||
stale: false
|
||||
},
|
||||
{
|
||||
device_id:
|
||||
'9871e58aa2643ff9445cbc299b50397430ada75157d6c29b4c93548fff0f48f7',
|
||||
last_online: new Date('2020-11-16T16:21:35.948Z'),
|
||||
stale: false
|
||||
},
|
||||
{
|
||||
device_id:
|
||||
'5ae0d02dedeb77b6521bd5eb7c9159bdc025873fa0bcb6f87aaddfbda0c50913',
|
||||
last_online: new Date('2020-11-19T15:07:57.089Z'),
|
||||
stale: false
|
||||
},
|
||||
{
|
||||
device_id:
|
||||
'f02af604ca9010bd9ae04c427a24da90130da10d355f0a9b235886a89008fc05',
|
||||
last_online: new Date('2020-11-26T20:05:57.792Z'),
|
||||
stale: false
|
||||
},
|
||||
{
|
||||
device_id:
|
||||
'490ab16ee0c124512dc769be1f3e7ee3894ce1e5b4b8b975e134fb326e551e88',
|
||||
last_online: new Date('2020-12-04T16:48:05.129Z'),
|
||||
stale: false
|
||||
}
|
||||
]
|
||||
|
||||
function validateData(data) {
|
||||
const schema = yup.object().shape({
|
||||
operatorId: yup.string().required('operatorId not provided'),
|
||||
operator: yup.object().shape({
|
||||
name: yup.string().nullable(),
|
||||
phone: yup.string().nullable(),
|
||||
email: yup.string().email().nullable()
|
||||
}),
|
||||
timestamp: yup.string().required('timestamp not provided'),
|
||||
machines: yup.array().of(
|
||||
yup.object().shape({
|
||||
machineId: yup.string().required('machineId not provided'),
|
||||
address: yup.object().required('address object not provided').shape({
|
||||
streetAddress: yup.string().nullable(),
|
||||
city: yup.string().nullable(),
|
||||
region: yup.string().nullable(),
|
||||
postalCode: yup.string().nullable(),
|
||||
country: yup.string().nullable()
|
||||
}),
|
||||
location: yup.object().required('location object not provided').shape({
|
||||
name: yup.string().nullable(),
|
||||
url: yup.string().nullable(),
|
||||
phone: yup.string().nullable()
|
||||
}),
|
||||
status: yup
|
||||
.string()
|
||||
.required('status not provided')
|
||||
.oneOf(['online', 'offline']),
|
||||
lastOnline: yup
|
||||
.string()
|
||||
.required('date in isostring format not provided'),
|
||||
cashIn: yup.boolean().required('cashIn boolean not defined'),
|
||||
cashOut: yup.boolean().required('cashOut boolean not defined'),
|
||||
manufacturer: yup.string().required('manufacturer not provided'),
|
||||
cashInTxLimit: yup.number().nullable(),
|
||||
cashOutTxLimit: yup.number().nullable(),
|
||||
cashInDailyLimit: yup.number().nullable(),
|
||||
cashOutDailyLimit: yup.number().nullable(),
|
||||
fiatCurrency: yup.string().required('fiatCurrency not provided'),
|
||||
identification: yup.object().shape({
|
||||
isPhone: yup.boolean().required('isPhone boolean not defined'),
|
||||
isPalmVein: yup.boolean().required('isPalmVein boolean not defined'),
|
||||
isPhoto: yup.boolean().required('isPhoto boolean not defined'),
|
||||
isIdDocScan: yup
|
||||
.boolean()
|
||||
.required('isIdDocScan boolean not defined'),
|
||||
isFingerprint: yup
|
||||
.boolean()
|
||||
.required('isFingerprint boolean not defined')
|
||||
}),
|
||||
coins: yup.array().of(
|
||||
yup.object().shape({
|
||||
cryptoCode: yup.string().required('cryptoCode not provided'),
|
||||
cashInFee: yup.number().nullable(),
|
||||
cashOutFee: yup.number().nullable(),
|
||||
cashInFixedFee: yup.number().nullable(),
|
||||
cashInRate: yup.number().nullable(),
|
||||
cashOutRate: yup.number().nullable()
|
||||
})
|
||||
)
|
||||
})
|
||||
)
|
||||
})
|
||||
return schema.validate(data)
|
||||
}
|
||||
|
||||
test('Verify axios request schema', async () => {
|
||||
const axios = require('axios')
|
||||
|
||||
jest.spyOn(axios, 'default').mockImplementation(
|
||||
jest.fn(req =>
|
||||
validateData(req.data)
|
||||
.then(() => ({ status: 'mock status 200' }))
|
||||
.catch(e => fail(e))
|
||||
)
|
||||
)
|
||||
|
||||
db.any.mockResolvedValue(dbResponse)
|
||||
await car.update(rates, settings)
|
||||
})
|
||||
|
|
@ -15,9 +15,8 @@ function maxDaysThreshold (triggers) {
|
|||
}
|
||||
|
||||
function getCashLimit (triggers) {
|
||||
const withFiat = _.filter(({ triggerType }) => _.includes(['txVolume', 'txAmount'])(triggerType))
|
||||
const blocking = _.filter(({ requirement }) => _.includes(['block', 'suspend'])(requirement))
|
||||
|
||||
const withFiat = _.filter(({ triggerType }) => _.includes(triggerType, ['txVolume', 'txAmount']))
|
||||
const blocking = _.filter(({ requirement }) => _.includes(requirement, ['block', 'suspend']))
|
||||
return _.compose(_.minBy('threshold'), blocking, withFiat)(triggers)
|
||||
}
|
||||
|
||||
|
|
|
|||
4697
package-lock.json
generated
4697
package-lock.json
generated
File diff suppressed because it is too large
Load diff
|
|
@ -75,7 +75,8 @@
|
|||
"winston-transport": "^4.3.0",
|
||||
"ws": "^3.1.0",
|
||||
"xml-stream": "^0.4.5",
|
||||
"xmlrpc": "^1.3.2"
|
||||
"xmlrpc": "^1.3.2",
|
||||
"yup": "^0.31.1"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
|
|
@ -109,6 +110,7 @@
|
|||
"scripts": {
|
||||
"start": "node bin/lamassu-server",
|
||||
"test": "mocha --recursive tests",
|
||||
"jtest": "jest",
|
||||
"build-admin": "npm run build-admin:css && npm run build-admin:main && npm run build-admin:lamassu",
|
||||
"server": "nodemon bin/lamassu-server --mockSms",
|
||||
"admin-server": "nodemon bin/lamassu-admin-server --dev",
|
||||
|
|
@ -123,6 +125,7 @@
|
|||
"devDependencies": {
|
||||
"ava": "3.8.2",
|
||||
"concurrently": "^5.3.0",
|
||||
"jest": "^26.6.3",
|
||||
"mocha": "^5.0.1",
|
||||
"nodemon": "^2.0.6",
|
||||
"rewire": "^4.0.1",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue