mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-09 15:37:56 -05:00
* config values * block protos * get_committee_indices * proto and ssz * attestation interface * Revert "Auxiliary commit to revert individual files from deadb2183723511721b3288c7168808a4fa97c64" This reverts commit 32ad5009537bc5ec0e6caf9f52143d380d00be85. * todos * get_attesting_indices * Revert "Auxiliary commit to revert individual files from dd2789723f90b15eb1f874b561d88d11dcc9c0bf" This reverts commit f39644ed3cb6f3964fc6c86fdf4bd5de2a9668c8. * beacon spec changes * Fix pending attestation. Build ok * Electra: add electra version * Electra: consensus types * gocognit exclusion * @potuz's suggestion * build fix * interfaces for indexed att and slashing * indexed att usage * BuildSignedBeaconBlockFromExecutionPayload * slashing usage * grpc stubs * remove unused methods * Electra attestation interfaces * cleanup * tests * make linter happy * simple casting * test fixes * Fix spectest failures * Regen pb and ssz files * Handle "not ok" type assertion cases * Setters that check version should always return an error. SetAttesterSlashings and SetAttestations * gofmt * Fix TestMinSpanChunksSlice_CheckSlashable --------- Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Preston Van Loon <preston@pvl.dev>
70 lines
2.7 KiB
Go
70 lines
2.7 KiB
Go
package kv
|
|
|
|
import (
|
|
"sort"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/go-bitfield"
|
|
"github.com/prysmaticlabs/prysm/v5/consensus-types/interfaces"
|
|
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 := []interfaces.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].GetData().Slot < returned[j].GetData().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 := []interfaces.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 := []interfaces.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())
|
|
}
|