Fix /eth/v1/validator/liveness/{epoch} call names and links in code (#5392)

* Fix getLiveness() call links and names.

* Add getLiveness() decoding test.

* Remove BN state updates from getLiveness() call.

* Fix AllTests.

* Reduce number of tests.
This commit is contained in:
Eugene Kabanov 2023-09-11 13:07:34 +03:00 committed by GitHub
parent 91a53e0cb6
commit 3c3c4e8edf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 57 additions and 14 deletions

View File

@ -587,9 +587,10 @@ OK: 1/1 Fail: 0/1 Skip: 0/1
+ bestSuccess() API timeout test OK
+ firstSuccessParallel() API timeout test OK
+ getAttestationDataScore() test vectors OK
+ getLiveness() response deserialization test OK
+ normalizeUri() test vectors OK
```
OK: 4/4 Fail: 0/4 Skip: 0/4
OK: 5/5 Fail: 0/5 Skip: 0/5
## Validator change pool testing suite
```diff
+ addValidatorChangeMessage/getAttesterSlashingMessage OK
@ -702,4 +703,4 @@ OK: 2/2 Fail: 0/2 Skip: 0/2
OK: 9/9 Fail: 0/9 Skip: 0/9
---TOTAL---
OK: 395/400 Fail: 0/400 Skip: 5/400
OK: 396/401 Fail: 0/401 Skip: 5/401

View File

@ -978,7 +978,7 @@ proc installValidatorApiHandlers*(router: var RestRouter, node: BeaconNode) =
return RestApiResponse.response("", Http200, "text/plain")
# https://github.com/ethereum/beacon-APIs/blob/master/apis/validator/liveness.yaml
# https://ethereum.github.io/beacon-APIs/#/Validator/getLiveness
router.api(MethodPost, "/eth/v1/validator/liveness/{epoch}") do (
epoch: Epoch, contentBody: Option[ContentBody]) -> RestApiResponse:
let

View File

@ -167,3 +167,4 @@ proc getValidatorsLiveness*(epoch: Epoch,
): RestPlainResponse {.
rest, endpoint: "/eth/v1/validator/liveness/{epoch}",
meth: MethodPost.}
## https://ethereum.github.io/beacon-APIs/#/Validator/getLiveness

View File

@ -2467,7 +2467,7 @@ proc getValidatorsLiveness*(
validators: seq[ValidatorIndex]
): Future[GetValidatorsLivenessResponse] {.async.} =
const
RequestName = "getValidatorsActivity"
RequestName = "getLiveness"
let resp = vc.onceToAll(RestPlainResponse,
SlotDuration,
ViableNodeStatus,
@ -2524,36 +2524,36 @@ proc getValidatorsLiveness*(
let failure = ApiNodeFailure.init(
ApiFailure.UnexpectedResponse, RequestName,
apiResponse.node, response.status, $res.error)
apiResponse.node.updateStatus(
RestBeaconNodeStatus.UnexpectedResponse, failure)
# We do not update beacon node's status anymore because of
# issue #5377.
continue
of 400:
let failure = ApiNodeFailure.init(
ApiFailure.Invalid, RequestName,
apiResponse.node, response.status, response.getErrorMessage())
apiResponse.node.updateStatus(
RestBeaconNodeStatus.Incompatible, failure)
# We do not update beacon node's status anymore because of
# issue #5377.
continue
of 500:
let failure = ApiNodeFailure.init(
ApiFailure.Internal, RequestName,
apiResponse.node, response.status, response.getErrorMessage())
apiResponse.node.updateStatus(
RestBeaconNodeStatus.InternalError, failure)
# We do not update beacon node's status anymore because of
# issue #5377.
continue
of 503:
let failure = ApiNodeFailure.init(
ApiFailure.NotSynced, RequestName,
apiResponse.node, response.status, response.getErrorMessage())
apiResponse.node.updateStatus(
RestBeaconNodeStatus.NotSynced, failure)
# We do not update beacon node's status anymore because of
# issue #5377.
continue
else:
let failure = ApiNodeFailure.init(
ApiFailure.UnexpectedCode, RequestName,
apiResponse.node, response.status, response.getErrorMessage())
apiResponse.node.updateStatus(
RestBeaconNodeStatus.UnexpectedCode, failure)
# We do not update beacon node's status anymore because of
# issue #5377.
continue
var response =

View File

@ -9,6 +9,7 @@
{.used.}
import std/strutils
import httputils
import chronos/unittest2/asynctests
import ../beacon_chain/validator_client/[api, common, scoring, fallback_service]
@ -335,3 +336,43 @@ suite "Validator Client test suite":
check:
response.isErr()
gotCancellation == true
test "getLiveness() response deserialization test":
proc generateLivenessResponse(T: typedesc[string],
start, count, modv: int): string =
var res: seq[string]
for index in start ..< (start + count):
let
validator = Base10.toString(uint64(index))
visibility = if index mod modv == 0: "true" else: "false"
res.add("{\"index\":\"" & validator & "\",\"is_live\":" &
visibility & "}")
"{\"data\":[" & res.join(",") & "]}"
proc generateLivenessResponse(
T: typedesc[RestLivenessItem],
start, count, modv: int
): seq[RestLivenessItem] =
var res: seq[RestLivenessItem]
for index in start ..< (start + count):
let visibility = if index mod modv == 0: true else: false
res.add(RestLivenessItem(index: ValidatorIndex(uint64(index)),
is_live: visibility))
res
const Tests = [(0, 2_000_000, 3)]
for test in Tests:
let
datastr = string.generateLivenessResponse(
test[0], test[1], test[2])
data = stringToBytes(datastr)
contentType = getContentType("application/json").get()
res = decodeBytes(GetValidatorsLivenessResponse,
data, Opt.some(contentType))
expect = RestLivenessItem.generateLivenessResponse(
test[0], test[1], test[2])
check:
res.isOk()
res.get().data == expect