Skip to content

Commit 5d7f312

Browse files
authored
Npg 1941 block_by_id (#4097)
* adding block0 test and incorrect id test * adding block test * fix decoding of block * refactor file structure * clean up unused imports * adding verifier * fix up test * fix clippy * modifying block test to run all fragments * fix assert_block name * fix conflicts * fix end line * fix fmt * remove should_panic as NPG-2899 has been fixed * fix error in test
1 parent cf8606f commit 5d7f312

File tree

14 files changed

+1624
-300
lines changed

14 files changed

+1624
-300
lines changed
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
query BlockById($id: String!){
2+
block(id: $id) {
3+
id
4+
date {
5+
epoch {
6+
id
7+
}
8+
slot
9+
}
10+
chainLength
11+
leader {
12+
__typename
13+
... on Pool{ id }
14+
... on BftLeader{ id }
15+
}
16+
previousBlock { id }
17+
totalInput
18+
totalOutput
19+
isConfirmed
20+
branches { id }
21+
transactions{totalCount
22+
edges {
23+
node {
24+
id
25+
blocks{id date{...blockDate}}
26+
inputs{amount address{id}}
27+
outputs{amount address{id}}
28+
certificate{
29+
__typename
30+
... on StakeDelegation {account{id #delegation {... poolInfo} not implemented yet NPG-2247
31+
}
32+
pools {... poolInfo}}
33+
... on OwnerStakeDelegation {pools {... poolInfo}}
34+
... on PoolRegistration {pool {... poolInfo}
35+
startValidity
36+
managementThreshold
37+
owners
38+
operators
39+
rewards {fixed ratio {numerator denominator} maxLimit}
40+
rewardAccount {id #delegation {... poolInfo} not implemented yet NPG-2247
41+
}
42+
}
43+
... on PoolRetirement {poolId retirementTime}
44+
... on PoolUpdate {poolId startValidity}
45+
... on VotePlan{voteStart{...blockDate}
46+
voteEnd{...blockDate}
47+
committeeEnd{...blockDate}
48+
payloadType
49+
proposals {externalId}
50+
}
51+
... on VoteCast {votePlan proposalIndex}
52+
... on VoteTally {votePlan}
53+
... on UpdateProposal {changes { configParams {...configParam}}
54+
proposerId{id}
55+
}
56+
... on UpdateVote{proposalId voterId{id}}
57+
... on MintToken{name}
58+
... on EvmMapping {address}
59+
}
60+
}
61+
}}
62+
}
63+
}
64+
65+
fragment poolInfo on Pool {
66+
id
67+
blocks(first: 1000){totalCount}
68+
registration{pool{id}}
69+
retirement{poolId}
70+
}
71+
72+
fragment blockDate on BlockDate{
73+
epoch{id}
74+
slot
75+
}
76+
77+
fragment configParam on ConfigParam
78+
{
79+
__typename
80+
... on Block0Date { block0Date }
81+
... on Discrimination { discrimination }
82+
... on ConsensusType { consensusType }
83+
... on SlotsPerEpoch { slotsPerEpoch }
84+
... on SlotDuration { slotDuration}
85+
... on EpochStabilityDepth { epochStabilityDepth }
86+
... on Milli { milli}
87+
... on BlockContentMaxSize { blockContentMaxSize}
88+
... on AddBftLeader { addBftLeader{ id }}
89+
... on RemoveBftLeader { removeBftLeader { id }}
90+
... on LinearFee {
91+
constant
92+
coefficient
93+
certificate
94+
perCertificateFees {
95+
certificatePoolRegistration
96+
certificateStakeDelegation
97+
certificateOwnerStakeDelegation
98+
}
99+
perVoteCertificateFees {
100+
certificateVotePlan
101+
certificateVoteCast
102+
}}
103+
... on ProposalExpiration{ proposalExpiration }
104+
... on KesUpdateSpeed { kesUpdateSpeed}
105+
... on TreasuryAdd { treasuryAdd }
106+
... on TreasuryParams { treasuryParams {
107+
fixed
108+
ratio {
109+
numerator
110+
denominator
111+
}
112+
maxLimit
113+
}}
114+
... on RewardPot { rewardPot }
115+
... on RewardParams { rewardParams {
116+
__typename
117+
... on LinearRewardParams{
118+
constant
119+
ratio {
120+
numerator
121+
denominator
122+
}
123+
epochStart
124+
epochRate
125+
}
126+
... on HalvingRewardParams {
127+
constant
128+
ratio {
129+
numerator
130+
denominator
131+
}
132+
epochStart
133+
epochRate
134+
}
135+
}}
136+
... on PerCertificateFee{
137+
certificatePoolRegistration
138+
certificateStakeDelegation
139+
certificateOwnerStakeDelegation
140+
}
141+
... on FeesInTreasury { feesInTreasury}
142+
... on RewardLimitNone { rewardLimitNone }
143+
... on RewardLimitByAbsoluteStake { rewardLimitByAbsoluteStake {
144+
numerator
145+
denominator
146+
}}
147+
... on PoolRewardParticipationCapping { min max }
148+
... on AddCommitteeId { addCommitteeId}
149+
... on RemoveCommitteeId { removeCommitteeId }
150+
... on PerVoteCertificateFee {
151+
certificateVotePlan
152+
certificateVoteCast
153+
}
154+
... on TransactionMaxExpiryEpochs { transactionMaxExpiryEpochs }
155+
}

testing/jormungandr-automation/src/jormungandr/explorer/data.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ pub struct TransactionByIdCertificates;
116116
)]
117117
pub struct AllVotePlans;
118118

119+
#[derive(GraphQLQuery)]
120+
#[allow(clippy::upper_case_acronyms)]
121+
#[graphql(
122+
query_path = "resources/explorer/graphql/block_by_id.graphql",
123+
schema_path = "resources/explorer/graphql/schema.graphql",
124+
response_derives = "Debug,Clone"
125+
)]
126+
pub struct BlockById;
127+
119128
#[derive(GraphQLQuery)]
120129
#[graphql(
121130
query_path = "resources/explorer/graphql/voteplan_by_id.graphql",

testing/jormungandr-automation/src/jormungandr/explorer/mod.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ use self::{
22
client::GraphQlClient,
33
configuration::ExplorerParams,
44
data::{
5-
address, all_blocks, all_stake_pools, all_vote_plans, block, blocks_by_chain_length, epoch,
6-
last_block, settings, stake_pool, transaction_by_id, transaction_by_id_certificates,
7-
transactions_by_address, vote_plan_by_id, Address, AllBlocks, AllStakePools, AllVotePlans,
8-
Block, BlocksByChainLength, Epoch, LastBlock, Settings, StakePool, TransactionById,
9-
TransactionByIdCertificates, TransactionsByAddress, VotePlanById,
5+
address, all_blocks, all_stake_pools, all_vote_plans, block, block_by_id,
6+
blocks_by_chain_length, epoch, last_block, settings, stake_pool, transaction_by_id,
7+
transaction_by_id_certificates, transactions_by_address, vote_plan_by_id, Address,
8+
AllBlocks, AllStakePools, AllVotePlans, Block, BlockById, BlocksByChainLength, Epoch,
9+
LastBlock, Settings, StakePool, TransactionById, TransactionByIdCertificates,
10+
TransactionsByAddress, VotePlanById,
1011
},
1112
};
1213
use crate::testing::configuration::get_explorer_app;
@@ -20,7 +21,7 @@ use std::{
2021
mod client;
2122
pub mod configuration;
2223
pub mod data;
23-
pub mod verifier;
24+
pub mod verifiers;
2425
mod wrappers;
2526

2627
use super::get_available_port;
@@ -225,6 +226,18 @@ impl Explorer {
225226
Ok(response_body)
226227
}
227228

229+
pub fn block_by_id(
230+
&self,
231+
id: String,
232+
) -> Result<Response<block_by_id::ResponseData>, ExplorerError> {
233+
let query = BlockById::build_query(block_by_id::Variables { id });
234+
self.print_request(&query);
235+
let response = self.client.run(query).map_err(ExplorerError::ClientError)?;
236+
let response_body: Response<block_by_id::ResponseData> = response.json()?;
237+
self.print_log(&response_body);
238+
Ok(response_body)
239+
}
240+
228241
pub fn blocks(&self, limit: i64) -> Result<Response<all_blocks::ResponseData>, ExplorerError> {
229242
let query = AllBlocks::build_query(all_blocks::Variables { last: limit });
230243
self.print_request(&query);

0 commit comments

Comments
 (0)