mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-11 20:20:05 +00:00
7067c84c69
* include validator client stream * Update validator/client/validator_attest.go * gazelle * rem extraneous logs * fixing tests * resolve most tests * gaz * add lock * ivan feedback * pass tests for update protect * gaz * duties gaz * no need for canonical head slot * fix ctx leak * fmt * add in feature flag * add streaming subpackage * add polling/streaming separation * able to build * fix duplicate package names * fix polling * imports * confirm it works * fixed up comment * go lint comments * gaz * build * Update validator/client/streaming/service_test.go Co-authored-by: terence tsao <terence@prysmaticlabs.com> * tidy * fmt * add stream duties to e2e * add stream duties to e2e flags Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com> Co-authored-by: terence tsao <terence@prysmaticlabs.com>
154 lines
3.5 KiB
Go
154 lines
3.5 KiB
Go
package streaming
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/prysmaticlabs/prysm/shared/featureconfig"
|
|
)
|
|
|
|
func cancelledContext() context.Context {
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
return ctx
|
|
}
|
|
|
|
func TestCancelledContext_CleansUpValidator(t *testing.T) {
|
|
v := &fakeValidator{}
|
|
run(cancelledContext(), v)
|
|
if !v.DoneCalled {
|
|
t.Error("Expected Done() to be called")
|
|
}
|
|
}
|
|
|
|
func TestCancelledContext_WaitsForChainStart(t *testing.T) {
|
|
v := &fakeValidator{}
|
|
run(cancelledContext(), v)
|
|
if !v.WaitForChainStartCalled {
|
|
t.Error("Expected WaitForChainStart() to be called")
|
|
}
|
|
}
|
|
|
|
func TestCancelledContext_WaitsForSynced(t *testing.T) {
|
|
cfg := &featureconfig.Flags{
|
|
WaitForSynced: true,
|
|
}
|
|
reset := featureconfig.InitWithReset(cfg)
|
|
defer reset()
|
|
v := &fakeValidator{}
|
|
run(cancelledContext(), v)
|
|
if !v.WaitForSyncedCalled {
|
|
t.Error("Expected WaitForSynced() to be called")
|
|
}
|
|
}
|
|
|
|
func TestCancelledContext_WaitsForActivation(t *testing.T) {
|
|
v := &fakeValidator{}
|
|
run(cancelledContext(), v)
|
|
if !v.WaitForActivationCalled {
|
|
t.Error("Expected WaitForActivation() to be called")
|
|
}
|
|
}
|
|
|
|
func TestRoleAt_NextSlot(t *testing.T) {
|
|
v := &fakeValidator{}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
slot := uint64(55)
|
|
ticker := make(chan uint64)
|
|
v.NextSlotRet = ticker
|
|
go func() {
|
|
ticker <- slot
|
|
|
|
cancel()
|
|
}()
|
|
|
|
run(ctx, v)
|
|
|
|
if !v.RoleAtCalled {
|
|
t.Fatalf("Expected RoleAt(%d) to be called", slot)
|
|
}
|
|
if v.RoleAtArg1 != slot {
|
|
t.Errorf("RoleAt called with the wrong arg. Want=%d, got=%d", slot, v.RoleAtArg1)
|
|
}
|
|
}
|
|
|
|
func TestAttests_NextSlot(t *testing.T) {
|
|
v := &fakeValidator{}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
slot := uint64(55)
|
|
ticker := make(chan uint64)
|
|
v.NextSlotRet = ticker
|
|
v.RolesAtRet = []validatorRole{roleAttester}
|
|
go func() {
|
|
ticker <- slot
|
|
|
|
cancel()
|
|
}()
|
|
timer := time.NewTimer(200 * time.Millisecond)
|
|
run(ctx, v)
|
|
<-timer.C
|
|
if !v.AttestToBlockHeadCalled {
|
|
t.Fatalf("SubmitAttestation(%d) was not called", slot)
|
|
}
|
|
if v.AttestToBlockHeadArg1 != slot {
|
|
t.Errorf("SubmitAttestation was called with wrong arg. Want=%d, got=%d", slot, v.AttestToBlockHeadArg1)
|
|
}
|
|
}
|
|
|
|
func TestProposes_NextSlot(t *testing.T) {
|
|
v := &fakeValidator{}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
slot := uint64(55)
|
|
ticker := make(chan uint64)
|
|
v.NextSlotRet = ticker
|
|
v.RolesAtRet = []validatorRole{roleProposer}
|
|
go func() {
|
|
ticker <- slot
|
|
|
|
cancel()
|
|
}()
|
|
timer := time.NewTimer(200 * time.Millisecond)
|
|
run(ctx, v)
|
|
<-timer.C
|
|
if !v.ProposeBlockCalled {
|
|
t.Fatalf("ProposeBlock(%d) was not called", slot)
|
|
}
|
|
if v.ProposeBlockArg1 != slot {
|
|
t.Errorf("ProposeBlock was called with wrong arg. Want=%d, got=%d", slot, v.AttestToBlockHeadArg1)
|
|
}
|
|
}
|
|
|
|
func TestBothProposesAndAttests_NextSlot(t *testing.T) {
|
|
v := &fakeValidator{}
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
|
|
slot := uint64(55)
|
|
ticker := make(chan uint64)
|
|
v.NextSlotRet = ticker
|
|
v.RolesAtRet = []validatorRole{roleAttester, roleProposer}
|
|
go func() {
|
|
ticker <- slot
|
|
|
|
cancel()
|
|
}()
|
|
timer := time.NewTimer(200 * time.Millisecond)
|
|
run(ctx, v)
|
|
<-timer.C
|
|
if !v.AttestToBlockHeadCalled {
|
|
t.Fatalf("SubmitAttestation(%d) was not called", slot)
|
|
}
|
|
if v.AttestToBlockHeadArg1 != slot {
|
|
t.Errorf("SubmitAttestation was called with wrong arg. Want=%d, got=%d", slot, v.AttestToBlockHeadArg1)
|
|
}
|
|
if !v.ProposeBlockCalled {
|
|
t.Fatalf("ProposeBlock(%d) was not called", slot)
|
|
}
|
|
if v.ProposeBlockArg1 != slot {
|
|
t.Errorf("ProposeBlock was called with wrong arg. Want=%d, got=%d", slot, v.AttestToBlockHeadArg1)
|
|
}
|
|
}
|