Skip to content

Commit

Permalink
Merge branch 'v6/develop' into improvement/fixed-gas-limit-removal
Browse files Browse the repository at this point in the history
  • Loading branch information
NZT48 authored Sep 7, 2023
2 parents b3e34f7 + 40c317c commit 6055570
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 47 deletions.
7 changes: 4 additions & 3 deletions src/service/validation-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ class ValidationService {
this.validateAssertionId(assertion, assertionId);

// TODO: get assertion data in one call

await this.validateAssertionSize(blockchain, assertionId, assertion);
await this.validateTriplesNumber(blockchain, assertionId, assertion);
await this.validateChunkSize(blockchain, assertionId, assertion);
Expand All @@ -56,7 +55,8 @@ class ValidationService {
}
const assertionSize = assertionMetadata.getAssertionSizeInBytes(assertion);
if (blockchainAssertionSize !== assertionSize) {
throw Error(
// todo after corrective component is implemented, update this logic
this.logger.warn(
`Invalid assertion size, value read from blockchain: ${blockchainAssertionSize}, calculated: ${assertionSize}`,
);
}
Expand Down Expand Up @@ -90,7 +90,8 @@ class ValidationService {
const calculatedAssertionId = this.validationModuleManager.calculateRoot(assertion);

if (assertionId !== calculatedAssertionId) {
throw Error(
// todo after corrective component is implemented, update this logic
this.logger.warn(
`Invalid assertion id. Received value: ${assertionId}, calculated: ${calculatedAssertionId}`,
);
}
Expand Down
90 changes: 46 additions & 44 deletions test/unit/service/validation-service.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,23 @@ describe('Validation service test', async () => {
});

it('Tries to validate assertion but fails due to assertion size mismatch', async () => {
let errorThrown = false;
try {
await validationService.validateAssertion(
'0xde58cc52a5ce3a04ae7a05a13176226447ac02489252e4d37a72cbe0aea46b42',
'hardhat',
{
'@context': 'https://schema.org',
'@id': 'https://tesla.modelX/2321',
'@type': 'Car',
name: 'Tesla Model X',
},
);
} catch (error) {
errorThrown = true;
}
expect(errorThrown).to.be.true;
// todo after corrective component is implemented, update this logic
// let errorThrown = false;
// try {
// await validationService.validateAssertion(
// '0xde58cc52a5ce3a04ae7a05a13176226447ac02489252e4d37a72cbe0aea46b42',
// 'hardhat',
// {
// '@context': 'https://schema.org',
// '@id': 'https://tesla.modelX/2321',
// '@type': 'Car',
// name: 'Tesla Model X',
// },
// );
// } catch (error) {
// errorThrown = true;
// }
// expect(errorThrown).to.be.true;
});

it('Tries to validate assertion but fails due to triple number mismatch', async () => {
Expand Down Expand Up @@ -136,34 +137,35 @@ describe('Validation service test', async () => {
});

it('Tries to validate assertion but fails due to validation manager returning wrong assertion id', async () => {
// todo after corrective component is implemented, update this logic
// Will lead to mismatch with passed assertion id
validationService.validationModuleManager.calculateRoot = (assertion) => '';

let errorThrown = false;
try {
await validationService.validateAssertion(
'0xde58cc52a5ce3a04ae7a05a13176226447ac02489252e4d37a72cbe0aea46b42',
'hardhat',
{
'@context': 'https://schema.org',
'@id': 'https://tesla.modelX/2321',
'@type': 'Car',
name: 'Tesla Model X',
brand: {
'@type': 'Brand',
name: 'Tesla',
},
model: 'Model X',
manufacturer: {
'@type': 'Organization',
name: 'Tesla, Inc.',
},
fuelType: 'Electric',
},
);
} catch (error) {
errorThrown = true;
}
expect(errorThrown).to.be.true;
// validationService.validationModuleManager.calculateRoot = (assertion) => '';
//
// let errorThrown = false;
// try {
// await validationService.validateAssertion(
// '0xde58cc52a5ce3a04ae7a05a13176226447ac02489252e4d37a72cbe0aea46b42',
// 'hardhat',
// {
// '@context': 'https://schema.org',
// '@id': 'https://tesla.modelX/2321',
// '@type': 'Car',
// name: 'Tesla Model X',
// brand: {
// '@type': 'Brand',
// name: 'Tesla',
// },
// model: 'Model X',
// manufacturer: {
// '@type': 'Organization',
// name: 'Tesla, Inc.',
// },
// fuelType: 'Electric',
// },
// );
// } catch (error) {
// errorThrown = true;
// }
// expect(errorThrown).to.be.true;
});
});

0 comments on commit 6055570

Please sign in to comment.