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

tests: Add tests for NoopExecutionEngine mock API #4114

Merged
merged 3 commits into from
Feb 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
from eth2spec.test.context import (
BELLATRIX,
CAPELLA,
spec_state_test,
with_bellatrix_and_later,
with_phases,
)
from eth2spec.test.helpers.execution_payload import (
build_empty_execution_payload,
)
from eth2spec.test.helpers.state import next_slot
from eth2spec.utils.ssz.ssz_typing import Bytes32


@with_bellatrix_and_later
@spec_state_test
def test_noop_execution_engine_notify_forkchoice_updated(spec, state):
"""
Test NoopExecutionEngine.notify_forkchoice_updated returns None and doesn't modify state
"""
engine = spec.NoopExecutionEngine()
pre_state = state.copy()

# Test notify_forkchoice_updated
result = engine.notify_forkchoice_updated(
head_block_hash=Bytes32(),
safe_block_hash=Bytes32(),
finalized_block_hash=Bytes32(),
payload_attributes=None
)

# Verify behavior
assert result is None
assert state == pre_state


@with_bellatrix_and_later
@spec_state_test
def test_noop_execution_engine_get_payload(spec, state):
"""
Test NoopExecutionEngine.get_payload raises NotImplementedError
"""
engine = spec.NoopExecutionEngine()
pre_state = state.copy()

# Test get_payload raises NotImplementedError
try:
engine.get_payload(payload_id=None)
raise AssertionError("get_payload should raise NotImplementedError")
except NotImplementedError:
pass

# Verify state wasn't modified
assert state == pre_state


@with_bellatrix_and_later
@spec_state_test
def test_noop_execution_engine_verify_and_notify_new_payload(spec, state):
"""
Test NoopExecutionEngine.verify_and_notify_new_payload returns True and doesn't modify state
"""
engine = spec.NoopExecutionEngine()
pre_state = state.copy()

result = engine.verify_and_notify_new_payload(new_payload_request=None)

assert result is True
assert state == pre_state


@with_phases([BELLATRIX, CAPELLA])
@spec_state_test
def test_noop_execution_engine_notify_new_payload_bellatrix_capella(spec, state):
"""
Test NoopExecutionEngine.notify_new_payload returns True and doesn't modify state
"""
engine = spec.NoopExecutionEngine()

next_slot(spec, state)
payload = build_empty_execution_payload(spec, state)
result = engine.notify_new_payload(execution_payload=payload)

assert result is True


@with_phases([BELLATRIX, CAPELLA])
@spec_state_test
def test_noop_execution_engine_is_valid_block_hash_bellatrix_capella(spec, state):
"""
Test NoopExecutionEngine.is_valid_block_hash returns True and doesn't modify state
"""
engine = spec.NoopExecutionEngine()

next_slot(spec, state)
payload = build_empty_execution_payload(spec, state)
result = engine.is_valid_block_hash(execution_payload=payload)

assert result is True
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
from eth2spec.test.context import (
DENEB,
spec_state_test,
with_phases,
with_deneb_and_later,
)
from eth2spec.test.helpers.execution_payload import (
build_empty_execution_payload,
)
from eth2spec.test.helpers.state import next_slot


@with_deneb_and_later
@spec_state_test
def test_noop_execution_engine_is_valid_versioned_hashes(spec, state):
"""
Test NoopExecutionEngine.is_valid_versioned_hashes returns True and doesn't modify state
"""
engine = spec.NoopExecutionEngine()
pre_state = state.copy()

# Test is_valid_versioned_hashes
result = engine.is_valid_versioned_hashes(new_payload_request=None)

# Verify behavior
assert result is True
assert state == pre_state


@with_phases([DENEB])
@spec_state_test
def test_noop_execution_engine_notify_new_payload_deneb(spec, state):
"""
Test NoopExecutionEngine.notify_new_payload returns True and doesn't modify state
"""
engine = spec.NoopExecutionEngine()

next_slot(spec, state)
payload = build_empty_execution_payload(spec, state)
result = engine.notify_new_payload(
execution_payload=payload,
parent_beacon_block_root=state.latest_block_header.parent_root,
)

assert result is True


@with_phases([DENEB])
@spec_state_test
def test_noop_execution_engine_is_valid_block_hash_deneb(spec, state):
"""
Test NoopExecutionEngine.is_valid_block_hash returns True and doesn't modify state
"""
engine = spec.NoopExecutionEngine()

next_slot(spec, state)
payload = build_empty_execution_payload(spec, state)
result = engine.is_valid_block_hash(
execution_payload=payload,
parent_beacon_block_root=state.latest_block_header.parent_root,
)

assert result is True
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
from eth2spec.test.context import (
ELECTRA,
spec_state_test,
with_phases,
)
from eth2spec.test.helpers.execution_payload import (
build_empty_execution_payload,
)
from eth2spec.test.helpers.state import next_slot


@with_phases([ELECTRA])
@spec_state_test
def test_noop_execution_engine_notify_new_payload_electra(spec, state):
"""
Test NoopExecutionEngine.notify_new_payload returns True and doesn't modify state
"""
engine = spec.NoopExecutionEngine()

next_slot(spec, state)
payload = build_empty_execution_payload(spec, state)
result = engine.notify_new_payload(
execution_payload=payload,
parent_beacon_block_root=state.latest_block_header.parent_root,
execution_requests_list=[]
)
assert result is True


@with_phases([ELECTRA])
@spec_state_test
def test_noop_execution_engine_is_valid_block_hash_electra(spec, state):
"""
Test NoopExecutionEngine.is_valid_block_hash returns True and doesn't modify state
"""
engine = spec.NoopExecutionEngine()

next_slot(spec, state)
payload = build_empty_execution_payload(spec, state)
result = engine.is_valid_block_hash(
execution_payload=payload,
parent_beacon_block_root=state.latest_block_header.parent_root,
execution_requests_list=[]
)

assert result is True