Skip to content

Commit

Permalink
Add tests for the admin_key types
Browse files Browse the repository at this point in the history
Signed-off-by: sdimitrov9 <stoyan.dimitrov@limechain.tech>
  • Loading branch information
sdimitrov9 committed Nov 22, 2024
1 parent 66f2822 commit ecd3793
Show file tree
Hide file tree
Showing 7 changed files with 910 additions and 2 deletions.
30 changes: 30 additions & 0 deletions hedera-mirror-rest/__tests__/integrationDomainOps.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const setup = async (testDataJson) => {
await loadFileData(testDataJson.filedata);
await loadNetworkStakes(testDataJson.networkstakes);
await loadNfts(testDataJson.nfts);
await loadNodes(testDataJson.nodes);
await loadNodeStakes(testDataJson.nodestakes);
await loadRecordFiles(testDataJson.recordFiles);
await loadSchedules(testDataJson.schedules);
Expand Down Expand Up @@ -383,6 +384,16 @@ const loadNetworkStakes = async (networkStakes) => {
}
};

const loadNodes = async (nodes) => {
if (nodes == null) {
return;
}

for (const node of nodes) {
await addNode(node);
}
};

const loadNodeStakes = async (nodeStakes) => {
if (nodeStakes == null) {
return;
Expand Down Expand Up @@ -1055,6 +1066,14 @@ const contractStateDefaults = {
value: 1,
};

const nodeDefaults = {
admin_key: 'OiG1sc5qQaLDwUfqfBg8urypfFGcwlesArZzBDsEgvyr0MQ',
created_timestamp: 1664365660048674966,
deleted: false,
node_id: 0,
timestamp_range: '[0,)',
};

const addContractAction = async (contractActionInput) => {
const action = {
...contractActionDefaults,
Expand Down Expand Up @@ -1547,6 +1566,16 @@ const addNft = async (custom) => {
await insertDomainObject(getTableName('nft', nft), insertFields, nft);
};

const addNode = async (nodeInput) => {
const node = {
...nodeDefaults,
...nodeInput,
};

convertByteaFields(['admin_key'], node);
await insertDomainObject('node', Object.keys(nodeDefaults), node);
};

const addNodeStake = async (nodeStakeInput) => {
const stakingPeriodEnd = 86_400_000_000_000n - 1n;
const nodeStake = {
Expand Down Expand Up @@ -1662,6 +1691,7 @@ export default {
loadEthereumTransactions,
loadFileData,
loadNetworkStakes,
loadNodes,
loadNodeStakes,
loadRecordFiles,
loadStakingRewardTransfers,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
{
"description": "Network nodes API with all params",
"setup": {
"addressbooks": [
{
"start_consensus_timestamp": 1,
"memo": null,
"file_id": 101,
"node_count": 1
},
{
"start_consensus_timestamp": 2,
"file_id": 102,
"node_count": 1
},
{
"start_consensus_timestamp": 187654000123456,
"memo": null,
"file_id": 101,
"node_count": 2
},
{
"start_consensus_timestamp": 187654000123457,
"file_id": 102,
"node_count": 2
}
],
"addressbookentries": [
{
"consensus_timestamp": 1,
"node_id": 0,
"node_account_id": 3
},
{
"consensus_timestamp": 2,
"memo": "0.0.3",
"node_id": 0,
"node_account_id": 3
},
{
"consensus_timestamp": 187654000123456,
"node_id": 0,
"node_account_id": 3
},
{
"consensus_timestamp": 187654000123456,
"node_id": 1,
"node_account_id": 4
},
{
"consensus_timestamp": 187654000123457,
"memo": "0.0.3",
"node_id": 0,
"node_account_id": 3
},
{
"consensus_timestamp": 187654000123457,
"memo": "0.0.4",
"node_id": 1,
"node_account_id": 4
}
],
"addressbookserviceendpoints": [
{
"consensus_timestamp": 1,
"ip_address_v4": "127.0.0.1",
"node_id": 0,
"port": 50211
},
{
"consensus_timestamp": 2,
"ip_address_v4": "128.0.0.1",
"node_id": 0,
"port": 50212
},
{
"consensus_timestamp": 187654000123456,
"ip_address_v4": "127.0.0.3",
"node_id": 0,
"port": 50213
},
{
"consensus_timestamp": 187654000123456,
"ip_address_v4": "127.0.0.4",
"node_id": 1,
"port": 50214
},
{
"consensus_timestamp": 187654000123457,
"domain_name": "https://www.node5.com",
"ip_address_v4": "",
"port": 50215,
"node_id": 0
},
{
"consensus_timestamp": 187654000123457,
"ip_address_v4": "128.0.0.6",
"node_id": 1,
"port": 50216
}
],
"nodestakes": [
{
"consensus_timestamp": 1,
"epoch_day": 1,
"node_id": 0,
"reward_rate": 5,
"stake": 10,
"stake_rewarded": 2
},
{
"consensus_timestamp": 2,
"epoch_day": 2,
"node_id": 0,
"reward_rate": 6,
"stake": 11,
"stake_rewarded": 3
},
{
"consensus_timestamp": 187654000123456,
"epoch_day": 3,
"node_id": 0,
"reward_rate": 7,
"stake": 12,
"stake_rewarded": 4
},
{
"consensus_timestamp": 187654000123456,
"epoch_day": 1,
"node_id": 1,
"reward_rate": 8,
"stake": 100,
"stake_rewarded": 20
},
{
"_description": "An old entry without data for max_stake, min_stake, and stake_not_rewarded",
"consensus_timestamp": 187654000123457,
"max_stake": -1,
"min_stake": -1,
"epoch_day": 4,
"node_id": 0,
"reward_rate": 9,
"stake": 13,
"stake_not_rewarded": -1,
"stake_rewarded": 5
},
{
"consensus_timestamp": 187654000123457,
"epoch_day": 2,
"node_id": 1,
"reward_rate": 10,
"stake": 101,
"stake_rewarded": 21
}
],
"nodes": [
{
"admin_key": "OiG1sc5qQaLDwUfqfBg8urypfFGcwlesArZzBDsEgvyr0MQ=",
"node_id": 0,
"created_timestamp": 1664365660048674966,
"deleted": false,
"timestamp_range": "[0,)"
},
{
"admin_key": "df6d34=",
"node_id": 25,
"created_timestamp": 1664365660048674966,
"deleted": false,
"timestamp_range": "[0,)"
}
]
},
"url": "/api/v1/network/nodes?file.id=102&node.id=0&limit=1&order=desc",
"responseStatus": 200,
"responseJson": {
"nodes": [
{
"admin_key": {
"_type": "ECDSA_SECP256K1",
"key": "b5b1ce6a41a2c3c147ea7c183cbabca97c519cc257ac02b673043b0482fcabd0c4"
},
"description": "description",
"file_id": "0.0.102",
"max_stake": null,
"memo": "0.0.3",
"min_stake": null,
"node_account_id": "0.0.3",
"node_cert_hash": "0x01d173753810c0aae794ba72d5443c292e9ff962b01046220dd99f5816422696e0569c977e2f169e1e5688afc8f4aa16",
"node_id": 0,
"public_key": "0x4a5ad514f0957fa170a676210c9bdbddf3bc9519702cf915fa6767a40463b96f",
"reward_rate_start": 9,
"service_endpoints": [
{
"domain_name": "https://www.node5.com",
"ip_address_v4": "",
"port": 50215
}
],
"stake": 13,
"stake_not_rewarded": null,
"stake_rewarded": 5,
"staking_period": {
"from": "86400.000000000",
"to": "172800.000000000"
},
"timestamp": {
"from": "187654.000123457",
"to": null
}
}
],
"links": {
"next": "/api/v1/network/nodes?file.id=102&node.id=0&limit=1&order=desc"
}
}
}
Loading

0 comments on commit ecd3793

Please sign in to comment.