Skip to content

Commit

Permalink
Feature/#308 Calculate Positions Implementation for Fulfil and Reject (
Browse files Browse the repository at this point in the history
…#96)

* PositionHandler::positions::commit
* Avoid knex version warning: http://knexjs.org/#Schema-timestamps
* Fixing minor bugs
* .then to await
* Fulfil reject scenario
* Move projection to facade transaction
* Unit tests batch 1
* Transfer facade unit test coverage 100 percent
* Position facade unit test coverage 100 percent
* Inserting placeholders for integration tests
* refactored the integration tests for testPI2/integration/domain/participant/index.test.js (#7)
* Integration test handlers reworked
* Updated registerHandler functions for positions and prepare to allow for specific registration of FSPs (#8)
* Updated registerHandler functions for positions and prepare to allow for specific registration of FSPs
* Removed comment and fixed jsdoc param name
* handlers integration test additions
* integration tests additions
* Finilizing integration tests work
* added unit tests (#9)
* seeds and domain/participant 100
* Adding more unit tests to improve coverage
* Reduce wait time during unit testing for time.js
* Enable sidecar and auth keychain
* Disable dev seed
* Changes as per request by rmothilal
  • Loading branch information
ggrg committed Jul 30, 2018
1 parent 89c7993 commit 2f2adb7
Show file tree
Hide file tree
Showing 109 changed files with 4,413 additions and 1,555 deletions.
6 changes: 3 additions & 3 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ HTTP/1.1 200 OK
"accounts": "http://central-ledger/accounts",
"send_message": "http://central-ledger/messages",
"transfer": "http://central-ledger/transfers/:id",
"transfer_fulfillment": "http://central-ledger/transfers/:id/fulfilment",
"transfer_fulfilment": "http://central-ledger/transfers/:id/fulfilment",
"transfer_rejection": "http://central-ledger/transfers/:id/rejection",
"notifications": "ws://central-ledger/websocket"
},
Expand Down Expand Up @@ -2332,8 +2332,8 @@ A notification object can have the following fields:
| ---- | ---- | ----------- |
| resource | Object | [Transfer object](#transfer-object) that is the subject of the notification |
| related_resources | Object | *Optional* Additional resources relevant to the event |
| related\_resources.execution\_condition_fulfillment | String | *Optional* Proof of condition completion |
| related\_resources.cancellation\_condition_fulfillment | String | *Optional* Proof of condition completion |
| related\_resources.execution\_condition_fulfilment | String | *Optional* Proof of condition completion |
| related\_resources.cancellation\_condition_fulfilment | String | *Optional* Proof of condition completion |

### Metadata Object

Expand Down
1 change: 1 addition & 0 deletions config/knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const Config = require('../src/lib/config')

module.exports = {
client: 'mysql',
version: '5.5',
connection: Config.DATABASE_URI,
migrations: {
directory: migrationsDirectory,
Expand Down
9 changes: 6 additions & 3 deletions seeds/currency.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,14 @@ const currencies = [
}
]

exports.seed = async function (knex, Promise) {
exports.seed = async function (knex) {
try {
return await knex('currency').insert(currencies)
} catch (err) {
if (err.code === 'ER_DUP_ENTRY') return
else console.log(`Uploading seeds for currency has failed with the following error: ${err}`)
if (err.code === 'ER_DUP_ENTRY') return -1001
else {
console.log(`Uploading seeds for currency has failed with the following error: ${err}`)
return -1000
}
}
}
9 changes: 6 additions & 3 deletions seeds/endpointType.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ const endpointTypes = [
}
]

exports.seed = async function (knex, Promise) {
exports.seed = async function (knex) {
try {
return await knex('endpointType').insert(endpointTypes)
} catch (err) {
if (err.code === 'ER_DUP_ENTRY') return
else console.log(`Uploading seeds for endpointType has failed with the following error: ${err}`)
if (err.code === 'ER_DUP_ENTRY') return -1001
else {
console.log(`Uploading seeds for endpointType has failed with the following error: ${err}`)
return -1000
}
}
}
9 changes: 6 additions & 3 deletions seeds/ledgerEntryType.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ const ledgerEntryTypes = [
}
]

exports.seed = async function (knex, Promise) {
exports.seed = async function (knex) {
try {
return await knex('ledgerEntryType').insert(ledgerEntryTypes)
} catch (err) {
if (err.code === 'ER_DUP_ENTRY') return
else console.log(`Uploading seeds for ledgerEntryType has failed with the following error: ${err}`)
if (err.code === 'ER_DUP_ENTRY') return -1001
else {
console.log(`Uploading seeds for ledgerEntryType has failed with the following error: ${err}`)
return -1000
}
}
}
9 changes: 6 additions & 3 deletions seeds/participantLimitType.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,14 @@ const participantLimitTypes = [
}
]

exports.seed = async function (knex, Promise) {
exports.seed = async function (knex) {
try {
return await knex('participantLimitType').insert(participantLimitTypes)
} catch (err) {
if (err.code === 'ER_DUP_ENTRY') return
else console.log(`Uploading seeds for participantLimitType has failed with the following error: ${err}`)
if (err.code === 'ER_DUP_ENTRY') return -1001
else {
console.log(`Uploading seeds for participantLimitType has failed with the following error: ${err}`)
return -1000
}
}
}
9 changes: 6 additions & 3 deletions seeds/transferParticipantRoleType.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,14 @@ const transferParticipantRoleTypes = [
}
]

exports.seed = async function (knex, Promise) {
exports.seed = async function (knex) {
try {
return await knex('transferParticipantRoleType').insert(transferParticipantRoleTypes)
} catch (err) {
if (err.code === 'ER_DUP_ENTRY') return
else console.log(`Uploading seeds for transferParticipantRoleType has failed with the following error: ${err}`)
if (err.code === 'ER_DUP_ENTRY') return -1001
else {
console.log(`Uploading seeds for transferParticipantRoleType has failed with the following error: ${err}`)
return -1000
}
}
}
9 changes: 6 additions & 3 deletions seeds/transferState.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ const transferStates = [
}
]

exports.seed = async function (knex, Promise) {
exports.seed = async function (knex) {
try {
return await knex('transferState').insert(transferStates)
} catch (err) {
if (err.code === 'ER_DUP_ENTRY') return
else console.log(`Uploading seeds for transferState has failed with the following error: ${err}`)
if (err.code === 'ER_DUP_ENTRY') return -1001
else {
console.log(`Uploading seeds for transferState has failed with the following error: ${err}`)
return -1000
}
}
}
122 changes: 122 additions & 0 deletions seeds/zzzDEVseed.js--
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
/*****
License
--------------
Copyright © 2017 Bill & Melinda Gates Foundation
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
http://www.apache.org/licenses/LICENSE-2.0
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.
Contributors
--------------
This is the official list of the Mojaloop project contributors for this file.
Names of the original copyright holders (individuals or organizations)
should be listed with a '*' in the first column. People who have
contributed from an organization can be listed under the organization
that actually holds the copyright for their contributions (see the
Gates Foundation organization for an example). Those individuals should have
their names indented and be marked with a '-'. Email address can be added
optionally within square brackets <email>.
* Gates Foundation
- Name Surname <name.surname@gatesfoundation.com>

* Georgi Georgiev <georgi.georgiev@modusbox.com>
--------------
******/

'use strict'

const createdBy = 'zzzDEVseed'
const createdDate = new Date()

const participants = [
{
'name': 'dfsp1',
createdDate,
createdBy
},
{
'name': 'dfsp2',
createdDate,
createdBy
}
]

const participantCurrencies = [
{
'participantId': 1,
'currencyId': 'USD',
createdDate,
createdBy
},
{
'participantId': 1,
'currencyId': 'EUR',
createdDate,
createdBy
},
{
'participantId': 2,
'currencyId': 'USD',
createdDate,
createdBy
}
]

const participantLimits = [
{
'participantCurrencyId': 1,
'participantLimitTypeId': 1,
'value': 1000,
createdDate,
createdBy
},
{
'participantCurrencyId': 2,
'participantLimitTypeId': 1,
'value': 1000,
createdDate,
createdBy
},
{
'participantCurrencyId': 3,
'participantLimitTypeId': 1,
'value': 1000,
createdDate,
createdBy
}
]

const participantPositions = [
{
'participantCurrencyId': 1,
'value': 100,
'reservedValue': 0,
changedDate: createdDate
},
{
'participantCurrencyId': 2,
'value': 100,
'reservedValue': 0,
changedDate: createdDate
},
{
'participantCurrencyId': 3,
'value': 500,
'reservedValue': 0,
changedDate: createdDate
}
]
exports.seed = async function (knex) {
try {
await knex('participant').insert(participants)
await knex('participantCurrency').insert(participantCurrencies)
await knex('participantLimit').insert(participantLimits)
await knex('participantPosition').insert(participantPositions)
return true
} catch (err) {
if (err.code === 'ER_DUP_ENTRY') return -1001
else {
console.log(`Uploading development seeds has failed with the following error: ${err}`)
return -1000
}
}
}
1 change: 0 additions & 1 deletion src/admin/auth/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,3 @@ module.exports = {
scheme: 'jwt-strategy',
validate: validate
}

6 changes: 3 additions & 3 deletions src/admin/participants/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ const getEndpoint = async function (request, h) {
}
}

const addInitialPositionAndLimits = async function (request, h) {
const addLimitAndInitialPosition = async function (request, h) {
Sidecar.logRequest(request)
try {
await Participant.addInitialPositionAndLimits(request.params.name, request.payload)
await Participant.addLimitAndInitialPosition(request.params.name, request.payload)
return h.response().code(201)
} catch (err) {
throw Boom.badRequest()
Expand All @@ -145,5 +145,5 @@ module.exports = {
update,
addEndpoint,
getEndpoint,
addInitialPositionAndLimits
addLimitAndInitialPosition
}
2 changes: 1 addition & 1 deletion src/admin/participants/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ module.exports = [
{
method: 'POST',
path: '/participants/{name}/initialPositionAndLimits',
handler: Handler.addInitialPositionAndLimits,
handler: Handler.addLimitAndInitialPosition,
options: {
id: 'participants_limits_pos_add',
tags: tags,
Expand Down
1 change: 0 additions & 1 deletion src/api/auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ exports.strategy = (optional = false) => {
strategy
}
}

1 change: 0 additions & 1 deletion src/api/auth/token.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ module.exports = {
scheme: 'bearer',
validate: TokenAuth.validate
}

8 changes: 4 additions & 4 deletions src/api/sockets/validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ const validateSubscriptionRequest = (data, cb) => {
return cb(reformatValidationError(err))
}
P.all(result.params.participant.map(participantUri => ParticipantService.exists(participantUri)))
.then(() => cb(null, { id: result.id, jsonrpc: result.jsonrpc, participantUris: result.params.participant }))
.catch(e => {
cb(new InvalidSubscriptionRequestError({ message: e.message }))
})
.then(() => cb(null, { id: result.id, jsonrpc: result.jsonrpc, participantUris: result.params.participant }))
.catch(e => {
cb(new InvalidSubscriptionRequestError({ message: e.message }))
})
})
} catch (e) {
return cb(new InvalidSubscriptionRequestError({ message: e.message }))
Expand Down
4 changes: 2 additions & 2 deletions src/api/transfers/handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ exports.getTransferById = async function (request, h) {
return buildGetTransferResponse(record)
}

exports.getTransferFulfillment = async function (request, h) {
const result = await TransferService.getFulfillment(request.params.id)
exports.getTransferFulfilment = async function (request, h) {
const result = await TransferService.getFulfilment(request.params.id)
return h.response(result).type('text/plain')
}
4 changes: 2 additions & 2 deletions src/api/transfers/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ module.exports = [{
path: '/transfers/{id}/fulfilment',
handler: Handler.fulfillTransfer,
options: {
id: 'transfer_fulfillment',
id: 'transfer_fulfilment',
tags: tags,
auth: Auth.strategy(),
description: 'Fulfil a transfer',
Expand Down Expand Up @@ -102,7 +102,7 @@ module.exports = [{
{
method: 'GET',
path: '/transfers/{id}/fulfilment',
handler: Handler.getTransferFulfillment,
handler: Handler.getTransferFulfilment,
options: {
tags: tags,
description: 'Get transfer fulfilment',
Expand Down
8 changes: 4 additions & 4 deletions src/cryptoConditions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const validateCondition = (conditionUri) => {
}
}

const validateFulfillment = (fulfilment, condition) => {
const validateFulfilment = (fulfilment, condition) => {
try {
const fulfillmentCondition = FiveBellsCondition.fulfillmentToCondition(fulfilment)
if (fulfillmentCondition === condition) {
const fulfilmentCondition = FiveBellsCondition.fulfillmentToCondition(fulfilment)
if (fulfilmentCondition === condition) {
return FiveBellsCondition.validateFulfillment(fulfilment, condition)
}
} catch (error) {
Expand All @@ -25,5 +25,5 @@ const validateFulfillment = (fulfilment, condition) => {

module.exports = {
validateCondition,
validateFulfillment
validateFulfilment
}
Loading

0 comments on commit 2f2adb7

Please sign in to comment.