mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-05 09:14:28 +00:00
5a66807989
* First take at updating everything to v5 * Patch gRPC gateway to use prysm v5 Fix patch * Update go ssz --------- Co-authored-by: Preston Van Loon <pvanloon@offchainlabs.com>
69 lines
2.6 KiB
Go
69 lines
2.6 KiB
Go
package kv
|
|
|
|
import (
|
|
"sort"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/assert"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/require"
|
|
"github.com/prysmaticlabs/prysm/v5/testing/util"
|
|
)
|
|
|
|
func TestKV_Forkchoice_CanSaveRetrieve(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
|
|
att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}})
|
|
att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}})
|
|
att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}})
|
|
atts := []*ethpb.Attestation{att1, att2, att3}
|
|
|
|
for _, att := range atts {
|
|
require.NoError(t, cache.SaveForkchoiceAttestation(att))
|
|
}
|
|
|
|
returned := cache.ForkchoiceAttestations()
|
|
|
|
sort.Slice(returned, func(i, j int) bool {
|
|
return returned[i].Data.Slot < returned[j].Data.Slot
|
|
})
|
|
|
|
assert.DeepEqual(t, atts, returned)
|
|
}
|
|
|
|
func TestKV_Forkchoice_CanDelete(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
|
|
att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}})
|
|
att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}})
|
|
att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}})
|
|
atts := []*ethpb.Attestation{att1, att2, att3}
|
|
|
|
for _, att := range atts {
|
|
require.NoError(t, cache.SaveForkchoiceAttestation(att))
|
|
}
|
|
|
|
require.NoError(t, cache.DeleteForkchoiceAttestation(att1))
|
|
require.NoError(t, cache.DeleteForkchoiceAttestation(att3))
|
|
|
|
returned := cache.ForkchoiceAttestations()
|
|
wanted := []*ethpb.Attestation{att2}
|
|
assert.DeepEqual(t, wanted, returned)
|
|
}
|
|
|
|
func TestKV_Forkchoice_CanCount(t *testing.T) {
|
|
cache := NewAttCaches()
|
|
|
|
att1 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 1}, AggregationBits: bitfield.Bitlist{0b1101}})
|
|
att2 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 2}, AggregationBits: bitfield.Bitlist{0b1101}})
|
|
att3 := util.HydrateAttestation(ðpb.Attestation{Data: ðpb.AttestationData{Slot: 3}, AggregationBits: bitfield.Bitlist{0b1101}})
|
|
atts := []*ethpb.Attestation{att1, att2, att3}
|
|
|
|
for _, att := range atts {
|
|
require.NoError(t, cache.SaveForkchoiceAttestation(att))
|
|
}
|
|
|
|
require.Equal(t, 3, cache.ForkchoiceAttestationCount())
|
|
}
|