2022-08-01 10:49:44 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2022-11-17 19:40:08 +00:00
|
|
|
std/options,
|
2022-11-04 09:52:08 +00:00
|
|
|
testutils/unittests,
|
|
|
|
chronos
|
2022-08-01 10:49:44 +00:00
|
|
|
import
|
2023-01-27 13:31:58 +00:00
|
|
|
../../../waku/common/protobuf,
|
2023-12-19 14:10:27 +00:00
|
|
|
../../../waku/common/paging,
|
2023-08-09 17:11:50 +00:00
|
|
|
../../../waku/waku_core,
|
|
|
|
../../../waku/waku_store/rpc,
|
|
|
|
../../../waku/waku_store/rpc_codec,
|
2023-02-13 10:43:49 +00:00
|
|
|
../testlib/common,
|
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":
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
test "PagingIndexRPC protobuf codec":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
2022-11-09 17:50:18 +00:00
|
|
|
let index = PagingIndexRPC.compute(fakeWakuMessage(), receivedTime=ts(), pubsubTopic=DefaultPubsubTopic)
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## When
|
|
|
|
let encodedIndex = index.encode()
|
2022-11-09 17:50:18 +00:00
|
|
|
let decodedIndexRes = PagingIndexRPC.decode(encodedIndex.buffer)
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
decodedIndexRes.isOk()
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2022-08-01 10:49:44 +00:00
|
|
|
let decodedIndex = decodedIndexRes.tryGet()
|
|
|
|
check:
|
|
|
|
# The fields of decodedIndex must be the same as the original index
|
|
|
|
decodedIndex == index
|
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
test "PagingIndexRPC protobuf codec - empty index":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
2022-11-09 17:50:18 +00:00
|
|
|
let emptyIndex = PagingIndexRPC()
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2022-08-01 10:49:44 +00:00
|
|
|
let encodedIndex = emptyIndex.encode()
|
2022-11-09 17:50:18 +00:00
|
|
|
let decodedIndexRes = PagingIndexRPC.decode(encodedIndex.buffer)
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
decodedIndexRes.isOk()
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2022-08-01 10:49:44 +00:00
|
|
|
let decodedIndex = decodedIndexRes.tryGet()
|
|
|
|
check:
|
2022-11-09 17:50:18 +00:00
|
|
|
# Check the correctness of init and encode for an empty PagingIndexRPC
|
2022-08-01 10:49:44 +00:00
|
|
|
decodedIndex == emptyIndex
|
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
test "PagingInfoRPC protobuf codec":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
|
|
|
let
|
2022-11-09 17:50:18 +00:00
|
|
|
index = PagingIndexRPC.compute(fakeWakuMessage(), receivedTime=ts(), pubsubTopic=DefaultPubsubTopic)
|
2023-12-19 14:10:27 +00:00
|
|
|
pagingInfo = PagingInfoRPC(pageSize: some(1'u64), cursor: some(index), direction: some(PagingDirection.FORWARD))
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2022-08-01 10:49:44 +00:00
|
|
|
## When
|
|
|
|
let pb = pagingInfo.encode()
|
2022-11-09 17:50:18 +00:00
|
|
|
let decodedPagingInfo = PagingInfoRPC.decode(pb.buffer)
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
decodedPagingInfo.isOk()
|
|
|
|
|
|
|
|
check:
|
2022-11-17 19:40:08 +00:00
|
|
|
# The fields of decodedPagingInfo must be the same as the original pagingInfo
|
2022-08-01 10:49:44 +00:00
|
|
|
decodedPagingInfo.value == pagingInfo
|
|
|
|
decodedPagingInfo.value.direction == pagingInfo.direction
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
test "PagingInfoRPC protobuf codec - empty paging info":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
2022-11-09 17:50:18 +00:00
|
|
|
let emptyPagingInfo = PagingInfoRPC()
|
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 = emptyPagingInfo.encode()
|
2022-11-09 17:50:18 +00:00
|
|
|
let decodedEmptyPagingInfo = PagingInfoRPC.decode(pb.buffer)
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
decodedEmptyPagingInfo.isOk()
|
|
|
|
|
|
|
|
check:
|
2022-11-09 17:50:18 +00:00
|
|
|
# check the correctness of init and encode for an empty PagingInfoRPC
|
2022-08-01 10:49:44 +00:00
|
|
|
decodedEmptyPagingInfo.value == emptyPagingInfo
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
test "HistoryQueryRPC protobuf codec":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
|
|
|
let
|
2022-11-09 17:50:18 +00:00
|
|
|
index = PagingIndexRPC.compute(fakeWakuMessage(), receivedTime=ts(), pubsubTopic=DefaultPubsubTopic)
|
2023-12-19 14:10:27 +00:00
|
|
|
pagingInfo = PagingInfoRPC(pageSize: some(1'u64), cursor: some(index), direction: some(PagingDirection.BACKWARD))
|
2022-11-17 19:40:08 +00:00
|
|
|
query = HistoryQueryRPC(
|
|
|
|
contentFilters: @[HistoryContentFilterRPC(contentTopic: DefaultContentTopic), HistoryContentFilterRPC(contentTopic: DefaultContentTopic)],
|
2023-01-27 13:31:58 +00:00
|
|
|
pagingInfo: some(pagingInfo),
|
|
|
|
startTime: some(Timestamp(10)),
|
2022-11-17 19:40:08 +00:00
|
|
|
endTime: some(Timestamp(11))
|
|
|
|
)
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2022-08-01 10:49:44 +00:00
|
|
|
## When
|
|
|
|
let pb = query.encode()
|
2022-11-09 17:50:18 +00:00
|
|
|
let decodedQuery = HistoryQueryRPC.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
|
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
test "HistoryQueryRPC protobuf codec - empty history query":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
2022-11-09 17:50:18 +00:00
|
|
|
let emptyQuery = HistoryQueryRPC()
|
2022-08-01 10:49:44 +00:00
|
|
|
|
|
|
|
## When
|
2022-11-07 15:24:16 +00:00
|
|
|
let pb = emptyQuery.encode()
|
2022-11-09 17:50:18 +00:00
|
|
|
let decodedEmptyQuery = HistoryQueryRPC.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
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
test "HistoryResponseRPC protobuf codec":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
|
|
|
let
|
|
|
|
message = fakeWakuMessage()
|
2022-11-09 17:50:18 +00:00
|
|
|
index = PagingIndexRPC.compute(message, receivedTime=ts(), pubsubTopic=DefaultPubsubTopic)
|
2023-12-19 14:10:27 +00:00
|
|
|
pagingInfo = PagingInfoRPC(pageSize: some(1'u64), cursor: some(index), direction: some(PagingDirection.BACKWARD))
|
2022-11-17 19:40:08 +00:00
|
|
|
res = HistoryResponseRPC(messages: @[message], pagingInfo: some(pagingInfo), error: HistoryResponseErrorRPC.INVALID_CURSOR)
|
2023-01-27 13:31:58 +00:00
|
|
|
|
2022-08-01 10:49:44 +00:00
|
|
|
## When
|
|
|
|
let pb = res.encode()
|
2022-11-09 17:50:18 +00:00
|
|
|
let decodedRes = HistoryResponseRPC.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
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
test "HistoryResponseRPC protobuf codec - empty history response":
|
2022-08-01 10:49:44 +00:00
|
|
|
## Given
|
2022-11-09 17:50:18 +00:00
|
|
|
let emptyRes = HistoryResponseRPC()
|
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()
|
2022-11-09 17:50:18 +00:00
|
|
|
let decodedEmptyRes = HistoryResponseRPC.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
|