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

Commit

Permalink
✅ Add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nagdahimanshu committed Feb 6, 2024
1 parent f52bc5b commit 3cdf63a
Show file tree
Hide file tree
Showing 11 changed files with 1,017 additions and 408 deletions.
2 changes: 1 addition & 1 deletion services/export/shared/regex.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const PARTIAL_FILENAME =
const STANDARDIZED_INTERVAL =
/^\b((\d{4})-((1[012])|(0?[1-9]))-(([012][1-9])|([123]0)|31)):((\d{4})-((1[012])|(0?[1-9]))-(([012][1-9])|([123]0)|31))\b$/g;
const EXCEL_FILE_URL =
/^\/api\/v3\/export\/download\?filename=transactions_(lsk[a-hjkm-z2-9]{38})_((\d{4})-((1[012])|(0?[1-9]))-(([012][1-9])|([123]0)|31))_((\d{4})-((1[012])|(0?[1-9]))-(([012][1-9])|([123]0)|31))\.xlsx$/g;
/^\/api\/v3\/export\/download\?filename=transactions_([a-fA-F0-9]{8})_(lsk[a-hjkm-z2-9]{38})_((\d{4})-((1[012])|(0?[1-9]))-(([012][1-9])|([123]0)|31))_((\d{4})-((1[012])|(0?[1-9]))-(([012][1-9])|([123]0)|31))\.xlsx$/g;
const MAINCHAIN_ID = /^[a-fA-F0-9]{2}000000$/;

module.exports = {
Expand Down
7 changes: 7 additions & 0 deletions services/export/shared/transactionsExport.js
Original file line number Diff line number Diff line change
Expand Up @@ -980,4 +980,11 @@ module.exports = {
// For functional tests
formatTransaction,
formatBlocks,
getChainInfo,
getBlockRewardEntries,
getGeneratorFeeEntries,
getSharedRewardsAssignedEntries,
getMessageFeeEntries,
getOutgoingTransferCCEntries,
getIncomingTransferCCEntries,
};
35 changes: 35 additions & 0 deletions services/export/tests/constants/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,41 @@ const blocks = [
isFinal: false,
reward: 0,
},

{
id: 'bc62dabae94b2d146a9fb72424b87d65cfdc4b41d57d7e95343a8bd246b74b75',
version: 2,
timestamp: 1704198870,
height: 21016494,
previousBlockID: '40cf694c59aa0f4ccddaf1b37e77c752c5b2ae17253c76dbe26a8463be204fdb',
generator: {
address: 'lskkg45aupy3mnzeko7thpgzwaqh9cjcrjfo46kjt',
name: 'different_dish',
publicKey: 'ae79e3d4fcfc8b9d7acbf2a72f2281cb85a98cd9a5b18b2164b06113032bea78',
},
transactionRoot: '5b24f16b9313b7954c086743ab784af77ecab4854cff5538c14633b50bb728fa',
assetRoot: 'f74d106522e5f9350edc170eb8603168438c85030d6294a37239961ab10bfd3a',
stateRoot: 'e0587de5aabe73bf478a9f94aeae9ee86e771d1cc01d9ee3b78d8d45aa278abd',
eventRoot: '907db89b436269e870cc234844fd4d26e484380d33b724d078cf65deebbe0e44',
maxHeightPrevoted: 21016419,
maxHeightGenerated: 21016363,
validatorsHash: 'f111c95be02cd8924791a24c97bc1a014a8aad7906b85f1f4ecc40e195234211',
aggregateCommit: {
height: 21016347,
aggregationBits: '',
},
certificateSignature: '',
numberOfTransactions: 1,
numberOfAssets: 1,
numberOfEvents: 10,
totalForged: '22268530',
totalBurnt: '194000',
networkFee: '9806000',
signature:
'e25aefd645ae92251e029c0679486464ed10795ee27955243e99436f977cbfec185c7cd6a66d57516a65f59b83990c9998519212e9002a43b8371245361ba606',
reward: '12268530',
isFinal: true,
},
];

module.exports = {
Expand Down
167 changes: 167 additions & 0 deletions services/export/tests/constants/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
/*
* 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 tokenMintedEvent = {
id: '000f293a862a5b5c55f44cba8fb656cdab94ce4ebd99cc9f97329b87a70248f3',
module: 'token',
name: 'lock',
data: {
address: 'lskbrukhb5ctdodhy8z6any4b6u2qrkugz43w78pr',
module: 'fee',
tokenID: '0100000000000000',
amount: '161000',
result: 0,
},
topics: [
'041c425c907ba819e64da0166de38fe50ae9de29d9a3fd2bbeda2e89c045917fe3',
'lskbrukhb5ctdodhy8z6any4b6u2qrkugz43w78pr',
],
};

const tokenLockedEvent = {
id: 'e2e8622d572985863166015c62b90ad0c8339f6eb9331eff7eb8011d89882358',
module: 'token',
name: 'mint',
data: {
address: 'lskywqe2cuw5j9burca4sm6rpfxnxyzksv5r99b9g',
tokenID: '0100000000000000',
amount: '131000',
result: 0,
},
topics: ['03', 'lskywqe2cuw5j9burca4sm6rpfxnxyzksv5r99b9g'],
};

const genFeeProcessed = {
id: 'ab21335d06196f58608c60c77fa2cfc285697a5471d95fa295521d6798d32e5d',
module: 'fee',
name: 'generatorFeeProcessed',
data: {
senderAddress: 'lskmv6entvj8cnrhfdoa38ojx34pv4rd9q44788r7',
generatorAddress: 'lskme8ohf9geuno8nwpvdqm8wr8bvz5nzguftwpxp',
burntAmount: '179000',
generatorAmount: '21000',
},
topics: [
'04d41e8fbb909fdf44ffccef6f5b0fb5edf853f0dcf699243a0a92403d2a4f1d1d',
'lskmv6entvj8cnrhfdoa38ojx34pv4rd9q44788r7',
'lskme8ohf9geuno8nwpvdqm8wr8bvz5nzguftwpxp',
],
};

const rewardsAssigned = {
id: '5630ae1886ab96412db5924193ee1782ac4acc72c6196e8eadb0cf8adbef3de2',
module: 'pos',
name: 'rewardsAssigned',
data: {
stakerAddress: 'lskmg3sdmjp4smz6x9k2cuyuwags5ehgtexe4w2ds',
validatorAddress: 'lsk26s9p9rb74ygzxayuf9cx6x7x5wuvp2v9yrns7',
tokenID: '0100000000000000',
amount: '87694485125',
},
topics: [
'04732923c6e8780251c1dcd179e3e657827ae9318a6df920de595d743f1ed70a40',
'lskmg3sdmjp4smz6x9k2cuyuwags5ehgtexe4w2ds',
],
};

const relayerFeeProcessed = {
id: '40f44afac6097dcec6dfd945000990f0ea95e7a1ad9e86562cb02ee36ee39e4c',
module: 'interoperability',
name: 'relayerFeeProcessed',
data: {
ccmID: 'e6a22f3c4489ceba8e20eeea0ce617d9c385e92aeb9a710a53eb941d34b5f92e',
relayerAddress: 'lskmg3sdmjp4smz6x9k2cuyuwags5ehgtexe4w2ds',
burntAmount: '10000000',
relayerAmount: '0',
},
topics: ['lskmg3sdmjp4smz6x9k2cuyuwags5ehgtexe4w2ds'],
};

const ccmSendSuccess = {
id: 'df34de3aa6461285698e023135edf6708e963510048a9be5b5a7acfe1ecd3ac1',
module: 'interoperability',
name: 'ccmSendSuccess',
data: {
ccm: {
module: 'token',
crossChainCommand: 'transferCrossChain',
nonce: '57',
fee: '109000',
sendingChainID: '04000000',
receivingChainID: '04000002',
params:
'0a0801000000000000001080c2d72f1a145a88fb2d14453327d896adc860e711d26123bd9022145a88fb2d14453327d896adc860e711d26123bd902a00',
status: 0,
},
},
topics: [
'0434548b99aa37a5a450712c7e3f1e13b62be872d65dd7a8c1d54859408ca4914b',
'01000000',
'01000002',
'5ec6bd1dbbcecaef8edad082cfd333c7cf1fdbfeb248c8a80a236179484d06c8',
],
};

const transferCrossChain = {
id: 'f01ba39c143282f7a21e2680b50f7b9b8450afcabc24c35dd72793e389a1bcab',
module: 'token',
name: 'transferCrossChain',
data: {
senderAddress: 'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
recipientAddress: 'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
tokenID: '0400000000000000',
amount: '100000000',
receivingChainID: '04000002',
result: 0,
},
topics: [
'0434548b99aa37a5a450712c7e3f1e13b62be872d65dd7a8c1d54859408ca4914b',
'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
'01000002',
],
};

const ccmTransfer = {
id: 'f01ba39c143282f7a21e2680b50f7b9b8450afcabc24c35dd72793e389a1bcab',
module: 'token',
name: 'transferCrossChain',
data: {
senderAddress: 'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
recipientAddress: 'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
tokenID: '0400000000000000',
amount: '100000000',
receivingChainID: '04000002',
result: 0,
},
topics: [
'd16d1cb5fa32df64988b4ab5de66b7d43c8fbfdaf043aca84d649f914d66189f',
'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
],
};

module.exports = {
events: {
tokenMintedEvent,
tokenLockedEvent,
genFeeProcessed,
rewardsAssigned,
relayerFeeProcessed,
ccmSendSuccess,
transferCrossChain,
ccmTransfer,
},
};
114 changes: 114 additions & 0 deletions services/export/tests/constants/transaction.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,126 @@ const tokenTransferCrossChainTransaction = {
index: 1,
};

const posClaimedRewards = {
id: '732923c6e8780251c1dcd179e3e657827ae9318a6df920de595d743f1ed70a40',
moduleCommand: 'pos:claimRewards',
nonce: '92',
fee: '127000',
minFee: '127000',
size: 127,
block: {
id: 'd6be2fd9ebd06406122ed971b7638621b8f5104f84b46e21d4067fd28b3db72e',
height: 21304948,
timestamp: 1707134570,
isFinal: true,
},
sender: {
address: 'lskmg3sdmjp4smz6x9k2cuyuwags5ehgtexe4w2ds',
publicKey: 'f0fda0461215e4e63a68d12c79d293833c32519cfe3a5e01ca08b0a0a7493de5',
name: null,
},
params: {},
signatures: [
'd219f9362bd2a6fcd8357bcfdc26b66efade5526407d884e4f34750934965b1f3367f7f71e9ddfd29160f6b101a0136ee456a1b7721519d85fff6d6ca65be401',
],
executionStatus: 'successful',
index: 0,
};

const transferCrossChain = {
id: '34548b99aa37a5a450712c7e3f1e13b62be872d65dd7a8c1d54859408ca4914b',
moduleCommand: 'token:transferCrossChain',
nonce: '41',
fee: '10000000',
minFee: '194000',
size: 195,
block: {
id: 'bc62dabae94b2d146a9fb72424b87d65cfdc4b41d57d7e95343a8bd246b74b75',
height: 21016494,
timestamp: 1704198870,
isFinal: true,
},
sender: {
address: 'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
publicKey: '344c75738c096e4bd94459fe81eba45503382181d003a9d2c8be75a2f38b49fa',
name: null,
},
params: {
tokenID: '0400000000000000',
amount: '100000000',
receivingChainID: '04000002',
recipientAddress: 'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
data: '',
messageFee: '109000',
messageFeeTokenID: '0400000000000000',
},
signatures: [
'cbe755352a175b11a3dc4ae4b5e890ebc4ce1d5cc11c6dbdf5cf21b19f7605e7845b4650779191fdbfc1a1afe90edc1a049717b60858f140f4ae0ad67e93d505',
],
executionStatus: 'successful',
index: 0,
meta: {
recipient: {
address: 'lsk56p8e53k3kar8epeqwpbxa2yd4urn8ouzhfvgs',
publicKey: '344c75738c096e4bd94459fe81eba45503382181d003a9d2c8be75a2f38b49fa',
name: null,
},
},
};

const submitMainchainCrossChainUpdate = {
id: 'd16d1cb5fa32df64988b4ab5de66b7d43c8fbfdaf043aca84d649f914d66189f',
moduleCommand: 'interoperability: submitMainchainCrossChainUpdate',
nonce: '140',
fee: '3000000',
minFee: '422000',
size: 423,
block: {
id: '5333974cf1763909f6e63e4a419d942ae4a6a0a2f3477e620f214cf23a4c7342',
height: 21102804,
timestamp: 1705079500,
isFinal: true,
},
sender: {
address: 'lskcd7tbbhkyebmg2fhdd4w4omvnfhzp5rb7wmz4d',
publicKey: 'b5e96c1a5ab6f9d96eb08360cbfe4f1d8826591c515d307b9b9eeb1567a19013',
name: null,
},
params: {
sendingChainID: '04000000',
certificate:
'0a20e38e39a33032916b31c6f092047d6aa4919d88760b9185fe631c19d1669a45fc10f60418f4ac84ad0622204dd143faa3c027e456369f75c89bd32befb9229dfcc3cd0b83ecbbca1e0656a42a2076965cc0331adc28fd8d16e63a64d6520397ee3fb3397da59afe60a506bcd909320dffffffffffffffffffffffff013a60b42c2b251e7621e8fd4915167a8360967860898484f29d0faf1e5536ba74bae59da15de420e209182843f884e6aea1b7078095fbeffdbac4169ac3689d06a49e49abd9a4aa9ee78708b7978e2de477993589ed0d2114d3fca5267da867510502',
activeValidatorsUpdate: {
blsKeysUpdate: [],
bftWeightsUpdate: ['0'],
bftWeightsUpdateBitmap: '00000000000000000020000000',
},
certificateThreshold: '65',
inboxUpdate: {
crossChainMessages: [],
messageWitnessHashes: [],
outboxRootWitness: {
bitmap: '',
siblingHashes: [],
},
},
},
signatures: [
'ded5534277972e71ca062b3ac58ce1e6e71fe5f9b5a91c091e5e8ddc879726263c2c6cd23bc1ca1e18f5cdc36767ca243773180ee05caa7bbe724324c20a300d',
],
executionStatus: 'failed',
index: 0,
};

module.exports = {
transactions: {
reclaim: reclaimTransaction,
tokenTransfer: tokenTransferTransaction,
tokenTransferSelf: tokenTransferTransactionSelf,
tokenTransferCrossChain: tokenTransferCrossChainTransaction,
stake: stakeTransaction,
claimedRewards: posClaimedRewards,
transferCrossChain,
submitMainchainCrossChainUpdate,
},
};
Loading

0 comments on commit 3cdf63a

Please sign in to comment.