-
Notifications
You must be signed in to change notification settings - Fork 997
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2977 from ethereum/dev
v1.2.0-rc.3
- Loading branch information
Showing
13 changed files
with
340 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.2.0-rc.2 | ||
1.2.0-rc.3 |
85 changes: 85 additions & 0 deletions
85
tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_deposit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
from eth2spec.test.context import ( | ||
spec_state_test, | ||
always_bls, | ||
with_bellatrix_and_later, | ||
) | ||
from eth2spec.test.helpers.deposits import ( | ||
deposit_from_context, | ||
run_deposit_processing, | ||
) | ||
from eth2spec.test.helpers.keys import ( | ||
privkeys, | ||
pubkeys, | ||
) | ||
from eth2spec.utils import bls | ||
|
||
|
||
def _run_deposit_processing_with_specific_fork_version( | ||
spec, | ||
state, | ||
fork_version, | ||
valid, | ||
effective): | ||
validator_index = len(state.validators) | ||
amount = spec.MAX_EFFECTIVE_BALANCE | ||
|
||
pubkey = pubkeys[validator_index] | ||
privkey = privkeys[validator_index] | ||
withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX + spec.hash(pubkey)[1:] | ||
|
||
deposit_message = spec.DepositMessage(pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, amount=amount) | ||
domain = spec.compute_domain(domain_type=spec.DOMAIN_DEPOSIT, fork_version=fork_version) | ||
deposit_data = spec.DepositData( | ||
pubkey=pubkey, withdrawal_credentials=withdrawal_credentials, amount=amount, | ||
signature=bls.Sign(privkey, spec.compute_signing_root(deposit_message, domain)) | ||
) | ||
deposit, root, _ = deposit_from_context(spec, [deposit_data], 0) | ||
|
||
state.eth1_deposit_index = 0 | ||
state.eth1_data.deposit_root = root | ||
state.eth1_data.deposit_count = 1 | ||
|
||
yield from run_deposit_processing(spec, state, deposit, validator_index, valid=valid, effective=effective) | ||
|
||
|
||
@with_bellatrix_and_later | ||
@spec_state_test | ||
@always_bls | ||
def test_deposit_with_previous_fork_version__valid_ineffective(spec, state): | ||
assert state.fork.previous_version != state.fork.current_version | ||
|
||
yield from _run_deposit_processing_with_specific_fork_version( | ||
spec, | ||
state, | ||
fork_version=state.fork.previous_version, | ||
valid=True, | ||
effective=False, | ||
) | ||
|
||
|
||
@with_bellatrix_and_later | ||
@spec_state_test | ||
@always_bls | ||
def test_deposit_with_genesis_fork_version__valid_effective(spec, state): | ||
assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version) | ||
|
||
yield from _run_deposit_processing_with_specific_fork_version( | ||
spec, | ||
state, | ||
fork_version=spec.config.GENESIS_FORK_VERSION, | ||
valid=True, | ||
effective=True, | ||
) | ||
|
||
|
||
@with_bellatrix_and_later | ||
@spec_state_test | ||
@always_bls | ||
def test_deposit_with_bad_fork_version__valid_ineffective(spec, state): | ||
yield from _run_deposit_processing_with_specific_fork_version( | ||
spec, | ||
state, | ||
fork_version=spec.Version('0xAaBbCcDd'), | ||
valid=True, | ||
effective=False, | ||
) |
133 changes: 133 additions & 0 deletions
133
tests/core/pyspec/eth2spec/test/bellatrix/block_processing/test_process_voluntary_exit.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
from eth2spec.test.context import ( | ||
spec_state_test, | ||
always_bls, | ||
with_bellatrix_and_later, | ||
) | ||
from eth2spec.test.helpers.keys import pubkey_to_privkey | ||
from eth2spec.test.helpers.state import ( | ||
next_epoch, | ||
) | ||
from eth2spec.test.helpers.voluntary_exits import ( | ||
run_voluntary_exit_processing, | ||
sign_voluntary_exit, | ||
) | ||
|
||
|
||
def _run_voluntary_exit_processing_test( | ||
spec, | ||
state, | ||
fork_version, | ||
is_before_fork_epoch, | ||
valid): | ||
# create a fork | ||
next_epoch(spec, state) | ||
state.fork.epoch = spec.get_current_epoch(state) | ||
|
||
voluntary_exit_epoch = 0 if is_before_fork_epoch else state.fork.epoch | ||
|
||
# move state forward SHARD_COMMITTEE_PERIOD epochs to allow for exit | ||
state.slot += spec.config.SHARD_COMMITTEE_PERIOD * spec.SLOTS_PER_EPOCH | ||
|
||
current_epoch = spec.get_current_epoch(state) | ||
validator_index = spec.get_active_validator_indices(state, current_epoch)[0] | ||
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey] | ||
|
||
voluntary_exit = spec.VoluntaryExit( | ||
epoch=voluntary_exit_epoch, | ||
validator_index=validator_index, | ||
) | ||
signed_voluntary_exit = sign_voluntary_exit( | ||
spec, | ||
state, | ||
voluntary_exit, | ||
privkey, | ||
fork_version=fork_version, | ||
) | ||
|
||
yield from run_voluntary_exit_processing(spec, state, signed_voluntary_exit, valid=valid) | ||
|
||
|
||
@with_bellatrix_and_later | ||
@spec_state_test | ||
@always_bls | ||
def test_voluntary_exit_with_current_fork_version_is_before_fork_epoch__invalid(spec, state): | ||
yield from _run_voluntary_exit_processing_test( | ||
spec, | ||
state, | ||
fork_version=state.fork.current_version, | ||
is_before_fork_epoch=True, | ||
valid=False, | ||
) | ||
|
||
|
||
@with_bellatrix_and_later | ||
@spec_state_test | ||
@always_bls | ||
def test_voluntary_exit_with_current_fork_version_not_is_before_fork_epoch__valid(spec, state): | ||
yield from _run_voluntary_exit_processing_test( | ||
spec, | ||
state, | ||
fork_version=state.fork.current_version, | ||
is_before_fork_epoch=False, | ||
valid=True, | ||
) | ||
|
||
|
||
@with_bellatrix_and_later | ||
@spec_state_test | ||
@always_bls | ||
def test_voluntary_exit_with_previous_fork_version_is_before_fork_epoch__valid(spec, state): | ||
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=True, | ||
) | ||
|
||
|
||
@with_bellatrix_and_later | ||
@spec_state_test | ||
@always_bls | ||
def test_voluntary_exit_with_previous_fork_version_not_is_before_fork_epoch__invalid(spec, state): | ||
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_bellatrix_and_later | ||
@spec_state_test | ||
@always_bls | ||
def test_voluntary_exit_with_genesis_fork_version_is_before_fork_epoch__invalid(spec, state): | ||
assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version) | ||
|
||
yield from _run_voluntary_exit_processing_test( | ||
spec, | ||
state, | ||
fork_version=spec.config.GENESIS_FORK_VERSION, | ||
is_before_fork_epoch=True, | ||
valid=False, | ||
) | ||
|
||
|
||
@with_bellatrix_and_later | ||
@spec_state_test | ||
@always_bls | ||
def test_voluntary_exit_with_genesis_fork_version_not_is_before_fork_epoch__invalid(spec, state): | ||
assert spec.config.GENESIS_FORK_VERSION not in (state.fork.previous_version, state.fork.current_version) | ||
|
||
yield from _run_voluntary_exit_processing_test( | ||
spec, | ||
state, | ||
fork_version=spec.config.GENESIS_FORK_VERSION, | ||
is_before_fork_epoch=False, | ||
valid=False, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.