diff --git a/package-lock.json b/package-lock.json index eb1cab8d..54bad951 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "central-settlement", - "version": "8.1.0", + "version": "8.2.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -443,9 +443,9 @@ } }, "@hapi/joi": { - "version": "16.1.4", - "resolved": "https://registry.npmjs.org/@hapi/joi/-/joi-16.1.4.tgz", - "integrity": "sha512-m7ctezhxjob+dSpXnCNlgAj6rrEpdSsaWu3GWL3g1AybQCU36mlAo9IwGFJwIxD+oHgdO6mYyviYlaejX+qN6g==", + "version": "16.1.5", + "resolved": "https://registry.npmjs.org/@hapi/joi/-/joi-16.1.5.tgz", + "integrity": "sha512-FnVe0t1YQbF0H4fhFM6qBL7lIP4wdVHdFFBkloxgCkpKKdaCB6Z2UaNI0UalaDRHbRM9BvfTfyUKJg7tGtBSXg==", "requires": { "@hapi/address": "^2.1.2", "@hapi/formula": "^1.2.0", @@ -700,6 +700,27 @@ "ws": "7.1.2" }, "dependencies": { + "@hapi/joi": { + "version": "16.1.4", + "resolved": "https://registry.npmjs.org/@hapi/joi/-/joi-16.1.4.tgz", + "integrity": "sha512-m7ctezhxjob+dSpXnCNlgAj6rrEpdSsaWu3GWL3g1AybQCU36mlAo9IwGFJwIxD+oHgdO6mYyviYlaejX+qN6g==", + "requires": { + "@hapi/address": "^2.1.2", + "@hapi/formula": "^1.2.0", + "@hapi/hoek": "^8.2.4", + "@hapi/pinpoint": "^1.0.2", + "@hapi/topo": "^3.1.3" + } + }, + "@mojaloop/central-services-error-handling": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@mojaloop/central-services-error-handling/-/central-services-error-handling-7.5.0.tgz", + "integrity": "sha512-Spjllgyx6Y7En5vj7LaRVM5aTU+uuEykawPQaYzj3ZXAQdyHO4Slns8/ggwQ65T2qyMv1PXiqLK5dPBcIRlWYg==", + "requires": { + "@mojaloop/sdk-standard-components": "7.4.0", + "lodash": "4.17.15" + } + }, "@mojaloop/central-services-logger": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/@mojaloop/central-services-logger/-/central-services-logger-8.1.1.tgz", @@ -763,6 +784,11 @@ "url": "0.11.0" }, "dependencies": { + "bluebird": { + "version": "3.5.5", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", + "integrity": "sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==" + }, "commander": { "version": "2.20.1", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.1.tgz", @@ -793,12 +819,27 @@ } }, "@mojaloop/central-services-error-handling": { - "version": "7.5.0", - "resolved": "https://registry.npmjs.org/@mojaloop/central-services-error-handling/-/central-services-error-handling-7.5.0.tgz", - "integrity": "sha512-Spjllgyx6Y7En5vj7LaRVM5aTU+uuEykawPQaYzj3ZXAQdyHO4Slns8/ggwQ65T2qyMv1PXiqLK5dPBcIRlWYg==", + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/@mojaloop/central-services-error-handling/-/central-services-error-handling-8.2.0.tgz", + "integrity": "sha512-zXQf+DqlKA/ZmNLVAridULHTOyTDKXK5R6vVaf1stembIYlo+BonfxVwdQKovRxYZKSZ3ucc+HGUEor2Dm84RQ==", "requires": { - "@mojaloop/sdk-standard-components": "7.4.0", + "@mojaloop/sdk-standard-components": "8.1.0", "lodash": "4.17.15" + }, + "dependencies": { + "@mojaloop/sdk-standard-components": { + "version": "8.1.0", + "resolved": "https://registry.npmjs.org/@mojaloop/sdk-standard-components/-/sdk-standard-components-8.1.0.tgz", + "integrity": "sha512-RzCx4Au0jptn1k/f7trwzZpD+rewYn6b7sz6OCArC/8gV+yFHLmFo0iszrUgYiDtApk3SUMxuy4zJ1QFISDd3A==", + "requires": { + "base64url": "^3.0.1", + "ilp-packet": "2.2.0", + "jsonwebtoken": "^8.5.1", + "jws": "^3.2.2", + "request": "^2.34", + "request-promise-native": "^1.0.7" + } + } } }, "@mojaloop/central-services-health": { @@ -813,6 +854,15 @@ "tslib": "1.10.0" }, "dependencies": { + "@mojaloop/central-services-error-handling": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@mojaloop/central-services-error-handling/-/central-services-error-handling-7.5.0.tgz", + "integrity": "sha512-Spjllgyx6Y7En5vj7LaRVM5aTU+uuEykawPQaYzj3ZXAQdyHO4Slns8/ggwQ65T2qyMv1PXiqLK5dPBcIRlWYg==", + "requires": { + "@mojaloop/sdk-standard-components": "7.4.0", + "lodash": "4.17.15" + } + }, "@mojaloop/central-services-logger": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/@mojaloop/central-services-logger/-/central-services-logger-8.1.1.tgz", @@ -894,6 +944,15 @@ "raw-body": "2.4.1" }, "dependencies": { + "@mojaloop/central-services-error-handling": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@mojaloop/central-services-error-handling/-/central-services-error-handling-7.5.0.tgz", + "integrity": "sha512-Spjllgyx6Y7En5vj7LaRVM5aTU+uuEykawPQaYzj3ZXAQdyHO4Slns8/ggwQ65T2qyMv1PXiqLK5dPBcIRlWYg==", + "requires": { + "@mojaloop/sdk-standard-components": "7.4.0", + "lodash": "4.17.15" + } + }, "@mojaloop/central-services-logger": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/@mojaloop/central-services-logger/-/central-services-logger-8.1.1.tgz", @@ -918,6 +977,15 @@ "raw-body": "2.4.1" }, "dependencies": { + "@mojaloop/central-services-error-handling": { + "version": "7.5.0", + "resolved": "https://registry.npmjs.org/@mojaloop/central-services-error-handling/-/central-services-error-handling-7.5.0.tgz", + "integrity": "sha512-Spjllgyx6Y7En5vj7LaRVM5aTU+uuEykawPQaYzj3ZXAQdyHO4Slns8/ggwQ65T2qyMv1PXiqLK5dPBcIRlWYg==", + "requires": { + "@mojaloop/sdk-standard-components": "7.4.0", + "lodash": "4.17.15" + } + }, "@mojaloop/central-services-logger": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/@mojaloop/central-services-logger/-/central-services-logger-8.1.1.tgz", @@ -1005,6 +1073,21 @@ } } }, + "@mojaloop/ml-number": { + "version": "8.2.0", + "resolved": "https://registry.npmjs.org/@mojaloop/ml-number/-/ml-number-8.2.0.tgz", + "integrity": "sha512-9g08YprQ/6MdI3SfW+EGJ2uQ7oWhXw7vxTo55BUoVzrOnZckXXuJy/jsZSADjUAyQtm/+Bcl9mrRaOGNeS8ayA==", + "requires": { + "bignumber.js": "9.0.0" + }, + "dependencies": { + "bignumber.js": { + "version": "9.0.0", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.0.tgz", + "integrity": "sha512-t/OYhhJ2SD+YGBQcjY8GzzDHEk9f3nerxjtfa6tlMXfe7frs/WozhvCNoGvpM0P3bNf3Gq5ZRMlGr5f3r4/N8A==" + } + } + }, "@mojaloop/sdk-standard-components": { "version": "7.4.0", "resolved": "https://registry.npmjs.org/@mojaloop/sdk-standard-components/-/sdk-standard-components-7.4.0.tgz", @@ -1709,9 +1792,9 @@ } }, "bluebird": { - "version": "3.5.5", - "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.5.tgz", - "integrity": "sha512-5am6HnnfN+urzt4yfg7IgTbotDjIT/u8AJpEt0sIU9FtXfVeezXAPKswrG+xKUCOYAINpSdgZVDU6QFh+cuH3w==" + "version": "3.7.0", + "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.7.0.tgz", + "integrity": "sha512-aBQ1FxIa7kSWCcmKHlcHFlT2jt6J/l4FzC7KcPELkOJOsPOb/bccdhmIrKDfXhwFrmc7vDoDrrepFvGqjyXGJg==" }, "bn.js": { "version": "4.11.8", @@ -2896,9 +2979,9 @@ "integrity": "sha1-G2HAViGQqN/2rjuyzwIAyhMLhtQ=" }, "eslint": { - "version": "6.5.0", - "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.5.0.tgz", - "integrity": "sha512-IIbSW+vKOqMatPmS9ayyku4tvWxHY2iricSRtOz6+ZA5IPRlgXzEL0u/j6dr4eha0ugmhMwDTqxtmNu3kj9O4w==", + "version": "6.5.1", + "resolved": "https://registry.npmjs.org/eslint/-/eslint-6.5.1.tgz", + "integrity": "sha512-32h99BoLYStT1iq1v2P9uwpyznQ4M2jRiFB6acitKz52Gqn+vPaMDUTB1bYi1WN4Nquj2w+t+bimYUG83DC55A==", "dev": true, "requires": { "@babel/code-frame": "^7.0.0", diff --git a/package.json b/package.json index c88f2ee2..90cae965 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "central-settlement", "description": "Central settlements hosted by a scheme to record and make settlements", - "version": "8.1.0", + "version": "8.2.0", "license": "Apache-2.0", "private": false, "author": "ModusBox", @@ -30,12 +30,13 @@ "@mojaloop/central-ledger": "8.1.1", "@mojaloop/central-services-auth": "5.2.1", "@mojaloop/central-services-database": "7.4.0", - "@mojaloop/central-services-error-handling": "7.5.0", + "@mojaloop/central-services-error-handling": "8.2.0", "@mojaloop/central-services-health": "8.1.1", "@mojaloop/central-services-logger": "8.1.2", "@mojaloop/central-services-shared": "8.1.5", "@mojaloop/central-services-stream": "8.1.1", "@mojaloop/forensic-logging-client": "5.2.0", + "@mojaloop/ml-number": "8.2.0", "@now-ims/hapi-now-auth": "2.0.0", "blipp": "4.0.1", "hapi-auth-bearer-token": "6.2.1", @@ -46,9 +47,9 @@ "uuid4": "1.1.4" }, "devDependencies": { - "@hapi/joi": "16.1.4", - "bluebird": "3.5.5", - "eslint": "6.5.0", + "@hapi/joi": "16.1.5", + "bluebird": "3.7.0", + "eslint": "6.5.1", "faucet": "0.0.1", "node-fetch": "2.6.0", "nodemon": "1.19.3", diff --git a/src/models/settlement/facade.js b/src/models/settlement/facade.js index b947d1d7..7555da88 100644 --- a/src/models/settlement/facade.js +++ b/src/models/settlement/facade.js @@ -27,6 +27,7 @@ 'use strict' const ErrorHandler = require('@mojaloop/central-services-error-handling') +const MLNumber = require('@mojaloop/ml-number') const Db = require('../../lib/db') const Uuid = require('uuid4') const Crypto = require('crypto') @@ -282,13 +283,13 @@ const settlementTransfersReserve = async function (settlementId, transactionTime // TODO: insert new limit with correct value for startAfterParticipantPositionChangeId await ParticipantFacade.adjustLimits(dfspAccountId, { type: 'NET_DEBIT_CAP', - value: netDebitCap + dfspAmount + value: new MLNumber(netDebitCap).add(dfspAmount).toNumber() }, trx) } // Persist dfsp latestPosition await knex('participantPosition') - .update('value', dfspPositionValue + dfspAmount) + .update('value', new MLNumber(dfspPositionValue).add(dfspAmount).toNumber()) .where('participantPositionId', dfspPositionId) .transacting(trx) @@ -297,7 +298,7 @@ const settlementTransfersReserve = async function (settlementId, transactionTime .insert({ participantPositionId: dfspPositionId, transferStateChangeId: transferStateChangeId, - value: dfspPositionValue + dfspAmount, + value: new MLNumber(dfspPositionValue).add(dfspAmount).toNumber(), reservedValue: dfspReservedValue, createdDate: transactionTimestamp }) @@ -308,7 +309,7 @@ const settlementTransfersReserve = async function (settlementId, transactionTime const destination = dfspName const payload = { currency: currencyId, - value: dfspPositionValue + dfspAmount, + value: new MLNumber(dfspPositionValue).add(dfspAmount).toNumber(), changedDate: new Date().toISOString() } const message = Facade.getNotificationMessage(action, destination, payload) @@ -324,7 +325,7 @@ const settlementTransfersReserve = async function (settlementId, transactionTime // Persist hub latestPosition await knex('participantPosition') - .update('value', hubPositionValue + hubAmount) + .update('value', new MLNumber(hubPositionValue).add(hubAmount).toNumber()) .where('participantPositionId', hubPositionId) .transacting(trx) @@ -333,7 +334,7 @@ const settlementTransfersReserve = async function (settlementId, transactionTime .insert({ participantPositionId: hubPositionId, transferStateChangeId: transferStateChangeId, - value: hubPositionValue + hubAmount, + value: new MLNumber(hubPositionValue).add(hubAmount).toNumber(), reservedValue: 0, createdDate: transactionTimestamp }) @@ -616,7 +617,7 @@ const settlementTransfersCommit = async function (settlementId, transactionTimes // Persist dfsp latestPosition await knex('participantPosition') - .update('value', dfspPositionValue + dfspAmount) + .update('value', new MLNumber(dfspPositionValue).add(dfspAmount).toNumber()) .where('participantPositionId', dfspPositionId) .transacting(trx) @@ -625,7 +626,7 @@ const settlementTransfersCommit = async function (settlementId, transactionTimes .insert({ participantPositionId: dfspPositionId, transferStateChangeId: transferStateChangeId, - value: dfspPositionValue + dfspAmount, + value: new MLNumber(dfspPositionValue).add(dfspAmount).toNumber(), reservedValue: dfspReservedValue, createdDate: transactionTimestamp }) @@ -641,7 +642,7 @@ const settlementTransfersCommit = async function (settlementId, transactionTimes // Persist hub latestPosition await knex('participantPosition') - .update('value', hubPositionValue + hubAmount) + .update('value', new MLNumber(hubPositionValue).add(hubAmount).toNumber()) .where('participantPositionId', hubPositionId) .transacting(trx) @@ -650,7 +651,7 @@ const settlementTransfersCommit = async function (settlementId, transactionTimes .insert({ participantPositionId: hubPositionId, transferStateChangeId: transferStateChangeId, - value: hubPositionValue + hubAmount, + value: new MLNumber(hubPositionValue).add(hubAmount).toNumber(), reservedValue: 0, createdDate: transactionTimestamp }) @@ -661,7 +662,7 @@ const settlementTransfersCommit = async function (settlementId, transactionTimes const destination = dfspName const payload = { currency: currencyId, - value: dfspPositionValue + dfspAmount, + value: new MLNumber(dfspPositionValue).add(dfspAmount).toNumber(), changedDate: new Date().toISOString() } const message = Facade.getNotificationMessage(action, destination, payload) diff --git a/test/integration-runner.sh b/test/integration-runner.sh index b3e9e5d0..23c70dfc 100644 --- a/test/integration-runner.sh +++ b/test/integration-runner.sh @@ -355,7 +355,7 @@ docker logs $APP_HOST >&1 echo "Copy results to local directory" docker cp $APP_HOST:$DOCKER_WORKING_DIR/$APP_DIR_TEST_RESULTS $TEST_DIR -if [ "$test_exit_code" == 0 ] +if [ "$test_exit_code" = "0" ] then >&1 echo "Showing results..." cat $APP_DIR_TEST_RESULTS/$TEST_RESULTS_FILE diff --git a/test/integration/settlementTransfer.test.js b/test/integration/settlementTransfer.test.js index d53fc605..831fdc41 100644 --- a/test/integration/settlementTransfer.test.js +++ b/test/integration/settlementTransfer.test.js @@ -26,6 +26,7 @@ const Test = require('tapes')(require('tape')) const Sinon = require('sinon') const Logger = require('@mojaloop/central-services-logger') +const MLNumber = require('@mojaloop/ml-number') const PrepareTransferData = require('./helpers/transferData') const Models = require('./helpers/models') const Config = require('../../src/lib/config') @@ -307,7 +308,7 @@ Test('SettlementTransfer should', async settlementTransferTest => { test.equal(currentPayerPosition, initialPayerPosition, 'position for NET_SETTLEMENT_SENDER is not changed') const currentPayeePosition = (await ParticipantPositionModel.getPositionByCurrencyId(netRecipientAccountId)).value - test.equal(currentPayeePosition, initialPayeePosition + netSettlementAmount, 'position for NET_SETTLEMENT_RECIPIENT is adjusted') + test.equal(currentPayeePosition, new MLNumber(initialPayeePosition).add(netSettlementAmount).toNumber(), 'position for NET_SETTLEMENT_RECIPIENT is adjusted') test.end() } catch (err) {