mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 20:20:05 +00:00
963acefe12
Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com> Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com> Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> Co-authored-by: kasey <489222+kasey@users.noreply.github.com> Co-authored-by: Dan Loewenherz <dloewenherz.adm@gmail.com> Co-authored-by: prestonvanloon <preston@prysmaticlabs.com> Co-authored-by: Fredrik Svantes <fredrik@ethereum.org> Co-authored-by: Leo Lara <leolara@users.noreply.github.com>
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
package v3
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/encoding/bytesutil"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/testing/require"
|
|
)
|
|
|
|
func TestBeaconState_LatestBlockHeader(t *testing.T) {
|
|
s, err := InitializeFromProto(ðpb.BeaconStateBellatrix{})
|
|
require.NoError(t, err)
|
|
got := s.LatestBlockHeader()
|
|
require.DeepEqual(t, (*ethpb.BeaconBlockHeader)(nil), got)
|
|
|
|
want := ðpb.BeaconBlockHeader{Slot: 100}
|
|
s, err = InitializeFromProto(ðpb.BeaconStateBellatrix{LatestBlockHeader: want})
|
|
require.NoError(t, err)
|
|
got = s.LatestBlockHeader()
|
|
require.DeepEqual(t, want, got)
|
|
|
|
// Test copy does not mutate.
|
|
got.Slot = 101
|
|
require.DeepNotEqual(t, want, got)
|
|
}
|
|
|
|
func TestBeaconState_BlockRoots(t *testing.T) {
|
|
s, err := InitializeFromProto(ðpb.BeaconStateBellatrix{})
|
|
require.NoError(t, err)
|
|
got := s.BlockRoots()
|
|
require.DeepEqual(t, ([][]byte)(nil), got)
|
|
|
|
want := [][]byte{{'a'}}
|
|
s, err = InitializeFromProto(ðpb.BeaconStateBellatrix{BlockRoots: want})
|
|
require.NoError(t, err)
|
|
got = s.BlockRoots()
|
|
require.DeepEqual(t, want, got)
|
|
|
|
// Test copy does not mutate.
|
|
got[0][0] = 'b'
|
|
require.DeepNotEqual(t, want, got)
|
|
}
|
|
|
|
func TestBeaconState_BlockRootAtIndex(t *testing.T) {
|
|
s, err := InitializeFromProto(ðpb.BeaconStateBellatrix{})
|
|
require.NoError(t, err)
|
|
got, err := s.BlockRootAtIndex(0)
|
|
require.NoError(t, err)
|
|
require.DeepEqual(t, ([]byte)(nil), got)
|
|
|
|
r := [][]byte{{'a'}}
|
|
s, err = InitializeFromProto(ðpb.BeaconStateBellatrix{BlockRoots: r})
|
|
require.NoError(t, err)
|
|
got, err = s.BlockRootAtIndex(0)
|
|
require.NoError(t, err)
|
|
want := bytesutil.PadTo([]byte{'a'}, 32)
|
|
require.DeepSSZEqual(t, want, got)
|
|
}
|