Skip to content

Commit

Permalink
fix after review, added extra check
Browse files Browse the repository at this point in the history
  • Loading branch information
sstanculeanu committed Nov 20, 2023
1 parent 4a34b5f commit 8aef7db
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
3 changes: 3 additions & 0 deletions process/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,6 @@ var ErrEmptyAppVersionString = errors.New("empty app version string")

// ErrEmptyCommitString signals than an empty commit id string has been provided
var ErrEmptyCommitString = errors.New("empty commit id string")

// ErrEmptyPubKey signals that an empty public key has been provided
var ErrEmptyPubKey = errors.New("public key is empty")
4 changes: 4 additions & 0 deletions process/nodeGroupProcessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,10 @@ func (ngp *NodeGroupProcessor) handleHeartbeatCacheUpdate() {

// GetWaitingEpochsLeftForPublicKey returns the number of epochs left for the public key until it becomes eligible
func (ngp *NodeGroupProcessor) GetWaitingEpochsLeftForPublicKey(publicKey string) (*data.WaitingEpochsLeftApiResponse, error) {
if len(publicKey) == 0 {
return nil, ErrEmptyPubKey
}

observers, err := ngp.proc.GetAllObservers()
if err != nil {
return nil, err
Expand Down
17 changes: 15 additions & 2 deletions process/nodeGroupProcessor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,19 @@ func TestNodeGroupProcessor_GetWaitingEpochsLeftForPublicKey(t *testing.T) {
t.Parallel()

expectedErr := errors.New("expected error")
t.Run("empty pub key should error", func(t *testing.T) {
t.Parallel()

proc, _ := process.NewNodeGroupProcessor(
&mock.ProcessorStub{},
&mock.HeartbeatCacherMock{},
10,
)

response, err := proc.GetWaitingEpochsLeftForPublicKey("")
require.Nil(t, response)
require.Equal(t, process.ErrEmptyPubKey, err)
})
t.Run("GetAllObservers returns error should error", func(t *testing.T) {
t.Parallel()

Expand All @@ -650,7 +663,7 @@ func TestNodeGroupProcessor_GetWaitingEpochsLeftForPublicKey(t *testing.T) {
10,
)

response, err := proc.GetWaitingEpochsLeftForPublicKey("")
response, err := proc.GetWaitingEpochsLeftForPublicKey("key")
require.Nil(t, response)
require.Equal(t, expectedErr, err)
})
Expand All @@ -673,7 +686,7 @@ func TestNodeGroupProcessor_GetWaitingEpochsLeftForPublicKey(t *testing.T) {
10,
)

response, err := proc.GetWaitingEpochsLeftForPublicKey("")
response, err := proc.GetWaitingEpochsLeftForPublicKey("key")
require.Nil(t, response)
require.Equal(t, process.ErrSendingRequest, err)
})
Expand Down

0 comments on commit 8aef7db

Please sign in to comment.