From aecaed7a662ffc7ad73b098b1834840b725fe76d Mon Sep 17 00:00:00 2001 From: protolambda Date: Thu, 27 Jun 2019 01:47:15 +0200 Subject: [PATCH] move genesis tests, structure properly, add yield keys for future test-vec generator --- .../pyspec/eth2spec/test/genesis/__init__.py | 0 .../eth2spec/test/genesis/test_genesis.py | 37 ++++++++ .../test/genesis/test_genesis_trigger.py | 54 ++++++++++++ .../eth2spec/test/sanity/test_genesis.py | 87 ------------------- 4 files changed, 91 insertions(+), 87 deletions(-) create mode 100644 test_libs/pyspec/eth2spec/test/genesis/__init__.py create mode 100644 test_libs/pyspec/eth2spec/test/genesis/test_genesis.py create mode 100644 test_libs/pyspec/eth2spec/test/genesis/test_genesis_trigger.py delete mode 100644 test_libs/pyspec/eth2spec/test/sanity/test_genesis.py diff --git a/test_libs/pyspec/eth2spec/test/genesis/__init__.py b/test_libs/pyspec/eth2spec/test/genesis/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/test_libs/pyspec/eth2spec/test/genesis/test_genesis.py b/test_libs/pyspec/eth2spec/test/genesis/test_genesis.py new file mode 100644 index 000000000..a89ec8793 --- /dev/null +++ b/test_libs/pyspec/eth2spec/test/genesis/test_genesis.py @@ -0,0 +1,37 @@ +from eth2spec.test.context import with_phases, spectest_with_bls_switch +from eth2spec.test.helpers.deposits import ( + prepare_genesis_deposits, +) + + +@with_phases(['phase0']) +@spectest_with_bls_switch +def test_genesis(spec): + deposit_count = spec.GENESIS_ACTIVE_VALIDATOR_COUNT + genesis_deposits, deposit_root = prepare_genesis_deposits(spec, deposit_count, spec.MAX_EFFECTIVE_BALANCE) + genesis_time = 1546300800 + block_hash = b'\x12' * 32 + + yield "deposits", genesis_deposits + yield "time", genesis_time + + genesis_eth1_data = spec.Eth1Data( + deposit_root=deposit_root, + deposit_count=deposit_count, + block_hash=block_hash, + ) + + yield "eth1_data", genesis_eth1_data + genesis_state = spec.get_genesis_beacon_state( + genesis_deposits, + genesis_time, + genesis_eth1_data, + ) + + assert genesis_state.genesis_time == genesis_time + assert len(genesis_state.validators) == deposit_count + assert genesis_state.eth1_data.deposit_root == deposit_root + assert genesis_state.eth1_data.deposit_count == deposit_count + assert genesis_state.eth1_data.block_hash == block_hash + + yield "state", genesis_state diff --git a/test_libs/pyspec/eth2spec/test/genesis/test_genesis_trigger.py b/test_libs/pyspec/eth2spec/test/genesis/test_genesis_trigger.py new file mode 100644 index 000000000..873638dc9 --- /dev/null +++ b/test_libs/pyspec/eth2spec/test/genesis/test_genesis_trigger.py @@ -0,0 +1,54 @@ +from eth2spec.test.context import with_phases, spectest_with_bls_switch +from eth2spec.test.helpers.deposits import ( + prepare_genesis_deposits, +) + + +@with_phases(['phase0']) +@spectest_with_bls_switch +def test_is_genesis_trigger_false(spec): + deposit_count = 2 + genesis_deposits, deposit_root = prepare_genesis_deposits(spec, deposit_count, spec.MAX_EFFECTIVE_BALANCE) + genesis_time = 1546300800 + + yield "deposits", genesis_deposits + yield "time", genesis_time + yield "deposit_root", deposit_root + + is_triggered = spec.is_genesis_trigger(genesis_deposits, genesis_time) + assert is_triggered is False + + yield "is_triggered", is_triggered + + +@with_phases(['phase0']) +@spectest_with_bls_switch +def test_is_genesis_trigger_true(spec): + deposit_count = spec.GENESIS_ACTIVE_VALIDATOR_COUNT + genesis_deposits, deposit_root = prepare_genesis_deposits(spec, deposit_count, spec.MAX_EFFECTIVE_BALANCE) + genesis_time = 1546300800 + + yield "deposits", genesis_deposits + yield "time", genesis_time + yield "deposit_root", deposit_root + + is_triggered = spec.is_genesis_trigger(genesis_deposits, genesis_time) + assert is_triggered is True + + yield "is_triggered", is_triggered + + +@with_phases(['phase0']) +@spectest_with_bls_switch +def test_is_genesis_trigger_not_enough_balance(spec): + deposit_count = spec.GENESIS_ACTIVE_VALIDATOR_COUNT + genesis_deposits, deposit_root = prepare_genesis_deposits(spec, deposit_count, spec.MAX_EFFECTIVE_BALANCE - 1) + genesis_time = 1546300800 + yield "deposits", genesis_deposits + yield "time", genesis_time + yield "deposit_root", deposit_root + + is_triggered = spec.is_genesis_trigger(genesis_deposits, genesis_time) + assert is_triggered is False + + yield "is_triggered", is_triggered diff --git a/test_libs/pyspec/eth2spec/test/sanity/test_genesis.py b/test_libs/pyspec/eth2spec/test/sanity/test_genesis.py deleted file mode 100644 index 780d039eb..000000000 --- a/test_libs/pyspec/eth2spec/test/sanity/test_genesis.py +++ /dev/null @@ -1,87 +0,0 @@ -from eth2spec.test.context import with_phases, spectest_with_bls_switch -from eth2spec.test.helpers.deposits import ( - prepare_genesis_deposits, -) - - -@with_phases(['phase0']) -@spectest_with_bls_switch -def test_is_genesis_trigger_false(spec): - deposit_count = 2 - genesis_deposits, deposit_root = prepare_genesis_deposits(spec, deposit_count, spec.MAX_EFFECTIVE_BALANCE) - genesis_time = 1546300800 - - yield genesis_deposits - yield genesis_time - yield deposit_root - - is_triggered = spec.is_genesis_trigger(genesis_deposits, genesis_time, deposit_root) - assert is_triggered is False - - yield is_triggered - - -@with_phases(['phase0']) -@spectest_with_bls_switch -def test_is_genesis_trigger_true(spec): - deposit_count = spec.GENESIS_ACTIVE_VALIDATOR_COUNT - genesis_deposits, deposit_root = prepare_genesis_deposits(spec, deposit_count, spec.MAX_EFFECTIVE_BALANCE) - genesis_time = 1546300800 - - yield genesis_deposits - yield genesis_time - yield deposit_root - - is_triggered = spec.is_genesis_trigger(genesis_deposits, genesis_time, deposit_root) - assert is_triggered is True - - yield is_triggered - - -@with_phases(['phase0']) -@spectest_with_bls_switch -def test_is_genesis_trigger_not_enough_balance(spec): - deposit_count = spec.GENESIS_ACTIVE_VALIDATOR_COUNT - genesis_deposits, deposit_root = prepare_genesis_deposits(spec, deposit_count, spec.MAX_EFFECTIVE_BALANCE - 1) - genesis_time = 1546300800 - yield genesis_deposits - yield genesis_time - yield deposit_root - - is_triggered = spec.is_genesis_trigger(genesis_deposits, genesis_time, deposit_root) - assert is_triggered is False - - yield is_triggered - - -@with_phases(['phase0']) -@spectest_with_bls_switch -def test_genesis(spec): - deposit_count = spec.GENESIS_ACTIVE_VALIDATOR_COUNT - genesis_deposits, deposit_root = prepare_genesis_deposits(spec, deposit_count, spec.MAX_EFFECTIVE_BALANCE) - genesis_time = 1546300800 - block_hash = b'\x12' * 32 - - yield genesis_deposits - yield genesis_time - - genesis_eth1_data = spec.Eth1Data( - deposit_root=deposit_root, - deposit_count=deposit_count, - block_hash=block_hash, - ) - - yield genesis_eth1_data - genesis_state = spec.get_genesis_beacon_state( - genesis_deposits, - genesis_time, - genesis_eth1_data, - ) - - assert genesis_state.genesis_time == genesis_time - assert len(genesis_state.validators) == deposit_count - assert genesis_state.eth1_data.deposit_root == deposit_root - assert genesis_state.eth1_data.deposit_count == deposit_count - assert genesis_state.eth1_data.block_hash == block_hash - - yield genesis_state