mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-27 07:06:42 +00:00
Add timestamp field to the waku message (#450)
* adds timestamp field * unit test for timestamp * adds comments * updates test title
This commit is contained in:
parent
683577f045
commit
192c2c7ea0
@ -2,6 +2,7 @@
|
||||
import
|
||||
std/[algorithm, options],
|
||||
testutils/unittests, nimcrypto/sha2,
|
||||
libp2p/protobuf/minprotobuf,
|
||||
../../waku/v2/protocol/waku_store/waku_store,
|
||||
../test_helpers
|
||||
|
||||
@ -214,3 +215,47 @@ procSuite "pagination":
|
||||
newPagingInfo.cursor == pagingInfo.cursor
|
||||
newPagingInfo.direction == pagingInfo.direction
|
||||
newPagingInfo.pageSize == 0
|
||||
|
||||
suite "time-window history query":
|
||||
test "Encode/Decode waku message with timestamp":
|
||||
# test encoding and decoding of the timestamp field of a WakuMessage
|
||||
# Encoding
|
||||
let
|
||||
version = 0'u32
|
||||
payload = @[byte 0, 1, 2]
|
||||
proof = @[byte 0, 1, 2, 3]
|
||||
timestamp = float64(10)
|
||||
msg = WakuMessage(payload: payload, version: version, proof: proof, timestamp: timestamp)
|
||||
pb = msg.encode()
|
||||
|
||||
# Decoding
|
||||
let
|
||||
msgDecoded = WakuMessage.init(pb.buffer)
|
||||
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
|
||||
|
||||
# Encoding
|
||||
let
|
||||
version = 0'u32
|
||||
payload = @[byte 0, 1, 2]
|
||||
proof = @[byte 0, 1, 2, 3]
|
||||
msg = WakuMessage(payload: payload, version: version, proof: proof)
|
||||
pb = msg.encode()
|
||||
|
||||
# Decoding
|
||||
let
|
||||
msgDecoded = WakuMessage.init(pb.buffer)
|
||||
doAssert:
|
||||
msgDecoded.isOk()
|
||||
|
||||
let
|
||||
timestampDecoded = msgDecoded.value.timestamp
|
||||
check:
|
||||
timestampDecoded == float64(0)
|
||||
|
@ -19,6 +19,8 @@ type
|
||||
# the proof field indicates that the message is not a spam
|
||||
# this field will be used in the rln-relay protocol
|
||||
proof*: seq[byte]
|
||||
# sender generated timestamp
|
||||
timestamp*: float64
|
||||
|
||||
# Encoding and decoding -------------------------------------------------------
|
||||
proc init*(T: type WakuMessage, buffer: seq[byte]): ProtoResult[T] =
|
||||
@ -29,6 +31,7 @@ proc init*(T: type WakuMessage, buffer: seq[byte]): ProtoResult[T] =
|
||||
discard ? pb.getField(2, msg.contentTopic)
|
||||
discard ? pb.getField(3, msg.version)
|
||||
discard ? pb.getField(4, msg.proof)
|
||||
discard ? pb.getField(5, msg.timestamp)
|
||||
|
||||
ok(msg)
|
||||
|
||||
@ -39,3 +42,4 @@ proc encode*(message: WakuMessage): ProtoBuffer =
|
||||
result.write(2, message.contentTopic)
|
||||
result.write(3, message.version)
|
||||
result.write(4, message.proof)
|
||||
result.write(5, message.timestamp)
|
||||
|
Loading…
x
Reference in New Issue
Block a user