From 216b0844b8de874ea5a71e367df2a1b5e3fe22e5 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Mon, 18 Nov 2024 17:41:00 +0100 Subject: [PATCH 1/5] Add await to calculate root (#3416) * Add await * version bump --- package-lock.json | 4 ++-- package.json | 2 +- src/commands/common/validate-asset-command.js | 2 +- src/migration/pending-storage-migration.js | 2 +- src/modules/validation/implementation/merkle-validation.js | 2 +- src/modules/validation/validation-module-manager.js | 2 +- src/service/validation-service.js | 6 +++--- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/package-lock.json b/package-lock.json index b0cba1c9e1..8d30cac658 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "8.1.2+beta.0", + "version": "8.1.3+beta.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "8.1.2+beta.0", + "version": "8.1.3+beta.1", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", diff --git a/package.json b/package.json index 6ef9cfaab4..5b74232f9c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "8.1.3+beta.0", + "version": "8.1.3+beta.1", "description": "OTNode V8", "main": "index.js", "type": "module", diff --git a/src/commands/common/validate-asset-command.js b/src/commands/common/validate-asset-command.js index 36a34aacd1..e4a4bb27d6 100644 --- a/src/commands/common/validate-asset-command.js +++ b/src/commands/common/validate-asset-command.js @@ -86,7 +86,7 @@ class ValidateAssetCommand extends Command { ); try { - this.validationService.validateAssertionId( + await this.validationService.validateAssertionId( cachedData.private.assertion, cachedData.private.assertionId, ); diff --git a/src/migration/pending-storage-migration.js b/src/migration/pending-storage-migration.js index 040cf491a5..a19fbdf957 100644 --- a/src/migration/pending-storage-migration.js +++ b/src/migration/pending-storage-migration.js @@ -20,7 +20,7 @@ class PendingStorageMigration extends BaseMigration { const cachedData = await this.fileService.readFile(newDirectoryPath, true); await this.fileService.removeFile(newDirectoryPath); if (cachedData?.public?.assertion) { - const newDocumentName = calculateRoot(cachedData.public.assertion); + const newDocumentName = await calculateRoot(cachedData.public.assertion); await this.fileService.writeContentsToFile( newDirectoryPath, newDocumentName, diff --git a/src/modules/validation/implementation/merkle-validation.js b/src/modules/validation/implementation/merkle-validation.js index 72980825f5..999ab47819 100644 --- a/src/modules/validation/implementation/merkle-validation.js +++ b/src/modules/validation/implementation/merkle-validation.js @@ -12,7 +12,7 @@ class MerkleValidation { }; } - calculateRoot(assertion) { + async calculateRoot(assertion) { return calculateRoot(assertion); } diff --git a/src/modules/validation/validation-module-manager.js b/src/modules/validation/validation-module-manager.js index 8f326905ae..f56c16df24 100644 --- a/src/modules/validation/validation-module-manager.js +++ b/src/modules/validation/validation-module-manager.js @@ -5,7 +5,7 @@ class ValidationModuleManager extends BaseModuleManager { return 'validation'; } - calculateRoot(assertion) { + async calculateRoot(assertion) { if (this.initialized) { if (!assertion) { throw new Error('Calculation failed: Assertion cannot be null or undefined.'); diff --git a/src/service/validation-service.js b/src/service/validation-service.js index 6782ddbc36..e8b0f0256f 100644 --- a/src/service/validation-service.js +++ b/src/service/validation-service.js @@ -34,7 +34,7 @@ class ValidationService { async validateAssertion(assertionId, blockchain, assertion) { this.logger.info(`Validating assertionId: ${assertionId}`); - this.validateAssertionId(assertion, assertionId); + await this.validateAssertionId(assertion, assertionId); const blockchainAssertionData = await this.blockchainModuleManager.getAssertionData( blockchain, assertionId, @@ -80,8 +80,8 @@ class ValidationService { } } - validateAssertionId(assertion, assertionId) { - const calculatedAssertionId = this.validationModuleManager.calculateRoot(assertion); + async validateAssertionId(assertion, assertionId) { + const calculatedAssertionId = await this.validationModuleManager.calculateRoot(assertion); if (assertionId !== calculatedAssertionId) { // todo after corrective component is implemented, update this logic From 32f3d28a946b256a8352d8128831ae678b05de64 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Mon, 18 Nov 2024 17:53:11 +0100 Subject: [PATCH 2/5] package update --- package-lock.json | 15 +++++++++------ package.json | 4 ++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8d30cac658..a7d04fd0f9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "origintrail_node", - "version": "8.1.3+beta.1", + "version": "8.1.3+beta.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "origintrail_node", - "version": "8.1.3+beta.1", + "version": "8.1.3+beta.2", "license": "ISC", "dependencies": { "@comunica/query-sparql": "^2.4.3", @@ -18,7 +18,7 @@ "@polkadot/util": "^10.1.7", "@polkadot/util-crypto": "^10.1.7", "app-root-path": "^3.1.0", - "assertion-tools": "^2.0.2", + "assertion-tools": "^2.2.1", "async": "^3.2.4", "async-mutex": "^0.3.2", "awilix": "^7.0.3", @@ -6143,8 +6143,9 @@ } }, "node_modules/assertion-tools": { - "version": "2.1.0", - "license": "ISC", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/assertion-tools/-/assertion-tools-2.2.1.tgz", + "integrity": "sha512-JlA1S16Ox93PnYb45HvxNcax/Ii4gqTO8HLGa/ykj/ddp8EEHlokn6inJR2yMiz173WSFkCc0ciLJzGeaYBANw==", "dependencies": { "ethers": "^5.7.2", "jsonld": "^8.1.0", @@ -25754,7 +25755,9 @@ } }, "assertion-tools": { - "version": "2.1.0", + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/assertion-tools/-/assertion-tools-2.2.1.tgz", + "integrity": "sha512-JlA1S16Ox93PnYb45HvxNcax/Ii4gqTO8HLGa/ykj/ddp8EEHlokn6inJR2yMiz173WSFkCc0ciLJzGeaYBANw==", "requires": { "ethers": "^5.7.2", "jsonld": "^8.1.0", diff --git a/package.json b/package.json index 5b74232f9c..9458964aa0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "origintrail_node", - "version": "8.1.3+beta.1", + "version": "8.1.3+beta.2", "description": "OTNode V8", "main": "index.js", "type": "module", @@ -73,7 +73,7 @@ "@polkadot/util": "^10.1.7", "@polkadot/util-crypto": "^10.1.7", "app-root-path": "^3.1.0", - "assertion-tools": "^2.2.0", + "assertion-tools": "^2.2.1", "async": "^3.2.4", "async-mutex": "^0.3.2", "awilix": "^7.0.3", From 91ab57ff000280e2e2979eceba6c3b5675eb2b91 Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Wed, 20 Nov 2024 14:36:11 +0100 Subject: [PATCH 3/5] Add async for getMerkleProof --- src/modules/validation/implementation/merkle-validation.js | 2 +- src/modules/validation/validation-module-manager.js | 2 +- test/unit/modules/validation/validation-module-manager.test.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/validation/implementation/merkle-validation.js b/src/modules/validation/implementation/merkle-validation.js index 999ab47819..f832b616f8 100644 --- a/src/modules/validation/implementation/merkle-validation.js +++ b/src/modules/validation/implementation/merkle-validation.js @@ -16,7 +16,7 @@ class MerkleValidation { return calculateRoot(assertion); } - getMerkleProof(nquadsArray, challenge) { + async getMerkleProof(nquadsArray, challenge) { return getMerkleProof(nquadsArray, challenge); } diff --git a/src/modules/validation/validation-module-manager.js b/src/modules/validation/validation-module-manager.js index f56c16df24..e5be437621 100644 --- a/src/modules/validation/validation-module-manager.js +++ b/src/modules/validation/validation-module-manager.js @@ -15,7 +15,7 @@ class ValidationModuleManager extends BaseModuleManager { throw new Error('Validation module is not initialized.'); } - getMerkleProof(assertion, index) { + async getMerkleProof(assertion, index) { if (this.initialized) { if (!assertion) { throw new Error('Get merkle proof failed: Assertion cannot be null or undefined.'); diff --git a/test/unit/modules/validation/validation-module-manager.test.js b/test/unit/modules/validation/validation-module-manager.test.js index 4cabe5041a..2a3f68f809 100644 --- a/test/unit/modules/validation/validation-module-manager.test.js +++ b/test/unit/modules/validation/validation-module-manager.test.js @@ -76,7 +76,7 @@ describe.only('Validation module manager', async () => { }); it('successful getting merkle proof hash', async () => { - const calculatedMerkleHash = validationManager.getMerkleProof(assertion, 0); + const calculatedMerkleHash = await validationManager.getMerkleProof(assertion, 0); assert(expect(calculatedMerkleHash).to.exist); expect(calculatedMerkleHash).to.be.instanceof(Object); From 5c67b81b7b6ba347deff468382971afbbe9ac1fd Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Wed, 20 Nov 2024 14:41:46 +0100 Subject: [PATCH 4/5] Add await to tests --- .../validation/validation-module-manager.test.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/test/unit/modules/validation/validation-module-manager.test.js b/test/unit/modules/validation/validation-module-manager.test.js index 2a3f68f809..5f3f7fabb7 100644 --- a/test/unit/modules/validation/validation-module-manager.test.js +++ b/test/unit/modules/validation/validation-module-manager.test.js @@ -88,19 +88,20 @@ describe.only('Validation module manager', async () => { validationManager.initialized = false; try { - validationManager.getMerkleProof(assertion, 0); + await validationManager.getMerkleProof(assertion, 0); } catch (error) { expect(error.message).to.equal('Validation module is not initialized.'); } }); - it('failed merkle prof hash calculation when assertion is null or undefined', async () => { - invalidValues.forEach((value) => { - expect(() => validationManager.getMerkleProof(value, 0)).to.throw( + it('failed merkle proof hash calculation when assertion is null or undefined', async () => { + for (const value of invalidValues) { + // eslint-disable-next-line no-await-in-loop + expect(await validationManager.getMerkleProof(value, 0)).to.be.rejectedWith( Error, 'Get merkle proof failed: Assertion cannot be null or undefined.', ); - }); + } }); it('validate getting function name', async () => { From 72367584eaa8637c64a4d2a1c1887a6244b52c3a Mon Sep 17 00:00:00 2001 From: Mihajlo Pavlovic Date: Wed, 20 Nov 2024 14:50:32 +0100 Subject: [PATCH 5/5] more awaits --- src/commands/protocols/common/submit-proofs-command.js | 2 +- .../modules/validation/validation-module-manager.test.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/commands/protocols/common/submit-proofs-command.js b/src/commands/protocols/common/submit-proofs-command.js index 57b4b7d028..1db3f7a013 100644 --- a/src/commands/protocols/common/submit-proofs-command.js +++ b/src/commands/protocols/common/submit-proofs-command.js @@ -84,7 +84,7 @@ class SubmitProofsCommand extends SendTransactionCommand { return Command.empty(); } - const { leaf, proof } = this.validationModuleManager.getMerkleProof( + const { leaf, proof } = await this.validationModuleManager.getMerkleProof( assertion, Number(challenge), ); diff --git a/test/unit/modules/validation/validation-module-manager.test.js b/test/unit/modules/validation/validation-module-manager.test.js index 5f3f7fabb7..4e2306d1f0 100644 --- a/test/unit/modules/validation/validation-module-manager.test.js +++ b/test/unit/modules/validation/validation-module-manager.test.js @@ -49,8 +49,8 @@ describe.only('Validation module manager', async () => { }); it('validate successful root hash calculation, expect to be matched', async () => { - const expectedRootHash = calculateRoot(assertion); - const calculatedRootHash = validationManager.calculateRoot(assertion); + const expectedRootHash = await calculateRoot(assertion); + const calculatedRootHash = await validationManager.calculateRoot(assertion); assert(expect(calculatedRootHash).to.exist); expect(calculatedRootHash).to.equal(expectedRootHash); @@ -60,7 +60,7 @@ describe.only('Validation module manager', async () => { validationManager.initialized = false; try { - validationManager.calculateRoot(assertion); + await validationManager.calculateRoot(assertion); } catch (error) { expect(error.message).to.equal('Validation module is not initialized.'); }