Skip to content

Commit

Permalink
Merge pull request #1321 from OriginTrail/prerelease/testnet
Browse files Browse the repository at this point in the history
OriginTrail Testnet Release v4.1.8
  • Loading branch information
Kuki145 authored Jul 21, 2020
2 parents 2e21e00 + aa289cc commit f77a089
Show file tree
Hide file tree
Showing 28 changed files with 899 additions and 297 deletions.
10 changes: 7 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ env:
- NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=third
- NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=fourth
- NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=fifth
- NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=sixth
- NODE_ENV=development ARTIFACTS_DIR=$TRAVIS_BUILD_DIR/artifacts CUCUMBER_ARTIFACTS_DIR=$ARTIFACTS_DIR/cucumber BDD_SECTION=docker

cache:
Expand Down Expand Up @@ -42,15 +43,18 @@ script:
- if [[ ("$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "fourth" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "fourth" ) ]]; then
travis_wait 50 npm run test:bdd -- --tags=@fourth --world-parameters '{"appDataBaseDir":"$CUCUMBER_ARTIFACTS_DIR","keepFailedArtifacts":true}';
fi
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "fifth" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "first" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "first" ) ]]; then
- if [[ ("$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "fifth" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "fifth" ) ]]; then
travis_wait 50 npm run test:bdd -- --tags=@fifth --world-parameters '{"appDataBaseDir":"$CUCUMBER_ARTIFACTS_DIR","keepFailedArtifacts":true}';
fi
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "sixth" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "first" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "first" ) ]]; then
npm test 2> $ARTIFACTS_DIR/mocha-logs.log;
fi
# compile and check Smart Contracts
- npm run ganache &> $ARTIFACTS_DIR/ganache.log &
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "fifth" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "second" ) ]]; then
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "sixth" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "sixth" ) ]]; then
npm run truffle:test > $ARTIFACTS_DIR/truffle-test.log;
fi
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "fifth" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "docker" ) || ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "docker" ) ]]; then
- if [[ ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "sixth" ) || ( "$TRAVIS_EVENT_TYPE" == "push" && "$BDD_SECTION" == "second" ) || ( "$TRAVIS_EVENT_TYPE" == "cron" && "$BDD_SECTION" == "sixth" ) || ( "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "docker" )]]; then
npm run truffle:deploy:ganache > $ARTIFACTS_DIR/truffle-migrate.log;
fi
- if [[ "$TRAVIS_EVENT_TYPE" == "pull_request" && "$BDD_SECTION" == "docker" ]]; then ./test/docker/check_image.sh; fi
Expand Down
177 changes: 96 additions & 81 deletions modules/Blockchain/Ethereum/index.js

Large diffs are not rendered by default.

42 changes: 42 additions & 0 deletions modules/Database/Arangojs.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,48 @@ class ArangoJS {
return result;
}

/**
* Finds objects based on ids and datasets which contain them
*
* @param {Array} ids - Encrypted color (0=RED,1=GREEN,2=BLUE)
* @param {object} datasets - Object which maps which datasets contain the requested object,
* in the following format { id: [datasets] }
* @return {Promise}
*/
async findTrailExtension(ids, datasets) {
const queryParams = {
ids,
datasets,
};
const queryString = `LET trailEntities = (
FOR entity IN ot_vertices
FILTER entity.uid IN @ids
AND LENGTH(INTERSECTION(entity.datasets, @datasets[entity.uid])) > 0
RETURN entity
)
FOR trailObject in trailEntities
FILTER trailObject != null
LET objectsRelated = (
FOR v, e in 1..1 OUTBOUND trailObject ot_edges
FILTER e.edgeType IN ['IdentifierRelation','dataRelation','otRelation']
AND e.datasets != null
AND v.datasets != null
AND LENGTH(INTERSECTION(e.datasets, v.datasets, trailObject.datasets)) > 0
RETURN {
"vertex": v,
"edge": e
}
)
RETURN {
"rootObject": trailObject,
"relatedObjects": objectsRelated
}`;

const result = await this.runQuery(queryString, queryParams);
return result;
}


async getConsensusEvents(sender_id) {
const query = `FOR v IN ot_vertices
Expand Down
22 changes: 22 additions & 0 deletions modules/Database/GraphStorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,28 @@ class GraphStorage {
});
}

/**
* Finds objects based on ids and datasets which contain them
*
* @param {Array} ids - Encrypted color (0=RED,1=GREEN,2=BLUE)
* @param {object} datasets - Object which maps which datasets contain the requested object,
* in the following format { id: [datasets] }
* @return {Promise}
*/
findTrailExtension(ids, datasets) {
return new Promise((resolve, reject) => {
if (!this.db) {
reject(Error('Not connected to graph database.'));
} else {
this.db.findTrailExtension(ids, datasets).then((result) => {
resolve(result);
}).catch((err) => {
reject(err);
});
}
});
}

/**
* Finds imports IDs based on data location query
*
Expand Down
2 changes: 1 addition & 1 deletion modules/ImportUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ class ImportUtilities {
* Fill in dataset header
* @private
*/
static createDatasetHeader(config, transpilationInfo = null, datasetTags = [], datasetTitle = '', datasetDescription = '', OTJSONVersion = '1.1', datasetCreationTimestamp = new Date().toISOString()) {
static createDatasetHeader(config, transpilationInfo = null, datasetTags = [], datasetTitle = '', datasetDescription = '', OTJSONVersion = '1.2', datasetCreationTimestamp = new Date().toISOString()) {
const header = {
OTJSONVersion,
datasetCreationTimestamp,
Expand Down
2 changes: 1 addition & 1 deletion modules/OtJsonUtilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class OtJsonUtilities {
static _getDatasetVersion(dataset) {
if (!dataset || !dataset.datasetHeader ||
!dataset.datasetHeader.OTJSONVersion) {
return '1.1';
return '1.2';
// throw new Error('Could not determine dataset ot-json version!');
}
return dataset.datasetHeader.OTJSONVersion;
Expand Down
10 changes: 10 additions & 0 deletions modules/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,16 @@ exports.PROCESS_NAME = {
litigationHandling: 'litigation-handling',
};

/**
*
* @constant {integer} PROCESS_NAME -
* Name of the process for grouping events for bugsnag
*/
exports.TRAIL_REACH_PARAMETERS = {
extended: 'extended',
narrow: 'narrow',
};

/**
*
* @constant {string} PERMISSIONED_DATA_VISIBILITY_SHOW_ATTRIBUTE -
Expand Down
105 changes: 105 additions & 0 deletions modules/controller/dh-controller.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const Utilities = require('../Utilities');
const Models = require('../../models');
const constants = require('../constants');

/**
* Encapsulates DH related methods
Expand All @@ -9,6 +10,8 @@ class DHController {
this.config = ctx.config;
this.logger = ctx.logger;
this.blockchain = ctx.blockchain;
this.graphStorage = ctx.graphStorage;
this.importService = ctx.importService;
}

isParameterProvided(request, response, parameter_name) {
Expand Down Expand Up @@ -85,6 +88,108 @@ class DHController {
status: 'SUCCESS',
});
}

async getTrail(req, res) {
if (req.body === undefined ||
req.body.identifier_types === undefined ||
req.body.identifier_values === undefined
) {
res.status(400);
res.send({
message: 'Bad request',
});
return;
}

const { identifier_types, identifier_values } = req.body;

if (Utilities.arrayze(identifier_types).length !==
Utilities.arrayze(identifier_values).length) {
res.status(400);
res.send({
message: 'Identifier array length mismatch',
});
return;
}

const depth = req.body.depth === undefined ?
this.graphStorage.getDatabaseInfo().max_path_length :
parseInt(req.body.depth, 10);

const reach = req.body.reach === undefined ?
constants.TRAIL_REACH_PARAMETERS.narrow : req.body.reach.toLowerCase();

const { connection_types } = req.body;

const keys = [];

const typesArray = Utilities.arrayze(identifier_types);
const valuesArray = Utilities.arrayze(identifier_values);

for (let i = 0; i < typesArray.length; i += 1) {
keys.push(Utilities.keyFrom(typesArray[i], valuesArray[i]));
}

try {
const trail =
await this.graphStorage.findTrail({
identifierKeys: keys,
depth,
connectionTypes: connection_types,
});

let response = this.importService.packTrailData(trail);

if (reach === constants.TRAIL_REACH_PARAMETERS.extended) {
response = await this._extendResponse(response);
}

res.status(200);
res.send(response);
} catch (e) {
res.status(400);
res.send(e);
}
}

async _extendResponse(response) {
const missingObjects = {};
for (const trailElement of response) {
const object = trailElement.otObject;

const elementIsMissing =
(array, element) => !array.find(e => e.otObject['@id'] === element['@id']);

for (const relation of object.relations) {
if (elementIsMissing(response, relation.linkedObject)) {
if (!missingObjects[relation.linkedObject['@id']]) {
missingObjects[relation.linkedObject['@id']] = trailElement.datasets;
} else {
missingObjects[relation.linkedObject['@id']] =
[...new Set(missingObjects[relation.linkedObject['@id']], trailElement.datasets)];
}
}
}
}

if (Object.keys(missingObjects).length > 0) {
/*
missingObjects: {
id1: [ dataset 1, dataset 2, ... ],
id2: [ dataset 2, dataset x, ... ],
...
}
*/

const missingIds = Object.keys(missingObjects);
const missingElements =
await this.graphStorage.findTrailExtension(missingIds, missingObjects);

const trailExtension = this.importService.packTrailData(missingElements);

return response.concat(trailExtension);
}
}
}

module.exports = DHController;
Loading

0 comments on commit f77a089

Please sign in to comment.