Skip to content

Commit 5c184fc

Browse files
Update a unit test
1 parent b333d36 commit 5c184fc

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

beacon-chain/sync/validate_beacon_blocks_test.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -714,8 +714,21 @@ func TestValidateBeaconBlockPubSub_SeenProposerSlot(t *testing.T) {
714714
msg.Signature, err = signing.ComputeDomainAndSign(beaconState, 0, msg.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
715715
require.NoError(t, err)
716716

717-
chainService := &mock.ChainService{Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
718-
State: beaconState,
717+
// Create a clone of the same block (same signature, not an equivocation)
718+
msgClone := util.NewBeaconBlock()
719+
msgClone.Block.Slot = 1
720+
msgClone.Block.ProposerIndex = proposerIdx
721+
msgClone.Block.ParentRoot = bRoot[:]
722+
msgClone.Signature = msg.Signature // Use the same signature
723+
724+
signedBlock, err := blocks.NewSignedBeaconBlock(msg)
725+
require.NoError(t, err)
726+
727+
slashingPool := &slashingsmock.PoolMock{}
728+
chainService := &mock.ChainService{
729+
Genesis: time.Unix(time.Now().Unix()-int64(params.BeaconConfig().SecondsPerSlot), 0),
730+
State: beaconState,
731+
Block: signedBlock, // Set the first block as the head block
719732
FinalizedCheckPoint: &ethpb.Checkpoint{
720733
Epoch: 0,
721734
Root: make([]byte, 32),
@@ -729,17 +742,23 @@ func TestValidateBeaconBlockPubSub_SeenProposerSlot(t *testing.T) {
729742
chain: chainService,
730743
clock: startup.NewClock(chainService.Genesis, chainService.ValidatorsRoot),
731744
blockNotifier: chainService.BlockNotifier(),
745+
slashingPool: slashingPool,
732746
},
733747
seenBlockCache: lruwrpr.New(10),
734748
badBlockCache: lruwrpr.New(10),
735749
slotToPendingBlocks: gcache.New(time.Second, 2*time.Second),
736750
seenPendingBlocks: make(map[[32]byte]bool),
737751
}
738752

753+
// Mark the proposer/slot as seen
754+
r.setSeenBlockIndexSlot(msg.Block.Slot, msg.Block.ProposerIndex)
755+
time.Sleep(10 * time.Millisecond) // Wait for cached value to pass through buffers
756+
757+
// Prepare and validate the second message (clone)
739758
buf := new(bytes.Buffer)
740-
_, err = p.Encoding().EncodeGossip(buf, msg)
759+
_, err = p.Encoding().EncodeGossip(buf, msgClone)
741760
require.NoError(t, err)
742-
topic := p2p.GossipTypeMapping[reflect.TypeOf(msg)]
761+
topic := p2p.GossipTypeMapping[reflect.TypeOf(msgClone)]
743762
digest, err := r.currentForkDigest()
744763
assert.NoError(t, err)
745764
topic = r.addDigestToTopic(topic, digest)
@@ -749,11 +768,14 @@ func TestValidateBeaconBlockPubSub_SeenProposerSlot(t *testing.T) {
749768
Topic: &topic,
750769
},
751770
}
752-
r.setSeenBlockIndexSlot(msg.Block.Slot, msg.Block.ProposerIndex)
753-
time.Sleep(10 * time.Millisecond) // Wait for cached value to pass through buffers.
771+
772+
// Since this is not an equivocation (same signature), it should be ignored
754773
res, err := r.validateBeaconBlockPubSub(ctx, "", m)
755774
assert.NoError(t, err)
756-
assert.Equal(t, res, pubsub.ValidationIgnore, "seen proposer block should be ignored")
775+
assert.Equal(t, pubsub.ValidationIgnore, res, "block with same signature should be ignored")
776+
777+
// Verify no slashings were created
778+
assert.Equal(t, 0, len(slashingPool.PendingPropSlashings), "Expected no slashings for same signature")
757779
}
758780

759781
func TestValidateBeaconBlockPubSub_FilterByFinalizedEpoch(t *testing.T) {

0 commit comments

Comments
 (0)