-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
90 additions
and
16 deletions.
There are no files selected for viewing
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
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
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,63 @@ | ||
package attestation_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" | ||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" | ||
"github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1/attestation" | ||
"github.com/prysmaticlabs/prysm/v5/testing/assert" | ||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
"github.com/prysmaticlabs/prysm/v5/testing/util" | ||
) | ||
|
||
func TestNewId(t *testing.T) { | ||
t.Run("full source", func(t *testing.T) { | ||
att := util.HydrateAttestation(ðpb.Attestation{}) | ||
_, err := attestation.NewId(att, attestation.Full) | ||
assert.NoError(t, err) | ||
}) | ||
t.Run("data source Phase 0", func(t *testing.T) { | ||
att := util.HydrateAttestation(ðpb.Attestation{}) | ||
_, err := attestation.NewId(att, attestation.Data) | ||
assert.NoError(t, err) | ||
}) | ||
t.Run("data source Electra", func(t *testing.T) { | ||
cb := primitives.NewAttestationCommitteeBits() | ||
cb.SetBitAt(0, true) | ||
att := util.HydrateAttestationElectra(ðpb.AttestationElectra{CommitteeBits: cb}) | ||
_, err := attestation.NewId(att, attestation.Data) | ||
assert.NoError(t, err) | ||
}) | ||
t.Run("ID is different between versions", func(t *testing.T) { | ||
phase0Att := util.HydrateAttestation(ðpb.Attestation{}) | ||
phase0Id, err := attestation.NewId(phase0Att, attestation.Data) | ||
require.NoError(t, err) | ||
cb := primitives.NewAttestationCommitteeBits() | ||
cb.SetBitAt(0, true) // setting committee bit 0 for Electra corresponds to attestation data's committee index 0 for Phase 0 | ||
electraAtt := util.HydrateAttestationElectra(ðpb.AttestationElectra{CommitteeBits: cb}) | ||
electraId, err := attestation.NewId(electraAtt, attestation.Data) | ||
require.NoError(t, err) | ||
|
||
assert.NotEqual(t, phase0Id, electraId) | ||
}) | ||
t.Run("invalid source", func(t *testing.T) { | ||
att := util.HydrateAttestation(ðpb.Attestation{}) | ||
_, err := attestation.NewId(att, 123) | ||
assert.ErrorContains(t, "invalid source requested", err) | ||
}) | ||
t.Run("data source Electra - 0 bits set", func(t *testing.T) { | ||
cb := primitives.NewAttestationCommitteeBits() | ||
att := util.HydrateAttestationElectra(ðpb.AttestationElectra{CommitteeBits: cb}) | ||
_, err := attestation.NewId(att, attestation.Data) | ||
assert.ErrorContains(t, "0 committee bits are set", err) | ||
}) | ||
t.Run("data source Electra - multiple bits set", func(t *testing.T) { | ||
cb := primitives.NewAttestationCommitteeBits() | ||
cb.SetBitAt(0, true) | ||
cb.SetBitAt(1, true) | ||
att := util.HydrateAttestationElectra(ðpb.AttestationElectra{CommitteeBits: cb}) | ||
_, err := attestation.NewId(att, attestation.Data) | ||
assert.ErrorContains(t, "2 committee bits are set", err) | ||
}) | ||
} |