2022-06-15 13:02:02 +00:00
|
|
|
{.used.}
|
|
|
|
|
2022-11-04 09:52:08 +00:00
|
|
|
import
|
2023-02-13 14:22:24 +00:00
|
|
|
stew/results,
|
2022-11-04 09:52:08 +00:00
|
|
|
stew/byteutils,
|
|
|
|
testutils/unittests,
|
2022-06-02 09:45:00 +00:00
|
|
|
json_serialization
|
2023-02-13 14:22:24 +00:00
|
|
|
import
|
2022-06-15 13:02:02 +00:00
|
|
|
../../waku/v2/node/rest/serdes,
|
2023-02-13 14:22:24 +00:00
|
|
|
../../waku/v2/node/rest/debug/types
|
2022-06-02 09:45:00 +00:00
|
|
|
|
|
|
|
|
2023-02-13 14:22:24 +00:00
|
|
|
suite "Waku v2 REST API - Debug - serialization":
|
2022-06-02 09:45:00 +00:00
|
|
|
|
|
|
|
suite "DebugWakuInfo - decode":
|
|
|
|
test "optional field is not provided":
|
|
|
|
# Given
|
|
|
|
let jsonBytes = toBytes("""{ "listenAddresses":["123"] }""")
|
|
|
|
|
|
|
|
# When
|
|
|
|
let res = decodeFromJsonBytes(DebugWakuInfo, jsonBytes, requireAllFields = true)
|
|
|
|
|
|
|
|
# Then
|
2023-02-13 14:22:24 +00:00
|
|
|
require(res.isOk())
|
2022-06-02 09:45:00 +00:00
|
|
|
let value = res.get()
|
|
|
|
check:
|
|
|
|
value.listenAddresses == @["123"]
|
2023-02-13 14:22:24 +00:00
|
|
|
value.enrUri.isNone()
|
2022-06-02 09:45:00 +00:00
|
|
|
|
|
|
|
suite "DebugWakuInfo - encode":
|
|
|
|
test "optional field is none":
|
|
|
|
# Given
|
|
|
|
let data = DebugWakuInfo(listenAddresses: @["GO"], enrUri: none(string))
|
|
|
|
|
|
|
|
# When
|
|
|
|
let res = encodeIntoJsonBytes(data)
|
|
|
|
|
|
|
|
# Then
|
2023-02-13 14:22:24 +00:00
|
|
|
require(res.isOk())
|
2022-06-02 09:45:00 +00:00
|
|
|
let value = res.get()
|
|
|
|
check:
|
|
|
|
value == toBytes("""{"listenAddresses":["GO"]}""")
|