Skip to content
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,81 @@
from eth2spec.test.context import (
always_bls,
spec_state_test,
with_electra_and_later,
)
from eth2spec.test.helpers.attestations import (
run_attestation_processing,
get_valid_attestation,
sign_attestation,
)
from eth2spec.test.helpers.state import (
next_slots,
)


@with_electra_and_later
@spec_state_test
def test_invalid_attestation_data_index_not_zero(spec, state):
"""
EIP-7549 test
"""
committee_index = 1
attestation = get_valid_attestation(spec, state, index=committee_index)
next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY)

# flip the attestations index to make it non-zero and invalid
assert committee_index == spec.get_committee_indices(attestation.committee_bits)[0]
attestation.data.index = committee_index

sign_attestation(spec, state, attestation)

yield from run_attestation_processing(spec, state, attestation, valid=False)


@with_electra_and_later
@spec_state_test
@always_bls
def test_invalid_committe_index(spec, state):
"""
EIP-7549 test
"""
committee_index = 0
attestation = get_valid_attestation(spec, state, index=committee_index, signed=True)
next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY)

# flip the bits of the attestation to make it invalid
assert attestation.committee_bits[committee_index] == 1
attestation.committee_bits[committee_index] = 0
attestation.committee_bits[committee_index + 1] = 1

yield from run_attestation_processing(spec, state, attestation, valid=False)


@with_electra_and_later
@spec_state_test
def test_invalid_too_many_committe_bits(spec, state):
"""
EIP-7549 test
"""
committee_index = 0
attestation = get_valid_attestation(spec, state, index=committee_index, signed=True)
next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY)

attestation.committee_bits[committee_index + 1] = 1

yield from run_attestation_processing(spec, state, attestation, valid=False)


@with_electra_and_later
@spec_state_test
def test_invalid_nonset_committe_bits(spec, state):
"""
EIP-7549 test
"""
committee_index = 0
attestation = get_valid_attestation(spec, state, index=committee_index, signed=True)
next_slots(spec, state, spec.MIN_ATTESTATION_INCLUSION_DELAY)

attestation.committee_bits[committee_index] = 0

yield from run_attestation_processing(spec, state, attestation, valid=False)
Empty file.
438 changes: 438 additions & 0 deletions tests/core/pyspec/eth2spec/test/electra/random/test_random.py

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions tests/core/pyspec/eth2spec/test/utils/randomized_block_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ def randomize_state_deneb(spec, state, stats, exit_fraction=0.1, slash_fraction=
return scenario_state


def randomize_state_electra(spec, state, stats, exit_fraction=0.1, slash_fraction=0.1):
scenario_state = randomize_state_deneb(
spec,
state,
stats,
exit_fraction=exit_fraction,
slash_fraction=slash_fraction,
)
return scenario_state


# epochs

def epochs_until_leak(spec):
Expand Down Expand Up @@ -248,6 +259,12 @@ def random_block_deneb(spec, state, signed_blocks, scenario_state, rng=Random(34
return block


def random_block_electra(spec, state, signed_blocks, scenario_state, rng=Random(3456)):
block = random_block_deneb(spec, state, signed_blocks, scenario_state, rng=rng)

return block


# validations

def no_op_validation(_spec, _state):
Expand Down
1 change: 1 addition & 0 deletions tests/generators/operations/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
deneb_mods = combine_mods(_new_deneb_mods, capella_mods)

_new_electra_mods = {key: 'eth2spec.test.electra.block_processing.test_process_' + key for key in [
'attestation',
'deposit_receipt',
'execution_layer_exit',
]}
Expand Down
2 changes: 2 additions & 0 deletions tests/generators/random/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ all:
rm -f ../../core/pyspec/eth2spec/test/bellatrix/random/test_random.py
rm -f ../../core/pyspec/eth2spec/test/capella/random/test_random.py
rm -f ../../core/pyspec/eth2spec/test/deneb/random/test_random.py
rm -f ../../core/pyspec/eth2spec/test/electra/random/test_random.py
python3 generate.py phase0 > ../../core/pyspec/eth2spec/test/phase0/random/test_random.py
python3 generate.py altair > ../../core/pyspec/eth2spec/test/altair/random/test_random.py
python3 generate.py bellatrix > ../../core/pyspec/eth2spec/test/bellatrix/random/test_random.py
python3 generate.py capella > ../../core/pyspec/eth2spec/test/capella/random/test_random.py
python3 generate.py deneb > ../../core/pyspec/eth2spec/test/deneb/random/test_random.py
python3 generate.py electra > ../../core/pyspec/eth2spec/test/electra/random/test_random.py
11 changes: 10 additions & 1 deletion tests/generators/random/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@
randomize_state_bellatrix,
randomize_state_capella,
randomize_state_deneb,
randomize_state_electra,
random_block,
random_block_altair_with_cycling_sync_committee_participation,
random_block_bellatrix,
random_block_capella,
random_block_deneb,
random_block_electra,
last_slot_in_epoch,
random_slot_in_epoch,
penultimate_slot_in_epoch,
Expand All @@ -36,7 +38,7 @@
transition_to_leaking,
transition_without_leak,
)
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA


# Ensure this many blocks are present in *each* randomized scenario
Expand Down Expand Up @@ -281,5 +283,12 @@ def run_generate_tests_to_std_out(phase, state_randomizer, block_randomizer):
state_randomizer=randomize_state_deneb,
block_randomizer=random_block_deneb,
)
if ELECTRA in sys.argv:
did_generate = True
run_generate_tests_to_std_out(
ELECTRA,
state_randomizer=randomize_state_electra,
block_randomizer=random_block_electra,
)
if not did_generate:
warnings.warn("no phase given for test generation")
8 changes: 7 additions & 1 deletion tests/generators/random/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from eth2spec.test.helpers.constants import PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB
from eth2spec.test.helpers.constants import (
PHASE0, ALTAIR, BELLATRIX, CAPELLA, DENEB, ELECTRA,
)
from eth2spec.gen_helpers.gen_from_tests.gen import run_state_test_generators


Expand All @@ -18,13 +20,17 @@
deneb_mods = {key: 'eth2spec.test.deneb.random.test_' + key for key in [
'random',
]}
electra_mods = {key: 'eth2spec.test.electra.random.test_' + key for key in [
'random',
]}

all_mods = {
PHASE0: phase_0_mods,
ALTAIR: altair_mods,
BELLATRIX: bellatrix_mods,
CAPELLA: capella_mods,
DENEB: deneb_mods,
ELECTRA: electra_mods,
}

run_state_test_generators(runner_name="random", all_mods=all_mods)