logos-messaging-go-bindings/tests/test_utils_compat.nim
Ivan Folgueira Bande 2f6de9187f Squashed 'third-party/nwaku/' content from commit d94cb7c7
git-subtree-dir: third-party/nwaku
git-subtree-split: d94cb7c73631ffd4b934839ba58bc622d331a135
2025-10-02 11:52:12 +02:00

49 lines
1.2 KiB
Nim

{.used.}
import testutils/unittests
import stew/results, waku/waku_core/message, waku/waku_core/time, ./testlib/common
suite "Waku Payload":
test "Encode/Decode waku message with timestamp":
## Test encoding and decoding of the timestamp field of a WakuMessage
## Given
let
version = 0'u32
payload = @[byte 0, 1, 2]
timestamp = Timestamp(10)
msg = WakuMessage(payload: payload, version: version, timestamp: timestamp)
## When
let pb = msg.encode()
let msgDecoded = WakuMessage.decode(pb.buffer)
## Then
check:
msgDecoded.isOk()
let timestampDecoded = msgDecoded.value.timestamp
check:
timestampDecoded == timestamp
test "Encode/Decode waku message without timestamp":
## Test the encoding and decoding of a WakuMessage with an empty timestamp field
## Given
let
version = 0'u32
payload = @[byte 0, 1, 2]
msg = WakuMessage(payload: payload, version: version)
## When
let pb = msg.encode()
let msgDecoded = WakuMessage.decode(pb.buffer)
## Then
check:
msgDecoded.isOk()
let timestampDecoded = msgDecoded.value.timestamp
check:
timestampDecoded == Timestamp(0)