Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Indexed paylaod attestation test #14299

Merged
merged 7 commits into from
Aug 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 114 additions & 0 deletions consensus-types/epbs/indexed_payload_attestation_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package epbs

import (
"testing"

"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives"
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v5/testing/require"
)

func TestGetAttestingIndices(t *testing.T) {
testCases := []struct {
name string
attestingIndices []primitives.ValidatorIndex
}{
{
name: "Test 1",
attestingIndices: []primitives.ValidatorIndex{1, 2, 3},
},
{
name: "Test 2",
attestingIndices: []primitives.ValidatorIndex{55, 66, 787},
},
{
name: "Empty AttestingIndices",
attestingIndices: []primitives.ValidatorIndex{},
},
{
name: "Nil AttestingIndices",
attestingIndices: []primitives.ValidatorIndex(nil),
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
pa := &IndexedPayloadAttestation{
AttestingIndices: tt.attestingIndices,
}
got := pa.GetAttestingIndices()
require.DeepEqual(t, tt.attestingIndices, got)
})
}
}

func TestGetData(t *testing.T) {
testCases := []struct {
name string
data *eth.PayloadAttestationData
}{
{
name: "Test 1",
data: &eth.PayloadAttestationData{
Slot: primitives.Slot(1),
},
},
{
name: "Test 2",
data: &eth.PayloadAttestationData{
Slot: primitives.Slot(100),
},
},
{
name: "Zero slot",
data: &eth.PayloadAttestationData{
Slot: primitives.Slot(0),
},
},
{
name: "Nil slot",
data: nil,
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
pa := &IndexedPayloadAttestation{
Data: tt.data,
}
got := pa.GetData()
require.DeepEqual(t, tt.data, got)
})
}
}

func TestGetSignature(t *testing.T) {
testCases := []struct {
name string
sig []byte
}{
{
name: "Test 1",
sig: []byte{1, 2},
},
{
name: "Test 2",
sig: []byte{29, 100},
},
{
name: "Zero signature",
sig: []byte{0},
},
{
name: "Nil signature",
sig: nil,
},
}
for _, tt := range testCases {
t.Run(tt.name, func(t *testing.T) {
pa := &IndexedPayloadAttestation{
Signature: tt.sig,
}
got := pa.GetSignature()
require.DeepEqual(t, tt.sig, got)
})
}
}
Loading