mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
ec4de10001
* Starting * Merge branch 'master' of github.com:prysmaticlabs/prysm into domain-and-sign * core blocks tests: updated * core state tests: updated * rpc validator tests updated * sync tests updated * testutil updated * Beacon-chain: update tests * Shared: update tests * Rest of the tests * Merge branch 'master' of github.com:prysmaticlabs/prysm into domain-and-sign * Merge refs/heads/master into domain-and-sign * Merge refs/heads/master into domain-and-sign * Merge refs/heads/master into domain-and-sign * Merge refs/heads/master into domain-and-sign * Sync with master * Merge branch 'domain-and-sign' of github.com:prysmaticlabs/prysm into domain-and-sign * Merge refs/heads/master into domain-and-sign
69 lines
2.0 KiB
Go
69 lines
2.0 KiB
Go
package testutil
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil/require"
|
|
)
|
|
|
|
func TestBlockSignature(t *testing.T) {
|
|
beaconState, privKeys := DeterministicGenesisState(t, 100)
|
|
block, err := GenerateFullBlock(beaconState, privKeys, nil, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := beaconState.SetSlot(beaconState.Slot() + 1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
if err := beaconState.SetSlot(beaconState.Slot() - 1); err != nil {
|
|
t.Error(err)
|
|
}
|
|
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)
|
|
if err != nil {
|
|
t.Error(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)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
|
|
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
buf := make([]byte, 32)
|
|
binary.LittleEndian.PutUint64(buf, epoch)
|
|
|
|
// We make the previous validator's index sign the message instead of the proposer.
|
|
epochSignature, err := helpers.ComputeDomainAndSign(beaconState, epoch, epoch, 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[:])
|
|
}
|
|
}
|