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 #1805 from LiskHQ/1804-transaction-estimate-fees-t…
Browse files Browse the repository at this point in the history
…hrows-error-for-cross-chain-transfer-transaction

Transaction estimate fees throws error for cross chain transfer transaction
  • Loading branch information
vardan10 authored Aug 17, 2023
2 parents 8c9c37f + 39dd99d commit 2d55c42
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 5 deletions.
2 changes: 1 addition & 1 deletion services/blockchain-connector/shared/sdk/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const { Logger, Signals } = require('lisk-service-framework');
const { getApiClient } = require('./client');
const { formatEvent } = require('./formatter');
const { getRegisteredEvents, getEventsByHeight, getNodeInfo } = require('./endpoints');
const { getEscrowedAmounts } = require('./tokens');
const { getEscrowedAmounts } = require('./token');

const logger = Logger();

Expand Down
4 changes: 2 additions & 2 deletions services/blockchain-connector/shared/sdk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ const {
getSupportedTokens,
getTotalSupply,
getTokenInitializationFees,
} = require('./tokens');
updateTokenInfo,
} = require('./token');

const {
getAllPosValidators,
Expand Down Expand Up @@ -104,7 +105,6 @@ const { getLegacyAccount } = require('./legacy');
const { getEventsByHeight } = require('./events');
const { invokeEndpointProxy } = require('./invoke');
const { setSchemas, setMetadata } = require('./schema');
const { updateTokenInfo } = require('./tokens');
const { getValidator, validateBLSKey } = require('./validators');
const {
getNetworkStatus,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,9 @@ const estimateTransactionFees = async params => {
const channelInfo = await resolveChannelInfo(params.transaction.params.receivingChainID);

const ccmByteFee = BigInt(ccmLength) * BigInt(channelInfo.minReturnFeePerByte);
const totalMessageFee = ccmByteFee
+ BigInt(additionalFees.params.messageFee.userAccountInitializationFee || 0);
const totalMessageFee = additionalFees.params.messageFee
? ccmByteFee + BigInt(additionalFees.params.messageFee.userAccountInitializationFee)
: ccmByteFee;

estimateTransactionFeesRes.data.transaction.params = {
messageFee: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,30 @@ const mockTransferCrossChainTxResult = {
},
};

const mockRegisterValidatorTxResult = {
data: {
transaction: {
fee: {
tokenID: '0400000000000000',
minimum: '130000',
},
params: {},
},
},
meta: {
breakdown: {
fee: {
minimum: {
byteFee: '160000',
additionalFees: {
validatorRegistrationFee: '1',
},
},
},
},
},
};

const mockTxsenderAddress = 'lskguo9kqnea2zsfo3a6qppozsxsg92nuuma3p7ad';

const mockTxAuthAccountInfo = {
Expand Down Expand Up @@ -266,6 +290,28 @@ const mockTransferCrossChainTxrequestConnector = {
minFee: '166000',
};

const mockRegisterValidatorTxrequestConnector = {
transaction: {
module: 'pos',
command: 'registerValidator',
fee: '100000000',
nonce: '1',
senderPublicKey: '3972849f2ab66376a68671c10a00e8b8b67d880434cc65b04c6ed886dfa91c2c',
signatures: [
'c7fd1abf9a552fa9c91b4121c87ae2c97cb0fc0aecc87d0ee8b1aa742238eef4a6815ddba31e21144c9652a7bd5c05577ae1100eac34fba43da6fc4879b8f206',
],
params: {
name: 'test_validator',
blsKey: 'a984c12c76b42b2d6ef2cae7ce09951e7d71eb160abdedbfba51bd216c42f2f3eda04a2e57b2cfb01768b94419b65190',
proofOfPossession: 'ab7661489a290464310c8615b387117ff27a209742e0e711f22d5ba3e7480de4eda293a651a48be9ae57b569a977d65e101179e1fcd73ab32c6c3fef4a1aedc7119e90eb2af7a3450399b15743c145bb49fdcb61b333817345c1d46769005d04',
generatorKey: 'b9c0211c8eb94ee61154a4dc7af36d2a36e14dd1644b43aa250186bfa107ce6b',
},
id: 'd96c777b67576ddf4cd933a97a60b4311881e68e3c8bef1393ac0020ec8a506c',
size: 167,
minFee: '166000',
},
};

const posConstants = {
data: {
factorSelfStakes: 10,
Expand Down Expand Up @@ -332,6 +378,8 @@ module.exports = {
mockTransferCrossChainTxResult,
mockAuthAccountInfo,
mockAuthInfoForMultisigAccount,
mockRegisterValidatorTxrequestConnector,
mockRegisterValidatorTxResult,

mockInteroperabilitySubmitMainchainCrossChainUpdateTxRequest,
mockInteroperabilitySubmitMainchainCrossChainUpdateTxResult,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ const {
mockInteroperabilityRegisterSidechainTxResult,
mockAuthAccountInfo,
mockAuthInfoForMultisigAccount,
mockRegisterValidatorTxrequestConnector,
mockRegisterValidatorTxResult,
} = require('../../constants/transactionEstimateFees');

jest.mock('lisk-service-framework', () => {
Expand Down Expand Up @@ -454,6 +456,25 @@ describe('Test transaction fees estimates', () => {
expect(result).toEqual(mockTransferCrossChainTxResult);
});

it('should calculate transaction fees correctly for register validator transaction', async () => {
// Mock the return values of the functions
getLisk32AddressFromPublicKey.mockReturnValue(mockTxsenderAddress);
getAuthAccountInfo.mockResolvedValue(mockTxAuthAccountInfo);
requestConnector
.mockReturnValueOnce(mockTxrequestConnector)
.mockReturnValue({ validatorRegistrationFee: '1', minFee: '130000', size: 160 });
getFeeEstimates.mockReturnValue(mockTxFeeEstimate);
calcAdditionalFees.mockResolvedValue({});
calcMessageFee.mockResolvedValue({});
getPosConstants.mockResolvedValue(posConstants);

const { estimateTransactionFees } = require(mockedTransactionFeeEstimatesFilePath);

// Call the function
const result = await estimateTransactionFees(mockRegisterValidatorTxrequestConnector);
expect(result).toEqual(mockRegisterValidatorTxResult);
});

it('should throw if empty, undefined or null object is passed', async () => {
// Mock the return values of the functions
getLisk32AddressFromPublicKey.mockReturnValue(mockTxsenderAddress);
Expand Down

0 comments on commit 2d55c42

Please sign in to comment.