mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 05:47:59 -05:00
Indexed paylaod attestation test (#14299)
* test-added * nil check fix * randomized inputs * hardcoded inputs * suggestions applied * minor-typo fixed * deleted
This commit is contained in:
114
consensus-types/epbs/indexed_payload_attestation_test.go
Normal file
114
consensus-types/epbs/indexed_payload_attestation_test.go
Normal file
@@ -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: ð.PayloadAttestationData{
|
||||
Slot: primitives.Slot(1),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Test 2",
|
||||
data: ð.PayloadAttestationData{
|
||||
Slot: primitives.Slot(100),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "Zero slot",
|
||||
data: ð.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)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user