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

Function create_test_initial_state

finalizer/src/tests/syncing.rs:84–129  ·  view source on GitHub ↗

Create a minimal initial ConsensusState for testing

(genesis_hash: [u8; 32], epoch_length: NonZeroU64)

Source from the content-addressed store, hash-verified

82/// Create a minimal initial ConsensusState for testing
83fn create_test_initial_state(genesis_hash: [u8; 32], epoch_length: NonZeroU64) -> ConsensusState {
84 use rand::SeedableRng;
85 let mut rng = rand::rngs::StdRng::seed_from_u64(42);
86
87 let mut validator_accounts = BTreeMap::new();
88
89 for i in 0..4u64 {
90 let node_key = ed25519::PrivateKey::from_seed(i);
91 let node_pubkey = node_key.public_key();
92 let consensus_key = bls12381::PrivateKey::random(&mut rng);
93 let consensus_pubkey = consensus_key.public_key();
94
95 let account = ValidatorAccount {
96 consensus_public_key: consensus_pubkey,
97 withdrawal_credentials: Address::from([i as u8; 20]),
98 balance: 32_000_000_000,
99 status: ValidatorStatus::Active,
100 has_pending_deposit: false,
101 has_pending_withdrawal: false,
102 joining_epoch: 0,
103 last_deposit_index: 0,
104 };
105
106 let key_bytes: [u8; 32] = node_pubkey.as_ref().try_into().unwrap();
107 validator_accounts.insert(key_bytes, account);
108 }
109
110 let forkchoice = ForkchoiceState {
111 head_block_hash: genesis_hash.into(),
112 safe_block_hash: genesis_hash.into(),
113 finalized_block_hash: genesis_hash.into(),
114 };
115 let mut state = ConsensusState::new(
116 forkchoice,
117 32_000_000_000,
118 64_000_000_000,
119 epoch_length,
120 10_000,
121 Address::ZERO,
122 10,
123 16,
124 0,
125 3,
126 0,
127 );
128 state.set_validator_accounts(validator_accounts);
129 state
130}
131
132/// Create an initial state that looks like it came from a checkpoint at a non-zero height.

Calls 2

public_keyMethod · 0.80

Tested by

no test coverage detected