From 62999d8ded3e52bf7c3f60a0e30cec3218faa73f Mon Sep 17 00:00:00 2001 From: protolambda Date: Fri, 17 May 2019 20:31:21 +0200 Subject: [PATCH] import fixes + fix import loop + fix minor signing things --- .../block_processing/test_process_attestation.py | 2 +- .../test_process_attester_slashing.py | 4 ++-- .../block_processing/test_process_block_header.py | 3 +-- .../test_process_proposer_slashing.py | 2 +- .../test/block_processing/test_process_transfer.py | 3 ++- test_libs/pyspec/eth2spec/test/context.py | 2 +- test_libs/pyspec/eth2spec/test/helpers/block.py | 11 +++++++++++ test_libs/pyspec/eth2spec/test/helpers/deposits.py | 2 +- test_libs/pyspec/eth2spec/test/helpers/genesis.py | 2 +- test_libs/pyspec/eth2spec/test/helpers/state.py | 13 +------------ 10 files changed, 22 insertions(+), 22 deletions(-) diff --git a/test_libs/pyspec/eth2spec/test/block_processing/test_process_attestation.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_attestation.py index c44e8e7b1..2c88f12b5 100644 --- a/test_libs/pyspec/eth2spec/test/block_processing/test_process_attestation.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_attestation.py @@ -14,10 +14,10 @@ from eth2spec.test.helpers.attestations import ( sign_attestation, ) from eth2spec.test.helpers.state import ( - apply_empty_block, next_epoch, next_slot, ) +from eth2spec.test.helpers.block import apply_empty_block def run_attestation_processing(state, attestation, valid=True): diff --git a/test_libs/pyspec/eth2spec/test/block_processing/test_process_attester_slashing.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_attester_slashing.py index 35e6b0f71..ea3a31aea 100644 --- a/test_libs/pyspec/eth2spec/test/block_processing/test_process_attester_slashing.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_attester_slashing.py @@ -6,10 +6,10 @@ from eth2spec.phase0.spec import ( from eth2spec.test.context import spec_state_test, expect_assertion_error from eth2spec.test.helpers.attestations import sign_indexed_attestation from eth2spec.test.helpers.attester_slashings import get_valid_attester_slashing +from eth2spec.test.helpers.block import apply_empty_block from eth2spec.test.helpers.state import ( get_balance, next_epoch, - apply_empty_block, ) @@ -63,7 +63,7 @@ def run_attester_slashing_processing(state, attester_slashing, valid=True): @spec_state_test def test_success_double(state): - attester_slashing = get_valid_attester_slashing(state) + attester_slashing = get_valid_attester_slashing(state, signed_1=True, signed_2=True) yield from run_attester_slashing_processing(state, attester_slashing) diff --git a/test_libs/pyspec/eth2spec/test/block_processing/test_process_block_header.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_block_header.py index 9d4d6192e..69bacc84f 100644 --- a/test_libs/pyspec/eth2spec/test/block_processing/test_process_block_header.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_block_header.py @@ -49,9 +49,8 @@ def test_success(state): @spec_state_test def test_invalid_slot(state): - block = build_empty_block_for_next_slot(state, signed=False) + block = build_empty_block_for_next_slot(state, signed=True) block.slot = state.slot + 2 # invalid slot - sign_block(state, block) yield from run_block_header_processing(state, block, valid=False) diff --git a/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py index 65d748ab5..f3d1593a8 100644 --- a/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_proposer_slashing.py @@ -67,7 +67,7 @@ def test_epochs_are_different(state): # set slots to be in different epochs proposer_slashing.header_2.slot += spec.SLOTS_PER_EPOCH - sign_block_header(state, proposer_slashing.header_2, privkeys[proposer_slashing.validator_index]) + sign_block_header(state, proposer_slashing.header_2, privkeys[proposer_slashing.proposer_index]) yield from run_proposer_slashing_processing(state, proposer_slashing, False) diff --git a/test_libs/pyspec/eth2spec/test/block_processing/test_process_transfer.py b/test_libs/pyspec/eth2spec/test/block_processing/test_process_transfer.py index dc63bf491..2bbc022d0 100644 --- a/test_libs/pyspec/eth2spec/test/block_processing/test_process_transfer.py +++ b/test_libs/pyspec/eth2spec/test/block_processing/test_process_transfer.py @@ -6,7 +6,8 @@ from eth2spec.phase0.spec import ( process_transfer, ) from eth2spec.test.context import spec_state_test, expect_assertion_error -from eth2spec.test.helpers.state import next_epoch, apply_empty_block +from eth2spec.test.helpers.state import next_epoch +from eth2spec.test.helpers.block import apply_empty_block from eth2spec.test.helpers.transfers import get_valid_transfer diff --git a/test_libs/pyspec/eth2spec/test/context.py b/test_libs/pyspec/eth2spec/test/context.py index ce088f81c..b2e67d761 100644 --- a/test_libs/pyspec/eth2spec/test/context.py +++ b/test_libs/pyspec/eth2spec/test/context.py @@ -1,7 +1,7 @@ from eth2spec.phase0 import spec from eth2spec.utils import bls -from .helpers import create_genesis_state +from .helpers.genesis import create_genesis_state from .utils import spectest, with_args diff --git a/test_libs/pyspec/eth2spec/test/helpers/block.py b/test_libs/pyspec/eth2spec/test/helpers/block.py index 36659f8fa..b9c4ca712 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/block.py +++ b/test_libs/pyspec/eth2spec/test/helpers/block.py @@ -2,6 +2,7 @@ from copy import deepcopy from eth2spec.phase0 import spec from eth2spec.phase0.spec import get_beacon_proposer_index, slot_to_epoch, get_domain, BeaconBlock +from eth2spec.phase0.state_transition import state_transition from eth2spec.test.helpers.keys import privkeys from eth2spec.test.helpers.state import next_slot from eth2spec.utils.bls import bls_sign @@ -39,6 +40,16 @@ def sign_block(state, block): return block +def apply_empty_block(state): + """ + Transition via an empty block (on current slot, assuming no block has been applied yet). + :return: the empty block that triggered the transition. + """ + block = build_empty_block(state, signed=True) + state_transition(state, block) + return block + + def build_empty_block(state, slot=None, signed=False): if slot is None: slot = state.slot diff --git a/test_libs/pyspec/eth2spec/test/helpers/deposits.py b/test_libs/pyspec/eth2spec/test/helpers/deposits.py index 1bea2f923..c5deb124e 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/deposits.py +++ b/test_libs/pyspec/eth2spec/test/helpers/deposits.py @@ -12,7 +12,7 @@ def build_deposit_data(state, pubkey, privkey, amount, signed=False): deposit_data = DepositData( pubkey=pubkey, # insecurely use pubkey as withdrawal key as well - withdrawal_credentials=spec.BLS_WITHDRAWAL_PREFIX_BYTE + hash(pubkey)[1:], + withdrawal_credentials=spec.BLS_WITHDRAWAL_PREFIX_BYTE + spec.hash(pubkey)[1:], amount=amount, ) if signed: diff --git a/test_libs/pyspec/eth2spec/test/helpers/genesis.py b/test_libs/pyspec/eth2spec/test/helpers/genesis.py index b991f74e7..01011cacd 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/genesis.py +++ b/test_libs/pyspec/eth2spec/test/helpers/genesis.py @@ -9,7 +9,7 @@ from eth2spec.utils.minimal_ssz import hash_tree_root def build_mock_validator(i: int, balance: int): pubkey = pubkeys[i] # insecurely use pubkey as withdrawal key as well - withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX_BYTE + hash(pubkey)[1:] + withdrawal_credentials = spec.BLS_WITHDRAWAL_PREFIX_BYTE + spec.hash(pubkey)[1:] return spec.Validator( pubkey=pubkeys[i], withdrawal_credentials=withdrawal_credentials, diff --git a/test_libs/pyspec/eth2spec/test/helpers/state.py b/test_libs/pyspec/eth2spec/test/helpers/state.py index 0261801df..e720a9709 100644 --- a/test_libs/pyspec/eth2spec/test/helpers/state.py +++ b/test_libs/pyspec/eth2spec/test/helpers/state.py @@ -1,8 +1,7 @@ # Access constants from spec pkg reference. import eth2spec.phase0.spec as spec -from eth2spec.phase0.state_transition import state_transition_to, state_transition -from eth2spec.test.helpers.block import build_empty_block +from eth2spec.phase0.state_transition import state_transition_to def get_balance(state, index): @@ -24,16 +23,6 @@ def next_epoch(state): state_transition_to(state, slot) -def apply_empty_block(state): - """ - Transition via an empty block (on current slot, assuming no block has been applied yet). - :return: the empty block that triggered the transition. - """ - block = build_empty_block(state) - state_transition(state, block) - return block - - def get_state_root(state, slot) -> bytes: """ Return the state root at a recent ``slot``.