Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1960 from LiskHQ/1958-empty-data-in-delete-transa…
Browse files Browse the repository at this point in the history
…ctions-event-payload

Empty data in delete transactions event payload
  • Loading branch information
sameersubudhi authored Dec 1, 2023
2 parents a155e74 + 67759ef commit 3132da6
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 9 deletions.
2 changes: 1 addition & 1 deletion services/blockchain-connector/shared/sdk/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const cacheBlocksFromWaitlist = async () => {
);
logger.debug(err.stack);
blockCacheWaitlist.splice(0, 0, block);
await delay(3000); // Delay loop to facilitate reads from cache when writes are failing due to DB locks
await delay(10000); // Delay loop to facilitate reads from cache when writes are failing due to DB locks
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,4 +288,5 @@ module.exports = {

// For unit test
validateParams,
normalizeTransactions,
};
12 changes: 7 additions & 5 deletions services/blockchain-indexer/shared/indexer/blockchainIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,13 @@ const deleteIndexedBlocks = async job => {
);
forkedTransactions = transactionsToDelete.filter(t => ![null, undefined].includes(t));
}
await transactionsTable.deleteByPrimaryKey(forkedTransactionIDs, dbTrx);
Signals.get('deleteTransactions').dispatch({
data: forkedTransactions,
meta: { offset: 0, count: forkedTransactions.length, total: forkedTransactions.length },
});
if (forkedTransactionIDs.length) {
await transactionsTable.deleteByPrimaryKey(forkedTransactionIDs, dbTrx);
Signals.get('deleteTransactions').dispatch({
data: forkedTransactions,
meta: { offset: 0, count: forkedTransactions.length, total: forkedTransactions.length },
});
}

// Update generatedBlocks count for the block generator
const validatorsTable = await getValidatorsTable();
Expand Down
3 changes: 1 addition & 2 deletions services/blockchain-indexer/shared/messageProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ const newRoundProcessor = async () => {
await reloadGeneratorsCache();
const limit = await getNumberOfGenerators();
const generators = await getGenerators({ limit, offset: 0 });
const response = { generators: generators.data.map(generator => generator.address) };
Signals.get('newRound').dispatch(response);
Signals.get('newRound').dispatch(generators);
logger.info(`Finished performing all updates on new round.`);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@
* Removal or modification of this copyright notice is prohibited.
*
*/
const { validateParams } = require('../../../../../shared/dataService/business/transactions');
const {
mockTxRequest,
mockTransferCrossChainTxRequest,
} = require('../../constants/transactionEstimateFees');

const {
validateParams,
normalizeTransactions,
} = require('../../../../../shared/dataService/business/transactions');

jest.mock('lisk-service-framework', () => {
const actual = jest.requireActual('lisk-service-framework');
Expand Down Expand Up @@ -64,3 +72,32 @@ describe('Test validateParams method', () => {
expect(() => validateParams(null)).rejects.toThrow();
});
});

describe('Test normalizeTransactions method', () => {
it('should return normalized transactions when called with valid transactions', async () => {
const transactions = [mockTxRequest.transaction, mockTransferCrossChainTxRequest.transaction];
const normalizedTransactions = await normalizeTransactions(transactions);

const expectedResult = [
{
...mockTxRequest.transaction,
moduleCommand: `${mockTxRequest.transaction.module}:${mockTxRequest.transaction.command}`,
},
{
...mockTransferCrossChainTxRequest.transaction,
moduleCommand: `${mockTransferCrossChainTxRequest.transaction.module}:${mockTransferCrossChainTxRequest.transaction.command}`,
},
];

expect(normalizedTransactions.length).toEqual(transactions.length);
expect(normalizedTransactions).toEqual(expectedResult);
});

it('should throw error when called with null', async () => {
expect(() => normalizeTransactions(null)).rejects.toThrow();
});

it('should throw error when called with undefined', async () => {
expect(() => normalizeTransactions(null)).rejects.toThrow();
});
});

0 comments on commit 3132da6

Please sign in to comment.