From 763e296731287e90b74bc858419070ed95a42cd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mamy=20Andr=C3=A9-Ratsimbazafy?= Date: Tue, 24 Sep 2019 16:56:12 +0200 Subject: [PATCH] Fix and activate the justification and finalization unit tests. --- tests/all_tests.nim | 3 ++- .../justification_finalization_helpers.nim | 11 ++++++----- .../test_process_justification_and_finalization.nim | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/tests/all_tests.nim b/tests/all_tests.nim index 5be8646b1..44b71215f 100644 --- a/tests/all_tests.nim +++ b/tests/all_tests.nim @@ -23,7 +23,8 @@ import # Refactor state transition unit tests ./spec_block_processing/test_genesis, ./spec_block_processing/test_process_deposits, ./spec_block_processing/test_process_attestation, - ./spec_epoch_processing/test_process_crosslinks + ./spec_epoch_processing/test_process_crosslinks, + ./spec_epoch_processing/test_process_justification_and_finalization import # Official fixtures that don't require SSZ parsing of invalid BLS signatures # https://github.com/status-im/nim-beacon-chain/issues/374 diff --git a/tests/spec_epoch_processing/justification_finalization_helpers.nim b/tests/spec_epoch_processing/justification_finalization_helpers.nim index 0565f5a19..2cea2ef83 100644 --- a/tests/spec_epoch_processing/justification_finalization_helpers.nim +++ b/tests/spec_epoch_processing/justification_finalization_helpers.nim @@ -29,18 +29,19 @@ iterator getShardsForSlot(state: BeaconState, slot: Slot): Shard = yield shard + Shard(i) proc addMockAttestations*( - state: BeaconState, epoch: Epoch, + state: var BeaconState, epoch: Epoch, source, target: Checkpoint, sufficient_support = false ) = # We must be at the end of the epoch doAssert (state.slot + 1) mod SLOTS_PER_EPOCH == 0 - var attestations: seq[PendingAttestation] + # Alias the attestations container + var attestations: ptr seq[PendingAttestation] if state.get_current_epoch() == epoch: - attestations = state.current_epoch_attestations + attestations = state.current_epoch_attestations.addr elif state.get_previous_epoch() == epoch: - attestations = state.previous_epoch_attestations + attestations = state.previous_epoch_attestations.addr else: raise newException(ValueError, &"Cannot include attestations from epoch {state.get_current_epoch()} in epoch {epoch}") @@ -79,7 +80,7 @@ proc addMockAttestations*( if idx != -1: aggregation_bits[idx] = false - attestations.add PendingAttestation( + attestations[].add PendingAttestation( aggregation_bits: aggregation_bits, data: AttestationData( beacon_block_root: [byte 0xFF] * 32, # Irrelevant for testing diff --git a/tests/spec_epoch_processing/test_process_justification_and_finalization.nim b/tests/spec_epoch_processing/test_process_justification_and_finalization.nim index 511929e01..d1ed25cc8 100644 --- a/tests/spec_epoch_processing/test_process_justification_and_finalization.nim +++ b/tests/spec_epoch_processing/test_process_justification_and_finalization.nim @@ -51,7 +51,7 @@ proc finalizeOn234(state: var BeaconState, epoch: Epoch, sufficient_support: boo # mock the 2nd latest epoch as justifiable, with 4th as the source addMockAttestations( state, - epoch = epoch - 1, + epoch = epoch - 2, source = c4, target = c2, sufficient_support = sufficient_support