fix genesis testing code, add missing constant temporarily, fix py Generator/map/list problems

This commit is contained in:
protolambda 2019-06-27 01:57:30 +02:00
parent aecaed7a66
commit a0c2f5c6b5
No known key found for this signature in database
GPG Key ID: EC89FDBB2B4C7623
3 changed files with 7 additions and 4 deletions

View File

@ -1137,14 +1137,16 @@ When `is_genesis_trigger(deposits, time) is True` for the first time let:
```python
def is_genesis_trigger(deposits: List[Deposit, 2**DEPOSIT_CONTRACT_TREE_DEPTH], time: uint64) -> bool:
SECONDS_PER_DAY = 86400
# Do not deploy too early
if time - time % SECONDS_PER_DAY + 2 * SECONDS_PER_DAY < MIN_GENESIS_TIME:
return False
# Initialize deposit root
state = BeaconState()
state.eth1_data.deposit_root = hash_tree_root(map(deposits, lambda deposit: deposit.data))
state.eth1_data.deposit_root = hash_tree_root(
Vector[DepositData, len(deposits)](list(map(lambda deposit: deposit.data, deposits)))
)
# Process deposits
for deposit in deposits:
process_deposit(state, deposit)

View File

@ -26,7 +26,8 @@ def test_is_genesis_trigger_false(spec):
def test_is_genesis_trigger_true(spec):
deposit_count = spec.GENESIS_ACTIVE_VALIDATOR_COUNT
genesis_deposits, deposit_root = prepare_genesis_deposits(spec, deposit_count, spec.MAX_EFFECTIVE_BALANCE)
genesis_time = 1546300800
SECONDS_PER_DAY = 86400
genesis_time = 1578009600 - 2 * SECONDS_PER_DAY
yield "deposits", genesis_deposits
yield "time", genesis_time

View File

@ -82,7 +82,7 @@ def prepare_genesis_deposits(spec, genesis_validator_count, amount, signed=False
tree = calc_merkle_tree_from_leaves(tuple(deposit_data_leaves))
root = get_merkle_root((tuple(deposit_data_leaves)))
genesis_deposits = (
genesis_deposits = list(
spec.Deposit(proof=list(get_merkle_proof(tree, item_index=index)), data=deposit_data)
for index, deposit_data in enumerate(genesis_deposit_data_list)
)