Fix tests
This commit is contained in:
parent
aaa7fc622b
commit
32036d84a3
|
@ -30,6 +30,8 @@
|
||||||
- [Block processing](#block-processing)
|
- [Block processing](#block-processing)
|
||||||
- [Execution payload](#execution-payload)
|
- [Execution payload](#execution-payload)
|
||||||
- [`process_execution_payload`](#process_execution_payload)
|
- [`process_execution_payload`](#process_execution_payload)
|
||||||
|
- [Modified `process_operations`](#modified-process_operations)
|
||||||
|
- [Modified `process_voluntary_exit`](#modified-process_voluntary_exit)
|
||||||
- [Blob KZG commitments](#blob-kzg-commitments)
|
- [Blob KZG commitments](#blob-kzg-commitments)
|
||||||
- [Testing](#testing)
|
- [Testing](#testing)
|
||||||
|
|
||||||
|
@ -281,7 +283,8 @@ def process_voluntary_exit(state: BeaconState, signed_voluntary_exit: SignedVolu
|
||||||
# Verify the validator has been active long enough
|
# Verify the validator has been active long enough
|
||||||
assert get_current_epoch(state) >= validator.activation_epoch + SHARD_COMMITTEE_PERIOD
|
assert get_current_epoch(state) >= validator.activation_epoch + SHARD_COMMITTEE_PERIOD
|
||||||
# Verify signature
|
# Verify signature
|
||||||
domain = compute_domain(DOMAIN_VOLUNTARY_EXIT, CAPELLA_FORK_VERSION, state.genesis_validators_root) # [Modified in Deneb]
|
# [Modified in Deneb]
|
||||||
|
domain = compute_domain(DOMAIN_VOLUNTARY_EXIT, CAPELLA_FORK_VERSION, state.genesis_validators_root)
|
||||||
signing_root = compute_signing_root(voluntary_exit, domain)
|
signing_root = compute_signing_root(voluntary_exit, domain)
|
||||||
assert bls.Verify(validator.pubkey, signing_root, signed_voluntary_exit.signature)
|
assert bls.Verify(validator.pubkey, signing_root, signed_voluntary_exit.signature)
|
||||||
# Initiate exit
|
# Initiate exit
|
||||||
|
|
|
@ -2,6 +2,12 @@ from eth2spec.test.context import (
|
||||||
spec_state_test,
|
spec_state_test,
|
||||||
always_bls,
|
always_bls,
|
||||||
with_bellatrix_and_later,
|
with_bellatrix_and_later,
|
||||||
|
with_phases,
|
||||||
|
)
|
||||||
|
from eth2spec.test.helpers.constants import (
|
||||||
|
BELLATRIX,
|
||||||
|
CAPELLA,
|
||||||
|
DENEB,
|
||||||
)
|
)
|
||||||
from eth2spec.test.helpers.keys import pubkey_to_privkey
|
from eth2spec.test.helpers.keys import pubkey_to_privkey
|
||||||
from eth2spec.test.helpers.state import (
|
from eth2spec.test.helpers.state import (
|
||||||
|
@ -12,8 +18,10 @@ from eth2spec.test.helpers.voluntary_exits import (
|
||||||
sign_voluntary_exit,
|
sign_voluntary_exit,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
BELLATRIX_AND_CAPELLA = [BELLATRIX, CAPELLA]
|
||||||
|
|
||||||
def _run_voluntary_exit_processing_test(
|
|
||||||
|
def run_voluntary_exit_processing_test(
|
||||||
spec,
|
spec,
|
||||||
state,
|
state,
|
||||||
fork_version,
|
fork_version,
|
||||||
|
@ -51,7 +59,7 @@ def _run_voluntary_exit_processing_test(
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
@always_bls
|
@always_bls
|
||||||
def test_invalid_voluntary_exit_with_current_fork_version_is_before_fork_epoch(spec, state):
|
def test_invalid_voluntary_exit_with_current_fork_version_is_before_fork_epoch(spec, state):
|
||||||
yield from _run_voluntary_exit_processing_test(
|
yield from run_voluntary_exit_processing_test(
|
||||||
spec,
|
spec,
|
||||||
state,
|
state,
|
||||||
fork_version=state.fork.current_version,
|
fork_version=state.fork.current_version,
|
||||||
|
@ -60,11 +68,11 @@ def test_invalid_voluntary_exit_with_current_fork_version_is_before_fork_epoch(s
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@with_bellatrix_and_later
|
@with_phases(BELLATRIX_AND_CAPELLA)
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
@always_bls
|
@always_bls
|
||||||
def test_voluntary_exit_with_current_fork_version_not_is_before_fork_epoch(spec, state):
|
def test_voluntary_exit_with_current_fork_version_not_is_before_fork_epoch(spec, state):
|
||||||
yield from _run_voluntary_exit_processing_test(
|
yield from run_voluntary_exit_processing_test(
|
||||||
spec,
|
spec,
|
||||||
state,
|
state,
|
||||||
fork_version=state.fork.current_version,
|
fork_version=state.fork.current_version,
|
||||||
|
@ -72,13 +80,13 @@ def test_voluntary_exit_with_current_fork_version_not_is_before_fork_epoch(spec,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@with_bellatrix_and_later
|
@with_phases([BELLATRIX, CAPELLA, DENEB])
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
@always_bls
|
@always_bls
|
||||||
def test_voluntary_exit_with_previous_fork_version_is_before_fork_epoch(spec, state):
|
def test_voluntary_exit_with_previous_fork_version_is_before_fork_epoch(spec, state):
|
||||||
assert state.fork.previous_version != state.fork.current_version
|
assert state.fork.previous_version != state.fork.current_version
|
||||||
|
|
||||||
yield from _run_voluntary_exit_processing_test(
|
yield from run_voluntary_exit_processing_test(
|
||||||
spec,
|
spec,
|
||||||
state,
|
state,
|
||||||
fork_version=state.fork.previous_version,
|
fork_version=state.fork.previous_version,
|
||||||
|
@ -86,13 +94,13 @@ def test_voluntary_exit_with_previous_fork_version_is_before_fork_epoch(spec, st
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@with_bellatrix_and_later
|
@with_phases(BELLATRIX_AND_CAPELLA)
|
||||||
@spec_state_test
|
@spec_state_test
|
||||||
@always_bls
|
@always_bls
|
||||||
def test_invalid_voluntary_exit_with_previous_fork_version_not_is_before_fork_epoch(spec, state):
|
def test_invalid_voluntary_exit_with_previous_fork_version_not_is_before_fork_epoch(spec, state):
|
||||||
assert state.fork.previous_version != state.fork.current_version
|
assert state.fork.previous_version != state.fork.current_version
|
||||||
|
|
||||||
yield from _run_voluntary_exit_processing_test(
|
yield from run_voluntary_exit_processing_test(
|
||||||
spec,
|
spec,
|
||||||
state,
|
state,
|
||||||
fork_version=state.fork.previous_version,
|
fork_version=state.fork.previous_version,
|
||||||
|
@ -107,7 +115,7 @@ def test_invalid_voluntary_exit_with_previous_fork_version_not_is_before_fork_ep
|
||||||
def test_invalid_voluntary_exit_with_genesis_fork_version_is_before_fork_epoch(spec, state):
|
def test_invalid_voluntary_exit_with_genesis_fork_version_is_before_fork_epoch(spec, state):
|
||||||
assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version)
|
assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version)
|
||||||
|
|
||||||
yield from _run_voluntary_exit_processing_test(
|
yield from run_voluntary_exit_processing_test(
|
||||||
spec,
|
spec,
|
||||||
state,
|
state,
|
||||||
fork_version=spec.config.GENESIS_FORK_VERSION,
|
fork_version=spec.config.GENESIS_FORK_VERSION,
|
||||||
|
@ -122,7 +130,7 @@ def test_invalid_voluntary_exit_with_genesis_fork_version_is_before_fork_epoch(s
|
||||||
def test_invalid_voluntary_exit_with_genesis_fork_version_not_is_before_fork_epoch(spec, state):
|
def test_invalid_voluntary_exit_with_genesis_fork_version_not_is_before_fork_epoch(spec, state):
|
||||||
assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version)
|
assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version)
|
||||||
|
|
||||||
yield from _run_voluntary_exit_processing_test(
|
yield from run_voluntary_exit_processing_test(
|
||||||
spec,
|
spec,
|
||||||
state,
|
state,
|
||||||
fork_version=spec.config.GENESIS_FORK_VERSION,
|
fork_version=spec.config.GENESIS_FORK_VERSION,
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
from eth2spec.test.context import (
|
||||||
|
always_bls,
|
||||||
|
spec_state_test,
|
||||||
|
with_phases,
|
||||||
|
with_deneb_and_later,
|
||||||
|
)
|
||||||
|
from eth2spec.test.helpers.constants import (
|
||||||
|
DENEB,
|
||||||
|
)
|
||||||
|
from eth2spec.test.bellatrix.block_processing.test_process_voluntary_exit import (
|
||||||
|
run_voluntary_exit_processing_test,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_deneb_and_later
|
||||||
|
@spec_state_test
|
||||||
|
@always_bls
|
||||||
|
def test_invalid_voluntary_exit_with_current_fork_version_not_is_before_fork_epoch(spec, state):
|
||||||
|
"""
|
||||||
|
Since Deneb, the VoluntaryExit domain is fixed to `CAPELLA_FORK_VERSION`
|
||||||
|
"""
|
||||||
|
yield from run_voluntary_exit_processing_test(
|
||||||
|
spec,
|
||||||
|
state,
|
||||||
|
fork_version=state.fork.current_version,
|
||||||
|
is_before_fork_epoch=False,
|
||||||
|
valid=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_phases([DENEB])
|
||||||
|
@spec_state_test
|
||||||
|
@always_bls
|
||||||
|
def test_voluntary_exit_with_previous_fork_version_not_is_before_fork_epoch(spec, state):
|
||||||
|
"""
|
||||||
|
Since Deneb, the VoluntaryExit domain is fixed to `CAPELLA_FORK_VERSION`
|
||||||
|
"""
|
||||||
|
assert state.fork.previous_version != state.fork.current_version
|
||||||
|
|
||||||
|
yield from run_voluntary_exit_processing_test(
|
||||||
|
spec,
|
||||||
|
state,
|
||||||
|
fork_version=state.fork.previous_version,
|
||||||
|
is_before_fork_epoch=False,
|
||||||
|
)
|
|
@ -0,0 +1,44 @@
|
||||||
|
from eth2spec.test.context import (
|
||||||
|
always_bls,
|
||||||
|
spec_state_test,
|
||||||
|
with_eip6110_and_later,
|
||||||
|
)
|
||||||
|
from eth2spec.test.bellatrix.block_processing.test_process_voluntary_exit import (
|
||||||
|
run_voluntary_exit_processing_test,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_eip6110_and_later
|
||||||
|
@spec_state_test
|
||||||
|
@always_bls
|
||||||
|
def test_invalid_voluntary_exit_with_previous_fork_version_not_is_before_fork_epoch(spec, state):
|
||||||
|
"""
|
||||||
|
Since Deneb, the VoluntaryExit domain is fixed to `CAPELLA_FORK_VERSION`
|
||||||
|
"""
|
||||||
|
assert state.fork.previous_version != state.fork.current_version
|
||||||
|
|
||||||
|
yield from run_voluntary_exit_processing_test(
|
||||||
|
spec,
|
||||||
|
state,
|
||||||
|
fork_version=state.fork.previous_version,
|
||||||
|
is_before_fork_epoch=False,
|
||||||
|
valid=False,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@with_eip6110_and_later
|
||||||
|
@spec_state_test
|
||||||
|
@always_bls
|
||||||
|
def test_invalid_voluntary_exit_with_previous_fork_version_is_before_fork_epoch(spec, state):
|
||||||
|
"""
|
||||||
|
Since Deneb, the VoluntaryExit domain is fixed to `CAPELLA_FORK_VERSION`
|
||||||
|
"""
|
||||||
|
assert state.fork.previous_version != state.fork.current_version
|
||||||
|
|
||||||
|
yield from run_voluntary_exit_processing_test(
|
||||||
|
spec,
|
||||||
|
state,
|
||||||
|
fork_version=state.fork.previous_version,
|
||||||
|
is_before_fork_epoch=True,
|
||||||
|
valid=False,
|
||||||
|
)
|
|
@ -1,29 +1,31 @@
|
||||||
from random import Random
|
from random import Random
|
||||||
from eth2spec.utils import bls
|
from eth2spec.utils import bls
|
||||||
from eth2spec.test.context import expect_assertion_error
|
from eth2spec.test.context import expect_assertion_error
|
||||||
|
from eth2spec.test.helpers.forks import is_post_deneb
|
||||||
from eth2spec.test.helpers.keys import privkeys
|
from eth2spec.test.helpers.keys import privkeys
|
||||||
|
|
||||||
|
|
||||||
def prepare_signed_exits(spec, state, indices, fork_version=None):
|
def prepare_signed_exits(spec, state, indices, fork_version=None):
|
||||||
if fork_version is None:
|
|
||||||
domain = spec.get_domain(state, spec.DOMAIN_VOLUNTARY_EXIT)
|
|
||||||
else:
|
|
||||||
domain = spec.compute_domain(spec.DOMAIN_VOLUNTARY_EXIT, fork_version, state.genesis_validators_root)
|
|
||||||
|
|
||||||
def create_signed_exit(index):
|
def create_signed_exit(index):
|
||||||
exit = spec.VoluntaryExit(
|
voluntary_exit = spec.VoluntaryExit(
|
||||||
epoch=spec.get_current_epoch(state),
|
epoch=spec.get_current_epoch(state),
|
||||||
validator_index=index,
|
validator_index=index,
|
||||||
)
|
)
|
||||||
signing_root = spec.compute_signing_root(exit, domain)
|
return sign_voluntary_exit(spec, state, voluntary_exit, privkeys[index], fork_version=fork_version)
|
||||||
return spec.SignedVoluntaryExit(message=exit, signature=bls.Sign(privkeys[index], signing_root))
|
|
||||||
|
|
||||||
return [create_signed_exit(index) for index in indices]
|
return [create_signed_exit(index) for index in indices]
|
||||||
|
|
||||||
|
|
||||||
def sign_voluntary_exit(spec, state, voluntary_exit, privkey, fork_version=None):
|
def sign_voluntary_exit(spec, state, voluntary_exit, privkey, fork_version=None):
|
||||||
if fork_version is None:
|
if fork_version is None:
|
||||||
domain = spec.get_domain(state, spec.DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch)
|
if is_post_deneb(spec):
|
||||||
|
domain = spec.compute_domain(
|
||||||
|
spec.DOMAIN_VOLUNTARY_EXIT,
|
||||||
|
spec.config.CAPELLA_FORK_VERSION,
|
||||||
|
state.genesis_validators_root,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
domain = spec.get_domain(state, spec.DOMAIN_VOLUNTARY_EXIT, voluntary_exit.epoch)
|
||||||
else:
|
else:
|
||||||
domain = spec.compute_domain(spec.DOMAIN_VOLUNTARY_EXIT, fork_version, state.genesis_validators_root)
|
domain = spec.compute_domain(spec.DOMAIN_VOLUNTARY_EXIT, fork_version, state.genesis_validators_root)
|
||||||
|
|
||||||
|
|
|
@ -36,10 +36,14 @@ if __name__ == "__main__":
|
||||||
]}
|
]}
|
||||||
capella_mods = combine_mods(_new_capella_mods, bellatrix_mods)
|
capella_mods = combine_mods(_new_capella_mods, bellatrix_mods)
|
||||||
|
|
||||||
deneb_mods = capella_mods
|
_new_deneb_mods = {key: 'eth2spec.test.deneb.block_processing.test_process_' + key for key in [
|
||||||
|
'voluntary_exit',
|
||||||
|
]}
|
||||||
|
deneb_mods = combine_mods(_new_deneb_mods, capella_mods)
|
||||||
|
|
||||||
_new_eip6110_mods = {key: 'eth2spec.test.eip6110.block_processing.test_process_' + key for key in [
|
_new_eip6110_mods = {key: 'eth2spec.test.eip6110.block_processing.test_process_' + key for key in [
|
||||||
'deposit_receipt',
|
'deposit_receipt',
|
||||||
|
'voluntary_exit',
|
||||||
]}
|
]}
|
||||||
eip6110_mods = combine_mods(_new_eip6110_mods, deneb_mods)
|
eip6110_mods = combine_mods(_new_eip6110_mods, deneb_mods)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue