Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pkg/beacon/beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,10 @@ func (n *node) Genesis() (*v1.Genesis, error) {
n.genesisMu.RLock()
defer n.genesisMu.RUnlock()

if n.genesis == nil {
return nil, errors.New("genesis is not available")
}

return n.genesis, nil
}

Expand Down
21 changes: 21 additions & 0 deletions pkg/beacon/beacon_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,24 @@ func TestLifecycleStartStopSequence(t *testing.T) {
t.Error("context was not cancelled after Stop")
}
}

// TestGenesisErrorsWhenUnset matches Spec()'s behavior: both are cached
// values that may not be ready yet, and a consumer applying the same
// err-checking idiom to either one should get the same contract.
func TestGenesisErrorsWhenUnset(t *testing.T) {
n := &node{log: logrus.New()}

_, err := n.Spec()
if err == nil {
t.Fatal("expected Spec() to error when unset")
}

g, err := n.Genesis()
if err == nil {
t.Fatal("expected Genesis() to error when unset, matching Spec()")
}

if g != nil {
t.Fatalf("expected a nil genesis alongside the error, got %v", g)
}
}