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 #1933 from LiskHQ/1931-add-receivingChainID-reques…
Browse files Browse the repository at this point in the history
…t-param-support-to-transactions-endpoint

Add receivingChainID request param support to transactions endpoint
  • Loading branch information
priojeetpriyom authored Nov 21, 2023
2 parents 1f468af + a420a30 commit 06ce21f
Show file tree
Hide file tree
Showing 13 changed files with 433 additions and 97 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ module.exports = [
address: { optional: true, type: 'string' },
senderAddress: { optional: true, type: 'string' },
recipientAddress: { optional: true, type: 'string' },
receivingChainID: { optional: true, type: 'string' },
timestamp: { optional: true, type: 'string' },
nonce: { optional: true, type: 'string' },
blockID: { optional: true, type: 'string' },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ const validateParams = async params => {
if (params.senderAddress) validatedParams.senderAddress = params.senderAddress;
if (params.recipientAddress) validatedParams.recipientAddress = params.recipientAddress;
if (params.moduleCommand) validatedParams.moduleCommand = params.moduleCommand;
if (params.receivingChainID) validatedParams.receivingChainID = params.receivingChainID;
if (params.sort) validatedParams.sort = params.sort;

return validatedParams;
Expand Down Expand Up @@ -132,7 +133,9 @@ const getPendingTransactions = async params => {
transaction.sender.address === validatedParams.address ||
transaction.params.recipientAddress === validatedParams.address) &&
(!validatedParams.moduleCommand ||
transaction.moduleCommand === validatedParams.moduleCommand),
transaction.moduleCommand === validatedParams.moduleCommand) &&
(!validatedParams.receivingChainID ||
transaction.params.receivingChainID === validatedParams.receivingChainID),
);

pendingTransactions.data = filteredPendingTxs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ module.exports = {
amount: { type: 'range' },
data: { type: 'key' },
senderAddress: { type: 'key' },
receivingChainID: { type: 'key' },
executionStatus: { type: 'key' },
},
purge: {},
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const mockSenderAddress = 'lskvq67zzev53sa6ozt39ft3dsmwxxztb7h29275k';
const mockRecipientAddress = 'lskyvvam5rxyvbvofxbdfcupxetzmqxu22phm4yuo';

const mockSenderAccountDetails = {
name: 'genesis',
publicKey: '3972849f2ab66376a68671c10a00e8b8b67d880434cc65b04c6ed886dfa91c2c',
};

const mockPendingTransactions = [
{
module: 'token',
command: 'transfer',
fee: '100000000',
nonce: '1',
senderPublicKey: '3972849f2ab66376a68671c10a00e8b8b67d880434cc65b04c6ed886dfa91c2c',
signatures: [
'c7fd1abf9a552fa9c91b4121c87ae2c97cb0fc0aecc87d0ee8b1aa742238eef4a6815ddba31e21144c9652a7bd5c05577ae1100eac34fba43da6fc4879b8f206',
],
params: {
tokenID: '0000000000000000',
amount: '100000000000',
recipientAddress: 'lskyvvam5rxyvbvofxbdfcupxetzmqxu22phm4yuo',
data: '',
},
id: 'd96c777b67576ddf4cd933a97a60b4311881e68e3c8bef1393ac0020ec8a506c',
size: 167,
minFee: '166000',
},
{
module: 'token',
command: 'transferCrossChain',
fee: '100000000',
nonce: '1',
senderPublicKey: '3972849f2ab66376a68671c10a00e8b8b67d880434cc65b04c6ed886dfa91c2c',
signatures: [
'c7fd1abf9a552fa9c91b4121c87ae2c97cb0fc0aecc87d0ee8b1aa742238eef4a6815ddba31e21144c9652a7bd5c05577ae1100eac34fba43da6fc4879b8f206',
],
params: {
tokenID: '0000000000000000',
amount: '100000000000',
recipientAddress: 'lskyvvam5rxyvbvofxbdfcupxetzmqxu22phm4yuo',
receivingChainID: '02000000',
data: '',
messageFee: '10000000',
messageFeeTokenID: '0200000000000000',
},
id: 'd96c777b67576ddf4cd933a97a60b4311881e68e3c8bef1393ac0020ec8a506d',
size: 167,
minFee: '166000',
},
];

module.exports = {
mockPendingTransactions,
mockSenderAddress,
mockRecipientAddress,
mockSenderAccountDetails,
};
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@
*
*/
const {
validateParams,
} = require('../../../../../shared/dataService/business/pendingTransactions');
mockPendingTransactions,
mockSenderAddress,
mockSenderAccountDetails,
mockRecipientAddress,
} = require('../../constants/pendingTransactions');

jest.mock('lisk-service-framework', () => {
const actual = jest.requireActual('lisk-service-framework');
Expand All @@ -36,6 +39,24 @@ jest.mock('lisk-service-framework', () => {
};
});

jest.mock('../../../../../shared/utils/request', () => ({
requestConnector: jest.fn(() => mockPendingTransactions),
}));

jest.mock('../../../../../shared/utils/account', () => ({
getLisk32AddressFromPublicKey: jest.fn(() => mockSenderAddress),
}));

jest.mock('../../../../../shared/dataService/utils/account', () => ({
getIndexedAccountInfo: jest.fn(() => mockSenderAccountDetails),
}));

const {
validateParams,
loadAllPendingTransactions,
getPendingTransactions,
} = require('../../../../../shared/dataService/business/pendingTransactions');

describe('Test validateParams method', () => {
it('should return validated params when called with valid params', async () => {
const params = {
Expand All @@ -61,3 +82,80 @@ describe('Test validateParams method', () => {
expect(() => validateParams(null)).rejects.toThrow();
});
});

describe('Test getPendingTransactions method', () => {
beforeAll(async () => {
await loadAllPendingTransactions();
});

it('should return all pending transactions without any filters', async () => {
const params = {
sort: 'id:asc',
offset: 0,
limit: 10,
};

const result = await getPendingTransactions(params);
expect(result.data.length).toBe(mockPendingTransactions.length);
});

it('should return pending transactions with tx id', async () => {
const params = {
id: mockPendingTransactions[0].id,
sort: 'id:asc',
offset: 0,
limit: 10,
};

const result = await getPendingTransactions(params);
expect(result.data.length).toBe(1);
});

it('should return pending transactions with recipientAddress', async () => {
const params = {
recipientAddress: mockRecipientAddress,
sort: 'id:asc',
offset: 0,
limit: 10,
};

const result = await getPendingTransactions(params);

let txCountWithParams = 0;
mockPendingTransactions.forEach(transaction => {
if (transaction.params && transaction.params.recipientAddress === mockRecipientAddress) {
txCountWithParams++;
}
});

expect(result.data.length).toBe(txCountWithParams);
});

it('should return pending transactions with receivingChainID', async () => {
const params = {
receivingChainID: '02000000',
sort: 'id:asc',
offset: 0,
limit: 10,
};

const result = await getPendingTransactions(params);

let txCountWithParams = 0;
mockPendingTransactions.forEach(transaction => {
if (transaction.params && transaction.params.receivingChainID === '02000000') {
txCountWithParams++;
}
});

expect(result.data.length).toBe(txCountWithParams);
});

it('should throw ValidationException for invalid parameters', async () => {
const params = {
nonce: 123,
};

await expect(validateParams(params)).rejects.toThrow();
});
});
Loading

0 comments on commit 06ce21f

Please sign in to comment.