Skip to content

Commit

Permalink
feat(SPV-1106): add errors for merkleroots
Browse files Browse the repository at this point in the history
  • Loading branch information
dzolt-4chain committed Oct 24, 2024
1 parent 94b4a4b commit e2fd710
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
3 changes: 3 additions & 0 deletions bhserrors/definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ var ErrMerklerootNotInLongestChain = BHSError{Message: "Provided merkleroot is n
// ErrInvalidBatchSize is when user provided incorrect batchSize
var ErrInvalidBatchSize = BHSError{Message: "batchSize must be 0 or a positive integer", Code: "ErrInvalidBatchSize", StatusCode: 400}

// ErrGetChainTipHeight is when it fails to get a chain tip height
var ErrGetChainTipHeight = BHSError{Message: "Failed to get chain tip height", Code: "ErrGetChainTipHeight", StatusCode: 400}

// ////////////////////////////////// ACCESS ERRORS

// ErrTokenNotFound is when token was not found in Block Header Service
Expand Down
2 changes: 1 addition & 1 deletion database/sql/headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ func (h *HeadersDb) GetMerkleRootsConfirmations(
confirmations := make([]*dto.DbMerkleRootConfirmation, 0)
tipHeight, err := h.getChainTipHeight()
if err != nil {
return nil, errors.Wrap(err, "failed to get chain tip height")
return nil, bhserrors.ErrGetChainTipHeight.Wrap(err)
}

for _, item := range request {
Expand Down
2 changes: 1 addition & 1 deletion transports/http/endpoints/api/merkleroots/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ func (h *handler) verify(c *gin.Context) {
if err == nil {
c.JSON(http.StatusOK, mapToMerkleRootsConfirmationsResponses(mrcs))
} else {
c.JSON(http.StatusInternalServerError, err.Error())
bhserrors.ErrorResponse(c, err, h.log)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ func TestReturnFailureFromVerifyWhenAuthorizationIsTurnedOnAndCalledWithoutToken
query := []domains.MerkleRootConfirmationRequestItem{}
expectedResult := struct {
code int
body []byte
body string
}{
code: http.StatusUnauthorized,
body: []byte("\"empty auth header\""),
body: "{\"code\":\"ErrMissingAuthHeader\",\"message\":\"Empty auth header\"}",
}

// when
Expand All @@ -85,10 +85,7 @@ func TestReturnFailureFromVerifyWhenAuthorizationIsTurnedOnAndCalledWithoutToken
if res.Code != expectedResult.code {
t.Errorf("Expected to get status %d but instead got %d\n", expectedResult.code, res.Code)
}
body, _ := io.ReadAll(res.Body)
if !bytes.Equal(body, expectedResult.body) {
t.Errorf("Expected to get body %s but insead got %s\n", expectedResult.body, body)
}
require.JSONEq(t, expectedResult.body, res.Body.String())
}

func TestReturnInvalidFromVerify(t *testing.T) {
Expand Down

0 comments on commit e2fd710

Please sign in to comment.