@@ -17,6 +17,24 @@ import (
1717 "github.com/prysmaticlabs/prysm/v5/testing/util"
1818)
1919
20+ func TestKV_Unaggregated_UnaggregatedAttestations (t * testing.T ) {
21+ t .Run ("not returned when hasSeenBit fails" , func (t * testing.T ) {
22+ att := util .HydrateAttestation (& ethpb.Attestation {Data : & ethpb.AttestationData {Slot : 1 }, AggregationBits : bitfield.Bitlist {0b101 }})
23+ id , err := attestation .NewId (att , attestation .Data )
24+ require .NoError (t , err )
25+
26+ cache := NewAttCaches ()
27+ require .NoError (t , cache .SaveUnaggregatedAttestation (att ))
28+ cache .seenAtt .Delete (id .String ())
29+ // cache a bitlist whose length is different from the attestation bitlist's length
30+ cache .seenAtt .Set (id .String (), []bitfield.Bitlist {{0b1001 }}, c .DefaultExpiration )
31+
32+ atts , err := cache .UnaggregatedAttestations ()
33+ require .NoError (t , err )
34+ assert .Equal (t , 0 , len (atts ))
35+ })
36+ }
37+
2038func TestKV_Unaggregated_SaveUnaggregatedAttestation (t * testing.T ) {
2139 tests := []struct {
2240 name string
@@ -155,6 +173,21 @@ func TestKV_Unaggregated_DeleteUnaggregatedAttestation(t *testing.T) {
155173 require .NoError (t , err )
156174 assert .DeepEqual (t , []ethpb.Att {}, returned )
157175 })
176+
177+ t .Run ("deleted when insertSeenBit fails" , func (t * testing.T ) {
178+ att := util .HydrateAttestation (& ethpb.Attestation {Data : & ethpb.AttestationData {Slot : 1 }, AggregationBits : bitfield.Bitlist {0b101 }})
179+ id , err := attestation .NewId (att , attestation .Data )
180+ require .NoError (t , err )
181+
182+ cache := NewAttCaches ()
183+ require .NoError (t , cache .SaveUnaggregatedAttestation (att ))
184+ cache .seenAtt .Delete (id .String ())
185+ // cache a bitlist whose length is different from the attestation bitlist's length
186+ cache .seenAtt .Set (id .String (), []bitfield.Bitlist {{0b1001 }}, c .DefaultExpiration )
187+
188+ require .NoError (t , cache .DeleteUnaggregatedAttestation (att ))
189+ assert .Equal (t , 0 , len (cache .unAggregatedAtt ), "Attestation was not deleted" )
190+ })
158191}
159192
160193func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations (t * testing.T ) {
@@ -232,6 +265,23 @@ func TestKV_Unaggregated_DeleteSeenUnaggregatedAttestations(t *testing.T) {
232265 require .NoError (t , err )
233266 assert .DeepEqual (t , []ethpb.Att {}, returned )
234267 })
268+
269+ t .Run ("deleted when hasSeenBit fails" , func (t * testing.T ) {
270+ att := util .HydrateAttestation (& ethpb.Attestation {Data : & ethpb.AttestationData {Slot : 1 }, AggregationBits : bitfield.Bitlist {0b101 }})
271+ id , err := attestation .NewId (att , attestation .Data )
272+ require .NoError (t , err )
273+
274+ cache := NewAttCaches ()
275+ require .NoError (t , cache .SaveUnaggregatedAttestation (att ))
276+ cache .seenAtt .Delete (id .String ())
277+ // cache a bitlist whose length is different from the attestation bitlist's length
278+ cache .seenAtt .Set (id .String (), []bitfield.Bitlist {{0b1001 }}, c .DefaultExpiration )
279+
280+ count , err := cache .DeleteSeenUnaggregatedAttestations ()
281+ require .NoError (t , err )
282+ assert .Equal (t , 1 , count )
283+ assert .Equal (t , 0 , len (cache .unAggregatedAtt ), "Attestation was not deleted" )
284+ })
235285}
236286
237287func TestKV_Unaggregated_UnaggregatedAttestationsBySlotIndex (t * testing.T ) {
0 commit comments