Skip to content
This repository has been archived by the owner on Apr 16, 2021. It is now read-only.

Commit

Permalink
Merge pull request #97 from wibsonorg/WIB-859/filter-processed-emails
Browse files Browse the repository at this point in the history
Wib 859/Filter processed emails
  • Loading branch information
Meketh authored Jul 23, 2019
2 parents 6a64004 + efa20a7 commit cf55b97
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 9 deletions.
4 changes: 3 additions & 1 deletion notary-api/src/queues/notarizationsQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { notarizationResults, dataResponses } from '../utils/stores';
import { validateDataBatch } from '../services/validatorService';
import { completeNotarizationJob } from '../operations/completeNotarization';
import { decryptWithPrivateKey } from '../utils/wibson-lib/cryptography';
import { getDataOrder } from '../operations/dataExchange';

const queueName = 'NotarizationQueue';
const defaultJobOptions = {
Expand Down Expand Up @@ -52,8 +53,9 @@ export const notarize = async (lockingKeyHash) => {

const sellersToValidate = sellers.filter(inAgreement);
if (sellersToValidate.length > 0) {
const { id } = await getDataOrder(orderId);
const dataBatch = await prepareDataBatchForValidation(orderId, sellersToValidate);
await validateDataBatch(lockingKeyHash, dataBatch);
await validateDataBatch(id, lockingKeyHash, dataBatch);
await notarizationResults.update(lockingKeyHash, { status: 'validating' });
} else {
completeNotarizationJob(lockingKeyHash);
Expand Down
46 changes: 43 additions & 3 deletions notary-api/src/routes/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,59 @@ const router = express.Router();
* description: |
* Receives and stores data validation results so that associated
* DataResponse can be closed.
* parameters:
* - in: body
* name: validationResponse
* required: true
* schema:
* $ref: "#/definitions/ValidationResponse"
* produces:
* - application/json
* responses:
* 200:
* description: When validation results are registered successfully
*
* definitions:
* ValidationResponse:
* type: object
* required:
* - dataGroupId
* - dataBatchId
* - result
* properties:
* dataGroupId:
* type: string
* description: The unique identifier for the validation batch.
* dataBatchId:
* type: string
* description: The unique identifier for the validation batch.
* result:
* type: array
* description: The result validation for that batch.
* items:
* type: object
* required:
* - id
* - validated
* - identified
* properties:
* id:
* type: string
* description: The unique identifier for that data.
* validated:
* type: boolean
* description: Whether the data was validated or not.
* identified:
* type: boolean
* description: Whether the validation result was positive or not.
*/
router.post('/validation-result', asyncError(async (req, res) => {
const { nonce, result } = req.body;
const notarization = await notarizationResults.safeFetch(nonce);
const { dataBatchId, result } = req.body;
const notarization = await notarizationResults.safeFetch(dataBatchId);
if (!notarization) {
res.boom.notFound('No notarization found');
} else {
await completeNotarization(nonce, result);
await completeNotarization(dataBatchId, result);
res.sendStatus(202);
}
}));
Expand Down
7 changes: 4 additions & 3 deletions notary-api/src/services/validatorService.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ const httpsAgent = new https.Agent({
});

/**
* @param {number} payloadID DataOrder ID in DataExchange
* @param {string} dataGroupId The unique identifier for the validation data group
* @param {string} dataBatchId The unique identifier for the validation batch
* @param {object[]} payload Information to validate
*/
export const validateDataBatch = async (payloadID, payload) =>
export const validateDataBatch = async (dataGroupId, dataBatchId, payload) =>
axios.post(
`${config.notaryValidatorUrl}/validate`,
{ nonce: payloadID, payload },
{ dataGroupId, dataBatchId, payload },
{ httpsAgent },
);

Expand Down
9 changes: 7 additions & 2 deletions notary-api/test/queues/notarizationsQueue.mock.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,13 @@ td.replace('../../src/queues/createQueue', {
createQueue: sinon.stub().returns(notarizationsQueue),
});

export const completeNotarizationJob = sinon.spy();
td.replace('../../src/operations/completeNotarization', { completeNotarizationJob });
export const { completeNotarizationJob } = td.replace('../../src/operations/completeNotarization', {
completeNotarizationJob: sinon.spy(),
});

export const { getDataOrder } = td.replace('../../src/operations/dataExchange', {
getDataOrder: sinon.spy(dxid => ({ id: `some-uuid-for-order-${dxid}` })),
});

test.beforeEach(() => {
decryptWithPrivateKey.returns(JSON.stringify({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ Generated by [AVA](https://ava.li).
## validateDataBatch.args

[
'some-uuid-for-order-42',
'0x7b9a465acbec4bbce6782e7b2f00d2c6e95c49eff319f1748c1119dc9393a2f6',
[
{
Expand Down
Binary file modified notary-api/test/queues/snapshots/notarizationsQueue.test.js.snap
Binary file not shown.

0 comments on commit cf55b97

Please sign in to comment.