Skip to content

Commit

Permalink
Npg 1941 block_by_id (#4097)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
kukkok3 committed Sep 28, 2022
1 parent cf8606f commit 5d7f312
Show file tree
Hide file tree
Showing 14 changed files with 1,624 additions and 300 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
query BlockById($id: String!){
block(id: $id) {
id
date {
epoch {
id
}
slot
}
chainLength
leader {
__typename
... on Pool{ id }
... on BftLeader{ id }
}
previousBlock { id }
totalInput
totalOutput
isConfirmed
branches { id }
transactions{totalCount
edges {
node {
id
blocks{id date{...blockDate}}
inputs{amount address{id}}
outputs{amount address{id}}
certificate{
__typename
... on StakeDelegation {account{id #delegation {... poolInfo} not implemented yet NPG-2247
}
pools {... poolInfo}}
... on OwnerStakeDelegation {pools {... poolInfo}}
... on PoolRegistration {pool {... poolInfo}
startValidity
managementThreshold
owners
operators
rewards {fixed ratio {numerator denominator} maxLimit}
rewardAccount {id #delegation {... poolInfo} not implemented yet NPG-2247
}
}
... on PoolRetirement {poolId retirementTime}
... on PoolUpdate {poolId startValidity}
... on VotePlan{voteStart{...blockDate}
voteEnd{...blockDate}
committeeEnd{...blockDate}
payloadType
proposals {externalId}
}
... on VoteCast {votePlan proposalIndex}
... on VoteTally {votePlan}
... on UpdateProposal {changes { configParams {...configParam}}
proposerId{id}
}
... on UpdateVote{proposalId voterId{id}}
... on MintToken{name}
... on EvmMapping {address}
}
}
}}
}
}

fragment poolInfo on Pool {
id
blocks(first: 1000){totalCount}
registration{pool{id}}
retirement{poolId}
}

fragment blockDate on BlockDate{
epoch{id}
slot
}

fragment configParam on ConfigParam
{
__typename
... on Block0Date { block0Date }
... on Discrimination { discrimination }
... on ConsensusType { consensusType }
... on SlotsPerEpoch { slotsPerEpoch }
... on SlotDuration { slotDuration}
... on EpochStabilityDepth { epochStabilityDepth }
... on Milli { milli}
... on BlockContentMaxSize { blockContentMaxSize}
... on AddBftLeader { addBftLeader{ id }}
... on RemoveBftLeader { removeBftLeader { id }}
... on LinearFee {
constant
coefficient
certificate
perCertificateFees {
certificatePoolRegistration
certificateStakeDelegation
certificateOwnerStakeDelegation
}
perVoteCertificateFees {
certificateVotePlan
certificateVoteCast
}}
... on ProposalExpiration{ proposalExpiration }
... on KesUpdateSpeed { kesUpdateSpeed}
... on TreasuryAdd { treasuryAdd }
... on TreasuryParams { treasuryParams {
fixed
ratio {
numerator
denominator
}
maxLimit
}}
... on RewardPot { rewardPot }
... on RewardParams { rewardParams {
__typename
... on LinearRewardParams{
constant
ratio {
numerator
denominator
}
epochStart
epochRate
}
... on HalvingRewardParams {
constant
ratio {
numerator
denominator
}
epochStart
epochRate
}
}}
... on PerCertificateFee{
certificatePoolRegistration
certificateStakeDelegation
certificateOwnerStakeDelegation
}
... on FeesInTreasury { feesInTreasury}
... on RewardLimitNone { rewardLimitNone }
... on RewardLimitByAbsoluteStake { rewardLimitByAbsoluteStake {
numerator
denominator
}}
... on PoolRewardParticipationCapping { min max }
... on AddCommitteeId { addCommitteeId}
... on RemoveCommitteeId { removeCommitteeId }
... on PerVoteCertificateFee {
certificateVotePlan
certificateVoteCast
}
... on TransactionMaxExpiryEpochs { transactionMaxExpiryEpochs }
}
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ pub struct TransactionByIdCertificates;
)]
pub struct AllVotePlans;

#[derive(GraphQLQuery)]
#[allow(clippy::upper_case_acronyms)]
#[graphql(
query_path = "resources/explorer/graphql/block_by_id.graphql",
schema_path = "resources/explorer/graphql/schema.graphql",
response_derives = "Debug,Clone"
)]
pub struct BlockById;

#[derive(GraphQLQuery)]
#[graphql(
query_path = "resources/explorer/graphql/voteplan_by_id.graphql",
Expand Down
25 changes: 19 additions & 6 deletions testing/jormungandr-automation/src/jormungandr/explorer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ use self::{
client::GraphQlClient,
configuration::ExplorerParams,
data::{
address, all_blocks, all_stake_pools, all_vote_plans, block, blocks_by_chain_length, epoch,
last_block, settings, stake_pool, transaction_by_id, transaction_by_id_certificates,
transactions_by_address, vote_plan_by_id, Address, AllBlocks, AllStakePools, AllVotePlans,
Block, BlocksByChainLength, Epoch, LastBlock, Settings, StakePool, TransactionById,
TransactionByIdCertificates, TransactionsByAddress, VotePlanById,
address, all_blocks, all_stake_pools, all_vote_plans, block, block_by_id,
blocks_by_chain_length, epoch, last_block, settings, stake_pool, transaction_by_id,
transaction_by_id_certificates, transactions_by_address, vote_plan_by_id, Address,
AllBlocks, AllStakePools, AllVotePlans, Block, BlockById, BlocksByChainLength, Epoch,
LastBlock, Settings, StakePool, TransactionById, TransactionByIdCertificates,
TransactionsByAddress, VotePlanById,
},
};
use crate::testing::configuration::get_explorer_app;
Expand All @@ -20,7 +21,7 @@ use std::{
mod client;
pub mod configuration;
pub mod data;
pub mod verifier;
pub mod verifiers;
mod wrappers;

use super::get_available_port;
Expand Down Expand Up @@ -225,6 +226,18 @@ impl Explorer {
Ok(response_body)
}

pub fn block_by_id(
&self,
id: String,
) -> Result<Response<block_by_id::ResponseData>, ExplorerError> {
let query = BlockById::build_query(block_by_id::Variables { id });
self.print_request(&query);
let response = self.client.run(query).map_err(ExplorerError::ClientError)?;
let response_body: Response<block_by_id::ResponseData> = response.json()?;
self.print_log(&response_body);
Ok(response_body)
}

pub fn blocks(&self, limit: i64) -> Result<Response<all_blocks::ResponseData>, ExplorerError> {
let query = AllBlocks::build_query(all_blocks::Variables { last: limit });
self.print_request(&query);
Expand Down

0 comments on commit 5d7f312

Please sign in to comment.