MCPcopy
hub / github.com/ethereum/research / test_proposer_slashing

Function test_proposer_slashing

spec_pythonizer/sanity_check.py:251–309  ·  view source on GitHub ↗
(state)

Source from the content-addressed store, hash-verified

249
250# @timeit
251def test_proposer_slashing(state):
252 test_state = deepcopy(state)
253 current_epoch = get_current_epoch(test_state)
254 validator_index = get_active_validator_indices(test_state.validator_registry, current_epoch)[-1]
255 pubkey = pubkeys[validator_index]
256 privkey = pubkey_to_privkey[pubkey]
257 slot = spec.GENESIS_SLOT
258 header_1 = BeaconBlockHeader(
259 slot=slot,
260 previous_block_root=b'\x00'*32,
261 state_root=b'\x00'*32,
262 block_body_root=b'\x00'*32,
263 signature=b'\x00'*96
264 )
265 header_2 = deepcopy(header_1)
266 header_2.previous_block_root = b'\x02'*32
267 header_2.slot = slot + 1
268
269 domain = get_domain(
270 fork=test_state.fork,
271 epoch=get_current_epoch(test_state),
272 domain_type=spec.DOMAIN_BEACON_BLOCK,
273 )
274 header_1.signature = bls.sign(
275 message_hash=signed_root(header_1),
276 privkey=privkey,
277 domain=domain,
278 )
279 header_2.signature = bls.sign(
280 message_hash=signed_root(header_2),
281 privkey=privkey,
282 domain=domain,
283 )
284
285 proposer_slashing = ProposerSlashing(
286 proposer_index=validator_index,
287 header_1=header_1,
288 header_2=header_2,
289 )
290
291 #
292 # Add to state via block transition
293 #
294 block = construct_empty_block_for_next_slot(test_state)
295 block.body.proposer_slashings.append(proposer_slashing)
296 state_transition(test_state, block)
297
298 assert not state.validator_registry[validator_index].initiated_exit
299 assert not state.validator_registry[validator_index].slashed
300
301 slashed_validator = test_state.validator_registry[validator_index]
302 assert not slashed_validator.initiated_exit
303 assert slashed_validator.slashed
304 assert slashed_validator.exit_epoch < spec.FAR_FUTURE_EPOCH
305 assert slashed_validator.withdrawable_epoch < spec.FAR_FUTURE_EPOCH
306 # lost whistleblower reward
307 assert test_state.validator_balances[validator_index] < state.validator_balances[validator_index]
308

Callers

nothing calls this directly

Calls 6

signed_rootFunction · 0.90
state_transitionFunction · 0.90
deepcopyFunction · 0.85
signMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected