-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Indexed paylaod attestation test (#14299)
* test-added * nil check fix * randomized inputs * hardcoded inputs * suggestions applied * minor-typo fixed * deleted
- Loading branch information
1 parent
8032cb5
commit d8e14b1
Showing
1 changed file
with
114 additions
and
0 deletions.
There are no files selected for viewing
114 changes: 114 additions & 0 deletions
114
consensus-types/epbs/indexed_payload_attestation_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: ð.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) | ||
}) | ||
} | ||
} |