mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-08 18:51:19 +00:00
State/v1: add atts and block roots getter tests (#9255)
* Add att and block getter tests * Update BUILD.bazel * Update getters_attestation_test.go * Update beacon-chain/state/v1/getters_block_test.go Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com> * Fix mutation tests Co-authored-by: Raul Jordan <raul@prysmaticlabs.com> Co-authored-by: Preston Van Loon <preston@prysmaticlabs.com>
This commit is contained in:
parent
5864795ca5
commit
526596a679
@ -74,6 +74,8 @@ go_test(
|
||||
name = "go_default_test",
|
||||
srcs = [
|
||||
"field_trie_test.go",
|
||||
"getters_attestation_test.go",
|
||||
"getters_block_test.go",
|
||||
"getters_test.go",
|
||||
"getters_validator_test.go",
|
||||
"helpers_test.go",
|
||||
|
46
beacon-chain/state/v1/getters_attestation_test.go
Normal file
46
beacon-chain/state/v1/getters_attestation_test.go
Normal file
@ -0,0 +1,46 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_PreviousEpochAttestations(t *testing.T) {
|
||||
s, err := InitializeFromProto(&pbp2p.BeaconState{})
|
||||
require.NoError(t, err)
|
||||
atts, err := s.PreviousEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, []*pbp2p.PendingAttestation(nil), atts)
|
||||
|
||||
want := []*pbp2p.PendingAttestation{{ProposerIndex: 100}}
|
||||
s, err = InitializeFromProto(&pbp2p.BeaconState{PreviousEpochAttestations: want})
|
||||
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) {
|
||||
s, err := InitializeFromProto(&pbp2p.BeaconState{})
|
||||
require.NoError(t, err)
|
||||
atts, err := s.CurrentEpochAttestations()
|
||||
require.NoError(t, err)
|
||||
require.DeepEqual(t, []*pbp2p.PendingAttestation(nil), atts)
|
||||
|
||||
want := []*pbp2p.PendingAttestation{{ProposerIndex: 101}}
|
||||
s, err = InitializeFromProto(&pbp2p.BeaconState{CurrentEpochAttestations: want})
|
||||
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)
|
||||
}
|
60
beacon-chain/state/v1/getters_block_test.go
Normal file
60
beacon-chain/state/v1/getters_block_test.go
Normal file
@ -0,0 +1,60 @@
|
||||
package v1
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
||||
v1alpha1 "github.com/prysmaticlabs/prysm/proto/prysm/v1alpha1"
|
||||
"github.com/prysmaticlabs/prysm/shared/bytesutil"
|
||||
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
||||
)
|
||||
|
||||
func TestBeaconState_LatestBlockHeader(t *testing.T) {
|
||||
s, err := InitializeFromProto(&pbp2p.BeaconState{})
|
||||
require.NoError(t, err)
|
||||
got := s.LatestBlockHeader()
|
||||
require.DeepEqual(t, (*v1alpha1.BeaconBlockHeader)(nil), got)
|
||||
|
||||
want := &v1alpha1.BeaconBlockHeader{Slot: 100}
|
||||
s, err = InitializeFromProto(&pbp2p.BeaconState{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(&pbp2p.BeaconState{})
|
||||
require.NoError(t, err)
|
||||
got := s.BlockRoots()
|
||||
require.DeepEqual(t, ([][]byte)(nil), got)
|
||||
|
||||
want := [][]byte{{'a'}}
|
||||
s, err = InitializeFromProto(&pbp2p.BeaconState{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(&pbp2p.BeaconState{})
|
||||
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(&pbp2p.BeaconState{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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user