Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test_genesis.py and cleanup genesis trigger #1202

Merged
merged 52 commits into from
Jun 30, 2019
Merged
Show file tree
Hide file tree
Changes from 47 commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7a16db1
Add test_genesis
hwwhww Jun 21, 2019
b36ffd5
default value of `deposit_index`
hwwhww Jun 21, 2019
ac34221
Fix `is_genesis_trigger` and add test case
hwwhww Jun 21, 2019
e7c595d
Fix test_process_deposit.py
hwwhww Jun 21, 2019
8828dad
minor updates
hwwhww Jun 21, 2019
47b29c8
Loose condition of effective genesis deposit
hwwhww Jun 22, 2019
7468fd0
Add more test
hwwhww Jun 22, 2019
24ad426
`spectest_with_bls_switch` decorator
hwwhww Jun 22, 2019
5f09212
yield for `is_genesis_trigger`
hwwhww Jun 22, 2019
b510115
Merge branch 'dev' into test_genesis
hwwhww Jun 22, 2019
6aef6c5
Clean up
hwwhww Jun 22, 2019
a3f8f50
Initialise deposit root properly
JustinDrake Jun 22, 2019
ccda508
Fix deposit root, add min_genesis_time, per-block processing
JustinDrake Jun 26, 2019
a62d026
merge with dev, fixed now
protolambda Jun 26, 2019
aecaed7
move genesis tests, structure properly, add yield keys for future tes…
protolambda Jun 26, 2019
a0c2f5c
fix genesis testing code, add missing constant temporarily, fix py Ge…
protolambda Jun 26, 2019
ee712ec
Make HW happy :)
JustinDrake Jun 27, 2019
2252142
padding version normal merkle tree
hwwhww Jun 28, 2019
4dc526f
In the end, `get_merkle_root` is back
hwwhww Jun 28, 2019
cb2bfd6
Apply Proto's feedback of list(map(...))
hwwhww Jun 28, 2019
7bc6a46
Fix `build_deposit`
hwwhww Jun 28, 2019
ad943bb
Make deposit root the root of an SSZ vector
JustinDrake Jun 29, 2019
d820dbd
Compile contract
JustinDrake Jun 29, 2019
34b8d8a
Start modifying test
JustinDrake Jun 29, 2019
d5d3e49
Tests pass
JustinDrake Jun 29, 2019
a7ceec1
Uncomment tests
JustinDrake Jun 29, 2019
7fdf59d
`active_validator_count >= GENESIS_ACTIVE_VALIDATOR_COUNT`: per Eth1 …
hwwhww Jun 29, 2019
b162a8f
simplify list creation
protolambda Jun 29, 2019
f0a8e39
WIP
JustinDrake Jun 29, 2019
d0009b0
Pass `genesis_eth1_block_hash` instead of `genesis_eth1_data`
hwwhww Jun 29, 2019
d475565
Merge branch 'deposit-root' into test_genesis
hwwhww Jun 29, 2019
1b66323
head to 1229
hwwhww Jun 29, 2019
c8dc30e
Recover from auto-merge
hwwhww Jun 29, 2019
354cd1c
Clean up leftover and linter
hwwhww Jun 29, 2019
e4eebef
fix broken deposits test, now same error as others
protolambda Jun 29, 2019
fb165dc
fixes a few tests, not all
protolambda Jun 29, 2019
ff185c3
fix deposit state mocking for tests
protolambda Jun 29, 2019
125660c
Update input `deposits` type from `Sequence[Deposit]` to `List[Deposi…
hwwhww Jun 29, 2019
56caa48
Should use Sequence
hwwhww Jun 29, 2019
12dff53
Renames:
hwwhww Jun 29, 2019
2247642
Cleanups; think about merging is_genesis_trigger into get_genesis_state
JustinDrake Jun 29, 2019
d00b5b9
Merge is_genesis_trigger into get_genesis_state
JustinDrake Jun 29, 2019
3a5872f
Cleanups and fixes
JustinDrake Jun 29, 2019
ada3cb2
Fix genesis balance bug (git add -u)
JustinDrake Jun 29, 2019
43beb74
typo
JustinDrake Jun 29, 2019
a356fc9
Fixes
JustinDrake Jun 29, 2019
6d45513
Make timestamp a uint64
JustinDrake Jun 29, 2019
03a243e
fix basic test
hwwhww Jun 29, 2019
47cdae4
Refactor
hwwhww Jun 29, 2019
8d2cbc9
add comments to make variations in genesis initialization clear, and …
protolambda Jun 30, 2019
4d5d597
fix genesis tests; sign deposit-datas, and lower min validator count …
protolambda Jun 30, 2019
f1749df
minor typo
djrtwo Jun 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions configs/constant_presets/mainnet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ MIN_PER_EPOCH_CHURN_LIMIT: 4
CHURN_LIMIT_QUOTIENT: 65536
# See issue 563
SHUFFLE_ROUND_COUNT: 90
# `2**16` (= 65,536)
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 65536


# Deposit contract
Expand Down
2 changes: 2 additions & 0 deletions configs/constant_presets/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ MIN_PER_EPOCH_CHURN_LIMIT: 4
CHURN_LIMIT_QUOTIENT: 65536
# [customized] Faster, but unsecure.
SHUFFLE_ROUND_COUNT: 10
# [customized]
MIN_GENESIS_ACTIVE_VALIDATOR_COUNT: 100


# Deposit contract
Expand Down
2 changes: 1 addition & 1 deletion deposit_contract/contracts/validator_registration.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions deposit_contract/contracts/validator_registration.v.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
AMOUNT_LENGTH: constant(uint256) = 8 # bytes
SIGNATURE_LENGTH: constant(uint256) = 96 # bytes

Deposit: event({
DepositEvent: event({
pubkey: bytes[48],
withdrawal_credentials: bytes[32],
amount: bytes[8],
Expand Down Expand Up @@ -42,16 +42,17 @@ def to_little_endian_64(value: uint256) -> bytes[8]:

@public
@constant
def get_deposit_root() -> bytes32:
node: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000000
def get_hash_tree_root() -> bytes32:
zero_bytes32: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000000
node: bytes32 = zero_bytes32
size: uint256 = self.deposit_count
for height in range(DEPOSIT_CONTRACT_TREE_DEPTH):
if bitwise_and(size, 1) == 1: # More gas efficient than `size % 2 == 1`
node = sha256(concat(self.branch[height], node))
else:
node = sha256(concat(node, self.zero_hashes[height]))
size /= 2
return node
return sha256(concat(node, self.to_little_endian_64(self.deposit_count), slice(zero_bytes32, start=0, len=24)))


@public
Expand All @@ -75,11 +76,11 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH],
assert len(withdrawal_credentials) == WITHDRAWAL_CREDENTIALS_LENGTH
assert len(signature) == SIGNATURE_LENGTH

# Emit `Deposit` log
# Emit `DepositEvent` log
amount: bytes[8] = self.to_little_endian_64(deposit_amount)
log.Deposit(pubkey, withdrawal_credentials, amount, signature, self.to_little_endian_64(self.deposit_count))
log.DepositEvent(pubkey, withdrawal_credentials, amount, signature, self.to_little_endian_64(self.deposit_count))

# Compute `DepositData` root
# Compute `DepositData` hash tree root
zero_bytes32: bytes32 = 0x0000000000000000000000000000000000000000000000000000000000000000
pubkey_root: bytes32 = sha256(concat(pubkey, slice(zero_bytes32, start=0, len=64 - PUBKEY_LENGTH)))
signature_root: bytes32 = sha256(concat(
Expand All @@ -91,7 +92,7 @@ def deposit(pubkey: bytes[PUBKEY_LENGTH],
sha256(concat(amount, slice(zero_bytes32, start=0, len=32 - AMOUNT_LENGTH), signature_root)),
))

# Add `DepositData` root to Merkle tree (update a single `branch` node)
# Add `DepositData` hash tree root to Merkle tree (update a single `branch` node)
self.deposit_count += 1
size: uint256 = self.deposit_count
for height in range(DEPOSIT_CONTRACT_TREE_DEPTH):
Expand Down
36 changes: 11 additions & 25 deletions deposit_contract/tests/contracts/test_deposit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,12 @@
DepositData,
)
from eth2spec.utils.hash_function import hash
from eth2spec.utils.ssz.ssz_typing import List
from eth2spec.utils.ssz.ssz_impl import (
hash_tree_root,
)


def compute_merkle_root(leaf_nodes):
assert len(leaf_nodes) >= 1
empty_node = b'\x00' * 32
child_nodes = leaf_nodes[:]
for _ in range(DEPOSIT_CONTRACT_TREE_DEPTH):
parent_nodes = []
if len(child_nodes) % 2 == 1:
child_nodes.append(empty_node)
for j in range(0, len(child_nodes), 2):
parent_nodes.append(hash(child_nodes[j] + child_nodes[j + 1]))
child_nodes = parent_nodes
empty_node = hash(empty_node + empty_node)
return child_nodes[0]


@pytest.fixture
def deposit_input():
"""
Expand Down Expand Up @@ -110,8 +96,8 @@ def test_deposit_inputs(registration_contract,
)


def test_deposit_log(registration_contract, a0, w3, deposit_input):
log_filter = registration_contract.events.Deposit.createFilter(
def test_deposit_event_log(registration_contract, a0, w3, deposit_input):
log_filter = registration_contract.events.DepositEvent.createFilter(
fromBlock='latest',
)

Expand All @@ -131,13 +117,14 @@ def test_deposit_log(registration_contract, a0, w3, deposit_input):
assert log['signature'] == deposit_input[2]
assert log['index'] == i.to_bytes(8, 'little')


def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input):
log_filter = registration_contract.events.Deposit.createFilter(
log_filter = registration_contract.events.DepositEvent.createFilter(
fromBlock='latest',
)

deposit_amount_list = [randint(MIN_DEPOSIT_AMOUNT, FULL_DEPOSIT_AMOUNT * 2) for _ in range(10)]
leaf_nodes = []
deposit_data_list = []
for i in range(0, 10):
tx_hash = registration_contract.functions.deposit(
*deposit_input,
Expand All @@ -151,13 +138,12 @@ def test_deposit_tree(registration_contract, w3, assert_tx_failed, deposit_input

assert log["index"] == i.to_bytes(8, 'little')

deposit_data = DepositData(
deposit_data_list.append(DepositData(
pubkey=deposit_input[0],
withdrawal_credentials=deposit_input[1],
amount=deposit_amount_list[i],
signature=deposit_input[2],
)
hash_tree_root_result = hash_tree_root(deposit_data)
leaf_nodes.append(hash_tree_root_result)
root = compute_merkle_root(leaf_nodes)
assert root == registration_contract.functions.get_deposit_root().call()
))

root = hash_tree_root(List[DepositData, 2**32](*deposit_data_list))
assert root == registration_contract.functions.get_hash_tree_root().call()
75 changes: 27 additions & 48 deletions specs/core/0_beacon-chain.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@
- [`initiate_validator_exit`](#initiate_validator_exit)
- [`slash_validator`](#slash_validator)
- [Genesis](#genesis)
- [Genesis trigger](#genesis-trigger)
- [Genesis state](#genesis-state)
- [Genesis block](#genesis-block)
- [Beacon chain state transition function](#beacon-chain-state-transition-function)
Expand Down Expand Up @@ -125,7 +124,6 @@
This document represents the specification for Phase 0 of Ethereum 2.0 -- The Beacon Chain.

At the core of Ethereum 2.0 is a system chain called the "beacon chain". The beacon chain stores and manages the registry of [validators](#dfn-validator). In the initial deployment phases of Ethereum 2.0, the only mechanism to become a [validator](#dfn-validator) is to make a one-way ETH transaction to a deposit contract on Ethereum 1.0. Activation as a [validator](#dfn-validator) happens when Ethereum 1.0 deposit receipts are processed by the beacon chain, the activation balance is reached, and a queuing process is completed. Exit is either voluntary or done forcibly as a penalty for misbehavior.

The primary source of load on the beacon chain is "attestations". Attestations are simultaneously availability votes for a shard block and proof-of-stake votes for a beacon block. A sufficient number of attestations for the same shard block create a "crosslink", confirming the shard segment up to that shard block into the beacon chain. Crosslinks also serve as infrastructure for asynchronous cross-shard communication.

## Notation
Expand Down Expand Up @@ -175,6 +173,7 @@ The following values are (non-configurable) constants used throughout the specif
| `ZERO_HASH` | `Hash(b'\x00' * 32)` |
| `BASE_REWARDS_PER_EPOCH` | `5` |
| `DEPOSIT_CONTRACT_TREE_DEPTH` | `2**5` (= 32) |
| `SECONDS_PER_DAY` | `86400` |

## Configuration

Expand All @@ -190,6 +189,8 @@ The following values are (non-configurable) constants used throughout the specif
| `MIN_PER_EPOCH_CHURN_LIMIT` | `2**2` (= 4) |
| `CHURN_LIMIT_QUOTIENT` | `2**16` (= 65,536) |
| `SHUFFLE_ROUND_COUNT` | `90` |
| `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT` | `2**16` (= 65,536) |
| `MIN_GENESIS_TIME` | `1578009600` (Jan 3, 2020) |
| `JUSTIFICATION_BITS_LENGTH` | `4` |

* For the safety of crosslinks, `TARGET_COMMITTEE_SIZE` exceeds [the recommended minimum committee size of 111](https://vitalik.ca/files/Ithaca201807_Sharding.pdf); with sufficient active validators (at least `SLOTS_PER_EPOCH * TARGET_COMMITTEE_SIZE`), the shuffling algorithm ensures committee sizes of at least `TARGET_COMMITTEE_SIZE`. (Unbiasable randomness with a Verifiable Delay Function (VDF) will improve committee robustness and lower the safe minimum committee size.)
Expand Down Expand Up @@ -437,7 +438,7 @@ class Attestation(Container):

```python
class Deposit(Container):
proof: Vector[Hash, DEPOSIT_CONTRACT_TREE_DEPTH] # Merkle path to deposit root
proof: Vector[Hash, DEPOSIT_CONTRACT_TREE_DEPTH + 1] # Merkle path to deposit data list root
data: DepositData
```

Expand Down Expand Up @@ -1089,63 +1090,41 @@ def slash_validator(state: BeaconState,

## Genesis

### Genesis trigger

Before genesis has been triggered and whenever the deposit contract emits a `Deposit` log, call the function `is_genesis_trigger(deposits: Sequence[Deposit], timestamp: uint64) -> bool` where:

* `deposits` is the list of all deposits, ordered chronologically, up to and including the deposit triggering the latest `Deposit` log
* `timestamp` is the Unix timestamp in the Ethereum 1.0 block that emitted the latest `Deposit` log

When `is_genesis_trigger(deposits, timestamp) is True` for the first time, let:

* `genesis_deposits = deposits`
* `genesis_time = timestamp - timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY` where `SECONDS_PER_DAY = 86400`
* `genesis_eth1_data` be the object of type `Eth1Data` where:
* `genesis_eth1_data.block_hash` is the Ethereum 1.0 block hash that emitted the log for the last deposit in `deposits`
* `genesis_eth1_data.deposit_root` is the deposit root for the last deposit in `deposits`
* `genesis_eth1_data.deposit_count = len(genesis_deposits)`

*Note*: The function `is_genesis_trigger` has yet to be agreed upon by the community, and can be updated as necessary. We define the following testing placeholder:

```python
def is_genesis_trigger(deposits: Sequence[Deposit], timestamp: uint64) -> bool:
# Process deposits
state = BeaconState()
for deposit in deposits:
process_deposit(state, deposit)
### Genesis state

# Count active validators at genesis
active_validator_count = 0
for validator in state.validators:
if validator.effective_balance == MAX_EFFECTIVE_BALANCE:
active_validator_count += 1
Before the Ethereum 2.0 genesis has been triggered, and for every Ethereum 1.0 block, call `get_genesis_beacon_state(eth1_block_hash, eth1_timestamp, deposits)` where:

# Check effective balance to trigger genesis
GENESIS_ACTIVE_VALIDATOR_COUNT = 2**16
return active_validator_count == GENESIS_ACTIVE_VALIDATOR_COUNT
```
* `eth1_block_hash` is the hash of the Ethereum 1.0 block
* `eth1_timestamp` is the Unix timestamp corresponding to `eth1_block_hash`
* `deposits` is the sequence of all deposits, ordered chronologically, up to the block with hash `eth1_block_hash`

### Genesis state
The genesis state `genesis_state` is the return value of the first call to `get_genesis_beacon_state` that does not trigger an `assert`.

Let `genesis_state = get_genesis_beacon_state(genesis_deposits, genesis_time, genesis_eth1_data)`.
*Note*: The two constants `MIN_GENESIS_TIME` and `MIN_GENESIS_ACTIVE_VALIDATOR_COUNT` have yet to be agreed upon by the community, and can be updated as necessary.

```python
def get_genesis_beacon_state(deposits: Sequence[Deposit], genesis_time: int, eth1_data: Eth1Data) -> BeaconState:
def get_genesis_beacon_state(eth1_block_hash: Hash, eth1_timestamp: uint64, deposits: Sequence[Deposit]) -> BeaconState:
state = BeaconState(
genesis_time=genesis_time,
eth1_data=eth1_data,
genesis_time=eth1_timestamp - eth1_timestamp % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY,
eth1_data=Eth1Data(block_hash=genesis_eth1_block_hash, deposit_count=len(deposits)),
latest_block_header=BeaconBlockHeader(body_root=hash_tree_root(BeaconBlockBody())),
)
assert state.genesis_time >= MIN_GENESIS_TIME

# Process genesis deposits
for deposit in deposits:
# Process deposits
leaves = list(map(lambda deposit: deposit.data, deposits))
for index, deposit in enumerate(deposits):
state.eth1_data.deposit_root = hash_tree_root(
protolambda marked this conversation as resolved.
Show resolved Hide resolved
List[DepositData, 2**DEPOSIT_CONTRACT_TREE_DEPTH](*leaves[:index + 1])
)
process_deposit(state, deposit)

# Process genesis activations
for validator in state.validators:
if validator.effective_balance >= MAX_EFFECTIVE_BALANCE:
# Process activations
for index, validator in enumerate(state.validators):
if state.balances[index] >= MAX_EFFECTIVE_BALANCE:
protolambda marked this conversation as resolved.
Show resolved Hide resolved
validator.activation_eligibility_epoch = GENESIS_EPOCH
validator.activation_epoch = GENESIS_EPOCH
assert len(get_active_validator_indices(state, GENESIS_EPOCH)) >= MIN_GENESIS_ACTIVE_VALIDATOR_COUNT

# Populate active_index_roots
genesis_active_index_root = hash_tree_root(
Expand Down Expand Up @@ -1438,7 +1417,7 @@ def process_registry_updates(state: BeaconState) -> None:
for index, validator in enumerate(state.validators):
if (
validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and
validator.effective_balance >= MAX_EFFECTIVE_BALANCE
validator.effective_balance == MAX_EFFECTIVE_BALANCE
):
validator.activation_eligibility_epoch = get_current_epoch(state)

Expand Down Expand Up @@ -1682,7 +1661,7 @@ def process_deposit(state: BeaconState, deposit: Deposit) -> None:
assert verify_merkle_branch(
leaf=hash_tree_root(deposit.data),
proof=deposit.proof,
depth=DEPOSIT_CONTRACT_TREE_DEPTH,
depth=DEPOSIT_CONTRACT_TREE_DEPTH + 1,
protolambda marked this conversation as resolved.
Show resolved Hide resolved
index=state.eth1_deposit_index,
root=state.eth1_data.deposit_root,
)
Expand Down
6 changes: 3 additions & 3 deletions specs/core/0_deposit-contract.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
- [`deposit` function](#deposit-function)
- [Deposit amount](#deposit-amount)
- [Withdrawal credentials](#withdrawal-credentials)
- [`Deposit` log](#deposit-log)
- [`DepositEvent` log](#depositevent-log)
- [Vyper code](#vyper-code)

<!-- /TOC -->
Expand Down Expand Up @@ -53,9 +53,9 @@ One of the `DepositData` fields is `withdrawal_credentials`. It is a commitment

The private key corresponding to `withdrawal_pubkey` will be required to initiate a withdrawal. It can be stored separately until a withdrawal is required, e.g. in cold storage.

#### `Deposit` log
#### `DepositEvent` log

Every Ethereum 1.0 deposit emits a `Deposit` log for consumption by the beacon chain. The deposit contract does little validation, pushing most of the validator onboarding logic to the beacon chain. In particular, the proof of possession (a BLS12-381 signature) is not verified by the deposit contract.
Every Ethereum 1.0 deposit emits a `DepositEvent` log for consumption by the beacon chain. The deposit contract does little validation, pushing most of the validator onboarding logic to the beacon chain. In particular, the proof of possession (a BLS12-381 signature) is not verified by the deposit contract.

## Vyper code

Expand Down
2 changes: 1 addition & 1 deletion specs/validator/0_beacon-chain-validator.md
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ epoch_signature = bls_sign(

##### Eth1 Data

The `block.eth1_data` field is for block proposers to vote on recent Eth 1.0 data. This recent data contains an Eth 1.0 block hash as well as the associated deposit root (as calculated by the `get_deposit_root()` method of the deposit contract) and deposit count after execution of the corresponding Eth 1.0 block. If over half of the block proposers in the current Eth 1.0 voting period vote for the same `eth1_data` then `state.eth1_data` updates at the end of the voting period. Each deposit in `block.body.deposits` must verify against `state.eth1_data.eth1_deposit_root`.
The `block.eth1_data` field is for block proposers to vote on recent Eth 1.0 data. This recent data contains an Eth 1.0 block hash as well as the associated deposit root (as calculated by the `get_hash_tree_root()` method of the deposit contract) and deposit count after execution of the corresponding Eth 1.0 block. If over half of the block proposers in the current Eth 1.0 voting period vote for the same `eth1_data` then `state.eth1_data` updates at the end of the voting period. Each deposit in `block.body.deposits` must verify against `state.eth1_data.eth1_deposit_root`.

Let `get_eth1_data(distance: int) -> Eth1Data` be the (subjective) function that returns the Eth 1.0 data at distance `distance` relative to the Eth 1.0 head at the start of the current Eth 1.0 voting period. Let `previous_eth1_distance` be the distance relative to the Eth 1.0 block corresponding to `state.eth1_data.block_hash` at the start of the current Eth 1.0 voting period. An honest block proposer sets `block.eth1_data = get_eth1_vote(state, previous_eth1_distance)` where:

Expand Down
6 changes: 5 additions & 1 deletion test_libs/pyspec/eth2spec/test/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ def entry(*args, **kw):
DEFAULT_BLS_ACTIVE = False


def spectest_with_bls_switch(fn):
return bls_switch(spectest()(fn))


# shorthand for decorating @with_state @spectest()
def spec_state_test(fn):
return with_state(bls_switch(spectest()(fn)))
return with_state(spectest_with_bls_switch(fn))


def expect_assertion_error(fn):
Expand Down
Empty file.
31 changes: 31 additions & 0 deletions test_libs/pyspec/eth2spec/test/genesis/test_genesis.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from eth2spec.test.context import with_phases, spectest_with_bls_switch
from eth2spec.test.helpers.deposits import (
prepare_genesis_deposits,
)


@with_phases(['phase0'])
@spectest_with_bls_switch
def test_genesis(spec):
deposit_count = spec.MIN_GENESIS_ACTIVE_VALIDATOR_COUNT
genesis_deposits, deposit_root = prepare_genesis_deposits(spec, deposit_count, spec.MAX_EFFECTIVE_BALANCE)
genesis_time = 1546300800
genesis_eth1_block_hash = b'\x12' * 32

yield "deposits", genesis_deposits
yield "genesis_time", genesis_time

yield "genesis_eth1_block_hash", genesis_eth1_block_hash
genesis_state = spec.get_genesis_beacon_state(
genesis_eth1_block_hash,
genesis_time,
genesis_deposits,
)

assert genesis_state.genesis_time == genesis_time
assert len(genesis_state.validators) == deposit_count
assert genesis_state.eth1_data.deposit_root == deposit_root
assert genesis_state.eth1_data.deposit_count == deposit_count
assert genesis_state.eth1_data.block_hash == genesis_eth1_block_hash

yield "state", genesis_state
Loading