2024-03-15 23:08:47 +00:00
|
|
|
import
|
2023-11-15 15:11:36 +00:00
|
|
|
unittest,
|
2024-03-15 23:08:47 +00:00
|
|
|
stew/[shims/net, results, byteutils],
|
2023-11-15 15:15:38 +00:00
|
|
|
nimcrypto/sha2,
|
|
|
|
libp2p/protocols/pubsub/rpc/messages
|
2023-11-15 15:11:36 +00:00
|
|
|
|
2024-07-05 22:03:38 +00:00
|
|
|
import waku/waku_relay/message_id, ../testlib/sequtils
|
2023-11-15 15:11:36 +00:00
|
|
|
|
|
|
|
suite "Message ID Provider":
|
|
|
|
test "Non-empty string":
|
|
|
|
let message = Message(data: "Hello, world!".toBytes())
|
|
|
|
let result = defaultMessageIdProvider(message)
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected = MDigest[256].fromHex(
|
|
|
|
"315f5bdb76d078c43b8ac0064e4a0164612b1fce77c869345bfc94c75894edd3"
|
|
|
|
)
|
2023-11-15 15:11:36 +00:00
|
|
|
check:
|
|
|
|
result.isOk()
|
|
|
|
result.get() == expected.data
|
|
|
|
|
|
|
|
test "Empty string":
|
|
|
|
let message = Message(data: "".toBytes())
|
|
|
|
let result = defaultMessageIdProvider(message)
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected = MDigest[256].fromHex(
|
|
|
|
"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"
|
|
|
|
)
|
2023-11-15 15:11:36 +00:00
|
|
|
check:
|
|
|
|
result.isOk()
|
|
|
|
result.get() == expected.data
|
2024-03-15 23:08:47 +00:00
|
|
|
|
2023-11-15 15:11:36 +00:00
|
|
|
test "Empty array":
|
|
|
|
let message = Message(data: @[])
|
|
|
|
let result = defaultMessageIdProvider(message)
|
2024-03-15 23:08:47 +00:00
|
|
|
let expected = MDigest[256].fromHex(
|
|
|
|
"E3B0C44298FC1C149AFBF4C8996FB92427AE41E4649B934CA495991B7852B855"
|
|
|
|
)
|
2023-11-15 15:11:36 +00:00
|
|
|
check:
|
|
|
|
result.isOk()
|
|
|
|
result.get() == expected.data
|