mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
a8e501b3cf
* update deps * update deps * update protos/* * update deps * reset protos * update protos * update shared/params/config * update protos * update /shared * update shared/slotutil and shared/testutil * update beacon-chain/core/helpers * updates beacon-chain/state * update beacon-chain/forkchoice * update beacon-chain/blockchain * update beacon-chain/cache * update beacon-chain/core * update beacon-chain/db * update beacon-chain/node * update beacon-chain/p2p * update beacon-chain/rpc * update beacon-chain/sync * go mod tidy * make sure that beacon-chain build suceeds * go fmt * update e2e tests * update slasher * remove redundant alias * update validator * gazelle * fix build errors in unit tests * go fmt * update deps * update fuzz/BUILD.bazel * fix unit tests * more unit test fixes * fix blockchain UTs * more unit test fixes
57 lines
2.0 KiB
Go
57 lines
2.0 KiB
Go
package testutil
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
|
p2ptypes "github.com/prysmaticlabs/prysm/beacon-chain/p2p/types"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/assert"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestBlockSignature(t *testing.T) {
|
|
beaconState, privKeys := DeterministicGenesisState(t, 100)
|
|
block, err := GenerateFullBlock(beaconState, privKeys, nil, 0)
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, beaconState.SetSlot(beaconState.Slot()+1))
|
|
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
|
|
assert.NoError(t, err)
|
|
|
|
assert.NoError(t, beaconState.SetSlot(beaconState.Slot()-1))
|
|
epoch := helpers.SlotToEpoch(block.Block.Slot)
|
|
blockSig, err := helpers.ComputeDomainAndSign(beaconState, epoch, block.Block, params.BeaconConfig().DomainBeaconProposer, privKeys[proposerIdx])
|
|
require.NoError(t, err)
|
|
|
|
signature, err := BlockSignature(beaconState, block.Block, privKeys)
|
|
assert.NoError(t, err)
|
|
|
|
if !bytes.Equal(blockSig, signature.Marshal()) {
|
|
t.Errorf("Expected block signatures to be equal, received %#x != %#x", blockSig, signature.Marshal())
|
|
}
|
|
}
|
|
|
|
func TestRandaoReveal(t *testing.T) {
|
|
beaconState, privKeys := DeterministicGenesisState(t, 100)
|
|
|
|
epoch := helpers.CurrentEpoch(beaconState)
|
|
randaoReveal, err := RandaoReveal(beaconState, epoch, privKeys)
|
|
assert.NoError(t, err)
|
|
|
|
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
|
|
assert.NoError(t, err)
|
|
buf := make([]byte, 32)
|
|
binary.LittleEndian.PutUint64(buf, uint64(epoch))
|
|
// We make the previous validator's index sign the message instead of the proposer.
|
|
sszUint := p2ptypes.SSZUint64(epoch)
|
|
epochSignature, err := helpers.ComputeDomainAndSign(beaconState, epoch, &sszUint, params.BeaconConfig().DomainRandao, privKeys[proposerIdx])
|
|
require.NoError(t, err)
|
|
|
|
if !bytes.Equal(randaoReveal, epochSignature) {
|
|
t.Errorf("Expected randao reveals to be equal, received %#x != %#x", randaoReveal, epochSignature)
|
|
}
|
|
}
|