2022-08-01 10:49:44 +00:00
|
|
|
{.used.}
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
import std/options, testutils/unittests, chronos
|
2022-08-01 10:49:44 +00:00
|
|
|
import
|
2024-07-05 22:03:38 +00:00
|
|
|
waku/
|
|
|
|
[common/protobuf, common/paging, waku_core, waku_store/common, waku_store/rpc_codec],
|
2023-04-05 14:01:51 +00:00
|
|
|
../testlib/wakucore
|
2023-02-13 10:43:49 +00:00
|
|
|
|
2022-08-01 10:49:44 +00:00
|
|
|
procSuite "Waku Store - RPC codec":
|
2024-04-25 13:09:52 +00:00
|
|
|
test "StoreQueryRequest protobuf codec":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
2024-04-25 13:09:52 +00:00
|
|
|
let query = StoreQueryRequest(
|
|
|
|
requestId: "0",
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
pubsubTopic: some(DefaultPubsubTopic),
|
|
|
|
contentTopics: @[DefaultContentTopic],
|
|
|
|
startTime: some(Timestamp(10)),
|
|
|
|
endTime: some(Timestamp(11)),
|
|
|
|
messageHashes: @[],
|
|
|
|
paginationCursor: none(WakuMessageHash),
|
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(DefaultPageSize),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## When
|
|
|
|
let pb = query.encode()
|
2024-04-25 13:09:52 +00:00
|
|
|
let decodedQuery = StoreQueryRequest.decode(pb.buffer)
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
decodedQuery.isOk()
|
|
|
|
|
|
|
|
check:
|
|
|
|
# the fields of decoded query decodedQuery must be the same as the original query query
|
|
|
|
decodedQuery.value == query
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
test "StoreQueryRequest protobuf codec - empty history query":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
2024-04-25 13:09:52 +00:00
|
|
|
let emptyQuery = StoreQueryRequest()
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## When
|
2022-11-07 15:24:16 +00:00
|
|
|
let pb = emptyQuery.encode()
|
2024-04-25 13:09:52 +00:00
|
|
|
let decodedEmptyQuery = StoreQueryRequest.decode(pb.buffer)
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
decodedEmptyQuery.isOk()
|
|
|
|
|
|
|
|
check:
|
2022-11-09 17:50:18 +00:00
|
|
|
# check the correctness of init and encode for an empty HistoryQueryRPC
|
2022-08-01 10:49:44 +00:00
|
|
|
decodedEmptyQuery.value == emptyQuery
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
test "StoreQueryResponse protobuf codec":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
|
|
|
let
|
|
|
|
message = fakeWakuMessage()
|
2024-04-25 13:09:52 +00:00
|
|
|
hash = computeMessageHash(DefaultPubsubTopic, message)
|
2024-05-08 19:35:56 +00:00
|
|
|
keyValue = WakuMessageKeyValue(
|
|
|
|
messageHash: hash, message: some(message), pubsubTopic: some(DefaultPubsubTopic)
|
|
|
|
)
|
2024-04-25 13:09:52 +00:00
|
|
|
res = StoreQueryResponse(
|
|
|
|
requestId: "1",
|
|
|
|
statusCode: 200,
|
|
|
|
statusDesc: "it's fine",
|
|
|
|
messages: @[keyValue],
|
|
|
|
paginationCursor: none(WakuMessageHash),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2022-08-01 10:49:44 +00:00
|
|
|
## When
|
|
|
|
let pb = res.encode()
|
2024-04-25 13:09:52 +00:00
|
|
|
let decodedRes = StoreQueryResponse.decode(pb.buffer)
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
decodedRes.isOk()
|
|
|
|
|
|
|
|
check:
|
|
|
|
# the fields of decoded response decodedRes must be the same as the original response res
|
|
|
|
decodedRes.value == res
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
test "StoreQueryResponse protobuf codec - empty history response":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
2024-04-25 13:09:52 +00:00
|
|
|
let emptyRes = StoreQueryResponse()
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2022-08-01 10:49:44 +00:00
|
|
|
## When
|
2022-11-07 15:24:16 +00:00
|
|
|
let pb = emptyRes.encode()
|
2024-04-25 13:09:52 +00:00
|
|
|
let decodedEmptyRes = StoreQueryResponse.decode(pb.buffer)
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
decodedEmptyRes.isOk()
|
|
|
|
|
|
|
|
check:
|
2022-11-09 17:50:18 +00:00
|
|
|
# check the correctness of init and encode for an empty HistoryResponseRPC
|
2022-11-17 19:40:08 +00:00
|
|
|
decodedEmptyRes.value == emptyRes
|