From df64eeefa07eb58364fe1eb86eb351f63bf32e86 Mon Sep 17 00:00:00 2001 From: Justin Drake Date: Wed, 24 Apr 2019 14:46:28 +1000 Subject: [PATCH] Start fixing tests --- specs/core/0_beacon-chain.md | 8 ++++---- .../tests/block_processing/test_process_transfer.py | 10 ++++------ test_libs/pyspec/tests/helpers.py | 1 - 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/specs/core/0_beacon-chain.md b/specs/core/0_beacon-chain.md index 033e3b2cb..159d2d839 100644 --- a/specs/core/0_beacon-chain.md +++ b/specs/core/0_beacon-chain.md @@ -931,7 +931,7 @@ def get_beacon_proposer_index(state: BeaconState) -> ValidatorIndex: candidate_index = first_committee[(current_epoch + i) % len(first_committee)] random_byte = hash(generate_seed(state, epoch) + int_to_bytes8(i // 32))[i % 32] effective_balance = state.validator_registry[candidate_index].effective_balance - if effective_balance * MAX_RANDOM_BYTE >= MAX_DEPOSIT_AMOUNT * random_byte: + if effective_balance * MAX_RANDOM_BYTE >= MAX_EFFECTIVE_BALANCE * random_byte: return candidate_index i += 1 ``` @@ -1291,7 +1291,7 @@ def get_genesis_beacon_state(genesis_validator_deposits: List[Deposit], # Process genesis activations for index, validator in enumerate(state.validator_registry): - if validator.effective_balance >= MAX_DEPOSIT_AMOUNT: + if validator.effective_balance >= MAX_EFFECTIVE_BALANCE: validator.activation_eligibility_epoch = GENESIS_EPOCH validator.activation_epoch = GENESIS_EPOCH @@ -1662,7 +1662,7 @@ Run the following function: def process_registry_updates(state: BeaconState) -> None: # Process activation eligibility and ejections for index, validator in enumerate(state.validator_registry): - if validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and validator.effective_balance >= MAX_DEPOSIT_AMOUNT: + if validator.activation_eligibility_epoch == FAR_FUTURE_EPOCH and validator.effective_balance >= MAX_EFFECTIVE_BALANCE: validator.activation_eligibility_epoch = get_current_epoch(state) if is_active_validator(validator, get_current_epoch(state)) and validator.effective_balance <= EJECTION_BALANCE: @@ -1717,7 +1717,7 @@ def process_final_updates(state: BeaconState) -> None: state.eth1_data_votes = [] # Update effective balances with hysteresis for index, validator in enumerate(state.validator_registry): - balance = min(state.balances[index], MAX_DEPOSIT_AMOUNT) + balance = min(state.balances[index], MAX_EFFECTIVE_BALANCE) HALF_INCREMENT = EFFECTIVE_BALANCE_INCREMENT // 2 if balance < validator.effective_balance or validator.effective_balance + 3 * HALF_INCREMENT < balance: validator.effective_balance = balance - balance % EFFECTIVE_BALANCE_INCREMENT diff --git a/test_libs/pyspec/tests/block_processing/test_process_transfer.py b/test_libs/pyspec/tests/block_processing/test_process_transfer.py index 71d0894bd..65df822de 100644 --- a/test_libs/pyspec/tests/block_processing/test_process_transfer.py +++ b/test_libs/pyspec/tests/block_processing/test_process_transfer.py @@ -5,11 +5,9 @@ import eth2spec.phase0.spec as spec from eth2spec.phase0.spec import ( get_active_validator_indices, - get_balance, get_beacon_proposer_index, get_current_epoch, process_transfer, - set_balance, ) from tests.helpers import ( get_valid_transfer, @@ -75,7 +73,7 @@ def test_success_withdrawable(state): def test_success_active_above_max_effective(state): sender_index = get_active_validator_indices(state, get_current_epoch(state))[-1] amount = spec.MAX_EFFECTIVE_BALANCE // 32 - set_balance(state, sender_index, spec.MAX_EFFECTIVE_BALANCE + amount) + state.validator_registry[sender_index] = spec.MAX_EFFECTIVE_BALANCE + amount transfer = get_valid_transfer(state, sender_index=sender_index, amount=amount, fee=0) pre_state, post_state = run_transfer_processing(state, transfer) @@ -86,7 +84,7 @@ def test_success_active_above_max_effective(state): def test_active_but_transfer_past_effective_balance(state): sender_index = get_active_validator_indices(state, get_current_epoch(state))[-1] amount = spec.MAX_EFFECTIVE_BALANCE // 32 - set_balance(state, sender_index, spec.MAX_EFFECTIVE_BALANCE) + state.validator_registry[sender_index] = spec.MAX_EFFECTIVE_BALANCE transfer = get_valid_transfer(state, sender_index=sender_index, amount=amount, fee=0) pre_state, post_state = run_transfer_processing(state, transfer, False) @@ -107,7 +105,7 @@ def test_incorrect_slot(state): def test_insufficient_balance(state): sender_index = get_active_validator_indices(state, get_current_epoch(state))[-1] amount = spec.MAX_EFFECTIVE_BALANCE - set_balance(state, sender_index, spec.MAX_EFFECTIVE_BALANCE) + state.validator_registry[sender_index] = spec.MAX_EFFECTIVE_BALANCE transfer = get_valid_transfer(state, sender_index=sender_index, amount=amount + 1, fee=0) # un-activate so validator can transfer @@ -140,4 +138,4 @@ def test_invalid_pubkey(state): pre_state, post_state = run_transfer_processing(state, transfer, False) - return pre_state, transfer, post_state \ No newline at end of file + return pre_state, transfer, post_state diff --git a/test_libs/pyspec/tests/helpers.py b/test_libs/pyspec/tests/helpers.py index 162c6fa62..465825c35 100644 --- a/test_libs/pyspec/tests/helpers.py +++ b/test_libs/pyspec/tests/helpers.py @@ -26,7 +26,6 @@ from eth2spec.phase0.spec import ( # functions convert_to_indexed, get_active_validator_indices, - get_balance, get_attesting_indices, get_block_root, get_crosslink_committees_at_slot,