mirror of
https://github.com/status-im/nimbus-eth2.git
synced 2025-03-02 07:00:49 +00:00
* Introduce new mocking proc to replace:
- makeFakeValidatorPrivKey
- hackPrivKey
- getNextBeaconProposerIndex
- addBlock
- makeBlock
* Add comments on datastructure unsynced with the spec
* Add merkle tree constructor and initial mocking for deposits (missing merkle proofs)
* [Mock] Implement sparse merkle tree and merkle proof builder
* [Mocking] Genesis deposits
* Add compact_committees_roots init + mock genesis state
* [Tests] Add first deposit test using the new mocking procedures
* [Tests -deposits] add at and over 32 ETH deposit tests
* [Tests - deposits] Add test for validator top-up
* [Tests -deposits] Mention the TODO to test for invalid conditions
* [Tests] Add stub to test "is_valid_genesis_state"
* [Merkle proofs] Implement round-trip checks
* Deactivate roundtrips test
* SSZ - use EF convention for hash_tree_root / hashTreeRoot
* [Tests - Attestation] Attestation mocking + initial test
* Add mocking + 3 new tests for valid attestations + mention future invalid attestation tests
* Add crosslinks test (1 failing to attestations in block being duplicated in state transition)
* Single attestation crosslink test - workaround https://github.com/status-im/nim-beacon-chain/issues/361
* Add test for failed crosslink penalty
* Rebase fixes + add refactored tests to test suite
* justif-finalization helpers first batch
* Add 234 finalization tests
* Fix justif test, Rule I 234 finalization does not happen with sufficient support.
(Also unittest check template does not fail properly in some cases)
* Add tests for all finalization rules
* Properly delete nim-byteutils following c91727e7e5 (diff-7c3613dba5171cb6027c67835dd3b9d4)
* use digest helper for deposit root
50 lines
1.6 KiB
Nim
50 lines
1.6 KiB
Nim
# beacon_chain
|
|
# Copyright (c) 2018-2019 Status Research & Development GmbH
|
|
# Licensed and distributed under either of
|
|
# * MIT license (license terms in the root directory or at http://opensource.org/licenses/MIT).
|
|
# * Apache v2 license (license terms in the root directory or at http://www.apache.org/licenses/LICENSE-2.0).
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
# Mocking a genesis state
|
|
# ---------------------------------------------------------------
|
|
|
|
import
|
|
# Specs
|
|
../../beacon_chain/spec/[datatypes, beaconstate, digest],
|
|
# Internals
|
|
../../beacon_chain/extras,
|
|
# Mocking procs
|
|
./mock_deposits,
|
|
# Helpers
|
|
../helpers/digest_helpers
|
|
|
|
|
|
proc initGenesisState*(num_validators: uint64, genesis_time: uint64 = 0): BeaconState =
|
|
|
|
# EF magic number (similar to https://en.wikipedia.org/wiki/Magic_number_(programming))
|
|
const deposit_root = [byte 0x42] * 32
|
|
|
|
let eth1_data = Eth1Data(
|
|
deposit_root: deposit_root,
|
|
deposit_count: num_validators,
|
|
block_hash: ZERO_HASH
|
|
)
|
|
|
|
let deposits = mockGenesisBalancedDeposits(
|
|
validatorCount = num_validators,
|
|
amountInEth = 32, # We create canonical validators with 32 Eth
|
|
flags = {skipValidation}
|
|
)
|
|
|
|
result = initialize_beacon_state_from_eth1(
|
|
genesis_validator_deposits = deposits,
|
|
genesis_time = 0,
|
|
genesis_eth1_data = eth1_data,
|
|
flags = {skipValidation}
|
|
)
|
|
|
|
when isMainModule:
|
|
# Smoke test
|
|
let state = initGenesisState(num_validators = SLOTS_PER_EPOCH)
|
|
doAssert state.validators.len == SLOTS_PER_EPOCH
|