mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-10 11:41:21 +00:00
5aac06f04e
* begin move * use same import path * imports * regen protos * regen * no rename * generate ssz * gaz * fmt * edit build file * imports * modify * remove generated files * remove protos * edit imports in prysm * beacon chain all builds * edit script * add generated pbs * add replace rules * license for ethereumapis protos * change visibility * fmt * update build files to gaz ignore * use proper form * edit imports * wrap block * revert scripts * revert go mod
49 lines
1.4 KiB
Go
49 lines
1.4 KiB
Go
// Package testing includes useful helpers for slasher-related
|
|
// unit tests.
|
|
package testing
|
|
|
|
import (
|
|
types "github.com/prysmaticlabs/eth2-types"
|
|
ethpb "github.com/prysmaticlabs/prysm/proto/eth/v1alpha1"
|
|
"github.com/prysmaticlabs/prysm/shared/rand"
|
|
)
|
|
|
|
// SignedBlockHeader given slot, proposer index this function generates signed block header.
|
|
// with random bytes as its signature.
|
|
func SignedBlockHeader(slot types.Slot, proposerIdx types.ValidatorIndex) (*ethpb.SignedBeaconBlockHeader, error) {
|
|
sig, err := genRandomByteArray(96)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
root := [32]byte{1, 2, 3}
|
|
return ðpb.SignedBeaconBlockHeader{
|
|
Header: ðpb.BeaconBlockHeader{
|
|
ProposerIndex: proposerIdx,
|
|
Slot: slot,
|
|
ParentRoot: root[:],
|
|
StateRoot: root[:],
|
|
BodyRoot: root[:],
|
|
},
|
|
Signature: sig,
|
|
}, nil
|
|
}
|
|
|
|
// BlockHeader given slot, proposer index this function generates block header.
|
|
func BlockHeader(slot types.Slot, proposerIdx types.ValidatorIndex) (*ethpb.BeaconBlockHeader, error) {
|
|
root := [32]byte{1, 2, 3}
|
|
return ðpb.BeaconBlockHeader{
|
|
ProposerIndex: proposerIdx,
|
|
Slot: slot,
|
|
ParentRoot: root[:],
|
|
StateRoot: root[:],
|
|
BodyRoot: root[:],
|
|
}, nil
|
|
}
|
|
|
|
func genRandomByteArray(length int) ([]byte, error) {
|
|
blk := make([]byte, length)
|
|
randGen := rand.NewDeterministicGenerator()
|
|
_, err := randGen.Read(blk)
|
|
return blk, err
|
|
}
|