From becda4f463d6e7091ff95e6645afd44b2bc597dc Mon Sep 17 00:00:00 2001 From: Carl Beekhuizen Date: Wed, 15 May 2019 16:26:49 +0200 Subject: [PATCH] Several changes before I break everything --- test_libs/pyspec/tests/phase0/conftest.py | 5 +- ...est_process_early_derived_secret_reveal.py | 18 ++--- test_libs/pyspec/tests/phase1/conftest.py | 21 +++++- test_libs/pyspec/tests/phase1/helpers.py | 11 +++ .../pyspec/tests/phase1/test_finality.py | 3 - test_libs/pyspec/tests/phase1/test_sanity.py | 68 +++++++++++++++++++ 6 files changed, 108 insertions(+), 18 deletions(-) create mode 100644 test_libs/pyspec/tests/phase1/test_sanity.py diff --git a/test_libs/pyspec/tests/phase0/conftest.py b/test_libs/pyspec/tests/phase0/conftest.py index 4deb65da8..a3ea0a00c 100644 --- a/test_libs/pyspec/tests/phase0/conftest.py +++ b/test_libs/pyspec/tests/phase0/conftest.py @@ -10,10 +10,9 @@ from tests.phase0.helpers import ( def pytest_addoption(parser): parser.addoption( - "--config", action="store", default="minimal", help="config: make the p yspec use the specified configuration" + "--config", action="store", default="minimal", help="config: make the pyspec use the specified configuration" ) - @pytest.fixture(autouse=True) def config(request): config_name = request.config.getoption("--config") @@ -24,12 +23,10 @@ def config(request): def num_validators(config): return spec.SLOTS_PER_EPOCH * 8 - @pytest.fixture def deposit_data_leaves(): return list() - @pytest.fixture def state(num_validators, deposit_data_leaves): return create_genesis_state(num_validators, deposit_data_leaves) diff --git a/test_libs/pyspec/tests/phase1/block_processing_phase1/test_process_early_derived_secret_reveal.py b/test_libs/pyspec/tests/phase1/block_processing_phase1/test_process_early_derived_secret_reveal.py index 54a90aca1..6661e883f 100644 --- a/test_libs/pyspec/tests/phase1/block_processing_phase1/test_process_early_derived_secret_reveal.py +++ b/test_libs/pyspec/tests/phase1/block_processing_phase1/test_process_early_derived_secret_reveal.py @@ -61,14 +61,14 @@ def test_reveal_from_current_epoch(state): return pre_state, randao_key_reveal, post_state -# Not currently possible as we are testing at epoch 0 -# -#def test_reveal_from_past_epoch(state): -# randao_key_reveal = get_valid_early_derived_secret_reveal(state, get_current_epoch(state) - 1) -# -# pre_state, post_state = run_early_derived_secret_reveal_processing(state, randao_key_reveal, False) -# -# return pre_state, randao_key_reveal, post_state + +@pytest.mark.skip(reason="Not currently possible as we are testing at epoch 0") +def test_reveal_from_past_epoch(state): + randao_key_reveal = get_valid_early_derived_secret_reveal(state, get_current_epoch(state) - 1) + + pre_state, post_state = run_early_derived_secret_reveal_processing(state, randao_key_reveal, False) + + return pre_state, randao_key_reveal, post_state def test_reveal_with_custody_padding(state): randao_key_reveal = get_valid_early_derived_secret_reveal(state, get_current_epoch(state) + CUSTODY_PERIOD_TO_RANDAO_PADDING) @@ -88,7 +88,7 @@ def test_double_reveal(state): pre_state, intermediate_state = run_early_derived_secret_reveal_processing(state, randao_key_reveal1) randao_key_reveal2 = get_valid_early_derived_secret_reveal(intermediate_state, get_current_epoch(pre_state) + RANDAO_PENALTY_EPOCHS + 1) - intermediate_state_, post_state = run_early_derived_secret_reveal_processing(intermediate_state, randao_key_reveal2, False) + _, post_state = run_early_derived_secret_reveal_processing(intermediate_state, randao_key_reveal2, False) return pre_state, [randao_key_reveal1, randao_key_reveal2], post_state diff --git a/test_libs/pyspec/tests/phase1/conftest.py b/test_libs/pyspec/tests/phase1/conftest.py index 4bacc1ea7..c73f25c1b 100644 --- a/test_libs/pyspec/tests/phase1/conftest.py +++ b/test_libs/pyspec/tests/phase1/conftest.py @@ -1,9 +1,26 @@ import pytest +from eth2spec.phase1 import spec +from preset_loader import loader + +from tests.phase0.helpers import ( + create_genesis_state, +) + from tests.phase0.conftest import ( pytest_addoption, - config, num_validators, deposit_data_leaves, - state, ) + +# This is redfined so that the constants are re-applied +@pytest.fixture(autouse=True) +def config(request): + config_name = request.config.getoption("--config") + presets = loader.load_presets('../../configs/', config_name) + spec.apply_constants_preset(presets) + +#This is redefined so that the BeaconState is the new SSZ Object +@pytest.fixture +def state(num_validators, deposit_data_leaves): + return create_genesis_state(num_validators, deposit_data_leaves) diff --git a/test_libs/pyspec/tests/phase1/helpers.py b/test_libs/pyspec/tests/phase1/helpers.py index b12519b62..8520ce9d7 100644 --- a/test_libs/pyspec/tests/phase1/helpers.py +++ b/test_libs/pyspec/tests/phase1/helpers.py @@ -15,7 +15,18 @@ from eth2spec.phase1.spec import ( ) from tests.phase0.helpers import ( + advance_slot, + get_balance, + build_deposit_data, + build_empty_block_for_next_slot, + fill_aggregate_attestation, + get_state_root, + get_valid_attestation, + get_valid_attester_slashing, + get_valid_proposer_slashing, + next_slot, privkeys, + pubkeys, ) def get_valid_early_derived_secret_reveal(state, epoch=None): diff --git a/test_libs/pyspec/tests/phase1/test_finality.py b/test_libs/pyspec/tests/phase1/test_finality.py index b0acaa7cb..4b57c9493 100644 --- a/test_libs/pyspec/tests/phase1/test_finality.py +++ b/test_libs/pyspec/tests/phase1/test_finality.py @@ -17,9 +17,6 @@ from tests.phase0.helpers import ( next_epoch, ) -# mark entire file as 'state' -# pytestmark = pytest.mark.state - from tests.phase0.test_finality import ( pytestmark, check_finality, diff --git a/test_libs/pyspec/tests/phase1/test_sanity.py b/test_libs/pyspec/tests/phase1/test_sanity.py new file mode 100644 index 000000000..45a08bd0e --- /dev/null +++ b/test_libs/pyspec/tests/phase1/test_sanity.py @@ -0,0 +1,68 @@ +from copy import deepcopy + +import pytest + +from py_ecc import bls +import eth2spec.phase1.spec as spec + +from eth2spec.utils.minimal_ssz import signing_root +from eth2spec.phase1.spec import ( + # constants + ZERO_HASH, + SLOTS_PER_HISTORICAL_ROOT, + # SSZ + Deposit, + Transfer, + VoluntaryExit, + # functions + get_active_validator_indices, + get_beacon_proposer_index, + get_block_root_at_slot, + get_current_epoch, + get_domain, + process_slot, + verify_merkle_branch, + state_transition, + hash, +) +from eth2spec.utils.merkle_minimal import ( + calc_merkle_tree_from_leaves, + get_merkle_proof, + get_merkle_root, +) +from .helpers import ( + advance_slot, + get_balance, + build_deposit_data, + build_empty_block_for_next_slot, + fill_aggregate_attestation, + get_state_root, + get_valid_attestation, + get_valid_attester_slashing, + get_valid_proposer_slashing, + next_slot, + privkeys, + pubkeys, +) + + +# mark entire file as 'sanity' +pytestmark = pytest.mark.sanity + +from tests.phase0.test_sanity import ( + test_slot_transition, + test_empty_block_transition, + test_skipped_slots, + test_empty_epoch_transition, + test_empty_epoch_transition_not_finalizing, + test_proposer_slashing, + test_attester_slashing, + test_deposit_in_block, + test_deposit_top_up, + test_attestation, + test_voluntary_exit, + test_transfer, + test_balance_driven_status_transitions, + test_historical_batch, + test_eth1_data_votes, +)