mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
83179376d4
* Clean testutil, change tool names to Deterministic * Cleanup errors * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into clean-testutil * Fix bug with generating deposits * Fix a few tests * Fix most tests * Clean up some tests * Remove err pt. 1 * Remove err pt. 2 * Change tests to use genesis state util * Remove err from deposits * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Remove circular dependency * Remove uncompressed signature test * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Merge branch 'master' into clean-testutil * Goimports * gazelle * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Add back error handling * New attestation pool (#4185) * New pool * Better namings * Fmt * Gazelle * Merge branch 'master' of https://github.com/prysmaticlabs/prysm into define-pool * Raul's feedback * Raul's feedback * Log peer conected log for incoming connections (#4173) * Log peer conected log for incoming connections * Merge branch 'master' into peerconnected * Merge branch 'master' into peerconnected * Update handshake.go * Update handshake.go * Merge branch 'master' into peerconnected * Merge branch 'master' into peerconnected * Attestation pool to use go-cache (#4187) * Update EthereumAPIs (#4186) * include new patch targeting latest ethapis master * ensure project builds * Merge branch 'master' into update-all-api * fix up committees * Merge branch 'update-all-api' of github.com:prysmaticlabs/prysm into update-all-api * include latest eth apis * Merge branch 'master' into update-all-api * update block tests * Merge branch 'update-all-api' of github.com:prysmaticlabs/prysm into update-all-api * Merge branch 'master' into update-all-api * add todos * Implement GetValidator RPC Endpoint (#4188) * include new patch targeting latest ethapis master * ensure project builds * Merge branch 'master' into update-all-api * fix up committees * Merge branch 'update-all-api' of github.com:prysmaticlabs/prysm into update-all-api * include latest eth apis * Merge branch 'master' into update-all-api * update block tests * Merge branch 'update-all-api' of github.com:prysmaticlabs/prysm into update-all-api * Merge branch 'master' into update-all-api * add todos * implement get validator rpc * add test for get validator * table driven test * fix up test * fix confs * tests for more cases * fix up tests and add out of range * Slasher optimization (#4172) * size * batching and concurrency improvements * gaz * merge fixes * fix comment * fix test * fix test * fix build * ethpb * ethpb * fix test * fix comment * add benchmark * fix benchmark * Handle error for all testutil uses * Fix errors * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Revert error handling Revert "Fix errors" This reverts commit db081f5486f62c854e7a34e792f5e380cfa922e7. Revert "Handle error for all testutil uses" This reverts commit bdabef230632dd184491c2dad63c7d3e74a3861b. Revert "Add back error handling" This reverts commit da7e3d2020cd906f45f452d4e441b566f2d5c8aa. * Change genesis state func to use testing.T * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Fix conflict * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Merge branch 'master' into clean-testutil * Merge branch 'master' into clean-testutil * Captialize other logs * Merge branch 'clean-testutil' of https://github.com/0xKiwi/Prysm into clean-testutil * Merge branch 'master' of https://github.com/prysmaticlabs/Prysm into clean-testutil * Merge branch 'master' into clean-testutil
70 lines
1.9 KiB
Go
70 lines
1.9 KiB
Go
package testutil
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"testing"
|
|
|
|
"github.com/prysmaticlabs/go-ssz"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/helpers"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
func TestBlockSignature(t *testing.T) {
|
|
helpers.ClearAllCaches()
|
|
|
|
beaconState, privKeys := DeterministicGenesisState(t, 100)
|
|
|
|
block, err := GenerateFullBlock(beaconState, privKeys, nil, 0)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
beaconState.Slot++
|
|
proposerIdx, err := helpers.BeaconProposerIndex(beaconState)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
beaconState.Slot--
|
|
signingRoot, err := ssz.SigningRoot(block)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
epoch := helpers.SlotToEpoch(block.Slot)
|
|
domain := helpers.Domain(beaconState.Fork, epoch, params.BeaconConfig().DomainBeaconProposer)
|
|
blockSig := privKeys[proposerIdx].Sign(signingRoot[:], domain).Marshal()
|
|
|
|
signature, err := BlockSignature(beaconState, 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)
|
|
domain := helpers.Domain(beaconState.Fork, epoch, params.BeaconConfig().DomainRandao)
|
|
// We make the previous validator's index sign the message instead of the proposer.
|
|
epochSignature := privKeys[proposerIdx].Sign(buf, domain).Marshal()
|
|
|
|
if !bytes.Equal(randaoReveal[:], epochSignature[:]) {
|
|
t.Errorf("Expected randao reveals to be equal, received %#x != %#x", randaoReveal[:], epochSignature[:])
|
|
}
|
|
}
|