2022-05-09 13:02:34 +00:00
|
|
|
package state_native
|
2022-01-13 11:23:53 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2023-03-17 18:52:56 +00:00
|
|
|
ethpb "github.com/prysmaticlabs/prysm/v4/proto/prysm/v1alpha1"
|
|
|
|
"github.com/prysmaticlabs/prysm/v4/testing/require"
|
2022-01-13 11:23:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestBeaconState_PreviousEpochAttestations(t *testing.T) {
|
2022-05-09 13:02:34 +00:00
|
|
|
s, err := InitializeFromProtoPhase0(ðpb.BeaconState{})
|
2022-01-13 11:23:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
atts, err := s.PreviousEpochAttestations()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.DeepEqual(t, []*ethpb.PendingAttestation(nil), atts)
|
|
|
|
|
|
|
|
want := []*ethpb.PendingAttestation{{ProposerIndex: 100}}
|
2022-05-09 13:02:34 +00:00
|
|
|
s, err = InitializeFromProtoPhase0(ðpb.BeaconState{PreviousEpochAttestations: want})
|
2022-01-13 11:23:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
got, err := s.PreviousEpochAttestations()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.DeepEqual(t, want, got)
|
|
|
|
|
|
|
|
// Test copy does not mutate.
|
|
|
|
got[0].ProposerIndex = 101
|
|
|
|
require.DeepNotEqual(t, want, got)
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestBeaconState_CurrentEpochAttestations(t *testing.T) {
|
2022-05-09 13:02:34 +00:00
|
|
|
s, err := InitializeFromProtoPhase0(ðpb.BeaconState{})
|
2022-01-13 11:23:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
atts, err := s.CurrentEpochAttestations()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.DeepEqual(t, []*ethpb.PendingAttestation(nil), atts)
|
|
|
|
|
|
|
|
want := []*ethpb.PendingAttestation{{ProposerIndex: 101}}
|
2022-05-09 13:02:34 +00:00
|
|
|
s, err = InitializeFromProtoPhase0(ðpb.BeaconState{CurrentEpochAttestations: want})
|
2022-01-13 11:23:53 +00:00
|
|
|
require.NoError(t, err)
|
|
|
|
got, err := s.CurrentEpochAttestations()
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.DeepEqual(t, want, got)
|
|
|
|
|
|
|
|
// Test copy does not mutate.
|
|
|
|
got[0].ProposerIndex = 102
|
|
|
|
require.DeepNotEqual(t, want, got)
|
|
|
|
}
|