2019-08-28 12:07:00 +00:00
|
|
|
# beacon_chain
|
2024-01-06 14:26:56 +00:00
|
|
|
# Copyright (c) 2018-2024 Status Research & Development GmbH
|
2019-08-28 12:07:00 +00:00
|
|
|
# Licensed and distributed under either of
|
2019-11-25 15:30:02 +00:00
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
2019-08-28 12:07:00 +00:00
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2024-02-29 13:24:08 +00:00
|
|
|
{.push raises: [].}
|
|
|
|
|
2019-08-28 12:07:00 +00:00
|
|
|
# Mocking a genesis state
|
|
|
|
# ---------------------------------------------------------------
|
|
|
|
|
|
|
|
import
|
|
|
|
# Specs
|
2021-09-13 22:56:37 +00:00
|
|
|
../../beacon_chain/spec/[beaconstate, forks, state_transition],
|
2019-08-28 12:07:00 +00:00
|
|
|
# Mocking procs
|
2019-11-14 10:47:55 +00:00
|
|
|
./mock_deposits
|
2019-08-28 12:07:00 +00:00
|
|
|
|
2023-08-25 09:28:42 +00:00
|
|
|
const mockEth1BlockHash* =
|
|
|
|
Eth2Digest.fromHex("0x4242424242424242424242424242424242424242")
|
|
|
|
|
2021-09-13 22:56:37 +00:00
|
|
|
proc initGenesisState*(
|
2021-09-22 17:50:10 +00:00
|
|
|
num_validators = 8'u64 * SLOTS_PER_EPOCH,
|
|
|
|
cfg = defaultRuntimeConfig): ref ForkedHashedBeaconState =
|
2019-08-28 12:07:00 +00:00
|
|
|
let deposits = mockGenesisBalancedDeposits(
|
|
|
|
validatorCount = num_validators,
|
2024-03-19 13:22:07 +00:00
|
|
|
amountInEth = 32.Ether, # We create canonical validators with 32 Eth
|
2020-07-08 04:55:23 +00:00
|
|
|
flags = {}
|
2019-08-28 12:07:00 +00:00
|
|
|
)
|
|
|
|
|
2021-09-13 22:56:37 +00:00
|
|
|
result = (ref ForkedHashedBeaconState)(
|
2023-01-28 19:53:41 +00:00
|
|
|
kind: ConsensusFork.Phase0,
|
2021-10-18 16:37:27 +00:00
|
|
|
phase0Data: initialize_hashed_beacon_state_from_eth1(
|
2023-08-25 09:28:42 +00:00
|
|
|
cfg, mockEth1BlockHash, 0, deposits, {}))
|
2021-09-13 22:56:37 +00:00
|
|
|
|
2021-09-30 01:07:24 +00:00
|
|
|
maybeUpgradeState(cfg, result[])
|
2021-09-13 22:56:37 +00:00
|
|
|
|
2019-08-28 12:07:00 +00:00
|
|
|
when isMainModule:
|
|
|
|
# Smoke test
|
|
|
|
let state = initGenesisState(num_validators = SLOTS_PER_EPOCH)
|
|
|
|
doAssert state.validators.len == SLOTS_PER_EPOCH
|