mirror of
https://github.com/logos-messaging/logos-delivery.git
synced 2026-07-20 03:30:22 +00:00
* convert all codecs except sds_persistency to proto2 * add common/protobuf_ext.nim: generic array[N,byte] protobuf extension * encode PeerId and MultiAddress via libp2p extensions * encode PublicKey as seq[byte] * change encode() to return seq[byte] and update all .encode().buffer call sites * reduce common/protobuf.nim to ProtobufError/ProtobufResult * add wire-format tests for message, filter v2, lightpush v3/legacy, rln proof * adapt chat2, chat2mix, chat2bridge, wakustealthcommitments * delete tests/common/test_protobuf_validation * add protobuf_serialization to logos_delivery.nimble
98 lines
2.6 KiB
Nim
98 lines
2.6 KiB
Nim
{.used.}
|
|
|
|
import results, testutils/unittests, chronos
|
|
import
|
|
logos_delivery/waku/
|
|
[common/protobuf, common/paging, waku_core, waku_store/common, waku_store/rpc_codec],
|
|
../testlib/wakucore
|
|
|
|
procSuite "Waku Store - RPC codec":
|
|
test "StoreQueryRequest protobuf codec":
|
|
## Given
|
|
let query = StoreQueryRequest(
|
|
requestId: "0",
|
|
includeData: true,
|
|
pubsubTopic: Opt.some(DefaultPubsubTopic),
|
|
contentTopics: @[DefaultContentTopic],
|
|
startTime: Opt.some(Timestamp(10)),
|
|
endTime: Opt.some(Timestamp(11)),
|
|
messageHashes: @[],
|
|
paginationCursor: Opt.none(WakuMessageHash),
|
|
paginationForward: PagingDirection.FORWARD,
|
|
paginationLimit: Opt.some(DefaultPageSize),
|
|
)
|
|
|
|
## When
|
|
let pb = query.encode()
|
|
let decodedQuery = StoreQueryRequest.decode(pb)
|
|
|
|
## Then
|
|
check:
|
|
decodedQuery.isOk()
|
|
|
|
check:
|
|
# the fields of decoded query decodedQuery must be the same as the original query query
|
|
decodedQuery.value == query
|
|
|
|
test "StoreQueryRequest protobuf codec - empty history query":
|
|
## Given
|
|
let emptyQuery = StoreQueryRequest()
|
|
|
|
## When
|
|
let pb = emptyQuery.encode()
|
|
let decodedEmptyQuery = StoreQueryRequest.decode(pb)
|
|
|
|
## Then
|
|
check:
|
|
decodedEmptyQuery.isOk()
|
|
|
|
check:
|
|
# check the correctness of init and encode for an empty HistoryQueryRPC
|
|
decodedEmptyQuery.value == emptyQuery
|
|
|
|
test "StoreQueryResponse protobuf codec":
|
|
## Given
|
|
let
|
|
message = fakeWakuMessage()
|
|
hash = computeMessageHash(DefaultPubsubTopic, message)
|
|
keyValue = WakuMessageKeyValue(
|
|
messageHash: hash,
|
|
message: Opt.some(message),
|
|
pubsubTopic: Opt.some(DefaultPubsubTopic),
|
|
)
|
|
res = StoreQueryResponse(
|
|
requestId: "1",
|
|
statusCode: 200,
|
|
statusDesc: "it's fine",
|
|
messages: @[keyValue],
|
|
paginationCursor: Opt.none(WakuMessageHash),
|
|
)
|
|
|
|
## When
|
|
let pb = res.encode()
|
|
let decodedRes = StoreQueryResponse.decode(pb)
|
|
|
|
## Then
|
|
check:
|
|
decodedRes.isOk()
|
|
|
|
check:
|
|
# the fields of decoded response decodedRes must be the same as the original response res
|
|
decodedRes.value == res
|
|
|
|
test "StoreQueryResponse protobuf codec - empty history response":
|
|
## Given
|
|
let emptyRes = StoreQueryResponse()
|
|
|
|
## When
|
|
let pb = emptyRes.encode()
|
|
let decodedEmptyRes = StoreQueryResponse.decode(pb)
|
|
|
|
## Then
|
|
check:
|
|
decodedEmptyRes.isOk()
|
|
|
|
check:
|
|
# check the correctness of init and encode for an empty HistoryResponseRPC
|
|
decodedEmptyRes.value == emptyRes
|