From 1a663308d8bed99e6a9ae7bcc68becc68e94d636 Mon Sep 17 00:00:00 2001 From: markolazic01 Date: Fri, 5 Jun 2026 14:14:47 +0200 Subject: [PATCH 1/3] fix: make isAttestation handler work with negative tests --- .../test/spec/presets/fork_choice.test.ts | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/packages/beacon-node/test/spec/presets/fork_choice.test.ts b/packages/beacon-node/test/spec/presets/fork_choice.test.ts index 728e5044ef76..d09781f28f89 100644 --- a/packages/beacon-node/test/spec/presets/fork_choice.test.ts +++ b/packages/beacon-node/test/spec/presets/fork_choice.test.ts @@ -179,15 +179,21 @@ const forkChoiceTest = // attestation step else if (isAttestation(step)) { - logger.debug(`Step ${i}/${stepsLen} attestation`, {root: step.attestation, valid: Boolean(step.valid)}); + const isValid = Boolean(step.valid ?? true); + logger.debug(`Step ${i}/${stepsLen} attestation`, {root: step.attestation, valid: isValid}); const attestation = testcase.attestations.get(step.attestation); if (!attestation) throw Error(`No attestation ${step.attestation}`); const headState = chain.getHeadState() as BeaconStateView; const attDataRootHex = toHexString(sszTypesFor(fork).AttestationData.hashTreeRoot(attestation.data)); - chain.forkChoice.onAttestation( - headState.cachedState.epochCtx.getIndexedAttestation(ForkSeq[fork], attestation), - attDataRootHex - ); + try { + chain.forkChoice.onAttestation( + headState.cachedState.epochCtx.getIndexedAttestation(ForkSeq[fork], attestation), + attDataRootHex + ); + if (!isValid) throw Error("Expect error since this is a negative test"); + } catch (e) { + if (isValid || (e as Error).message === "Expect error since this is a negative test") throw e; + } } // attester slashing step @@ -635,12 +641,7 @@ const forkChoiceTest = // unconditionally. Only the altair vectors exercise the changed condition (other forks pass). name.endsWith("altair/fork_choice/on_block/pyspec_tests/justified_update_always_if_better") || name.endsWith("altair/fork_choice/on_block/pyspec_tests/justified_update_not_realized_finality") || - name.endsWith("altair/fork_choice/get_head/pyspec_tests/voting_source_beyond_two_epoch") || - // TODO GLOAS: re-enable after the validate_on_attestation payload-status updates - // (consensus-specs #5275) are implemented. New gloas on_attestation vectors in v1.7.0-alpha.9. - name.endsWith("validate_on_attestation_beacon_root_payload_check") || - name.endsWith("validate_on_attestation_payload_invalid_index") || - name.endsWith("validate_on_attestation_same_slot_full_vote_rejected"), + name.endsWith("altair/fork_choice/get_head/pyspec_tests/voting_source_beyond_two_epoch") }, }; }; From f3c81e7a829f537b21b2fbdb40d11c1bd936b36e Mon Sep 17 00:00:00 2001 From: markolazic01 Date: Fri, 5 Jun 2026 14:24:18 +0200 Subject: [PATCH 2/3] chore: move test setup out of the try block --- packages/beacon-node/test/spec/presets/fork_choice.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/beacon-node/test/spec/presets/fork_choice.test.ts b/packages/beacon-node/test/spec/presets/fork_choice.test.ts index 4eca6fa9fd23..f917cf225a35 100644 --- a/packages/beacon-node/test/spec/presets/fork_choice.test.ts +++ b/packages/beacon-node/test/spec/presets/fork_choice.test.ts @@ -189,9 +189,10 @@ const forkChoiceTest = if (!attestation) throw Error(`No attestation ${step.attestation}`); const headState = chain.getHeadState() as BeaconStateView; const attDataRootHex = toHexString(sszTypesFor(fork).AttestationData.hashTreeRoot(attestation.data)); + const indexedAttestation = headState.cachedState.epochCtx.getIndexedAttestation(ForkSeq[fork], attestation); try { chain.forkChoice.onAttestation( - headState.cachedState.epochCtx.getIndexedAttestation(ForkSeq[fork], attestation), + indexedAttestation, attDataRootHex ); if (!isValid) throw Error("Expect error since this is a negative test"); From f2900ebe1f6a2fe8786cff36fed72016a7bbb83e Mon Sep 17 00:00:00 2001 From: markolazic01 Date: Fri, 5 Jun 2026 14:25:50 +0200 Subject: [PATCH 3/3] chore: format code --- .../test/spec/presets/fork_choice.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/beacon-node/test/spec/presets/fork_choice.test.ts b/packages/beacon-node/test/spec/presets/fork_choice.test.ts index f917cf225a35..cdd8cb3109cc 100644 --- a/packages/beacon-node/test/spec/presets/fork_choice.test.ts +++ b/packages/beacon-node/test/spec/presets/fork_choice.test.ts @@ -189,12 +189,12 @@ const forkChoiceTest = if (!attestation) throw Error(`No attestation ${step.attestation}`); const headState = chain.getHeadState() as BeaconStateView; const attDataRootHex = toHexString(sszTypesFor(fork).AttestationData.hashTreeRoot(attestation.data)); - const indexedAttestation = headState.cachedState.epochCtx.getIndexedAttestation(ForkSeq[fork], attestation); + const indexedAttestation = headState.cachedState.epochCtx.getIndexedAttestation( + ForkSeq[fork], + attestation + ); try { - chain.forkChoice.onAttestation( - indexedAttestation, - attDataRootHex - ); + chain.forkChoice.onAttestation(indexedAttestation, attDataRootHex); if (!isValid) throw Error("Expect error since this is a negative test"); } catch (e) { if (isValid || (e as Error).message === "Expect error since this is a negative test") throw e; @@ -745,7 +745,7 @@ const forkChoiceTest = // unconditionally. Only the altair vectors exercise the changed condition (other forks pass). name.endsWith("altair/fork_choice/on_block/pyspec_tests/justified_update_always_if_better") || name.endsWith("altair/fork_choice/on_block/pyspec_tests/justified_update_not_realized_finality") || - name.endsWith("altair/fork_choice/get_head/pyspec_tests/voting_source_beyond_two_epoch") + name.endsWith("altair/fork_choice/get_head/pyspec_tests/voting_source_beyond_two_epoch"), }, }; };