MCPcopy Create free account
hub / github.com/SeismicSystems/summit / create_test_finalizer_mailbox

Function create_test_finalizer_mailbox

rpc/tests/utils.rs:52–161  ·  view source on GitHub ↗

Creates a mock finalizer mailbox that responds to queries with test data

(
    state: MockFinalizerState,
)

Source from the content-addressed store, hash-verified

50 }
51}
52
53/// Creates a mock finalizer mailbox that responds to queries with test data
54pub fn create_test_finalizer_mailbox(
55 state: MockFinalizerState,
56) -> (ConsensusStateQuery<TestScheme>, JoinHandle<()>) {
57 let (query, mut rx) = ConsensusStateQuery::new(100);
58
59 let handle = tokio::spawn(async move {
60 while let Some((request, response)) = rx.next().await {
61 match request {
62 ConsensusStateRequest::GetLatestHeight => {
63 let _ =
64 response.send(ConsensusStateResponse::LatestHeight(state.latest_height));
65 }
66 ConsensusStateRequest::GetLatestEpoch => {
67 let _ = response.send(ConsensusStateResponse::LatestEpoch(state.latest_epoch));
68 }
69 ConsensusStateRequest::GetCheckpoint(epoch) => {
70 let checkpoint = state
71 .checkpoints
72 .get(&epoch)
73 .cloned()
74 .flatten()
75 .and_then(|checkpoint| Some((checkpoint, Block::genesis([0; 32]))));
76 let _ = response.send(ConsensusStateResponse::Checkpoint(checkpoint));
77 }
78 ConsensusStateRequest::GetLatestCheckpoint => {
79 let (latest_checkpoint, epoch) =
80 state.latest_checkpoint.clone().unwrap_or((None, 0));
81 let latest_checkpoint =
82 latest_checkpoint.map(|checkpoint| (checkpoint, Block::genesis([0; 32])));
83 let _ = response.send(ConsensusStateResponse::LatestCheckpoint((
84 latest_checkpoint,
85 epoch,
86 )));
87 }
88 ConsensusStateRequest::GetValidatorBalance(public_key) => {
89 let balance = state.validator_balances.get(&public_key).cloned().flatten();
90 let _ = response.send(ConsensusStateResponse::ValidatorBalance(balance));
91 }
92 ConsensusStateRequest::GetValidatorAccount(public_key) => {
93 let account = state.validator_accounts.get(&public_key).cloned().flatten();
94 let _ = response.send(ConsensusStateResponse::ValidatorAccount(account));
95 }
96 ConsensusStateRequest::GetFinalizedHeader(epoch) => {
97 let header = state.finalized_headers.get(&epoch).cloned().flatten();
98 let _ = response.send(ConsensusStateResponse::FinalizedHeader(header));
99 }
100 ConsensusStateRequest::GetMinimumStake => {
101 let _ =
102 response.send(ConsensusStateResponse::MinimumStake(state.minimum_stake));
103 }
104 ConsensusStateRequest::GetMaximumStake => {
105 let _ =
106 response.send(ConsensusStateResponse::MaximumStake(state.maximum_stake));
107 }
108 ConsensusStateRequest::GetStateRoot => {
109 let _ = response.send(ConsensusStateResponse::StateRoot {

Callers 10

test_health_endpointFunction · 0.85
test_get_latest_heightFunction · 0.85
test_get_latest_epochFunction · 0.85
test_get_public_keysFunction · 0.85
test_get_minimum_stakeFunction · 0.85
test_get_maximum_stakeFunction · 0.85

Calls 4

CheckpointClass · 0.85
ValidatorAccountClass · 0.85
sendMethod · 0.80
getMethod · 0.80

Tested by

no test coverage detected