Skip to content

Commit

Permalink
fix: proofer returns a new challenge if checking solution fails
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel-orlov committed Jul 14, 2023
1 parent 0a965c6 commit 885a4fa
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion internal/transport/middleware/proofer/proofer.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ func (mw *Proofer) handleSolutionCheck(c *gin.Context, solution string) error {
// Handle error
if err != nil {
mw.logger.Error("failed to check solution", zap.Error(err))
return err

// not retuning error here, because in any case we want to try to send a new challenge
// regardless if the client sent an invalid solution, tried to reuse a solution or there simply was an error
}

// If solution is not valid, return error and a new challenge, abort request
Expand Down
2 changes: 1 addition & 1 deletion internal/transport/middleware/proofer/proofer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func TestProofer_Use(t *testing.T) {

// Assertions
assert.Equal(t, http.StatusInternalServerError, w.Code, "status code should be 500")
assert.Equal(t, "{\"error\":\"failed to check solution\"}", w.Body.String())
assert.Equal(t, "{\"error\":\"failed to get new challenge\"}{\"error\":\"failed to check solution\"}", w.Body.String())
})

t.Run("Incorrect solution, get back with a new one", func(t *testing.T) {
Expand Down

0 comments on commit 885a4fa

Please sign in to comment.