2022-06-15 13:02:02 +00:00
|
|
|
{.used.}
|
|
|
|
|
2023-02-13 14:22:24 +00:00
|
|
|
import
|
2022-06-02 09:45:00 +00:00
|
|
|
stew/[results, byteutils],
|
2023-02-13 14:22:24 +00:00
|
|
|
chronicles,
|
|
|
|
unittest2,
|
2022-06-02 09:45:00 +00:00
|
|
|
json_serialization
|
2023-02-13 14:22:24 +00:00
|
|
|
import
|
2023-09-22 13:36:46 +00:00
|
|
|
../../waku/waku_api/rest/serdes,
|
|
|
|
../../waku/waku_api/rest/debug/types
|
2022-06-02 09:45:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
# TODO: Decouple this test suite from the `debug_api` module by defining
|
|
|
|
# private custom types for this test suite module
|
2023-02-13 14:22:24 +00:00
|
|
|
suite "Waku v2 Rest API - Serdes":
|
2022-06-02 09:45:00 +00:00
|
|
|
|
|
|
|
suite "decode":
|
|
|
|
test "decodeFromJsonString - use the corresponding readValue template":
|
|
|
|
# Given
|
|
|
|
let jsonString = JsonString("""{ "listenAddresses":["123"] }""")
|
|
|
|
|
|
|
|
# When
|
|
|
|
let res = decodeFromJsonString(DebugWakuInfo, jsonString, requireAllFields = true)
|
|
|
|
|
|
|
|
# Then
|
|
|
|
require(res.isOk)
|
|
|
|
let value = res.get()
|
|
|
|
check:
|
|
|
|
value.listenAddresses == @["123"]
|
|
|
|
value.enrUri.isNone
|
2023-02-13 14:22:24 +00:00
|
|
|
|
2022-06-02 09:45:00 +00:00
|
|
|
test "decodeFromJsonBytes - use the corresponding readValue template":
|
|
|
|
# Given
|
|
|
|
let jsonBytes = toBytes("""{ "listenAddresses":["123"] }""")
|
|
|
|
|
|
|
|
# When
|
|
|
|
let res = decodeFromJsonBytes(DebugWakuInfo, jsonBytes, requireAllFields = true)
|
|
|
|
|
|
|
|
# Then
|
|
|
|
require(res.isOk)
|
|
|
|
let value = res.get()
|
|
|
|
check:
|
|
|
|
value.listenAddresses == @["123"]
|
|
|
|
value.enrUri.isNone
|
|
|
|
|
|
|
|
suite "encode":
|
|
|
|
test "encodeIntoJsonString - use the corresponding writeValue template":
|
|
|
|
# Given
|
|
|
|
let data = DebugWakuInfo(listenAddresses: @["GO"])
|
|
|
|
|
|
|
|
# When
|
|
|
|
let res = encodeIntoJsonString(data)
|
|
|
|
|
|
|
|
# Then
|
|
|
|
require(res.isOk)
|
|
|
|
let value = res.get()
|
|
|
|
check:
|
|
|
|
value == """{"listenAddresses":["GO"]}"""
|
|
|
|
|
|
|
|
test "encodeIntoJsonBytes - use the corresponding writeValue template":
|
|
|
|
# Given
|
|
|
|
let data = DebugWakuInfo(listenAddresses: @["ABC"])
|
|
|
|
|
|
|
|
# When
|
|
|
|
let res = encodeIntoJsonBytes(data)
|
|
|
|
|
|
|
|
# Then
|
|
|
|
require(res.isOk)
|
|
|
|
let value = res.get()
|
|
|
|
check:
|
|
|
|
value == toBytes("""{"listenAddresses":["ABC"]}""" )
|