mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
d3494045a2
* Use state util to get block root * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge branch 'master' of github.com:prysmaticlabs/prysm * Merge branch 'master' of github.com:prysmaticlabs/prysm * Add UnaggregatedAttestationsBySlotIndex * Tests * New TestSubmitAggregateAndProof_UnaggregateOk test * Merge branch 'master' of github.com:prysmaticlabs/prysm into fix-aggregator-broadcast
82 lines
2.6 KiB
Go
82 lines
2.6 KiB
Go
package kv
|
|
|
|
import (
|
|
"reflect"
|
|
"strings"
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
)
|
|
|
|
func TestKV_Unaggregated_AlreadyAggregated(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
|
|
att := ðpb.Attestation{AggregationBits: bitfield.Bitlist{0b111}}
|
|
|
|
wanted := "attestation is aggregated"
|
|
if err := cache.SaveUnaggregatedAttestation(att); !strings.Contains(err.Error(), wanted) {
|
|
t.Error("Did not received wanted error")
|
|
}
|
|
}
|
|
|
|
func TestKV_Unaggregated_CanDelete(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
|
|
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b101}}
|
|
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b110}}
|
|
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b110}}
|
|
atts := []*ethpb.Attestation{att1, att2, att3}
|
|
|
|
for _, att := range atts {
|
|
if err := cache.SaveUnaggregatedAttestation(att); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
if err := cache.DeleteUnaggregatedAttestation(att1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := cache.DeleteUnaggregatedAttestation(att2); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := cache.DeleteUnaggregatedAttestation(att3); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
returned := cache.UnaggregatedAttestations()
|
|
|
|
if !reflect.DeepEqual([]*ethpb.Attestation{}, returned) {
|
|
t.Error("Did not receive correct aggregated atts")
|
|
}
|
|
}
|
|
|
|
func TestKV_Unaggregated_CanGetByCommitteeAndSlot(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
|
|
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b101}}
|
|
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1, CommitteeIndex: 2}, AggregationBits: bitfield.Bitlist{0b110}}
|
|
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2, CommitteeIndex: 1}, AggregationBits: bitfield.Bitlist{0b110}}
|
|
atts := []*ethpb.Attestation{att1, att2, att3}
|
|
|
|
for _, att := range atts {
|
|
if err := cache.SaveUnaggregatedAttestation(att); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
returned := cache.UnaggregatedAttestationsBySlotIndex(1, 1)
|
|
if !reflect.DeepEqual([]*ethpb.Attestation{att1}, returned) {
|
|
t.Error("Did not receive correct aggregated atts")
|
|
}
|
|
returned = cache.UnaggregatedAttestationsBySlotIndex(1, 2)
|
|
if !reflect.DeepEqual([]*ethpb.Attestation{att2}, returned) {
|
|
t.Error("Did not receive correct aggregated atts")
|
|
}
|
|
returned = cache.UnaggregatedAttestationsBySlotIndex(2, 1)
|
|
if !reflect.DeepEqual([]*ethpb.Attestation{att3}, returned) {
|
|
t.Error("Did not receive correct aggregated atts")
|
|
}
|
|
}
|