import fixes + fix import loop + fix minor signing things

This commit is contained in:
protolambda
2019-05-17 20:31:21 +02:00
parent eea6c8f645
commit 62999d8ded
10 changed files with 22 additions and 22 deletions

View File

@@ -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):

View File

@@ -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)

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -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:

View File

@@ -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,

View File

@@ -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``.