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

Commit

Permalink
✅ Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Feb 7, 2024
1 parent cb22381 commit 3b85279
Show file tree
Hide file tree
Showing 7 changed files with 234 additions and 2 deletions.
1 change: 1 addition & 0 deletions services/export/shared/transactionsExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -1051,4 +1051,5 @@ module.exports = {
getOutgoingTransferCCEntries,
getIncomingTransferCCEntries,
getLegacyAccountReclaimEntries,
getPomEntries,
};
1 change: 1 addition & 0 deletions services/export/tests/constants/csvExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const selfTokenTransferTransaction = {
const interval = {
startEnd: '2021-06-07:2021-09-19',
onlyStart: '2021-06-07',
invalid: '2021-06-07:20-09-2021',
};

module.exports = {
Expand Down
38 changes: 36 additions & 2 deletions services/export/tests/constants/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ const ccmTransfer = {
result: 0,
},
topics: [
'd16d1cb5fa32df64988b4ab5de66b7d43c8fbfdaf043aca84d649f914d66189f',
'05d16d1cb5fa32df64988b4ab5de66b7d43c8fbfdaf043aca84d649f914d66189f',
'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
],
Expand All @@ -163,12 +163,44 @@ const accountReclaimed = {
amount: '100000000',
},
topics: [
'6cff643daaa2bd1112d1b4591abef3e62f9e4f6e37a260fcd7508ce6a06f061c',
'046cff643daaa2bd1112d1b4591abef3e62f9e4f6e37a260fcd7508ce6a06f061c',
'15297866638783057016L',
'lskqz6gpqfu9tb5yc2jtqmqvqp3x8ze35g99u2zfd',
],
};

const validatorPunished = {
id: 'dae4b1bb546e9bdd15a05432f37ddf42ffcf1ad4dc790cb2f6391e830db49e28',
module: 'pos',
name: 'validatorPunished',
data: {
address: 'lskmjt3zuxo6rv3oc9qyanppe76hk22m8ca2ra7h5',
height: 1745,
},
topics: [
'04cd41e8fbb909fdf44ffccef6f5b0fb5edf853f0dcf699243a0a92403d2a4f1d1d',
'lskmjt3zuxo6rv3oc9qyanppe76hk22m8ca2ra7h5',
],
};

const tokenTransfer = {
id: '957c72e2cd0e057c7c251c35bd1149e35e9aa621ef8ab5d016373fe4ec786660',
module: 'token',
name: 'transfer',
data: {
senderAddress: 'lskmjt3zuxo6rv3oc9qyanppe76hk22m8ca2ra7h5',
recipientAddress: 'lskmjt3zuxo6rv3oc9qyanppe76hk22m8ca2ra7h5',
tokenID: '0400000000000000',
amount: '100000000',
result: 0,
},
topics: [
'04ce7082673acce922263e0256e717dc151fe86a88c6827bf53d42038ee387eca1',
'lskmjt3zuxo6rv3oc9qyanppe76hk22m8ca2ra7h5',
'lskmjt3zuxo6rv3oc9qyanppe76hk22m8ca2ra7h5',
],
};

module.exports = {
events: {
tokenMintedEvent,
Expand All @@ -180,5 +212,7 @@ module.exports = {
transferCrossChain,
ccmTransfer,
accountReclaimed,
validatorPunished,
tokenTransfer,
},
};
32 changes: 32 additions & 0 deletions services/export/tests/constants/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,37 @@ const submitMainchainCrossChainUpdate = {
index: 0,
};

const reportMisbehavior = {
id: 'ce7082673acce922263e0256e717dc151fe86a88c6827bf53d42038ee387eca1',
moduleCommand: 'pos:reportMisbehavior',
nonce: '67',
fee: '1000000',
minFee: '789000',
size: 789,
block: {
id: 'a8704e713299fd3e379686261aaffb792ef0f78950a0802dd65d0e7f07bc075c',
height: 23840061,
timestamp: 1706374150,
isFinal: true,
},
sender: {
address: 'lskhtpeyg2944gcjwubrc7vwp52qoshtu4fs9wmfn',
publicKey: 'd1d951c46376e108bab5e7a9f1dce725bb33f9823442a4a34841b6774bbb5b2f',
name: 'pom',
},
params: {
header1:
'080210e691d4ad0618ed81af0b2220f7ce365adcd30b8df395e05de8a423462ad405cb15c1e20e0cb7188ce91a45952a142f2680402c5484860db58e4e4259caed3182bc793220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8553a2083bf0bd3e2f270aab3d73a79d6e89fc7b7acf688340aa16af3a330d50b43a1454220967365364a7508afd9b9f6fc62b664108e009f45a1af480e3009d70ad999a1214a20729640338fcada3f24103beab6f27b7725ca5cb23da58603073680de42157cdb509b81af0b580060016a2081253514d52a57c27425f7002ef7eb4bdffa9a199037a8cd0bfe16c06142ae85720908c980af0b12001a007a40046e73201f12ec38e37b41d0b46e0af8c35eee296c66c11850093daaf018d25cc1945d387420416f7a4298a7feef1900df54289e3143d0622739234fae182608',
header2:
'080210fce7d4ad0618bc8aaf0b22208bb8a469affa254ae2d0120e8de964dfd0b0e4b82f6dc27399cc0c37a90ca8f62a142f2680402c5484860db58e4e4259caed3182bc793220e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b8553a20b863a36ba1cd1ae5106829aab159687c538e89451fb74b5cbd6b885590dbabe94220aab8361878bc8e35f1e5cff77817468806c904b3134c26c5f2141d927ba5ff954a20b5297e3a641cf61d79f316fa202643cf8c5f03b1ba2b4cac02c7812cf8f25e9450f189af0b580060016a20d53b9b41c0acd2d90969f6e3f9e3e3519be9b941a284288409fecaf8a190f63a720908b289af0b12001a007a4090f68d23abb5cb688c83c9cecd4636be7424c6aa69e1102e4b341a49aa3df5049f3a01f33fbb0dd864d88e8fe2fad777938fceba3f5ead1133adf6b257011700',
},
signatures: [
'f965d9cd093e8a765b0f8088b04517f7aca91882855a83abe8825f4f06e8c73145572b79607ef1729c390ff97999939be510c2e3da97e0df8b2123c6afdea001',
],
executionStatus: 'successful',
index: 0,
};

module.exports = {
transactions: {
reclaim: reclaimTransaction,
Expand All @@ -298,5 +329,6 @@ module.exports = {
claimedRewards: posClaimedRewards,
transferCrossChain,
submitMainchainCrossChainUpdate,
reportMisbehavior,
},
};
47 changes: 47 additions & 0 deletions services/export/tests/unit/shared/helpers/event.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* LiskHQ/lisk-service
* Copyright © 2024 Lisk Foundation
*
* See the LICENSE file at the top-level directory of this distribution
* for licensing information.
*
* Unless otherwise agreed in a custom licensing agreement with the Lisk Foundation,
* no part of this software, including this file, may be copied, modified,
* propagated, or distributed except according to the terms contained in the
* LICENSE file.
*
* Removal or modification of this copyright notice is prohibited.
*
*/
const {
getCcmIDFromTopic0,
getTransactionIDFromTopic0,
} = require('../../../../shared/helpers/event');

describe('Event utils', () => {
it('returns ccmID when called with valid topic (ccmID with prefix)', async () => {
const topic = '05ce7082673acce922263e0256e717dc151fe86a88c6827bf53d42038ee387eca1';
const ccmID = getCcmIDFromTopic0(topic);
const expectedResponse = 'ce7082673acce922263e0256e717dc151fe86a88c6827bf53d42038ee387eca1';
expect(ccmID).toBe(expectedResponse);
});

it('returns null when called with ccmID without prefix', async () => {
const topic = 'ce7082673acce922263e0256e717dc151fe86a88c6827bf53d42038ee387eca1';
const ccmID = getCcmIDFromTopic0(topic);
expect(ccmID).toBeNull();
});

it('returns transactionID when called with valid topic (transactionID with prefix)', async () => {
const topic = '04ce7082673acce922263e0256e717dc151fe86a88c6827bf53d42038ee387eca1';
const transactionID = getTransactionIDFromTopic0(topic);
const expectedResponse = 'ce7082673acce922263e0256e717dc151fe86a88c6827bf53d42038ee387eca1';
expect(transactionID).toBe(expectedResponse);
});

it('returns null when called with transactionID without prefix', async () => {
const topic = 'ce7082673acce922263e0256e717dc151fe86a88c6827bf53d42038ee387eca1';
const ccmID = getTransactionIDFromTopic0(topic);
expect(ccmID).toBeNull();
});
});
5 changes: 5 additions & 0 deletions services/export/tests/unit/shared/helpers/time.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ describe('Test standardizeIntervalFromParams method', () => {
expect(result).toMatch(STANDARDIZED_INTERVAL);
});

it('should throw error when invalid interval supplied', async () => {
const { standardizeIntervalFromParams } = require('../../../../shared/helpers/time');
expect(standardizeIntervalFromParams({ interval: interval.invalid })).rejects.toThrow();
});

it('should return standardized interval when dates not supplied', async () => {
jest.mock(mockedChainFilePath);
// eslint-disable-next-line import/no-dynamic-require
Expand Down
112 changes: 112 additions & 0 deletions services/export/tests/unit/shared/transactionsExport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -659,3 +659,115 @@ describe('Test getLegacyAccountReclaimEntries method', () => {
expect(legacyAccountReclaimEntries).toEqual(expectedResult);
});
});

describe('Test getPomEntries method', () => {
it('should return PoM entries reward deduction', async () => {
const address = 'lskmjt3zuxo6rv3oc9qyanppe76hk22m8ca2ra7h5';
jest.mock(mockedRequestFilePath, () => {
const actual = jest.requireActual(mockedRequestFilePath);
return {
...actual,
requestConnector() {
return {
posTokenID: '0400000000000000',
};
},
requestIndexer() {
return {
data: {
chainID: '04000000',
},
};
},
};
});

const { getPomEntries } = require('../../../shared/transactionsExport');

const pomEntries = await getPomEntries(
address,
events.tokenTransfer,
events.validatorPunished,
transactions.reportMisbehavior,
blocks[0],
);

const expectedResult = [
{
amount: '-100000000',
amountTokenID: '0400000000000000',
blockHeight: 15,
date: '2022-11-17',
fee: null,
moduleCommand: null,
note: 'PoM punishment validator reward deduction',
receivingChainID: '04000000',
recipientAddress: 'lskmjt3zuxo6rv3oc9qyanppe76hk22m8ca2ra7h5',
recipientPublicKey: null,
senderAddress: 'lskmjt3zuxo6rv3oc9qyanppe76hk22m8ca2ra7h5',
senderPublicKey: null,
sendingChainID: '04000000',
time: '11:52:28',
transactionID: 'ce7082673acce922263e0256e717dc151fe86a88c6827bf53d42038ee387eca1',
txFeeTokenID: null,
},
];

expect(pomEntries).toEqual(expectedResult);
});

it('should return PoM entries reward addition', async () => {
const address = 'lskqz6gpqfu9tb5yc2jtqmqvqp3x8ze35g99u2zfd';
jest.mock(mockedRequestFilePath, () => {
const actual = jest.requireActual(mockedRequestFilePath);
return {
...actual,
requestConnector() {
return {
posTokenID: '0400000000000000',
};
},
requestIndexer() {
return {
data: {
chainID: '04000000',
},
};
},
};
});

const { getPomEntries } = require('../../../shared/transactionsExport');

const pomEntries = await getPomEntries(
address,
events.tokenTransfer,
events.validatorPunished,
transactions.reportMisbehavior,
blocks[0],
);

const expectedResult = [
{
amount: '100000000',
amountTokenID: '0400000000000000',
blockHeight: 15,
date: '2022-11-17',
fee: null,
moduleCommand: null,
note: 'PoM successful report reward',
receivingChainID: '04000000',
recipientAddress: 'lskmjt3zuxo6rv3oc9qyanppe76hk22m8ca2ra7h5',
recipientPublicKey: null,
senderAddress: 'lskmjt3zuxo6rv3oc9qyanppe76hk22m8ca2ra7h5',
senderPublicKey: null,
sendingChainID: '04000000',
time: '11:52:28',
transactionID: 'ce7082673acce922263e0256e717dc151fe86a88c6827bf53d42038ee387eca1',
txFeeTokenID: null,
},
];

expect(pomEntries).toEqual(expectedResult);
});
});

0 comments on commit 3b85279

Please sign in to comment.