Skip to content

Commit

Permalink
test: Add additional verification with comparing json from file read …
Browse files Browse the repository at this point in the history
…query

Signed-off-by: Yordan Iliev <[email protected]>
  • Loading branch information
yiliev0 committed Oct 28, 2024
1 parent 702cb79 commit 766cbd1
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 36 deletions.
10 changes: 6 additions & 4 deletions automation/data/101.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
{
"serviceEndpoint": [
{
"ipAddressV4": "34.94.106.61",
"port": 50211
"ipAddressV4": "49.46.48.46.48.46.48",
"port": 1
}
],
"RSA_PubKey": "308201a2300d06092a864886f70d01010105000382018f003082018a0282018100a12006f2527242cd7f53b9c4fd5de869c562ff4ed8a4ab3a62963f3f8188be78f258eaf42b9c3e3e8f58697160413bbf77aadfaf0d9ffd86984b3bc4fb5f02e11e8acb6ec67e4264addca13ffde8367578c2792fc6ae326e7b34856d23f02574f5a27481560032d73749daf9d332a7883510e60ea222889a3bfc3bedf350f3a36cada39b94539c74fb8265678bd5c148fbc9169adcacf6719b92ee8d42a9d2f8923cc4fe3b494c467f4e98a2a49e0a0ef5aa433cbec438baa256ae61a0590ce4e67d0b3fe5f2da9ad90c26e229d28d679456978d6573573ebb46239bad4abfab4ffe64ea4a397c6bc5f7175e1ac36488f17c6773b5ed93415e57c41c6cd8866dbd12360062339cb154d85ad1aecd1d760a0941d80e28fe246033a868dbbc8975f3604431fce9af91dc42540ab04b1bbec21f35f75f30af6f05c8986429386e2b439bfd2fd5912c82600801e9c0857f165e887f2233dc2c098ba1267b059db8a2db714fe50668dbf093604a5df3c232146723211ce58552638fae9fc064a7f09b0203010001",
"nodeId": "0",
"nodeAccountId": "0.0.3",
"nodeCertHash": "a171e3ba83476747aeb2e2ac4d0e115caaab918203b0dfe1cdeab443438fc289abc8ba8a6aff83db5f1b334046da88c8",
"nodeId": "0"
"nodeCertHash": "",
"stake": "0"
}
]
}
27 changes: 7 additions & 20 deletions automation/data/102.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,15 @@
{
"serviceEndpoint": [
{
"ipAddressV4": "35.237.119.55",
"port": 50211
},
{
"ipAddressV4": "35.237.119.55",
"port": 50212
},
{
"ipAddressV4": "3.212.6.13",
"port": 50211
},
{
"ipAddressV4": "3.212.6.13",
"port": 50212
"ipAddressV4": "49.46.48.46.48.46.48",
"port": 1
}
],
"RSA_PubKey": "308201a2300d06092a864886f70d01010105000382018f003082018a0282018100c557af579fa83501be899b28907765bfdfcd52ab432b0195a1f1ecd86fc00ab6c5509b0fdd97edd3cb5cea56a295f312abb550831dbf963f450118b4fcc6e22cf4676200ce9cc8edfbbf558dc69f024264ad7d3dab23bed2133c274e6934489155db1087f90370905c64185a6211dc742fb9a6909d82186947b277463dfb3ff0acd47eff12ead1f6972ef2c1203793c45e77575be4fa110c7e40fa8db9c6187d113f4704014179071abf59be7d2b0de82de4215dc25506b1c9c26e4917401c997506e377e6bf03b688727e7940fad69c5e0da3cd5cbd2be777350aea2d0d47e97a448c84be6ce134d64bee0985c29162f4c1e567cca93d06a3c1be8abce35b557fb77f4fe671a66dec790756d0e8818165f2bacaa891aae7ac7437fc7175b6eb6deb7472378751bb6bf9b0e1483f9668e9fdbd5604c39b14d9e2bedeec846a980d704d171e7ba4b7fcd1a30d945ca12f47a325d9398aa18f97066054d4d15fc8994e2debe73e9271d548683f61ea44fb25071e3518a78ed3eb37e71a0691f2670203010001",
"nodeId": "1",
"nodeAccountId": "0.0.4",
"nodeCertHash": "7409dec2e494b627ee49c69b294be1ceaebca3fdcaf36789e88fc7d5b0eef5561f52b82d35191a39c2fbed6027267166",
"description": "Hosted by Hedera | East Coast, USA",
"stake": "71"
"RSA_PubKey": "308201a2300d06092a864886f70d01010105000382018f003082018a0282018100a12006f2527242cd7f53b9c4fd5de869c562ff4ed8a4ab3a62963f3f8188be78f258eaf42b9c3e3e8f58697160413bbf77aadfaf0d9ffd86984b3bc4fb5f02e11e8acb6ec67e4264addca13ffde8367578c2792fc6ae326e7b34856d23f02574f5a27481560032d73749daf9d332a7883510e60ea222889a3bfc3bedf350f3a36cada39b94539c74fb8265678bd5c148fbc9169adcacf6719b92ee8d42a9d2f8923cc4fe3b494c467f4e98a2a49e0a0ef5aa433cbec438baa256ae61a0590ce4e67d0b3fe5f2da9ad90c26e229d28d679456978d6573573ebb46239bad4abfab4ffe64ea4a397c6bc5f7175e1ac36488f17c6773b5ed93415e57c41c6cd8866dbd12360062339cb154d85ad1aecd1d760a0941d80e28fe246033a868dbbc8975f3604431fce9af91dc42540ab04b1bbec21f35f75f30af6f05c8986429386e2b439bfd2fd5912c82600801e9c0857f165e887f2233dc2c098ba1267b059db8a2db714fe50668dbf093604a5df3c232146723211ce58552638fae9fc064a7f09b0203010001",
"nodeId": "0",
"nodeAccountId": "0.0.3",
"nodeCertHash": "",
"stake": "0"
}
]
}
4 changes: 3 additions & 1 deletion automation/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
"bip39": "3.1.0",
"uuid": "10.0.0",
"fsevents": "2.3.2",
"long": "5.2.3"
"long": "5.2.3",
"lodash": "4.17.21",
"deep-diff": "1.0.2"
}
}
94 changes: 94 additions & 0 deletions automation/pages/OrganizationPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ const {
generateRandomPassword,
setupEnvironmentForTransactions,
waitForValidStart,
compareJsonFiles,
parsePropertiesContent,
} = require('../utils/util');
const { normalizeExchangeRateData, normalizeThrottleData } = require('../utils/dataNormalizer');
const {
getFirstPublicKeyByEmail,
getUserIdByEmail,
Expand All @@ -32,6 +35,7 @@ const {
insertKeyPair,
getLatestNotificationStatusByEmail,
} = require('../utils/databaseQueries');
const fs = require('fs');

class OrganizationPage extends BasePage {
constructor(window) {
Expand Down Expand Up @@ -955,6 +959,96 @@ class OrganizationPage extends BasePage {
return { txId, validStart };
}

/**
* Checks if a file from the application is identical to the corresponding file in the data folder.
* @param {string} fileId - The ID of the file to read and compare.
* @returns {boolean} - Returns true if files are identical, or false if there are differences.
*/
async areFilesIdentical(fileId) {
// Read the file content from the application
const textFromField = await this.transactionPage.readFile(fileId);
if (!textFromField || textFromField.trim() === '') {
throw new Error(`No data returned from application for fileId ${fileId}`);
}

// Mapping of file IDs to data files and file types
const fileMappings = {
'0.0.101': { path: 'data/101.json', type: 'json', keysToIgnore: [] },
'0.0.102': { path: 'data/102.json', type: 'json', keysToIgnore: [] },
'0.0.111': { path: 'data/feeSchedules.json', type: 'json', keysToIgnore: [] },
'0.0.112': {
path: 'data/exchangeRates.json',
type: 'json',
keysToIgnore: ['exchangeRateInCents'],
normalizer: normalizeExchangeRateData,
},
'0.0.121': { path: 'data/application.properties', type: 'properties', keysToIgnore: [] },
'0.0.122': { path: 'data/api-permission.properties', type: 'properties', keysToIgnore: [] },
'0.0.123': {
path: 'data/123.json',
type: 'json',
keysToIgnore: [],
normalizer: normalizeThrottleData,
},
};

const fileInfo = fileMappings[fileId];

if (!fileInfo) {
throw new Error(`Unsupported fileId: ${fileId}`);
}

// Read the local file content
const localFileContent = fs.readFileSync(fileInfo.path, 'utf8');

let localData, remoteData;

// Parse the files based on their type
if (fileInfo.type === 'json') {
// Parse local JSON file
try {
localData = JSON.parse(localFileContent);
} catch (error) {
throw new Error(`Failed to parse local JSON file ${fileInfo.path}: ${error.message}`);
}

// Parse remote JSON data from application
try {
remoteData = JSON.parse(textFromField);
} catch (error) {
throw new Error(`Failed to parse remote JSON data for fileId ${fileId}: ${error.message}`);
}
} else if (fileInfo.type === 'properties') {
// Parse local properties file into an object
localData = parsePropertiesContent(localFileContent);

// Parse remote properties content into an object
remoteData = parsePropertiesContent(textFromField);
} else {
throw new Error(`Unsupported file type for fileId ${fileId}`);
}

const keysToIgnore = fileInfo.keysToIgnore || [];

// Apply normalizer if present
if (fileInfo.normalizer) {
localData = fileInfo.normalizer(localData);
remoteData = fileInfo.normalizer(remoteData);
}

// Compare the two data objects
const differences = compareJsonFiles(localData, remoteData, keysToIgnore);

if (differences === null) {
console.log(`The files for fileId ${fileId} are identical.`);
return true;
} else {
console.log(`The files for fileId ${fileId} are not identical.`);
console.log('Differences:', JSON.stringify(differences, null, 2));
return false;
}
}

async getGroupTransactionIdText() {
return await this.getText(this.transactionIdInGroupSelector);
}
Expand Down
2 changes: 1 addition & 1 deletion automation/pages/TransactionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,7 @@ class TransactionPage extends BasePage {
}

async readFileContentFromTextArea() {
return await this.getTextFromInputField(this.fileContentReadTextFieldSelector);
return await this.getTextFromInputFieldWithRetry(this.fileContentReadTextFieldSelector);
}

async getPublicKeyText() {
Expand Down
22 changes: 22 additions & 0 deletions automation/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 47 additions & 10 deletions automation/tests/systemFileTests.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ let firstUser;

/**
* These tests verify that the user can execute file update transactions for system files
* Executing some of these tests breaks the local node and requires a restart
*/

test.describe.skip('System file tests', () => {
test.describe('System file tests', () => {
test.beforeAll(async () => {
test.slow();
await resetDbState();
Expand Down Expand Up @@ -85,9 +84,14 @@ test.describe.skip('System file tests', () => {

test('Verify user can execute file update transaction for node address book(101) ', async () => {
test.slow();

const { txId, validStart } = await organizationPage.updateSystemFile('0.0.101', 5, true);
const fileId = '0.0.101';
const { txId, validStart } = await organizationPage.updateSystemFile(fileId, 5, true);
await waitForValidStart(validStart);

//comparing the file from read query with the file from data folder
const areIdentical = await organizationPage.areFilesIdentical(fileId);
expect(areIdentical).toBe(true);

const transactionDetails = await transactionPage.mirrorGetTransactionResponse(txId);
const transactionType = transactionDetails.transactions[0]?.name;
const result = transactionDetails.transactions[0]?.result;
Expand All @@ -99,8 +103,14 @@ test.describe.skip('System file tests', () => {

test('Verify user can execute file update transaction for node address book(102) ', async () => {
test.slow();
const { txId, validStart } = await organizationPage.updateSystemFile('0.0.102', 5, true);
const fileId = '0.0.102';
const { txId, validStart } = await organizationPage.updateSystemFile(fileId, 5, true);
await waitForValidStart(validStart);

//comparing the file from read query with the file from data folder
const areIdentical = await organizationPage.areFilesIdentical(fileId);
expect(areIdentical).toBe(true);

const transactionDetails = await transactionPage.mirrorGetTransactionResponse(txId);
const transactionType = transactionDetails.transactions[0]?.name;
const result = transactionDetails.transactions[0]?.result;
Expand All @@ -110,10 +120,16 @@ test.describe.skip('System file tests', () => {
expect(result).toBe('SUCCESS');
});

test('Verify user can execute file update transaction for fee schedule(111)', async () => {
test.skip('Verify user can execute file update transaction for fee schedule(111)', async () => {
test.slow();
const { txId, validStart } = await organizationPage.updateSystemFile('0.0.111', 5, true);
const fileId = '0.0.111';
const { txId, validStart } = await organizationPage.updateSystemFile(fileId, 5, true);
await waitForValidStart(validStart);

//comparing the file from read query with the file from data folder
const areIdentical = await organizationPage.areFilesIdentical(fileId);
expect(areIdentical).toBe(true);

const transactionDetails = await transactionPage.mirrorGetTransactionResponse(txId);
const transactionType = transactionDetails.transactions[0]?.name;
const result = transactionDetails.transactions[0]?.result;
Expand All @@ -125,8 +141,14 @@ test.describe.skip('System file tests', () => {

test('Verify user can execute file update transaction for exchange rate(112)', async () => {
test.slow();
const { txId, validStart } = await organizationPage.updateSystemFile('0.0.112', 5, true);
const fileId = '0.0.112';
const { txId, validStart } = await organizationPage.updateSystemFile(fileId, 5, true);
await waitForValidStart(validStart);

//comparing the file from read query with the file from data folder
const areIdentical = await organizationPage.areFilesIdentical(fileId);
expect(areIdentical).toBe(true);

const transactionDetails = await transactionPage.mirrorGetTransactionResponse(txId);
const transactionType = transactionDetails.transactions[0]?.name;
const result = transactionDetails.transactions[0]?.result;
Expand All @@ -138,8 +160,13 @@ test.describe.skip('System file tests', () => {

test('Verify user can execute file update transaction for application properties(121) ', async () => {
test.slow();
const { txId, validStart } = await organizationPage.updateSystemFile('0.0.121', 5, true);
const fileId = '0.0.121';
const { txId, validStart } = await organizationPage.updateSystemFile(fileId, 5, true);
await waitForValidStart(validStart);

const areIdentical = await organizationPage.areFilesIdentical(fileId);
expect(areIdentical).toBe(true);

const transactionDetails = await transactionPage.mirrorGetTransactionResponse(txId);
const transactionType = transactionDetails.transactions[0]?.name;
const result = transactionDetails.transactions[0]?.result;
Expand All @@ -151,8 +178,13 @@ test.describe.skip('System file tests', () => {

test('Verify user can execute file update transaction for api permissions(122) ', async () => {
test.slow();
const fileId = '0.0.122';
const { txId, validStart } = await organizationPage.updateSystemFile('0.0.122', 5, true);
await waitForValidStart(validStart);

const areIdentical = await organizationPage.areFilesIdentical(fileId);
expect(areIdentical).toBe(true);

const transactionDetails = await transactionPage.mirrorGetTransactionResponse(txId);
const transactionType = transactionDetails.transactions[0]?.name;
const result = transactionDetails.transactions[0]?.result;
Expand All @@ -164,8 +196,13 @@ test.describe.skip('System file tests', () => {

test('Verify user can execute file update transaction for throttles(123) ', async () => {
test.slow();
const { txId, validStart } = await organizationPage.updateSystemFile('0.0.123', 5, true);
const fileId = '0.0.123';
const { txId, validStart } = await organizationPage.updateSystemFile(fileId, 5, true);
await waitForValidStart(validStart);

const areIdentical = await organizationPage.areFilesIdentical(fileId);
expect(areIdentical).toBe(true);

const transactionDetails = await transactionPage.mirrorGetTransactionResponse(txId);
const transactionType = transactionDetails.transactions[0]?.name;
const result = transactionDetails.transactions[0]?.result;
Expand Down
Loading

0 comments on commit 766cbd1

Please sign in to comment.