@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
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
* ModusBox
|
|
22
|
+
- Lazola Lucas <lazola.lucas@modusbox.com>
|
|
23
|
+
--------------
|
|
24
|
+
******/
|
|
25
|
+
'use strict'
|
|
26
|
+
|
|
27
|
+
const Test = require('tapes')(require('tape'))
|
|
28
|
+
const Sinon = require('sinon')
|
|
29
|
+
const Db = require('../../../../src/lib/db')
|
|
30
|
+
const Logger = require('@mojaloop/central-services-logger')
|
|
31
|
+
const IlpPacketsModel = require('../../../../src/models/ilpPackets/ilpPacket')
|
|
32
|
+
|
|
33
|
+
Test('IlpPackets', async (IlpPacketsTest) => {
|
|
34
|
+
let sandbox
|
|
35
|
+
|
|
36
|
+
IlpPacketsTest.beforeEach(t => {
|
|
37
|
+
sandbox = Sinon.createSandbox()
|
|
38
|
+
Db.ilpPacket = {
|
|
39
|
+
find: sandbox.stub()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
Db.from = (table) => {
|
|
43
|
+
return Db[table]
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
t.end()
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
IlpPacketsTest.afterEach(t => {
|
|
50
|
+
sandbox.restore()
|
|
51
|
+
|
|
52
|
+
t.end()
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
await IlpPacketsTest.test('get IlpPackets with transferId', async (assert) => {
|
|
56
|
+
try {
|
|
57
|
+
Db.ilpPacket.find.withArgs({ transferId: '6d3e964e-9a25-4ff5-a365-2cc5af348321' }).returns([
|
|
58
|
+
{
|
|
59
|
+
transferId: '6d3e964e-9a25-4ff5-a365-2cc5af348321',
|
|
60
|
+
value: 'AYIC-AAAAAAAAeIfHWcucGF5ZWVmc3AubXNpc2RuLjIyNTU2OTk5MTI1ggLOZXlKMGNtRnVjMkZqZEdsdmJrbGtJam9pTlRWa09ESXdObVV0T0RCaU55MDBPR00wTFRrNU5HTXRaREEyTmpRd01XRXdZbU00SWl3aWNYVnZkR1ZKWkNJNklqRmtPVGhpTkdReExXWmpOVFV0TkRaa09DMDROV1EyTFRnNVl6TXdZMkZoWWpRME5pSXNJbkJoZVdWbElqcDdJbkJoY25SNVNXUkpibVp2SWpwN0luQmhjblI1U1dSVWVYQmxJam9pVFZOSlUwUk9JaXdpY0dGeWRIbEpaR1Z1ZEdsbWFXVnlJam9pTWpJMU5UWTVPVGt4TWpVaUxDSm1jM0JKWkNJNkluQmhlV1ZsWm5Od0luMTlMQ0p3WVhsbGNpSTZleUp3WVhKMGVVbGtTVzVtYnlJNmV5SndZWEowZVVsa1ZIbHdaU0k2SWsxVFNWTkVUaUlzSW5CaGNuUjVTV1JsYm5ScFptbGxjaUk2SWpJeU5UQTNNREE0TVRneElpd2labk53U1dRaU9pSndZWGxsY21aemNDSjlMQ0p3WlhKemIyNWhiRWx1Wm04aU9uc2lZMjl0Y0d4bGVFNWhiV1VpT25zaVptbHljM1JPWVcxbElqb2lUV0YwY3lJc0lteGhjM1JPWVcxbElqb2lTR0ZuYldGdUluMHNJbVJoZEdWUFprSnBjblJvSWpvaU1UazRNeTB4TUMweU5TSjlmU3dpWVcxdmRXNTBJanA3SW1OMWNuSmxibU41SWpvaVZWTkVJaXdpWVcxdmRXNTBJam94TWpNMExqSXpmU3dpZEhKaGJuTmhZM1JwYjI1VWVYQmxJanA3SW5OalpXNWhjbWx2SWpvaVZGSkJUbE5HUlZJaUxDSnBibWwwYVdGMGIzSWlPaUpRUVZsRlVpSXNJbWx1YVhScFlYUnZjbFI1Y0dVaU9pSkRUMDVUVlUxRlVpSjlmUQA',
|
|
61
|
+
createdDate: '2020-05-23T17:31:29.000Z'
|
|
62
|
+
}])
|
|
63
|
+
const expected = [{
|
|
64
|
+
transferId: '6d3e964e-9a25-4ff5-a365-2cc5af348321',
|
|
65
|
+
value: 'AYIC-AAAAAAAAeIfHWcucGF5ZWVmc3AubXNpc2RuLjIyNTU2OTk5MTI1ggLOZXlKMGNtRnVjMkZqZEdsdmJrbGtJam9pTlRWa09ESXdObVV0T0RCaU55MDBPR00wTFRrNU5HTXRaREEyTmpRd01XRXdZbU00SWl3aWNYVnZkR1ZKWkNJNklqRmtPVGhpTkdReExXWmpOVFV0TkRaa09DMDROV1EyTFRnNVl6TXdZMkZoWWpRME5pSXNJbkJoZVdWbElqcDdJbkJoY25SNVNXUkpibVp2SWpwN0luQmhjblI1U1dSVWVYQmxJam9pVFZOSlUwUk9JaXdpY0dGeWRIbEpaR1Z1ZEdsbWFXVnlJam9pTWpJMU5UWTVPVGt4TWpVaUxDSm1jM0JKWkNJNkluQmhlV1ZsWm5Od0luMTlMQ0p3WVhsbGNpSTZleUp3WVhKMGVVbGtTVzVtYnlJNmV5SndZWEowZVVsa1ZIbHdaU0k2SWsxVFNWTkVUaUlzSW5CaGNuUjVTV1JsYm5ScFptbGxjaUk2SWpJeU5UQTNNREE0TVRneElpd2labk53U1dRaU9pSndZWGxsY21aemNDSjlMQ0p3WlhKemIyNWhiRWx1Wm04aU9uc2lZMjl0Y0d4bGVFNWhiV1VpT25zaVptbHljM1JPWVcxbElqb2lUV0YwY3lJc0lteGhjM1JPWVcxbElqb2lTR0ZuYldGdUluMHNJbVJoZEdWUFprSnBjblJvSWpvaU1UazRNeTB4TUMweU5TSjlmU3dpWVcxdmRXNTBJanA3SW1OMWNuSmxibU41SWpvaVZWTkVJaXdpWVcxdmRXNTBJam94TWpNMExqSXpmU3dpZEhKaGJuTmhZM1JwYjI1VWVYQmxJanA3SW5OalpXNWhjbWx2SWpvaVZGSkJUbE5HUlZJaUxDSnBibWwwYVdGMGIzSWlPaUpRUVZsRlVpSXNJbWx1YVhScFlYUnZjbFI1Y0dVaU9pSkRUMDVUVlUxRlVpSjlmUQA',
|
|
66
|
+
createdDate: '2020-05-23T17:31:29.000Z'
|
|
67
|
+
}]
|
|
68
|
+
const result = await IlpPacketsModel.getById('6d3e964e-9a25-4ff5-a365-2cc5af348321')
|
|
69
|
+
assert.deepEqual(JSON.stringify(result), JSON.stringify(expected))
|
|
70
|
+
assert.end()
|
|
71
|
+
} catch (err) {
|
|
72
|
+
Logger.error(`get IlpPackets with transferId failed with error - ${err}`)
|
|
73
|
+
assert.fail()
|
|
74
|
+
assert.end()
|
|
75
|
+
}
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
await IlpPacketsTest.test('get IlpPackets with empty transferId', async (assert) => {
|
|
79
|
+
Db.ilpPacket.find.withArgs().throws(new Error())
|
|
80
|
+
try {
|
|
81
|
+
await IlpPacketsModel.getById('')
|
|
82
|
+
assert.fail(' should throws an error ')
|
|
83
|
+
} catch (err) {
|
|
84
|
+
assert.assert(err instanceof Error, ` throws ${err} `)
|
|
85
|
+
}
|
|
86
|
+
assert.end()
|
|
87
|
+
})
|
|
88
|
+
await IlpPacketsTest.end()
|
|
89
|
+
})
|
|
@@ -68,17 +68,26 @@ Test('ledgerAccountType model', async (ledgerAccountTypeTest) => {
|
|
|
68
68
|
sandbox = Sinon.createSandbox()
|
|
69
69
|
Db.ledgerAccountType = {
|
|
70
70
|
findOne: sandbox.stub(),
|
|
71
|
-
destroy: sandbox.stub()
|
|
71
|
+
destroy: sandbox.stub(),
|
|
72
|
+
insert: sandbox.stub(),
|
|
73
|
+
find: sandbox.stub()
|
|
72
74
|
}
|
|
75
|
+
|
|
73
76
|
Db.participantCurrency = {
|
|
74
77
|
findOne: sandbox.stub(),
|
|
75
78
|
destroy: sandbox.stub()
|
|
76
79
|
}
|
|
80
|
+
|
|
81
|
+
Db.from = (table) => {
|
|
82
|
+
return Db[table]
|
|
83
|
+
}
|
|
84
|
+
|
|
77
85
|
t.end()
|
|
78
86
|
})
|
|
79
87
|
|
|
80
88
|
ledgerAccountTypeTest.afterEach(t => {
|
|
81
89
|
sandbox.restore()
|
|
90
|
+
|
|
82
91
|
t.end()
|
|
83
92
|
})
|
|
84
93
|
|
|
@@ -118,14 +127,254 @@ Test('ledgerAccountType model', async (ledgerAccountTypeTest) => {
|
|
|
118
127
|
}
|
|
119
128
|
})
|
|
120
129
|
|
|
121
|
-
await ledgerAccountTypeTest.test('
|
|
130
|
+
await ledgerAccountTypeTest.test('create should', async (test) => {
|
|
131
|
+
const ledgerAccountType = {
|
|
132
|
+
name: 'POSITION',
|
|
133
|
+
description: 'A single account for each currency with which the hub operates. The account is "held" by the Participant representing the hub in the switch',
|
|
134
|
+
isActive: 1,
|
|
135
|
+
isSettleable: true
|
|
136
|
+
}
|
|
137
|
+
try {
|
|
138
|
+
sandbox.stub(Db, 'getKnex')
|
|
139
|
+
const knexStub = sandbox.stub()
|
|
140
|
+
const trxStub = sandbox.stub()
|
|
141
|
+
trxStub.commit = sandbox.stub()
|
|
142
|
+
knexStub.transaction = sandbox.stub().callsArgWith(0, trxStub)
|
|
143
|
+
Db.getKnex.returns(knexStub)
|
|
144
|
+
const transactingStub = sandbox.stub()
|
|
145
|
+
const insertStub = sandbox.stub()
|
|
146
|
+
transactingStub.resolves()
|
|
147
|
+
insertStub.returns({ transacting: transactingStub })
|
|
148
|
+
knexStub.returns({ insert: insertStub })
|
|
149
|
+
const selectStub = sandbox.stub()
|
|
150
|
+
const fromStub = sandbox.stub()
|
|
151
|
+
const whereStub = sandbox.stub()
|
|
152
|
+
const expectedRecords = [
|
|
153
|
+
{
|
|
154
|
+
ledgerAccountTypeId: 100
|
|
155
|
+
}
|
|
156
|
+
]
|
|
157
|
+
transactingStub.resolves(expectedRecords)
|
|
158
|
+
whereStub.returns({ transacting: transactingStub })
|
|
159
|
+
fromStub.returns({ where: whereStub })
|
|
160
|
+
selectStub.returns({ from: fromStub })
|
|
161
|
+
knexStub.select = selectStub
|
|
162
|
+
|
|
163
|
+
const result = await Model.create(ledgerAccountType.name, ledgerAccountType.description, ledgerAccountType.isActive, ledgerAccountType.isSettleable, trxStub)
|
|
164
|
+
test.deepEqual(result, expectedRecords[0].ledgerAccountTypeId, 'return the created record id')
|
|
165
|
+
test.equal(insertStub.callCount, 1, 'call insert')
|
|
166
|
+
test.deepEqual(insertStub.lastCall.args[0], ledgerAccountType, 'pass the payload arguments to insert call')
|
|
167
|
+
test.equal(selectStub.callCount, 1, 'retrieve the created record')
|
|
168
|
+
test.equal(transactingStub.callCount, 2, 'make the database calls as transaction')
|
|
169
|
+
test.equal(transactingStub.lastCall.args[0], trxStub, 'run as transaction')
|
|
170
|
+
test.equal(trxStub.commit.callCount, 0, 'not commit the transaction if transaction is passed')
|
|
171
|
+
test.end()
|
|
172
|
+
} catch (err) {
|
|
173
|
+
console.log(err)
|
|
174
|
+
test.fail(`should have not throw an error ${err}`)
|
|
175
|
+
test.end()
|
|
176
|
+
}
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
await ledgerAccountTypeTest.test('create should', async (test) => {
|
|
180
|
+
const ledgerAccountType = {
|
|
181
|
+
name: 'POSITION',
|
|
182
|
+
description: 'A single account for each currency with which the hub operates. The account is "held" by the Participant representing the hub in the switch',
|
|
183
|
+
isActive: 1,
|
|
184
|
+
isSettleable: true
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
sandbox.stub(Db, 'getKnex')
|
|
188
|
+
const knexStub = sandbox.stub()
|
|
189
|
+
const trxStub = {
|
|
190
|
+
get commit () {
|
|
191
|
+
|
|
192
|
+
},
|
|
193
|
+
get rollback () {
|
|
194
|
+
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
const trxSpyCommit = sandbox.spy(trxStub, 'commit', ['get'])
|
|
198
|
+
|
|
199
|
+
knexStub.transaction = sandbox.stub().callsArgWith(0, trxStub)
|
|
200
|
+
Db.getKnex.returns(knexStub)
|
|
201
|
+
const transactingStub = sandbox.stub()
|
|
202
|
+
const insertStub = sandbox.stub()
|
|
203
|
+
transactingStub.resolves()
|
|
204
|
+
insertStub.returns({ transacting: transactingStub })
|
|
205
|
+
knexStub.returns({ insert: insertStub })
|
|
206
|
+
|
|
207
|
+
const selectStub = sandbox.stub()
|
|
208
|
+
const fromStub = sandbox.stub()
|
|
209
|
+
const whereStub = sandbox.stub()
|
|
210
|
+
const expectedRecords = [
|
|
211
|
+
{
|
|
212
|
+
ledgerAccountTypeId: 100
|
|
213
|
+
}
|
|
214
|
+
]
|
|
215
|
+
transactingStub.resolves(expectedRecords)
|
|
216
|
+
whereStub.returns({ transacting: transactingStub })
|
|
217
|
+
fromStub.returns({ where: whereStub })
|
|
218
|
+
selectStub.returns({ from: fromStub })
|
|
219
|
+
knexStub.select = selectStub
|
|
220
|
+
|
|
221
|
+
await Model.create(ledgerAccountType.name, ledgerAccountType.description, ledgerAccountType.isActive, ledgerAccountType.isSettleable)
|
|
222
|
+
test.equal(trxSpyCommit.get.calledOnce, true, 'commit the transaction if no transaction is passed')
|
|
223
|
+
test.end()
|
|
224
|
+
} catch (err) {
|
|
225
|
+
test.fail(`should not have thrown an error ${err}`)
|
|
226
|
+
test.end()
|
|
227
|
+
}
|
|
228
|
+
})
|
|
229
|
+
await ledgerAccountTypeTest.test('create should', async (test) => {
|
|
230
|
+
let trxStub
|
|
231
|
+
let trxSpyRollBack
|
|
232
|
+
const ledgerAccountType = {
|
|
233
|
+
name: 'POSITION',
|
|
234
|
+
description: 'A single account for each currency with which the hub operates. The account is "held" by the Participant representing the hub in the switch',
|
|
235
|
+
isActive: 1,
|
|
236
|
+
isSettleable: true
|
|
237
|
+
}
|
|
238
|
+
try {
|
|
239
|
+
sandbox.stub(Db, 'getKnex')
|
|
240
|
+
const knexStub = sandbox.stub()
|
|
241
|
+
trxStub = {
|
|
242
|
+
get commit () {
|
|
243
|
+
|
|
244
|
+
},
|
|
245
|
+
get rollback () {
|
|
246
|
+
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
trxSpyRollBack = sandbox.spy(trxStub, 'rollback', ['get'])
|
|
250
|
+
|
|
251
|
+
knexStub.transaction = sandbox.stub().callsArgWith(0, trxStub)
|
|
252
|
+
Db.getKnex.returns(knexStub)
|
|
253
|
+
const transactingStub = sandbox.stub()
|
|
254
|
+
const insertStub = sandbox.stub()
|
|
255
|
+
transactingStub.resolves()
|
|
256
|
+
knexStub.insert = insertStub.returns({ transacting: transactingStub })
|
|
257
|
+
const selectStub = sandbox.stub()
|
|
258
|
+
const fromStub = sandbox.stub()
|
|
259
|
+
const whereStub = sandbox.stub()
|
|
260
|
+
transactingStub.rejects(new Error())
|
|
261
|
+
whereStub.returns({ transacting: transactingStub })
|
|
262
|
+
fromStub.returns({ whereStub })
|
|
263
|
+
knexStub.select = selectStub.returns({ from: fromStub })
|
|
264
|
+
|
|
265
|
+
await Model.create(ledgerAccountType.name, ledgerAccountType.description, ledgerAccountType.isActive, ledgerAccountType.isSettleable)
|
|
266
|
+
test.fail('have thrown an error')
|
|
267
|
+
test.end()
|
|
268
|
+
} catch (err) {
|
|
269
|
+
test.pass('throw an error')
|
|
270
|
+
test.equal(trxSpyRollBack.get.calledOnce, true, 'rollback the transaction if no transaction is passed')
|
|
271
|
+
test.end()
|
|
272
|
+
}
|
|
273
|
+
})
|
|
274
|
+
|
|
275
|
+
await ledgerAccountTypeTest.test('create should', async (test) => {
|
|
276
|
+
let trxStub
|
|
277
|
+
let trxSpyRollBack
|
|
278
|
+
|
|
279
|
+
const ledgerAccountType = {
|
|
280
|
+
name: 'POSITION',
|
|
281
|
+
description: 'A single account for each currency with which the hub operates. The account is "held" by the Participant representing the hub in the switch',
|
|
282
|
+
isActive: 1,
|
|
283
|
+
isSettleable: true
|
|
284
|
+
}
|
|
285
|
+
try {
|
|
286
|
+
sandbox.stub(Db, 'getKnex')
|
|
287
|
+
const knexStub = sandbox.stub()
|
|
288
|
+
trxStub = {
|
|
289
|
+
get commit () {
|
|
290
|
+
|
|
291
|
+
},
|
|
292
|
+
get rollback () {
|
|
293
|
+
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
trxSpyRollBack = sandbox.spy(trxStub, 'rollback', ['get'])
|
|
297
|
+
|
|
298
|
+
knexStub.transaction = sandbox.stub().callsArgWith(0, trxStub)
|
|
299
|
+
Db.getKnex.returns(knexStub)
|
|
300
|
+
const transactingStub = sandbox.stub()
|
|
301
|
+
const insertStub = sandbox.stub()
|
|
302
|
+
transactingStub.resolves()
|
|
303
|
+
knexStub.insert = insertStub.returns({ transacting: transactingStub })
|
|
304
|
+
const selectStub = sandbox.stub()
|
|
305
|
+
const fromStub = sandbox.stub()
|
|
306
|
+
const whereStub = sandbox.stub()
|
|
307
|
+
transactingStub.rejects(new Error())
|
|
308
|
+
whereStub.returns({ transacting: transactingStub })
|
|
309
|
+
fromStub.returns({ whereStub })
|
|
310
|
+
knexStub.select = selectStub.returns({ from: fromStub })
|
|
311
|
+
|
|
312
|
+
await Model.create(ledgerAccountType.name, ledgerAccountType.description, ledgerAccountType.isActive, ledgerAccountType.isSettleable, trxStub)
|
|
313
|
+
test.fail('have thrown an error')
|
|
314
|
+
test.end()
|
|
315
|
+
} catch (err) {
|
|
316
|
+
test.pass('throw an error')
|
|
317
|
+
test.equal(trxSpyRollBack.get.calledOnce, false, 'not rollback the transaction if transaction is passed')
|
|
318
|
+
test.end()
|
|
319
|
+
}
|
|
320
|
+
})
|
|
321
|
+
|
|
322
|
+
await ledgerAccountTypeTest.test('create should', async (test) => {
|
|
323
|
+
try {
|
|
324
|
+
const ledgerAccountType = {
|
|
325
|
+
name: 'POSITION',
|
|
326
|
+
description: 'A single account for each currency with which the hub operates. The account is "held" by the Participant representing the hub in the switch',
|
|
327
|
+
isActive: 1,
|
|
328
|
+
isSettleable: true
|
|
329
|
+
}
|
|
330
|
+
sandbox.stub(Db, 'getKnex')
|
|
331
|
+
Db.getKnex.throws(new Error())
|
|
332
|
+
await Model.create(ledgerAccountType.name, ledgerAccountType.description, ledgerAccountType.isActive, ledgerAccountType.isSettleable)
|
|
333
|
+
test.fail('have thrown an error')
|
|
334
|
+
test.end()
|
|
335
|
+
} catch (err) {
|
|
336
|
+
test.pass('throw an error')
|
|
337
|
+
test.end()
|
|
338
|
+
}
|
|
339
|
+
})
|
|
340
|
+
|
|
341
|
+
await ledgerAccountTypeTest.test('getAll', async (assert) => {
|
|
342
|
+
const ledgerAccountTypes = [
|
|
343
|
+
{
|
|
344
|
+
name: 'POSITION',
|
|
345
|
+
description: 'A single account for each currency with which the hub operates. The account is "held" by the Participant representing the hub in the switch',
|
|
346
|
+
isActive: 1,
|
|
347
|
+
isSettleable: true
|
|
348
|
+
},
|
|
349
|
+
{
|
|
350
|
+
name: 'INTERCHANGE_FEE_SETTLEMENT',
|
|
351
|
+
description: 'settlement account for interchange fees',
|
|
352
|
+
isActive: 1,
|
|
353
|
+
isSettleable: true
|
|
354
|
+
}
|
|
355
|
+
]
|
|
356
|
+
|
|
357
|
+
try {
|
|
358
|
+
Db.ledgerAccountType.find.resolves(ledgerAccountTypes)
|
|
359
|
+
const result = await Model.getAll()
|
|
360
|
+
assert.equal(Db.ledgerAccountType.find.callCount, 1, 'should call the model create function')
|
|
361
|
+
assert.deepEqual(Db.ledgerAccountType.find.lastCall.args[0], {}, 'should call the model with the right arguments: empty object')
|
|
362
|
+
assert.deepEqual(result, ledgerAccountTypes)
|
|
363
|
+
assert.end()
|
|
364
|
+
} catch (err) {
|
|
365
|
+
assert.fail('should not have thrown an error: ' + err)
|
|
366
|
+
assert.end()
|
|
367
|
+
}
|
|
368
|
+
})
|
|
369
|
+
|
|
370
|
+
await ledgerAccountTypeTest.test('getAll when the db fails', async (assert) => {
|
|
122
371
|
try {
|
|
123
|
-
Db.ledgerAccountType.
|
|
124
|
-
|
|
125
|
-
assert.
|
|
372
|
+
Db.ledgerAccountType.find.throws(new Error())
|
|
373
|
+
await Model.getAll()
|
|
374
|
+
assert.fail('should have thrown an error')
|
|
126
375
|
assert.end()
|
|
127
376
|
} catch (err) {
|
|
128
|
-
assert.
|
|
377
|
+
assert.ok(err instanceof Error, 'should throw an error')
|
|
129
378
|
assert.end()
|
|
130
379
|
}
|
|
131
380
|
})
|