eth2.0-specs/test_libs/pyspec/eth2spec/test/helpers/proposer_slashings.py

33 lines
1016 B
Python
Raw Normal View History

2019-05-15 16:36:32 +00:00
from copy import deepcopy
2019-06-10 20:20:45 +00:00
from eth2spec.test.helpers.block_header import sign_block_header
2019-05-15 16:36:32 +00:00
from eth2spec.test.helpers.keys import pubkey_to_privkey
2019-05-30 20:57:18 +00:00
def get_valid_proposer_slashing(spec, state, signed_1=False, signed_2=False):
current_epoch = spec.get_current_epoch(state)
validator_index = spec.get_active_validator_indices(state, current_epoch)[-1]
2019-06-09 19:41:21 +00:00
privkey = pubkey_to_privkey[state.validators[validator_index].pubkey]
2019-05-15 16:36:32 +00:00
slot = state.slot
2019-05-30 20:57:18 +00:00
header_1 = spec.BeaconBlockHeader(
2019-05-15 16:36:32 +00:00
slot=slot,
2019-05-27 17:09:52 +00:00
parent_root=b'\x33' * 32,
2019-05-15 19:07:24 +00:00
state_root=b'\x44' * 32,
block_body_root=b'\x55' * 32,
2019-05-15 16:36:32 +00:00
)
header_2 = deepcopy(header_1)
2019-05-27 17:09:52 +00:00
header_2.parent_root = b'\x99' * 32
2019-05-15 16:36:32 +00:00
header_2.slot = slot + 1
2019-05-15 19:07:24 +00:00
if signed_1:
2019-05-30 20:57:18 +00:00
sign_block_header(spec, state, header_1, privkey)
2019-05-15 19:07:24 +00:00
if signed_2:
2019-05-30 20:57:18 +00:00
sign_block_header(spec, state, header_2, privkey)
2019-05-15 16:36:32 +00:00
2019-05-30 20:57:18 +00:00
return spec.ProposerSlashing(
2019-05-15 16:36:32 +00:00
proposer_index=validator_index,
header_1=header_1,
header_2=header_2,
)