From 235175d937fee37b3ba6f4a469a111423d348c6c Mon Sep 17 00:00:00 2001 From: Hsiao-Wei Wang Date: Mon, 29 Jun 2020 19:54:24 +0800 Subject: [PATCH] Add `CustodyKeyReveal` and `EarlyDerivedSecretReveal` tests --- .../test/phase1/sanity/test_blocks.py | 31 +++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tests/core/pyspec/eth2spec/test/phase1/sanity/test_blocks.py b/tests/core/pyspec/eth2spec/test/phase1/sanity/test_blocks.py index 508feb65d..621fbb55d 100644 --- a/tests/core/pyspec/eth2spec/test/phase1/sanity/test_blocks.py +++ b/tests/core/pyspec/eth2spec/test/phase1/sanity/test_blocks.py @@ -10,6 +10,8 @@ from eth2spec.test.helpers.block import build_empty_block from eth2spec.test.helpers.custody import ( get_valid_chunk_challenge, get_valid_custody_chunk_response, + get_valid_custody_key_reveal, + get_valid_early_derived_secret_reveal, ) from eth2spec.test.helpers.shard_block import ( build_shard_block, @@ -135,7 +137,7 @@ def test_process_beacon_block_with_empty_proposal_transition(spec, state): @with_all_phases_except([PHASE0]) @spec_state_test -def test_with_custody_challenge_and_response(spec, state): +def test_with_shard_transition_with_custody_challenge_and_response(spec, state): # NOTE: this test is only for full crosslink (minimal config), not for mainnet if not is_full_crosslink(spec, state): # skip @@ -159,12 +161,37 @@ def test_with_custody_challenge_and_response(spec, state): block.body.attestations = [attestation] block.body.shard_transitions = shard_transitions - # CustodyChunkChallenge and CustodyChunkResponse operations + # CustodyChunkChallenge operation challenge = get_valid_chunk_challenge(spec, state, attestation, shard_transitions[shard]) block.body.chunk_challenges = [challenge] + # CustodyChunkResponse operation chunk_challenge_index = state.custody_chunk_challenge_index custody_response = get_valid_custody_chunk_response( spec, state, challenge, chunk_challenge_index, block_length_or_custody_data=body) block.body.chunk_challenge_responses = [custody_response] yield from run_beacon_block(spec, state, block) + + +@with_all_phases_except([PHASE0]) +@spec_state_test +def test_with_custody_key_reveal(spec, state): + state = transition_to_valid_shard_slot(spec, state) + transition_to(spec, state, state.slot + spec.EPOCHS_PER_CUSTODY_PERIOD * spec.SLOTS_PER_EPOCH) + + block = build_empty_block(spec, state, slot=state.slot + 1) + custody_key_reveal = get_valid_custody_key_reveal(spec, state) + block.body.custody_key_reveals = [custody_key_reveal] + + yield from run_beacon_block(spec, state, block) + + +@with_all_phases_except([PHASE0]) +@spec_state_test +def test_with_early_derived_secret_reveal(spec, state): + state = transition_to_valid_shard_slot(spec, state) + block = build_empty_block(spec, state, slot=state.slot + 1) + early_derived_secret_reveal = get_valid_early_derived_secret_reveal(spec, state) + block.body.early_derived_secret_reveals = [early_derived_secret_reveal] + + yield from run_beacon_block(spec, state, block)