prysm-pulse/validator/attester/service_test.go
Raul Jordan ee91be2c4a
validator: Implementing Partial Implementation of Proposer Responsibility (#441)
* implementing basic proposer functionality

* checked in gomocks

* fix typo

* refactor using feeds

* use event feeds for assignment

* sending the latest beacon block over announcement chan

* 100 coverage, using feeds

* gazelle

* include parent hash from prev canonical block and slot number + 1

* including all other prop fields

* fix build

* proposer rpc method tests, implemented in beacon chain side

* godoc
2018-09-04 23:35:32 -04:00

58 lines
1.3 KiB
Go

package attester
import (
"context"
"io/ioutil"
"testing"
"github.com/ethereum/go-ethereum/event"
"github.com/prysmaticlabs/prysm/shared/testutil"
"github.com/sirupsen/logrus"
logTest "github.com/sirupsen/logrus/hooks/test"
)
func init() {
logrus.SetLevel(logrus.DebugLevel)
logrus.SetOutput(ioutil.Discard)
}
type mockAssigner struct{}
func (m *mockAssigner) AttesterAssignmentFeed() *event.Feed {
return new(event.Feed)
}
func TestLifecycle(t *testing.T) {
hook := logTest.NewGlobal()
cfg := &Config{
AssignmentBuf: 0,
Assigner: &mockAssigner{},
}
att := NewAttester(context.Background(), cfg)
att.Start()
testutil.AssertLogsContain(t, hook, "Starting service")
att.Stop()
testutil.AssertLogsContain(t, hook, "Stopping service")
}
func TestAttesterLoop(t *testing.T) {
hook := logTest.NewGlobal()
cfg := &Config{
AssignmentBuf: 0,
Assigner: &mockAssigner{},
}
att := NewAttester(context.Background(), cfg)
doneChan := make(chan struct{})
exitRoutine := make(chan bool)
go func() {
att.run(doneChan)
<-exitRoutine
}()
att.assignmentChan <- true
testutil.AssertLogsContain(t, hook, "Performing attester responsibility")
doneChan <- struct{}{}
exitRoutine <- true
testutil.AssertLogsContain(t, hook, "Attester context closed")
}