mirror of
https://github.com/status-im/eth2.0-specs.git
synced 2025-01-24 01:20:56 +00:00
update PowBlock generation with random hash
This commit is contained in:
parent
f3f1c86a57
commit
457b0396dd
@ -1,3 +1,4 @@
|
|||||||
|
from random import Random
|
||||||
from eth_utils import encode_hex
|
from eth_utils import encode_hex
|
||||||
from eth2spec.utils.ssz.ssz_typing import uint256
|
from eth2spec.utils.ssz.ssz_typing import uint256
|
||||||
from eth2spec.test.helpers.attestations import (
|
from eth2spec.test.helpers.attestations import (
|
||||||
@ -23,9 +24,12 @@ def add_block_to_store(spec, store, signed_block):
|
|||||||
spec.on_block(store, signed_block)
|
spec.on_block(store, signed_block)
|
||||||
|
|
||||||
|
|
||||||
def tick_and_add_block(spec, store, signed_block, test_steps, valid=True, allow_invalid_attestations=False):
|
def tick_and_add_block(spec, store, signed_block, test_steps, valid=True, allow_invalid_attestations=False,
|
||||||
|
merge_block=False):
|
||||||
pre_state = store.block_states[signed_block.message.parent_root]
|
pre_state = store.block_states[signed_block.message.parent_root]
|
||||||
block_time = pre_state.genesis_time + signed_block.message.slot * spec.config.SECONDS_PER_SLOT
|
block_time = pre_state.genesis_time + signed_block.message.slot * spec.config.SECONDS_PER_SLOT
|
||||||
|
if merge_block:
|
||||||
|
assert spec.is_merge_block(pre_state, signed_block.message.body)
|
||||||
|
|
||||||
if store.time < block_time:
|
if store.time < block_time:
|
||||||
on_tick_and_append_step(spec, store, block_time, test_steps)
|
on_tick_and_append_step(spec, store, block_time, test_steps)
|
||||||
@ -230,10 +234,10 @@ def apply_next_slots_with_attestations(spec,
|
|||||||
return post_state, store, last_signed_block
|
return post_state, store, last_signed_block
|
||||||
|
|
||||||
|
|
||||||
def prepare_empty_pow_block(spec):
|
def prepare_empty_pow_block(spec, rng=Random(3131)):
|
||||||
return spec.PowBlock(
|
return spec.PowBlock(
|
||||||
block_hash=spec.Hash32(),
|
block_hash=spec.Hash32(spec.hash(rng.randbytes(32))),
|
||||||
parent_hash=spec.Hash32(),
|
parent_hash=spec.Hash32(spec.hash(rng.randbytes(32))),
|
||||||
total_difficulty=uint256(0),
|
total_difficulty=uint256(0),
|
||||||
difficulty=uint256(0)
|
difficulty=uint256(0)
|
||||||
)
|
)
|
||||||
|
@ -102,7 +102,6 @@ def test_valid_terminal_pow_block_fail_just_after_terminal(spec, state):
|
|||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_process_merge_execution_payload_success(spec, state):
|
def test_process_merge_execution_payload_success(spec, state):
|
||||||
parent_block = prepare_empty_pow_block(spec)
|
parent_block = prepare_empty_pow_block(spec)
|
||||||
parent_block.block_hash = spec.Hash32(spec.hash(b'01'))
|
|
||||||
parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256(1)
|
parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256(1)
|
||||||
block = prepare_empty_pow_block(spec)
|
block = prepare_empty_pow_block(spec)
|
||||||
block.parent_hash = parent_block.block_hash
|
block.parent_hash = parent_block.block_hash
|
||||||
@ -116,13 +115,11 @@ def test_process_merge_execution_payload_success(spec, state):
|
|||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_process_merge_execution_payload_fail_block_lookup(spec, state):
|
def test_process_merge_execution_payload_fail_block_lookup(spec, state):
|
||||||
parent_block = prepare_empty_pow_block(spec)
|
parent_block = prepare_empty_pow_block(spec)
|
||||||
parent_block.block_hash = spec.Hash32(spec.hash(b'01'))
|
|
||||||
parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256(1)
|
parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256(1)
|
||||||
block = prepare_empty_pow_block(spec)
|
block = prepare_empty_pow_block(spec)
|
||||||
block.parent_hash = parent_block.block_hash
|
block.parent_hash = parent_block.block_hash
|
||||||
block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY
|
block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY
|
||||||
payload = spec.ExecutionPayload()
|
payload = spec.ExecutionPayload()
|
||||||
payload.parent_hash = spec.Hash32(spec.hash(b'02'))
|
|
||||||
yield from run_process_merge_execution_payload(spec, block, parent_block, payload,
|
yield from run_process_merge_execution_payload(spec, block, parent_block, payload,
|
||||||
block_lookup_success=False)
|
block_lookup_success=False)
|
||||||
|
|
||||||
@ -131,10 +128,8 @@ def test_process_merge_execution_payload_fail_block_lookup(spec, state):
|
|||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_process_merge_execution_payload_fail_parent_block_lookup(spec, state):
|
def test_process_merge_execution_payload_fail_parent_block_lookup(spec, state):
|
||||||
parent_block = prepare_empty_pow_block(spec)
|
parent_block = prepare_empty_pow_block(spec)
|
||||||
parent_block.block_hash = spec.Hash32(spec.hash(b'01'))
|
|
||||||
parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256(1)
|
parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY - uint256(1)
|
||||||
block = prepare_empty_pow_block(spec)
|
block = prepare_empty_pow_block(spec)
|
||||||
block.parent_hash = spec.Hash32(spec.hash(b'00'))
|
|
||||||
block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY
|
block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY
|
||||||
payload = spec.ExecutionPayload()
|
payload = spec.ExecutionPayload()
|
||||||
payload.parent_hash = block.block_hash
|
payload.parent_hash = block.block_hash
|
||||||
@ -146,7 +141,6 @@ def test_process_merge_execution_payload_fail_parent_block_lookup(spec, state):
|
|||||||
@spec_state_test
|
@spec_state_test
|
||||||
def test_process_merge_execution_payload_fail_after_terminal(spec, state):
|
def test_process_merge_execution_payload_fail_after_terminal(spec, state):
|
||||||
parent_block = prepare_empty_pow_block(spec)
|
parent_block = prepare_empty_pow_block(spec)
|
||||||
parent_block.block_hash = spec.Hash32(spec.hash(b'01'))
|
|
||||||
parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY
|
parent_block.total_difficulty = spec.config.TERMINAL_TOTAL_DIFFICULTY
|
||||||
block = prepare_empty_pow_block(spec)
|
block = prepare_empty_pow_block(spec)
|
||||||
block.parent_hash = parent_block.block_hash
|
block.parent_hash = parent_block.block_hash
|
||||||
|
Loading…
x
Reference in New Issue
Block a user