@@ -41,7 +41,7 @@ func TestKV_Aggregated_AggregateUnaggregatedAttestations(t *testing.T) {
4141 }
4242}
4343
44- func TestKV_Aggregated_SaveUnaggregatedAttestation (t * testing.T ) {
44+ func TestKV_Aggregated_SaveAggregatedAttestation (t * testing.T ) {
4545 tests := []struct {
4646 name string
4747 att * ethpb.Attestation
@@ -101,7 +101,47 @@ func TestKV_Aggregated_SaveUnaggregatedAttestation(t *testing.T) {
101101 return
102102 }
103103 if len (cache .aggregatedAtt ) != tt .count {
104- t .Errorf ("Wrong attestation count, want: %d, got: %d" , tt .count , len (cache .unAggregatedAtt ))
104+ t .Errorf ("Wrong attestation count, want: %d, got: %d" , tt .count , len (cache .aggregatedAtt ))
105+ }
106+ if cache .AggregatedAttestationCount () != tt .count {
107+ t .Errorf ("Wrong attestation count, want: %d, got: %d" , tt .count , cache .AggregatedAttestationCount ())
108+ }
109+ })
110+ }
111+ }
112+
113+ func TestKV_Aggregated_SaveAggregatedAttestations (t * testing.T ) {
114+ tests := []struct {
115+ name string
116+ atts []* ethpb.Attestation
117+ count int
118+ wantErrString string
119+ }{
120+ {
121+ name : "no duplicates" ,
122+ atts : []* ethpb.Attestation {
123+ {Data : & ethpb.AttestationData {Slot : 1 },
124+ AggregationBits : bitfield.Bitlist {0b1101 }},
125+ {Data : & ethpb.AttestationData {Slot : 1 },
126+ AggregationBits : bitfield.Bitlist {0b1101 }},
127+ },
128+ count : 1 ,
129+ },
130+ }
131+
132+ for _ , tt := range tests {
133+ t .Run (tt .name , func (t * testing.T ) {
134+ cache := NewAttCaches ()
135+ if len (cache .aggregatedAtt ) != 0 {
136+ t .Errorf ("Invalid start pool, atts: %d" , len (cache .unAggregatedAtt ))
137+ }
138+ err := cache .SaveAggregatedAttestations (tt .atts )
139+ if tt .wantErrString == "" && err != nil {
140+ t .Error (err )
141+ return
142+ }
143+ if len (cache .aggregatedAtt ) != tt .count {
144+ t .Errorf ("Wrong attestation count, want: %d, got: %d" , tt .count , len (cache .aggregatedAtt ))
105145 }
106146 if cache .AggregatedAttestationCount () != tt .count {
107147 t .Errorf ("Wrong attestation count, want: %d, got: %d" , tt .count , cache .AggregatedAttestationCount ())
0 commit comments