mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-07 10:12:19 +00:00
798bbbdc82
* coldstart flags for validator * WIP beacon node flags * wip beacon chain, flag fix in validator, arg fix in validator * checkpoint * Added interop service * working on mock chainstart * save the state lol * fix tests * Save genesis validators * gaz * fix validator help flags * WaitForChainStart actually waits for genesis time * cold start fixes * cache * change back * allow for genesis state too * remove logs * increase mmap size * dont process if head doesn't exist * add 10ms tolerance * enable libp2p debug at debug, fix pubsub * works with checkpt * initialize justified and finalized in db * Removed preloadStatePath from blockchain service * Clean up * Write to disk for now post state * revert b466dd536f8eadbdae2264a545a755370223d917 * Builds * Only RPC test fails now * use minimal config, no demo config * clean up branch * Lint * resolve lint * more lint fixes * lint * fix viz * Fixing RPC test * skip before epoch 2 * RPC time out * Fixed ordering * rename * remove some dbg statements * ensure index is correct * fix some panics * getting closer * fix tests * Fix private key * Fixed RPC test * Fixed beacon chain build for docker * Add interop.go to validator go_image * Fixed docker build * handle errors * skip test, skip disconnecting peers * Fixed docker build * tolerance for attestation processing * revert copy * clearer err message parse * fix launching from dep contract
122 lines
3.7 KiB
Go
122 lines
3.7 KiB
Go
package rpc
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
|
|
ptypes "github.com/gogo/protobuf/types"
|
|
"github.com/golang/mock/gomock"
|
|
mockChain "github.com/prysmaticlabs/prysm/beacon-chain/blockchain/testing"
|
|
dbt "github.com/prysmaticlabs/prysm/beacon-chain/db/testing"
|
|
mockPOW "github.com/prysmaticlabs/prysm/beacon-chain/powchain/testing"
|
|
mockRPC "github.com/prysmaticlabs/prysm/beacon-chain/rpc/testing"
|
|
ethereum_beacon_p2p_v1 "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
|
|
pb "github.com/prysmaticlabs/prysm/proto/beacon/rpc/v1"
|
|
"github.com/prysmaticlabs/prysm/shared/event"
|
|
"github.com/prysmaticlabs/prysm/shared/testutil"
|
|
logTest "github.com/sirupsen/logrus/hooks/test"
|
|
)
|
|
|
|
func TestWaitForChainStart_ContextClosed(t *testing.T) {
|
|
db := dbt.SetupDB(t)
|
|
defer dbt.TeardownDB(t, db)
|
|
ctx := context.Background()
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
beaconServer := &BeaconServer{
|
|
ctx: ctx,
|
|
chainStartFetcher: &mockPOW.FaultyMockPOWChain{
|
|
ChainFeed: new(event.Feed),
|
|
},
|
|
eth1InfoFetcher: &mockPOW.POWChain{},
|
|
stateFeedListener: &mockChain.ChainService{},
|
|
beaconDB: db,
|
|
}
|
|
|
|
exitRoutine := make(chan bool)
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
mockStream := mockRPC.NewMockBeaconService_WaitForChainStartServer(ctrl)
|
|
go func(tt *testing.T) {
|
|
if err := beaconServer.WaitForChainStart(&ptypes.Empty{}, mockStream); !strings.Contains(err.Error(), "context closed") {
|
|
tt.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
<-exitRoutine
|
|
}(t)
|
|
cancel()
|
|
exitRoutine <- true
|
|
}
|
|
|
|
func TestWaitForChainStart_AlreadyStarted(t *testing.T) {
|
|
db := dbt.SetupDB(t)
|
|
defer dbt.TeardownDB(t, db)
|
|
ctx := context.Background()
|
|
headBlockRoot := [32]byte{0x01, 0x02}
|
|
if err := db.SaveHeadBlockRoot(ctx, headBlockRoot); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := db.SaveState(ctx, ðereum_beacon_p2p_v1.BeaconState{Slot: 3}, headBlockRoot); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
beaconServer := &BeaconServer{
|
|
ctx: context.Background(),
|
|
chainStartFetcher: &mockPOW.POWChain{
|
|
ChainFeed: new(event.Feed),
|
|
},
|
|
eth1InfoFetcher: &mockPOW.POWChain{},
|
|
stateFeedListener: &mockChain.ChainService{},
|
|
beaconDB: db,
|
|
}
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
mockStream := mockRPC.NewMockBeaconService_WaitForChainStartServer(ctrl)
|
|
mockStream.EXPECT().Send(
|
|
&pb.ChainStartResponse{
|
|
Started: true,
|
|
GenesisTime: uint64(time.Unix(0, 0).Unix()),
|
|
},
|
|
).Return(nil)
|
|
if err := beaconServer.WaitForChainStart(&ptypes.Empty{}, mockStream); err != nil {
|
|
t.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestWaitForChainStart_NotStartedThenLogFired(t *testing.T) {
|
|
db := dbt.SetupDB(t)
|
|
defer dbt.TeardownDB(t, db)
|
|
|
|
hook := logTest.NewGlobal()
|
|
beaconServer := &BeaconServer{
|
|
ctx: context.Background(),
|
|
chainStartChan: make(chan time.Time, 1),
|
|
chainStartFetcher: &mockPOW.FaultyMockPOWChain{
|
|
ChainFeed: new(event.Feed),
|
|
},
|
|
eth1InfoFetcher: &mockPOW.POWChain{},
|
|
stateFeedListener: &mockChain.ChainService{},
|
|
beaconDB: db,
|
|
}
|
|
exitRoutine := make(chan bool)
|
|
ctrl := gomock.NewController(t)
|
|
defer ctrl.Finish()
|
|
mockStream := mockRPC.NewMockBeaconService_WaitForChainStartServer(ctrl)
|
|
mockStream.EXPECT().Send(
|
|
&pb.ChainStartResponse{
|
|
Started: true,
|
|
GenesisTime: uint64(time.Unix(0, 0).Unix()),
|
|
},
|
|
).Return(nil)
|
|
go func(tt *testing.T) {
|
|
if err := beaconServer.WaitForChainStart(&ptypes.Empty{}, mockStream); err != nil {
|
|
tt.Errorf("Could not call RPC method: %v", err)
|
|
}
|
|
<-exitRoutine
|
|
}(t)
|
|
beaconServer.chainStartChan <- time.Unix(0, 0)
|
|
exitRoutine <- true
|
|
testutil.AssertLogsContain(t, hook, "Sending ChainStart log and genesis time to connected validator clients")
|
|
}
|