mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 10:41:19 +00:00
c20d9ccbb3
* update aggregated * update block att * update forkchoice att * update unaggregated att * gazelle * Use copy * Locks * Genesis time * Fixed tests * Comments * Fixed tests
65 lines
1.9 KiB
Go
65 lines
1.9 KiB
Go
package kv
|
|
|
|
import (
|
|
"reflect"
|
|
"sort"
|
|
"testing"
|
|
|
|
ethpb "github.com/prysmaticlabs/ethereumapis/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
)
|
|
|
|
func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
|
|
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
|
|
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}
|
|
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}
|
|
atts := []*ethpb.Attestation{att1, att2, att3}
|
|
|
|
for _, att := range atts {
|
|
if err := cache.SaveForkchoiceAttestation(att); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
returned := cache.ForkchoiceAttestations()
|
|
|
|
sort.Slice(returned, func(i, j int) bool {
|
|
return returned[i].Data.Slot < returned[j].Data.Slot
|
|
})
|
|
|
|
if !reflect.DeepEqual(atts, returned) {
|
|
t.Error("Did not receive correct aggregated atts")
|
|
}
|
|
}
|
|
|
|
func TestKV_Forkchoice_CanDelete(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
|
|
att1 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}}
|
|
att2 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}}
|
|
att3 := ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}}
|
|
atts := []*ethpb.Attestation{att1, att2, att3}
|
|
|
|
for _, att := range atts {
|
|
if err := cache.SaveForkchoiceAttestation(att); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
if err := cache.DeleteForkchoiceAttestation(att1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := cache.DeleteForkchoiceAttestation(att3); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
returned := cache.ForkchoiceAttestations()
|
|
wanted := []*ethpb.Attestation{att2}
|
|
|
|
if !reflect.DeepEqual(wanted, returned) {
|
|
t.Error("Did not receive correct aggregated atts")
|
|
}
|
|
}
|