Skip to content

Commit

Permalink
NODE-2447 Return 404 for block request at invalid height (#3651)
Browse files Browse the repository at this point in the history
Co-authored-by: Ivan Mashonskii <[email protected]>
  • Loading branch information
ivan-mashonskiy and Ivan Mashonskii authored Mar 18, 2022
1 parent e05a253 commit b735f36
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,13 @@ case class BlocksApiRoute(settings: RestAPISettings, commonApi: CommonBlocksApi,
}
}

private def at(height: Int, includeTransactions: Boolean): StandardRoute = complete {
if (includeTransactions) commonApi.blockAtHeight(height).map(toJson) else commonApi.metaAtHeight(height).map(_.json())
private def at(height: Int, includeTransactions: Boolean): StandardRoute = {
val result = if (includeTransactions)
commonApi.blockAtHeight(height).map(toJson)
else
commonApi.metaAtHeight(height).map(_.json())

complete(result.toRight(BlockDoesNotExist))
}

private def seq(start: Int, end: Int, includeTransactions: Boolean): Route = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.wavesplatform.http

import akka.http.scaladsl.model.StatusCodes
import com.wavesplatform.TestWallet
import com.wavesplatform.api.BlockMeta
import com.wavesplatform.api.common.CommonBlocksApi
Expand Down Expand Up @@ -83,6 +84,12 @@ class BlocksApiRouteSpec
val response = responseAs[JsObject]
response shouldBe testBlock2Json
}

(blocksApi.blockAtHeight _).expects(3).returning(None).once()
Get(routePath("/at/3")) ~> route ~> check {
response.status shouldBe StatusCodes.NotFound
responseAs[String] should include("block does not exist")
}
}

routePath("/signature/{signature}") in {
Expand Down Expand Up @@ -175,6 +182,7 @@ class BlocksApiRouteSpec
routePath("/headers/at/{height}") in {
(blocksApi.metaAtHeight _).expects(1).returning(Some(testBlock1Meta)).once()
(blocksApi.metaAtHeight _).expects(2).returning(Some(testBlock2Meta)).once()
(blocksApi.metaAtHeight _).expects(3).returning(None).once()

Get(routePath("/headers/at/1")) ~> route ~> check {
val response = responseAs[JsObject]
Expand All @@ -185,6 +193,11 @@ class BlocksApiRouteSpec
val response = responseAs[JsObject]
response shouldBe testBlock2HeaderJson
}

Get(routePath("/headers/at/3")) ~> route ~> check {
response.status shouldBe StatusCodes.NotFound
responseAs[String] should include("block does not exist")
}
}

routePath("/headers/seq/{from}/{to}") in {
Expand Down

0 comments on commit b735f36

Please sign in to comment.