Fix unknown fields should be ignored when parsing liveness responses. (#5418)
This commit is contained in:
parent
47639ef89c
commit
e3fe762ec9
|
@ -940,6 +940,9 @@ template unrecognizedFieldWarning =
|
|||
trace "JSON field not recognized by the current version of Nimbus. Consider upgrading",
|
||||
fieldName, typeName = typetraits.name(typeof value)
|
||||
|
||||
template unrecognizedFieldIgnore =
|
||||
discard readValue(reader, JsonString)
|
||||
|
||||
## ForkedBeaconBlock
|
||||
template prepareForkedBlockReading(
|
||||
reader: var JsonReader[RestJson],
|
||||
|
@ -2767,7 +2770,7 @@ proc readValue*(reader: var JsonReader[RestJson],
|
|||
"Multiple `active` fields found", "RestActivityItem")
|
||||
active = some(reader.readValue(bool))
|
||||
else:
|
||||
discard
|
||||
unrecognizedFieldIgnore()
|
||||
|
||||
if index.isNone():
|
||||
reader.raiseUnexpectedValue("Missing or empty `index` value")
|
||||
|
@ -2807,7 +2810,7 @@ proc readValue*(reader: var JsonReader[RestJson],
|
|||
"Multiple `is_live` fields found", "RestLivenessItem")
|
||||
isLive = some(reader.readValue(bool))
|
||||
else:
|
||||
discard
|
||||
unrecognizedFieldIgnore()
|
||||
|
||||
if index.isNone():
|
||||
reader.raiseUnexpectedValue("Missing or empty `index` value")
|
||||
|
@ -2935,8 +2938,7 @@ proc readValue*(reader: var JsonReader[RestJson],
|
|||
"RestErrorMessage")
|
||||
stacktraces = some(reader.readValue(seq[string]))
|
||||
else:
|
||||
# We ignore all additional fields.
|
||||
discard reader.readValue(JsonString)
|
||||
unrecognizedFieldIgnore()
|
||||
|
||||
if code.isNone():
|
||||
reader.raiseUnexpectedValue("Missing or invalid `code` value")
|
||||
|
|
|
@ -376,3 +376,15 @@ suite "Validator Client test suite":
|
|||
check:
|
||||
res.isOk()
|
||||
res.get().data == expect
|
||||
|
||||
let vector = stringToBytes(
|
||||
"{\"data\":[{\"index\":\"100000\",\"epoch\":\"202919\",\"is_live\":true}]}")
|
||||
|
||||
let contentType = getContentType("application/json").tryGet()
|
||||
let res = decodeBytes(
|
||||
GetValidatorsLivenessResponse, vector, Opt.some(contentType))
|
||||
check:
|
||||
res.isOk()
|
||||
len(res.get().data) == 1
|
||||
res.get().data[0].index == 100000
|
||||
res.get().data[0].is_live == true
|
||||
|
|
Loading…
Reference in New Issue