nwaku/tests/waku_relay/test_message_id.nim
Álex Cabeza Romero f5f431382b
test(waku-relay): Relay (#2101)
* Implement message id tests.
* Implement relay tests.
* Update import paths to use test_all.
2023-11-15 16:11:36 +01:00

38 lines
1.1 KiB
Nim

import
unittest,
stew/shims/net,
stew/[results, byteutils]
import
stew/results,
nimcrypto/sha2,
libp2p/protocols/pubsub/rpc/messages,
../../../waku/waku_relay/message_id,
../testlib/sequtils
suite "Message ID Provider":
test "Non-empty string":
let message = Message(data: "Hello, world!".toBytes())
let result = defaultMessageIdProvider(message)
let expected = MDigest[256].fromHex("315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3")
check:
result.isOk()
result.get() == expected.data
test "Empty string":
let message = Message(data: "".toBytes())
let result = defaultMessageIdProvider(message)
let expected = MDigest[256].fromHex("E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855")
check:
result.isOk()
result.get() == expected.data
test "Empty array":
let message = Message(data: @[])
let result = defaultMessageIdProvider(message)
let expected = MDigest[256].fromHex("E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855")
check:
result.isOk()
result.get() == expected.data