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

Commit

Permalink
✅ Add/fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Feb 7, 2024
1 parent 36db00a commit 05cc4df
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 6 deletions.
2 changes: 1 addition & 1 deletion services/export/shared/helpers/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ const getTokenBalancesAtGenesis = async () => {

// Asynchronously fetch the token module genesis assets and cache locally
logger.info('Attempting to fetch and cache the token module genesis assets.');
requestConnector('getGenesisAssetsLength', {
await requestConnector('getGenesisAssetsLength', {
module: MODULE.TOKEN,
subStore: MODULE_SUB_STORE.TOKEN.USER,
})
Expand Down
1 change: 1 addition & 0 deletions services/export/shared/transactionsExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -1050,4 +1050,5 @@ module.exports = {
getMessageFeeEntries,
getOutgoingTransferCCEntries,
getIncomingTransferCCEntries,
getLegacyAccountReclaimEntries,
};
17 changes: 17 additions & 0 deletions services/export/tests/constants/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,22 @@ const ccmTransfer = {
],
};

const accountReclaimed = {
id: 'fe7ff8cbfd1243f0134271c868c73abf6a726bc9965440fcffdcb4cd03b582ba',
module: 'legacy',
name: 'accountReclaimed',
data: {
legacyAddress: '15297866638783057016L',
address: 'lskqz6gpqfu9tb5yc2jtqmqvqp3x8ze35g99u2zfd',
amount: '100000000',
},
topics: [
'6cff643daaa2bd1112d1b4591abef3e62f9e4f6e37a260fcd7508ce6a06f061c',
'15297866638783057016L',
'lskqz6gpqfu9tb5yc2jtqmqvqp3x8ze35g99u2zfd',
],
};

module.exports = {
events: {
tokenMintedEvent,
Expand All @@ -163,5 +179,6 @@ module.exports = {
ccmSendSuccess,
transferCrossChain,
ccmTransfer,
accountReclaimed,
},
};
11 changes: 9 additions & 2 deletions services/export/tests/unit/shared/helpers/account.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ describe('Account utils', () => {
});

describe('Test getTokenBalancesAtGenesis method', () => {
xit('should return token balances at genesis', async () => {
it('should return token balances at genesis', async () => {
const mockUserSubstore = [
{
address: 'lskyvvam5rxyvbvofxbdfcupxetzmqxu22phm4yuo',
Expand All @@ -252,7 +252,14 @@ describe('Account utils', () => {
const { getTokenBalancesAtGenesis } = require('../../../../shared/helpers/account');

const tokenBalances = await getTokenBalancesAtGenesis();
const expectedResponse = [{ amount: '100000000000000', tokenID: '0400000000000000' }];
const expectedResponse = [
{
tokenID: '0400000000000000',
address: 'lskyvvam5rxyvbvofxbdfcupxetzmqxu22phm4yuo',
availableBalance: '100000000000000',
lockedBalances: [],
},
];

expect(tokenBalances).toEqual(expectedResponse);
});
Expand Down
77 changes: 74 additions & 3 deletions services/export/tests/unit/shared/transactionsExport.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,6 @@ describe('Test getSharedRewardsAssignedEntries method', () => {
});
});

// Verify implementation
describe('Test getMessageFeeEntries method', () => {
const address = 'lskme8ohf9geuno8nwpvdqm8wr8bvz5nzguftwpxp';
const sendingChainID = '04000000';
Expand Down Expand Up @@ -448,11 +447,29 @@ describe('Test getMessageFeeEntries method', () => {

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

it('should return empty list when relayer amount is 0', async () => {
const { getMessageFeeEntries } = require('../../../shared/transactionsExport');

const messageFeeEntries = await getMessageFeeEntries(
address,
{
...events.relayerFeeProcessed,
data: { ...events.relayerFeeProcessed.data, relayerAmount: 0 },
},
transactions.tokenTransferCrossChain,
blocks[0],
messageFeeTokenID,
sendingChainID,
receivingChainID,
);
expect(messageFeeEntries).toHaveLength(0);
});
});

describe('Test getOutgoingTransferCCEntries method', () => {
const address = 'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs';
it('should return outgoing transfer cross chain entries', async () => {
it('should return outgoing transfer cross chain entries with amount deducted', async () => {
jest.mock(mockedRequestFilePath, () => {
const actual = jest.requireActual(mockedRequestFilePath);
return {
Expand Down Expand Up @@ -542,7 +559,7 @@ describe('Test getIncomingTransferCCEntries method', () => {
});

const address = 'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs';
it('should return incoming transfer cross chain entries', async () => {
it('should return incoming transfer cross chain entries with amount added', async () => {
const { getIncomingTransferCCEntries } = require('../../../shared/transactionsExport');

const incomingTransferCCEntries = await getIncomingTransferCCEntries(
Expand Down Expand Up @@ -588,3 +605,57 @@ describe('Test getIncomingTransferCCEntries method', () => {
expect(incomingTransferCCEntries).toHaveLength(0);
});
});

describe('Test getLegacyAccountReclaimEntries method', () => {
const address = 'lskqz6gpqfu9tb5yc2jtqmqvqp3x8ze35g99u2zfd';
it('should return generator fee reward entries', async () => {
jest.mock(mockedRequestFilePath, () => {
const actual = jest.requireActual(mockedRequestFilePath);
return {
...actual,
requestConnector() {
return '0400000000000000';
},
requestIndexer() {
return {
data: {
chainID: '04000000',
},
};
},
};
});

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

const legacyAccountReclaimEntries = await getLegacyAccountReclaimEntries(
address,
events.accountReclaimed,
transactions.reclaim,
blocks[0],
);

const expectedResult = [
{
amount: '100000000',
amountTokenID: '0400000000000000',
blockHeight: 15,
date: '2022-11-17',
fee: null,
moduleCommand: null,
note: 'Legacy account balance reclaimed',
receivingChainID: '04000000',
recipientAddress: 'lskqz6gpqfu9tb5yc2jtqmqvqp3x8ze35g99u2zfd',
recipientPublicKey: null,
senderAddress: null,
senderPublicKey: null,
sendingChainID: '04000000',
time: '11:52:28',
transactionID: '6cff643daaa2bd1112d1b4591abef3e62f9e4f6e37a260fcd7508ce6a06f061c',
txFeeTokenID: null,
},
];

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

0 comments on commit 05cc4df

Please sign in to comment.