mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-08 07:03:58 -05:00
85 lines
3.4 KiB
Go
85 lines
3.4 KiB
Go
package client
|
|
|
|
import (
|
|
"testing"
|
|
|
|
field_params "github.com/OffchainLabs/prysm/v7/config/fieldparams"
|
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
|
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
|
"github.com/OffchainLabs/prysm/v7/testing/assert"
|
|
"github.com/OffchainLabs/prysm/v7/testing/require"
|
|
"github.com/OffchainLabs/prysm/v7/testing/util"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestLogSubmittedAtts(t *testing.T) {
|
|
t.Run("phase0 attestations", func(t *testing.T) {
|
|
logHook := logTest.NewGlobal()
|
|
v := validator{
|
|
submittedAtts: make(map[submittedAttKey]*submittedAtt),
|
|
}
|
|
att := util.HydrateAttestation(ðpb.Attestation{})
|
|
att.Data.CommitteeIndex = 12
|
|
require.NoError(t, v.saveSubmittedAtt(att, make([]byte, field_params.BLSPubkeyLength), false))
|
|
v.LogSubmittedAtts(0)
|
|
assert.LogsContain(t, logHook, "committeeIndices=\"[12]\"")
|
|
})
|
|
t.Run("electra attestations", func(t *testing.T) {
|
|
logHook := logTest.NewGlobal()
|
|
v := validator{
|
|
submittedAtts: make(map[submittedAttKey]*submittedAtt),
|
|
}
|
|
att := util.HydrateAttestationElectra(ðpb.AttestationElectra{})
|
|
att.Data.CommitteeIndex = 0
|
|
att.CommitteeBits = primitives.NewAttestationCommitteeBits()
|
|
att.CommitteeBits.SetBitAt(44, true)
|
|
require.NoError(t, v.saveSubmittedAtt(att, make([]byte, field_params.BLSPubkeyLength), false))
|
|
v.LogSubmittedAtts(0)
|
|
assert.LogsContain(t, logHook, "committeeIndices=\"[44]\"")
|
|
})
|
|
t.Run("electra attestations multiple saved", func(t *testing.T) {
|
|
logHook := logTest.NewGlobal()
|
|
v := validator{
|
|
submittedAtts: make(map[submittedAttKey]*submittedAtt),
|
|
}
|
|
att := util.HydrateAttestationElectra(ðpb.AttestationElectra{})
|
|
att.Data.CommitteeIndex = 0
|
|
att.CommitteeBits = primitives.NewAttestationCommitteeBits()
|
|
att.CommitteeBits.SetBitAt(23, true)
|
|
require.NoError(t, v.saveSubmittedAtt(att, make([]byte, field_params.BLSPubkeyLength), false))
|
|
att2 := util.HydrateAttestationElectra(ðpb.AttestationElectra{})
|
|
att2.Data.CommitteeIndex = 0
|
|
att2.CommitteeBits = primitives.NewAttestationCommitteeBits()
|
|
att2.CommitteeBits.SetBitAt(2, true)
|
|
require.NoError(t, v.saveSubmittedAtt(att2, make([]byte, field_params.BLSPubkeyLength), false))
|
|
v.LogSubmittedAtts(0)
|
|
assert.LogsContain(t, logHook, "committeeIndices=\"[23 2]\"")
|
|
})
|
|
t.Run("phase0 aggregates", func(t *testing.T) {
|
|
logHook := logTest.NewGlobal()
|
|
v := validator{
|
|
submittedAggregates: make(map[submittedAttKey]*submittedAtt),
|
|
}
|
|
agg := ðpb.AggregateAttestationAndProof{}
|
|
agg.Aggregate = util.HydrateAttestation(ðpb.Attestation{})
|
|
agg.Aggregate.Data.CommitteeIndex = 12
|
|
require.NoError(t, v.saveSubmittedAtt(agg.AggregateVal(), make([]byte, field_params.BLSPubkeyLength), true))
|
|
v.LogSubmittedAtts(0)
|
|
assert.LogsContain(t, logHook, "committeeIndices=\"[12]\"")
|
|
})
|
|
t.Run("electra aggregates", func(t *testing.T) {
|
|
logHook := logTest.NewGlobal()
|
|
v := validator{
|
|
submittedAggregates: make(map[submittedAttKey]*submittedAtt),
|
|
}
|
|
agg := ðpb.AggregateAttestationAndProofElectra{}
|
|
agg.Aggregate = util.HydrateAttestationElectra(ðpb.AttestationElectra{})
|
|
agg.Aggregate.Data.CommitteeIndex = 0
|
|
agg.Aggregate.CommitteeBits = primitives.NewAttestationCommitteeBits()
|
|
agg.Aggregate.CommitteeBits.SetBitAt(63, true)
|
|
require.NoError(t, v.saveSubmittedAtt(agg.AggregateVal(), make([]byte, field_params.BLSPubkeyLength), true))
|
|
v.LogSubmittedAtts(0)
|
|
assert.LogsContain(t, logHook, "committeeIndices=\"[63]\"")
|
|
})
|
|
}
|