@mojaloop/central-ledger 9.2.2 → 15.1.3-snapshot.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +625 -204
- package/.env +3 -2
- package/.ncurc.yaml +9 -0
- package/.nvmrc +1 -1
- package/.versionrc +15 -0
- package/CHANGELOG.md +353 -0
- package/CODEOWNERS +31 -0
- package/Dockerfile +20 -14
- package/LICENSE.md +4 -4
- package/Onboarding.md +0 -7
- package/README.md +99 -22
- package/audit-resolve.json +136 -1
- package/config/default.json +82 -27
- package/docker/central-ledger/default.json +68 -21
- package/docker/ml-api-adapter/default.json +10 -1
- package/docker/wait-for/wait-for-objstore.sh +1 -6
- package/docker/wait-for/wait-for.env +1 -1
- package/docker-compose.integration.yml +8 -5
- package/docker-compose.yml +73 -16
- package/migrations/310203_transferParticipant-indexes.js +38 -0
- package/migrations/310503_participantLimit-indexes-composite.js +38 -0
- package/migrations/{400401_settlementWindowStateChange-indexes.js → 400401_settlmentWindowStateChange-indexes.js} +0 -0
- package/migrations/401301_settlementModel-indexes.js +2 -0
- package/migrations/500401_quote-hotfix-2719.js +58 -0
- package/migrations/500501_feature-fixSubIdRef.js +53 -0
- package/migrations/500601_party-2480.js +63 -0
- package/migrations/501001_quoteExtension-quote-service-174.js +46 -0
- package/migrations/501002_quoteExtension-2522.js +61 -0
- package/migrations/800101_feature-fixSubIdRef.js +90 -0
- package/migrations/910102_hotfix954.js +4 -1
- package/migrations/940100_quotePartyIdInfoExtension.js +52 -0
- package/migrations/940101_quotePartyIdInfoExtension-2522.js +64 -0
- package/migrations/950100_settlementContentAggregation-decimal184.js +40 -0
- package/migrations/950101_transferParticipantStateChange.js +46 -0
- package/migrations/950102_settlementModel-adjustPosition.js +42 -0
- package/migrations/950103_dropTransferParticipantStateChange.js +47 -0
- package/migrations/950104_settlementModel-settlementAccountTypeId.js +79 -0
- package/migrations/950106_unique_settlement_model_ledger_account_currency.js +38 -0
- package/migrations/950107_settlementWindowContent_foreign_settlementModel.js +60 -0
- package/package.json +99 -81
- package/scripts/_wait4_all.js +146 -0
- package/seeds/amountType.js +4 -6
- package/seeds/balanceOfPayments.js +4 -6
- package/seeds/bulkProcessingState.js +4 -6
- package/seeds/bulkTransferState.js +4 -6
- package/seeds/currency.js +4 -6
- package/seeds/endpointType.js +128 -7
- package/seeds/ledgerAccountType.js +11 -10
- package/seeds/ledgerEntryType.js +5 -7
- package/seeds/participant.js +4 -6
- package/seeds/participantLimitType.js +4 -6
- package/seeds/partyIdentifierType.js +4 -6
- package/seeds/partyType.js +4 -6
- package/seeds/settlementDelay.js +4 -6
- package/seeds/settlementGranularity.js +4 -6
- package/seeds/settlementInterchange.js +4 -6
- package/seeds/settlementState.js +4 -6
- package/seeds/settlementWindow1State.js +4 -6
- package/seeds/transactionInitiator.js +4 -6
- package/seeds/transactionInitiatorType.js +4 -6
- package/seeds/transactionScenario.js +4 -6
- package/seeds/transferParticipantRoleType.js +4 -6
- package/seeds/transferState.js +9 -6
- package/src/api/interface/swagger.json +728 -948
- package/src/api/ledgerAccountTypes/handler.js +55 -0
- package/src/api/ledgerAccountTypes/routes.js +63 -0
- package/src/api/metrics/handler.js +2 -2
- package/src/api/metrics/routes.js +1 -1
- package/src/api/participants/handler.js +43 -35
- package/src/api/participants/routes.js +13 -13
- package/src/api/root/routes.js +2 -2
- package/src/api/settlementModels/handler.js +9 -26
- package/src/api/settlementModels/routes.js +4 -4
- package/src/api/transactions/handler.js +46 -0
- package/src/api/transactions/routes.js +45 -0
- package/src/domain/bulkTransfer/index.js +6 -5
- package/src/domain/ledgerAccountTypes/index.js +58 -0
- package/src/domain/participant/index.js +55 -4
- package/src/domain/position/index.js +18 -2
- package/src/domain/settlement/index.js +39 -6
- package/src/domain/transactions/index.js +61 -0
- package/src/domain/transfer/index.js +22 -2
- package/src/domain/transfer/transform.js +3 -3
- package/src/handlers/admin/handler.js +24 -32
- package/src/handlers/bulk/fulfil/handler.js +89 -56
- package/src/handlers/bulk/get/handler.js +203 -0
- package/src/handlers/bulk/index.js +4 -1
- package/src/handlers/bulk/prepare/handler.js +30 -29
- package/src/handlers/bulk/processing/handler.js +61 -32
- package/src/handlers/bulk/shared/validator.js +13 -1
- package/src/handlers/index.js +18 -9
- package/src/handlers/positions/handler.js +67 -46
- package/src/handlers/register.js +7 -7
- package/src/handlers/timeouts/handler.js +9 -4
- package/src/handlers/transfers/handler.js +408 -182
- package/src/handlers/transfers/validator.js +41 -11
- package/src/lib/cache.js +8 -34
- package/src/lib/config.js +5 -7
- package/src/lib/enum.js +22 -22
- package/src/lib/enumCached.js +76 -0
- package/src/lib/healthCheck/subServiceHealth.js +2 -2
- package/src/lib/requestLogger.js +9 -9
- package/src/lib/urlParser.js +1 -1
- package/src/models/bulkTransfer/bulkTransfer.js +6 -6
- package/src/models/bulkTransfer/bulkTransferAssociation.js +3 -3
- package/src/models/bulkTransfer/bulkTransferDuplicateCheck.js +4 -4
- package/src/models/bulkTransfer/bulkTransferExtension.js +2 -2
- package/src/models/bulkTransfer/bulkTransferFulfilmentDuplicateCheck.js +4 -4
- package/src/models/bulkTransfer/bulkTransferStateChange.js +7 -7
- package/src/models/bulkTransfer/facade.js +54 -3
- package/src/models/bulkTransfer/individualTransfer.js +2 -2
- package/src/models/ilpPackets/ilpPacket.js +36 -0
- package/src/models/ledgerAccountType/ledgerAccountType.js +139 -3
- package/src/models/misc/migrationLock.js +1 -1
- package/src/models/misc/segment.js +1 -1
- package/src/models/participant/facade.js +226 -76
- package/src/models/participant/participant.js +6 -5
- package/src/models/participant/participantCached.js +8 -0
- package/src/models/participant/participantCurrency.js +7 -7
- package/src/models/participant/participantCurrencyCached.js +11 -1
- package/src/models/participant/participantLimit.js +13 -13
- package/src/models/participant/participantLimitCached.js +124 -0
- package/src/models/participant/participantPosition.js +34 -5
- package/src/models/participant/participantPositionChange.js +10 -2
- package/src/models/position/facade.js +112 -18
- package/src/models/position/participantPosition.js +6 -6
- package/src/models/settlement/settlementModel.js +92 -17
- package/src/models/settlement/settlementModelCached.js +139 -0
- package/src/models/transfer/facade.js +97 -32
- package/src/models/transfer/ilpPacket.js +4 -4
- package/src/models/transfer/transfer.js +7 -7
- package/src/models/transfer/transferDuplicateCheck.js +21 -5
- package/src/models/transfer/transferError.js +5 -5
- package/src/models/transfer/transferErrorDuplicateCheck.js +4 -4
- package/src/models/transfer/transferExtension.js +4 -4
- package/src/models/transfer/transferFulfilment.js +5 -5
- package/src/models/transfer/transferFulfilmentDuplicateCheck.js +4 -4
- package/src/models/transfer/transferParticipant.js +3 -3
- package/src/models/transfer/transferStateChange.js +11 -11
- package/src/models/transfer/transferTimeout.js +5 -5
- package/src/schema/bulkTransfer.js +4 -4
- package/src/shared/plugins.js +10 -9
- package/src/shared/setup.js +69 -46
- package/test/integration/domain/participant/index.test.js +2 -0
- package/test/integration/handlers/handlers.test.js +605 -166
- package/test/integration/handlers/root.test.js +1 -1
- package/test/integration/helpers/hubAccounts.js +62 -0
- package/test/integration/helpers/ilpPacket.js +1 -1
- package/test/integration/helpers/participantFundsInOut.js +80 -0
- package/test/integration/helpers/participantLimit.js +6 -1
- package/test/integration/helpers/settlementModels.js +88 -0
- package/test/integration/helpers/testConsumer.js +163 -0
- package/test/integration/helpers/testProducer.js +0 -1
- package/test/integration/helpers/transferDuplicateCheck.js +1 -1
- package/test/integration/helpers/transferStateChange.js +1 -1
- package/test/integration/helpers/transferTestHelper.js +3 -5
- package/test/integration/models/transfer/transferStateChange.test.js +6 -0
- package/test/unit/api/ledgerAccountTypes/handler.test.js +126 -0
- package/test/unit/api/ledgerAccountTypes/routes.test.js +52 -0
- package/test/unit/api/participants/handler.test.js +75 -33
- package/test/unit/api/root/handler.test.js +1 -1
- package/test/unit/api/root/routes.test.js +2 -2
- package/test/unit/api/settlementModels/handler.test.js +21 -57
- package/test/unit/api/transactions/handler.test.js +108 -0
- package/test/unit/api/transactions/routes.test.js +38 -0
- package/test/unit/domain/ledgerAccountTypes/index.test.js +197 -0
- package/test/unit/domain/participant/index.test.js +115 -2
- package/test/unit/domain/settlement/index.test.js +199 -29
- package/test/unit/domain/transactions/index.test.js +128 -0
- package/test/unit/domain/transfer/index.test.js +1 -0
- package/test/unit/domain/transfer/transform.test.js +2 -0
- package/test/unit/handlers/admin/handler.test.js +5 -5
- package/test/unit/handlers/bulk/get/handler.test.js +401 -0
- package/test/unit/handlers/index.test.js +6 -0
- package/test/unit/handlers/positions/handler.test.js +26 -0
- package/test/unit/handlers/register.test.js +2 -0
- package/test/unit/handlers/transfers/handler.test.js +491 -36
- package/test/unit/handlers/transfers/validator.test.js +31 -31
- package/test/unit/lib/cache.test.js +0 -64
- package/test/unit/lib/cachingOfEnums.test.js +121 -0
- package/test/unit/lib/config.test.js +34 -0
- package/test/unit/lib/enum.test.js +6 -1
- package/test/unit/lib/enumCached.test.js +82 -0
- package/test/unit/lib/healthCheck/subServiceHealth.test.js +2 -0
- package/test/unit/lib/requestLogger.test.js +14 -12
- package/test/unit/models/ilpPackets/ilpPacket.test.js +89 -0
- package/test/unit/models/ledgerAccountType/ledgerAccountType.test.js +255 -6
- package/test/unit/models/misc/migrationLock.test.js +4 -0
- package/test/unit/models/misc/segment.test.js +5 -0
- package/test/unit/models/participant/facade.test.js +493 -54
- package/test/unit/models/participant/participant.test.js +4 -0
- package/test/unit/models/participant/participantCurrency.test.js +22 -9
- package/test/unit/models/participant/participantCurrencyCached.test.js +1 -1
- package/test/unit/models/participant/participantLimit.test.js +97 -0
- package/test/unit/models/participant/participantLimitCached.test.js +232 -0
- package/test/unit/models/participant/participantPosition.test.js +217 -0
- package/test/unit/models/participant/participantPositionChange.test.js +3 -0
- package/test/unit/models/position/facade.test.js +318 -29
- package/test/unit/models/position/participantPosition.test.js +22 -7
- package/test/unit/models/settlement/settlementModel.test.js +18 -37
- package/test/unit/models/settlement/settlementModelCached.test.js +171 -0
- package/test/unit/models/transfer/facade.test.js +115 -0
- package/test/unit/models/transfer/ilpPacket.test.js +28 -11
- package/test/unit/models/transfer/transfer.test.js +13 -4
- package/test/unit/models/transfer/transferDuplicateCheck.test.js +4 -0
- package/test/unit/models/transfer/transferError.test.js +5 -1
- package/test/unit/models/transfer/transferErrorDuplicateCheck.test.js +4 -0
- package/test/unit/models/transfer/transferExtension.test.js +26 -9
- package/test/unit/models/transfer/transferFulfilment.test.js +14 -5
- package/test/unit/models/transfer/transferFulfilmentDuplicateCheck.test.js +4 -0
- package/test/unit/models/transfer/transferParticipant.test.js +14 -5
- package/test/unit/models/transfer/transferStateChange.test.js +3 -0
- package/test/unit/models/transfer/transferTimeout.test.js +6 -0
- package/test/unit/seeds/amountType.test.js +6 -22
- package/test/unit/seeds/balanceOfPayments.test.js +6 -22
- package/test/unit/seeds/bulkProcessingState.test.js +84 -0
- package/test/unit/{lib/sidecar/nullClient.test.js → seeds/bulkTransferState.test.js} +36 -39
- package/test/unit/seeds/currency.test.js +6 -22
- package/test/unit/seeds/endpointType.test.js +6 -22
- package/test/unit/seeds/ledgerAccountType.test.js +5 -22
- package/test/unit/seeds/ledgerEntryType.test.js +6 -22
- package/test/unit/seeds/participant.test.js +5 -22
- package/test/unit/seeds/participantLimitType.test.js +6 -22
- package/test/unit/seeds/partyIdentifierType.test.js +6 -22
- package/test/unit/seeds/partyType.test.js +6 -22
- package/test/unit/seeds/settlementState.test.js +5 -22
- package/test/unit/seeds/settlementWindow1State.test.js +5 -22
- package/test/unit/seeds/transactionInitiator.test.js +6 -22
- package/test/unit/seeds/transactionInitiatorType.test.js +6 -22
- package/test/unit/seeds/transactionScenario.test.js +6 -22
- package/test/unit/seeds/transferParticipantRoleType.test.js +6 -22
- package/test/unit/seeds/transferState.test.js +6 -22
- package/test/unit/shared/plugins.test.js +31 -1
- package/test/unit/shared/setup.test.js +25 -36
- package/test/util/helpers.js +37 -2
- package/test/util/randomTransfers.js +1 -1
- package/test/util/scripts/env.sh +6 -5
- package/test/util/scripts/populateTestData.sh +204 -181
- package/test/util/scripts/populateTestDataForLegacySimulator.sh +261 -0
- package/test/util/scripts/restartObjStore.sh +1 -1
- package/test-integration.Dockerfile +15 -15
- package/test.Dockerfile +12 -12
- package/.circleci/_set_up_deploy_envs.sh +0 -47
- package/.dockerignore +0 -17
- package/.ncurc.json +0 -3
- package/server.sh +0 -4
- package/sonar-project.properties +0 -17
- package/src/lib/sidecar/index.js +0 -47
- package/src/lib/sidecar/nullClient.js +0 -18
- package/test/.env +0 -8
- package/test/integration-config.json +0 -367
- package/test/integration-runner.env +0 -31
- package/test/integration-runner.sh +0 -264
- package/test/spec-runner.sh +0 -132
- package/test/unit/lib/sidecar/index.test.js +0 -148
- package/test/unit/models/position/participantLimit.test.js +0 -135
package/test/spec-runner.sh
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
#!/bin/bash
|
|
2
|
-
export POSTGRES_PARTY=${POSTGRES_PARTY:-'postgres'}
|
|
3
|
-
export POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-'postgres'}
|
|
4
|
-
export LEDGER_HOST=${HOST_IP:-'localhost'}
|
|
5
|
-
export CLEDG_HOSTNAME='http://localhost:3000'
|
|
6
|
-
export CLEDG_EXPIRES_TIMEOUT=5000
|
|
7
|
-
export API_IMAGE=${API_IMAGE:-'central-ledger'}
|
|
8
|
-
export ADMIN_IMAGE=${ADMIN_IMAGE:-'central-ledger-admin'}
|
|
9
|
-
export CENTRALLEDGER_TEST_HOST=${HOST_IP:-"centralledger-int"}
|
|
10
|
-
export POSTGRES_HOST=${HOST_IP:-"centralledger_postgres_1"}
|
|
11
|
-
TEST_CMD='node test/spec/index.js'
|
|
12
|
-
docker_compose_file='docker-compose.yml'
|
|
13
|
-
docker_functional_compose_file='docker-compose.functional.yml'
|
|
14
|
-
env_file=$1
|
|
15
|
-
|
|
16
|
-
#create a directory for test results
|
|
17
|
-
mkdir -p ./test/results
|
|
18
|
-
|
|
19
|
-
fpsql() {
|
|
20
|
-
docker run --rm -i \
|
|
21
|
-
--net centralledger_back \
|
|
22
|
-
--entrypoint psql \
|
|
23
|
-
-e PGPASSWORD=$POSTGRES_PASSWORD \
|
|
24
|
-
"postgres:9.4" \
|
|
25
|
-
--host postgres \
|
|
26
|
-
--username $POSTGRES_PARTY \
|
|
27
|
-
--dbname postgres \
|
|
28
|
-
--quiet --no-align --tuples-only \
|
|
29
|
-
"$@"
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
is_psql_up() {
|
|
33
|
-
fpsql -c '\l' > /dev/null 2>&1
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
fcurl() {
|
|
37
|
-
docker run --rm -i \
|
|
38
|
-
--net centralledger_back \
|
|
39
|
-
--entrypoint curl \
|
|
40
|
-
"jlekie/curl:latest" \
|
|
41
|
-
--output /dev/null --silent --head --fail \
|
|
42
|
-
"$@"
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
ftest() {
|
|
46
|
-
docker run --rm -i \
|
|
47
|
-
--net centralledger_back \
|
|
48
|
-
--env_file $env_file
|
|
49
|
-
$API_IMAGE \
|
|
50
|
-
"$@"
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
is_api_up() {
|
|
54
|
-
# curl --output /dev/null --silent --head --fail http://${LEDGER_HOST}:3000/health
|
|
55
|
-
fcurl "http://centralledger_central-ledger_1:3000/health?"
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
is_admin_up() {
|
|
59
|
-
# curl --output /dev/null --silent --head --fail http://${LEDGER_HOST}:3001/health
|
|
60
|
-
fcurl "http://centralledger_central-ledger-admin_1:3001/health?"
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
run_test_command()
|
|
64
|
-
{
|
|
65
|
-
# eval "$TEST_CMD"
|
|
66
|
-
# ftest $TEST_CMD
|
|
67
|
-
>&2 echo "Running Central Ledger Test command: $TEST_CMD"
|
|
68
|
-
docker run -i \
|
|
69
|
-
--net centralledger_back \
|
|
70
|
-
--name $CENTRALLEDGER_TEST_HOST \
|
|
71
|
-
--env API_HOST_IP="centralledger_central-ledger_1" \
|
|
72
|
-
--env ADMIN_HOST_IP="centralledger_central-ledger-admin_1" \
|
|
73
|
-
--env API_URI="http://centralledger_central-ledger_1:3000/participants" \
|
|
74
|
-
$API_IMAGE:test \
|
|
75
|
-
/bin/sh \
|
|
76
|
-
-c "$TEST_CMD"
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
shutdown_and_remove() {
|
|
80
|
-
docker-compose -p centralledger -f $docker_compose_file -f $docker_functional_compose_file stop
|
|
81
|
-
>&2 echo "Cleaning docker image: centralledger_central-ledger_1" && (docker rm centralledger_central-ledger_1) > /dev/null 2>&1
|
|
82
|
-
>&2 echo "Cleaning docker image: centralledger_central-ledger-admin_1" && (docker rm centralledger_central-ledger-admin_1) > /dev/null 2>&1
|
|
83
|
-
>&2 echo "Cleaning docker image: centralledger_postgres_1" && (docker rm centralledger_postgres_1) > /dev/null 2>&1
|
|
84
|
-
>&2 echo "Cleaning docker image: Central Ledger Test environment" && (docker stop $CENTRALLEDGER_TEST_HOST && docker rm $CENTRALLEDGER_TEST_HOST) > /dev/null 2>&1
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
>&2 echo "Loading environment variables"
|
|
88
|
-
. $env_file
|
|
89
|
-
|
|
90
|
-
>&2 echo "Postgres is starting"
|
|
91
|
-
docker-compose -p centralledger -f $docker_compose_file -f $docker_functional_compose_file up -d postgres
|
|
92
|
-
|
|
93
|
-
until is_psql_up; do
|
|
94
|
-
>&2 echo "Postgres is unavailable - sleeping"
|
|
95
|
-
sleep 1
|
|
96
|
-
done
|
|
97
|
-
|
|
98
|
-
>&2 echo "Postgres is up - creating functional database"
|
|
99
|
-
fpsql <<'EOSQL'
|
|
100
|
-
DROP DATABASE IF EXISTS "central_ledger_functional";
|
|
101
|
-
CREATE DATABASE "central_ledger_functional";
|
|
102
|
-
EOSQL
|
|
103
|
-
|
|
104
|
-
>&2 printf "Central-ledger is building ..."
|
|
105
|
-
docker-compose -p centralledger -f $docker_compose_file -f $docker_functional_compose_file up -d central-ledger
|
|
106
|
-
|
|
107
|
-
>&2 printf "Central-ledger is starting ..."
|
|
108
|
-
until is_api_up; do
|
|
109
|
-
>&2 printf "."
|
|
110
|
-
sleep 5
|
|
111
|
-
done
|
|
112
|
-
|
|
113
|
-
>&2 echo " done"
|
|
114
|
-
|
|
115
|
-
>&2 echo "Spec tests are starting"
|
|
116
|
-
run_test_command
|
|
117
|
-
test_exit_code=$?
|
|
118
|
-
|
|
119
|
-
if [ "$test_exit_code" != 0 ]
|
|
120
|
-
then
|
|
121
|
-
>&2 echo "Test failed..."
|
|
122
|
-
docker logs centralledger_central-ledger_1
|
|
123
|
-
>&2 echo "Test environment logs..."
|
|
124
|
-
docker logs $CENTRALLEDGER_TEST_HOST
|
|
125
|
-
fi
|
|
126
|
-
|
|
127
|
-
shutdown_and_remove
|
|
128
|
-
|
|
129
|
-
>&2 echo "Copy results to local directory"
|
|
130
|
-
docker cp $CENTRALLEDGER_TEST_HOST:/opt/central-ledger/test/results ./test
|
|
131
|
-
|
|
132
|
-
exit "$test_exit_code"
|
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const src = '../../../../src'
|
|
4
|
-
const Test = require('tapes')(require('tape'))
|
|
5
|
-
const Sinon = require('sinon')
|
|
6
|
-
const EventEmitter = require('events')
|
|
7
|
-
const Moment = require('moment')
|
|
8
|
-
const Config = require(`${src}/lib/config`)
|
|
9
|
-
const Proxyquire = require('proxyquire')
|
|
10
|
-
|
|
11
|
-
Test('Sidecar', sidecarTest => {
|
|
12
|
-
let oldSidecar
|
|
13
|
-
const sidecarSettings = { HOST: 'local', PORT: 1234, CONNECT_TIMEOUT: 10000, RECONNECT_INTERVAL: 2000 }
|
|
14
|
-
let sandbox
|
|
15
|
-
let stubs
|
|
16
|
-
let nullClientCreateStub
|
|
17
|
-
let clientCreateStub
|
|
18
|
-
|
|
19
|
-
sidecarTest.beforeEach(t => {
|
|
20
|
-
sandbox = Sinon.createSandbox()
|
|
21
|
-
sandbox.stub(Moment, 'utc')
|
|
22
|
-
|
|
23
|
-
oldSidecar = Config.SIDECAR
|
|
24
|
-
Config.SIDECAR = sidecarSettings
|
|
25
|
-
Config.SIDECAR_DISABLED = false
|
|
26
|
-
|
|
27
|
-
nullClientCreateStub = sandbox.stub()
|
|
28
|
-
clientCreateStub = sandbox.stub()
|
|
29
|
-
|
|
30
|
-
stubs = { './nullClient': { create: nullClientCreateStub }, '@mojaloop/forensic-logging-client': { create: clientCreateStub } }
|
|
31
|
-
|
|
32
|
-
t.end()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
sidecarTest.afterEach(t => {
|
|
36
|
-
sandbox.restore()
|
|
37
|
-
Config.SIDECAR = oldSidecar
|
|
38
|
-
t.end()
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
sidecarTest.test('import should', importTest => {
|
|
42
|
-
importTest.test('return null client if sidecar disabled', test => {
|
|
43
|
-
Config.SIDECAR_DISABLED = true
|
|
44
|
-
Proxyquire(`${src}/lib/sidecar`, stubs)
|
|
45
|
-
|
|
46
|
-
test.notOk(clientCreateStub.called)
|
|
47
|
-
test.ok(nullClientCreateStub.calledOnce)
|
|
48
|
-
test.end()
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
importTest.test('return sidecar client if not disabled', test => {
|
|
52
|
-
const sidecarStub = { on: sandbox.stub(), write: sandbox.stub() }
|
|
53
|
-
clientCreateStub.returns(sidecarStub)
|
|
54
|
-
|
|
55
|
-
Proxyquire(`${src}/lib/sidecar`, stubs)
|
|
56
|
-
|
|
57
|
-
test.notOk(nullClientCreateStub.called)
|
|
58
|
-
test.ok(clientCreateStub.calledOnce)
|
|
59
|
-
test.ok(clientCreateStub.calledWith(sandbox.match({
|
|
60
|
-
host: sidecarSettings.HOST,
|
|
61
|
-
port: sidecarSettings.PORT,
|
|
62
|
-
connectTimeout: sidecarSettings.CONNECT_TIMEOUT,
|
|
63
|
-
reconnectInterval: sidecarSettings.RECONNECT_INTERVAL
|
|
64
|
-
})))
|
|
65
|
-
test.end()
|
|
66
|
-
})
|
|
67
|
-
|
|
68
|
-
importTest.end()
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
sidecarTest.test('connect should', connectTest => {
|
|
72
|
-
connectTest.test('call sidecar client connect', test => {
|
|
73
|
-
const sidecarStub = { on: sandbox.stub(), connect: sandbox.stub() }
|
|
74
|
-
clientCreateStub.returns(sidecarStub)
|
|
75
|
-
|
|
76
|
-
const Sidecar = Proxyquire(`${src}/lib/sidecar`, stubs)
|
|
77
|
-
|
|
78
|
-
Sidecar.connect()
|
|
79
|
-
test.ok(sidecarStub.connect.calledOnce)
|
|
80
|
-
test.end()
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
connectTest.end()
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
sidecarTest.test('write should', writeTest => {
|
|
87
|
-
writeTest.test('write to sidecar client', test => {
|
|
88
|
-
const sidecarStub = { on: sandbox.stub(), write: sandbox.stub() }
|
|
89
|
-
clientCreateStub.returns(sidecarStub)
|
|
90
|
-
|
|
91
|
-
const Sidecar = Proxyquire(`${src}/lib/sidecar`, stubs)
|
|
92
|
-
|
|
93
|
-
const msg = 'message'
|
|
94
|
-
Sidecar.write(msg)
|
|
95
|
-
test.ok(sidecarStub.write.calledWith(msg))
|
|
96
|
-
test.end()
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
writeTest.end()
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
sidecarTest.test('logRequest should', logRequestTest => {
|
|
103
|
-
logRequestTest.test('write to sidecar client with request message', test => {
|
|
104
|
-
const sidecarStub = { on: sandbox.stub(), write: sandbox.stub() }
|
|
105
|
-
clientCreateStub.returns(sidecarStub)
|
|
106
|
-
|
|
107
|
-
const Sidecar = Proxyquire(`${src}/lib/sidecar`, stubs)
|
|
108
|
-
|
|
109
|
-
const now = new Date()
|
|
110
|
-
Moment.utc.returns(now)
|
|
111
|
-
|
|
112
|
-
const request = { method: 'post', url: { path: 'path' }, body: 'body', auth: 'auth' }
|
|
113
|
-
const msgJson = { method: 'post', timestamp: now.toISOString(), url: 'path', body: 'body', auth: 'auth' }
|
|
114
|
-
const msg = JSON.stringify(msgJson)
|
|
115
|
-
|
|
116
|
-
Sidecar.logRequest(request)
|
|
117
|
-
test.ok(sidecarStub.write.calledWith(msg))
|
|
118
|
-
test.end()
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
logRequestTest.end()
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
sidecarTest.test('receiving close event should', closeEventTest => {
|
|
125
|
-
closeEventTest.test('throw error', test => {
|
|
126
|
-
const sidecarStub = new EventEmitter()
|
|
127
|
-
sidecarStub.connect = sandbox.stub()
|
|
128
|
-
clientCreateStub.returns(sidecarStub)
|
|
129
|
-
|
|
130
|
-
const Sidecar = Proxyquire(`${src}/lib/sidecar`, stubs)
|
|
131
|
-
|
|
132
|
-
Sidecar.connect()
|
|
133
|
-
|
|
134
|
-
try {
|
|
135
|
-
sidecarStub.emit('close')
|
|
136
|
-
test.fail('Should have thrown error')
|
|
137
|
-
test.end()
|
|
138
|
-
} catch (err) {
|
|
139
|
-
test.equal(err.message, 'Sidecar connection closed')
|
|
140
|
-
test.end()
|
|
141
|
-
}
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
closeEventTest.end()
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
sidecarTest.end()
|
|
148
|
-
})
|
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/*****
|
|
2
|
-
License
|
|
3
|
-
--------------
|
|
4
|
-
Copyright © 2017 Bill & Melinda Gates Foundation
|
|
5
|
-
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
|
|
6
|
-
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
-
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
|
|
8
|
-
Contributors
|
|
9
|
-
--------------
|
|
10
|
-
This is the official list of the Mojaloop project contributors for this file.
|
|
11
|
-
Names of the original copyright holders (individuals or organizations)
|
|
12
|
-
should be listed with a '*' in the first column. People who have
|
|
13
|
-
contributed from an organization can be listed under the organization
|
|
14
|
-
that actually holds the copyright for their contributions (see the
|
|
15
|
-
Gates Foundation organization for an example). Those individuals should have
|
|
16
|
-
their names indented and be marked with a '-'. Email address can be added
|
|
17
|
-
optionally within square brackets <email>.
|
|
18
|
-
* Gates Foundation
|
|
19
|
-
- Name Surname <name.surname@gatesfoundation.com>
|
|
20
|
-
|
|
21
|
-
* Georgi Georgiev <georgi.georgiev@modusbox.com>
|
|
22
|
-
--------------
|
|
23
|
-
******/
|
|
24
|
-
|
|
25
|
-
'use strict'
|
|
26
|
-
|
|
27
|
-
const Test = require('tape')
|
|
28
|
-
const Sinon = require('sinon')
|
|
29
|
-
const Db = require('../../../../src/lib/db')
|
|
30
|
-
const Logger = require('@mojaloop/central-services-logger')
|
|
31
|
-
const Model = require('../../../../src/models/participant/participantLimit')
|
|
32
|
-
const Enum = require('@mojaloop/central-services-shared').Enum
|
|
33
|
-
|
|
34
|
-
Test('Participant Limit model', async (participantLimitTest) => {
|
|
35
|
-
const participantLimit1 = {
|
|
36
|
-
participantCurrencyId: 1,
|
|
37
|
-
participantLimitTypeId: Enum.Accounts.ParticipantLimitType.NET_DEBIT_CAP,
|
|
38
|
-
value: 1000,
|
|
39
|
-
thresholdAlarmPercentage: 10,
|
|
40
|
-
startAfterParticipantPositionChangeId: null,
|
|
41
|
-
isActive: true,
|
|
42
|
-
createDate: new Date(),
|
|
43
|
-
createdBy: 'unit-testing'
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const sandbox = Sinon.createSandbox()
|
|
47
|
-
Db.participantLimit = {
|
|
48
|
-
insert: sandbox.stub(),
|
|
49
|
-
update: sandbox.stub(),
|
|
50
|
-
findOne: sandbox.stub()
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
await participantLimitTest.test('insert participant limit', async (assert) => {
|
|
54
|
-
try {
|
|
55
|
-
Db.participantLimit.insert.withArgs(participantLimit1).returns(1)
|
|
56
|
-
const result = await Model.insert(participantLimit1)
|
|
57
|
-
assert.equal(result, 1, `returns ${result}`)
|
|
58
|
-
assert.end()
|
|
59
|
-
} catch (err) {
|
|
60
|
-
Logger.error(`insert participant limit failed with error - ${err}`)
|
|
61
|
-
assert.fail()
|
|
62
|
-
assert.end()
|
|
63
|
-
}
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
await participantLimitTest.test('insert participant limit should throw an error', async (assert) => {
|
|
67
|
-
try {
|
|
68
|
-
Db.participantLimit.insert.withArgs(participantLimit1).throws(new Error('message'))
|
|
69
|
-
await Model.insert(participantLimit1)
|
|
70
|
-
assert.fail('Error not thrown!')
|
|
71
|
-
assert.end()
|
|
72
|
-
} catch (err) {
|
|
73
|
-
Logger.error(`insert participant limit failed with error - ${err}`)
|
|
74
|
-
assert.assert(err instanceof Error, 'instance of Error')
|
|
75
|
-
assert.pass('Error thrown')
|
|
76
|
-
assert.end()
|
|
77
|
-
}
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
await participantLimitTest.test('update participant limit', async (assert) => {
|
|
81
|
-
try {
|
|
82
|
-
Db.participantLimit.update.withArgs({ participantCurrencyId: participantLimit1.participantCurrencyId }, { value: participantLimit1.value, isActive: participantLimit1.isActive }).returns(1)
|
|
83
|
-
const result = await Model.update(participantLimit1)
|
|
84
|
-
assert.equal(result, 1, `returns ${result}`)
|
|
85
|
-
assert.end()
|
|
86
|
-
} catch (err) {
|
|
87
|
-
Logger.error(`update participant limit failed with error - ${err}`)
|
|
88
|
-
assert.fail()
|
|
89
|
-
assert.end()
|
|
90
|
-
}
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
await participantLimitTest.test('update participant limit should throw an error', async (assert) => {
|
|
94
|
-
try {
|
|
95
|
-
Db.participantLimit.update.withArgs({ participantCurrencyId: participantLimit1.participantCurrencyId }, { value: participantLimit1.value, isActive: participantLimit1.isActive }).throws(new Error('message'))
|
|
96
|
-
await Model.update(participantLimit1)
|
|
97
|
-
assert.fail('Error not thrown!')
|
|
98
|
-
assert.end()
|
|
99
|
-
} catch (err) {
|
|
100
|
-
Logger.error(`update participant limit failed with error - ${err}`)
|
|
101
|
-
assert.assert(err instanceof Error, 'instance of Error')
|
|
102
|
-
assert.pass('Error thrown')
|
|
103
|
-
assert.end()
|
|
104
|
-
}
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
await participantLimitTest.test('getLimitByCurrencyId participant limit', async (assert) => {
|
|
108
|
-
try {
|
|
109
|
-
Db.participantLimit.findOne.withArgs({ participantCurrencyId: participantLimit1.participantCurrencyId }).returns(1)
|
|
110
|
-
const result = await Model.getLimitByCurrencyId(participantLimit1.participantCurrencyId)
|
|
111
|
-
assert.equal(result, 1, `returns ${result}`)
|
|
112
|
-
assert.end()
|
|
113
|
-
} catch (err) {
|
|
114
|
-
Logger.error(`getLimitByCurrencyId participant limit failed with error - ${err}`)
|
|
115
|
-
assert.fail()
|
|
116
|
-
assert.end()
|
|
117
|
-
}
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
await participantLimitTest.test('getLimitByCurrencyId participant limit should throw an error', async (assert) => {
|
|
121
|
-
try {
|
|
122
|
-
Db.participantLimit.findOne.withArgs({ participantCurrencyId: participantLimit1.participantCurrencyId }).throws(new Error('message'))
|
|
123
|
-
await Model.getLimitByCurrencyId(participantLimit1.participantCurrencyId)
|
|
124
|
-
assert.fail('Error not thrown!')
|
|
125
|
-
assert.end()
|
|
126
|
-
} catch (err) {
|
|
127
|
-
Logger.error(`getLimitByCurrencyId participant limit failed with error - ${err}`)
|
|
128
|
-
assert.assert(err instanceof Error, 'instance of Error')
|
|
129
|
-
assert.pass('Error thrown')
|
|
130
|
-
assert.end()
|
|
131
|
-
}
|
|
132
|
-
})
|
|
133
|
-
|
|
134
|
-
participantLimitTest.end()
|
|
135
|
-
})
|