From 55e17fb1f7d01db05b2135c5e302900655e64cb3 Mon Sep 17 00:00:00 2001 From: lsankar4033 Date: Mon, 15 Jun 2020 18:42:15 -0700 Subject: [PATCH] Add compute_subnet_for_attestation unittest --- .../test/validator/test_validator_unittest.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/core/pyspec/eth2spec/test/validator/test_validator_unittest.py b/tests/core/pyspec/eth2spec/test/validator/test_validator_unittest.py index 0ac1e7b46..09ceebad4 100644 --- a/tests/core/pyspec/eth2spec/test/validator/test_validator_unittest.py +++ b/tests/core/pyspec/eth2spec/test/validator/test_validator_unittest.py @@ -349,6 +349,22 @@ def test_get_attestation_signature(spec, state): ) +@with_all_phases +@spec_state_test +def test_compute_subnet_for_attestation(spec, state): + for committee_idx in range(spec.MAX_COMMITTEES_PER_SLOT): + for slot in range(state.slot, state.slot + spec.SLOTS_PER_EPOCH): + actual_subnet_id = spec.compute_subnet_for_attestation(state, slot, committee_idx) + + slots_since_epoch_start = slot % spec.SLOTS_PER_EPOCH + committees_since_epoch_start = spec.get_committee_count_at_slot( + state, slot) * slots_since_epoch_start + expected_subnet_id = (committees_since_epoch_start + + committee_idx) % spec.ATTESTATION_SUBNET_COUNT + + assert actual_subnet_id == expected_subnet_id + + # Attestation aggregation