mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2024-12-25 12:57:18 +00:00
12524ae8dd
* fix bug in eth1 data vote count increases * updating attester slashings * is double vote and attester pseudocode * attester slashing revamp complete * exits processing complete * all block operations aligned to spec * completed test revamp * builds properly * all done FINALLY * deprecate all instances of old randao logic * fix all broken tests and cleanup randao references across repo * builds but tests failing * fixing broken chaintests * only chaintests fail now * randao fully updated * add bls todo * lint * travis * fix unresolved property in struct * remove used randao var
123 lines
3.1 KiB
Go
123 lines
3.1 KiB
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"strconv"
|
|
"testing"
|
|
"time"
|
|
|
|
b "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/core/state"
|
|
"github.com/prysmaticlabs/prysm/beacon-chain/internal"
|
|
pbp2p "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/params"
|
|
)
|
|
|
|
func TestProposeBlock(t *testing.T) {
|
|
db := internal.SetupDB(t)
|
|
defer internal.TeardownDB(t, db)
|
|
mockChain := &mockChainService{}
|
|
|
|
genesis := b.NewGenesisBlock([]byte{})
|
|
if err := db.SaveBlock(genesis); err != nil {
|
|
t.Fatalf("Could not save genesis block: %v", err)
|
|
}
|
|
|
|
deposits := make([]*pbp2p.Deposit, params.BeaconConfig().DepositsForChainStart)
|
|
for i := 0; i < len(deposits); i++ {
|
|
depositData, err := b.EncodeDepositData(
|
|
&pbp2p.DepositInput{
|
|
Pubkey: []byte(strconv.Itoa(i)),
|
|
},
|
|
params.BeaconConfig().MaxDepositAmount,
|
|
time.Now().Unix(),
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("Could not encode deposit input: %v", err)
|
|
}
|
|
deposits[i] = &pbp2p.Deposit{
|
|
DepositData: depositData,
|
|
}
|
|
}
|
|
|
|
beaconState, err := state.InitialBeaconState(deposits, 0, nil)
|
|
if err != nil {
|
|
t.Fatalf("Could not instantiate initial state: %v", err)
|
|
}
|
|
|
|
if err := db.UpdateChainHead(genesis, beaconState); err != nil {
|
|
t.Fatalf("Could not save genesis state: %v", err)
|
|
}
|
|
|
|
proposerServer := &ProposerServer{
|
|
chainService: mockChain,
|
|
beaconDB: db,
|
|
powChainService: &mockPOWChainService{},
|
|
}
|
|
req := &pbp2p.BeaconBlock{
|
|
Slot: 5,
|
|
ParentRootHash32: []byte("parent-hash"),
|
|
}
|
|
if _, err := proposerServer.ProposeBlock(context.Background(), req); err != nil {
|
|
t.Errorf("Could not propose block correctly: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestComputeStateRoot(t *testing.T) {
|
|
db := internal.SetupDB(t)
|
|
defer internal.TeardownDB(t, db)
|
|
|
|
mockChain := &mockChainService{}
|
|
|
|
genesis := b.NewGenesisBlock([]byte{})
|
|
if err := db.SaveBlock(genesis); err != nil {
|
|
t.Fatalf("Could not save genesis block: %v", err)
|
|
}
|
|
|
|
deposits := make([]*pbp2p.Deposit, params.BeaconConfig().DepositsForChainStart)
|
|
for i := 0; i < len(deposits); i++ {
|
|
depositData, err := b.EncodeDepositData(
|
|
&pbp2p.DepositInput{
|
|
Pubkey: []byte(strconv.Itoa(i)),
|
|
},
|
|
params.BeaconConfig().MaxDepositAmount,
|
|
time.Now().Unix(),
|
|
)
|
|
if err != nil {
|
|
t.Fatalf("Could not encode deposit input: %v", err)
|
|
}
|
|
deposits[i] = &pbp2p.Deposit{
|
|
DepositData: depositData,
|
|
}
|
|
}
|
|
|
|
beaconState, err := state.InitialBeaconState(deposits, 0, nil)
|
|
if err != nil {
|
|
t.Fatalf("Could not instantiate initial state: %v", err)
|
|
}
|
|
|
|
beaconState.Slot = 10
|
|
|
|
if err := db.UpdateChainHead(genesis, beaconState); err != nil {
|
|
t.Fatalf("Could not save genesis state: %v", err)
|
|
}
|
|
|
|
proposerServer := &ProposerServer{
|
|
chainService: mockChain,
|
|
beaconDB: db,
|
|
powChainService: &mockPOWChainService{},
|
|
}
|
|
|
|
req := &pbp2p.BeaconBlock{
|
|
ParentRootHash32: nil,
|
|
Slot: 11,
|
|
RandaoRevealHash32: nil,
|
|
Body: &pbp2p.BeaconBlockBody{
|
|
ProposerSlashings: nil,
|
|
AttesterSlashings: nil,
|
|
},
|
|
}
|
|
|
|
_, _ = proposerServer.ComputeStateRoot(context.Background(), req)
|
|
}
|