From ff8622f87777294e61a861bec6c18c71ca030821 Mon Sep 17 00:00:00 2001 From: ABresting Date: Fri, 27 Oct 2023 12:33:50 +0200 Subject: [PATCH] feat: reviews updated --- tests/waku_archive/test_driver_queue.nim | 2 +- .../test_driver_queue_pagination.nim | 2 +- tests/waku_store/test_resume.nim | 2 +- tests/wakunode_rest/test_rest_store.nim | 16 ++++---- waku/waku_api/rest/store/client.nim | 2 +- waku/waku_api/rest/store/handlers.nim | 12 +++--- waku/waku_api/rest/store/types.nim | 40 +++++++++---------- waku/waku_archive/archive.nim | 8 ++-- waku/waku_archive/common.nim | 6 +-- waku/waku_archive/driver.nim | 2 +- .../postgres_driver/postgres_driver.nim | 2 +- .../driver/queue_driver/index.nim | 2 +- .../driver/queue_driver/queue_driver.nim | 2 +- .../driver/sqlite_driver/migrations.nim | 8 ++-- .../driver/sqlite_driver/sqlite_driver.nim | 4 +- waku/waku_store/common.nim | 8 ++-- waku/waku_store/rpc.nim | 6 +-- waku/waku_store/rpc_codec.nim | 2 +- 18 files changed, 63 insertions(+), 63 deletions(-) diff --git a/tests/waku_archive/test_driver_queue.nim b/tests/waku_archive/test_driver_queue.nim index ca2560559..d38416451 100644 --- a/tests/waku_archive/test_driver_queue.nim +++ b/tests/waku_archive/test_driver_queue.nim @@ -23,7 +23,7 @@ proc genIndexedWakuMessage(i: int8): IndexedWakuMessage = cursor = Index( receiverTime: Timestamp(i), senderTime: Timestamp(i), - messageHash: MessageDigest(data: data), + messageHash: MessageHash(data: data), pubsubTopic: "test-pubsub-topic" ) diff --git a/tests/waku_archive/test_driver_queue_pagination.nim b/tests/waku_archive/test_driver_queue_pagination.nim index 05bf70236..8fb41875e 100644 --- a/tests/waku_archive/test_driver_queue_pagination.nim +++ b/tests/waku_archive/test_driver_queue_pagination.nim @@ -25,7 +25,7 @@ proc getTestQueueDriver(numMessages: int): QueueDriver = index: Index( receiverTime: Timestamp(i), senderTime: Timestamp(i), - messageHash: MessageDigest(data: data) + messageHash: MessageHash(data: data) ) ) discard testQueueDriver.add(msg) diff --git a/tests/waku_store/test_resume.nim b/tests/waku_store/test_resume.nim index 1a4bfbef5..4b872a9a5 100644 --- a/tests/waku_store/test_resume.nim +++ b/tests/waku_store/test_resume.nim @@ -11,7 +11,7 @@ import ../../waku/node/message_store/sqlite_store, ../../waku/node/peer_manager, ../../waku/waku_core, - ../../waku/waku_store + ../../waku/waku_store, ./testlib/common, ./testlib/switch diff --git a/tests/wakunode_rest/test_rest_store.nim b/tests/wakunode_rest/test_rest_store.nim index 994f871d8..39f54ecae 100644 --- a/tests/wakunode_rest/test_rest_store.nim +++ b/tests/wakunode_rest/test_rest_store.nim @@ -53,19 +53,19 @@ proc testWakuNode(): WakuNode = ################################################################################ procSuite "Waku v2 Rest API - Store": - asyncTest "MessageDigest <-> string conversions": - # Validate MessageDigest conversion from a WakuMessage obj + asyncTest "MessageHash <-> string conversions": + # Validate MessageHash conversion from a WakuMessage obj let wakuMsg = WakuMessage( contentTopic: "Test content topic", payload: @[byte('H'), byte('i'), byte('!')] ) - let messageDigest = waku_store.computeDigest(wakuMsg, DefaultPubsubTopic) - let restMsgDigest = some(messageDigest.toRestStringMessageDigest()) + let messageHash = waku_store.computeDigest(wakuMsg, DefaultPubsubTopic) + let restMsgDigest = some(messageHash.toRestStringMessageDigest()) let parsedMsgDigest = restMsgDigest.parseMsgDigest().value check: - messageDigest == parsedMsgDigest.get() + messageHash == parsedMsgDigest.get() # Random validation. Obtained the raw values manually let expected = some("ZjNhM2Q2NDkwMTE0MjMzNDg0MzJlMDdiZGI3NzIwYTc%3D") @@ -198,7 +198,7 @@ procSuite "Waku v2 Rest API - Store": var reqPubsubTopic = DefaultPubsubTopic var reqSenderTime = Timestamp(0) var reqStoreTime = Timestamp(0) - var reqDigest = waku_store.MessageDigest() + var reqHash = waku_store.MessageHash() for i in 0..<2: let response = @@ -210,7 +210,7 @@ procSuite "Waku v2 Rest API - Store": "", # end time. Empty ignores the field. encodeUrl($reqSenderTime), # sender time encodeUrl($reqStoreTime), # store time - reqDigest.toRestStringMessageDigest(), # base64-encoded digest. Empty ignores the field. + reqHash.toRestStringMessageDigest(), # base64-encoded hash. Empty ignores the field. "7", # page size. Empty implies default page size. "true" # ascending ) @@ -224,7 +224,7 @@ procSuite "Waku v2 Rest API - Store": # populate the cursor for next page if response.data.cursor.isSome(): reqPubsubTopic = response.data.cursor.get().pubsubTopic - reqDigest = response.data.cursor.get().messageHash + reqHash = response.data.cursor.get().messageHash reqSenderTime = response.data.cursor.get().senderTime reqStoreTime = response.data.cursor.get().storeTime diff --git a/waku/waku_api/rest/store/client.nim b/waku/waku_api/rest/store/client.nim index 24a3dc2f3..e61b26854 100644 --- a/waku/waku_api/rest/store/client.nim +++ b/waku/waku_api/rest/store/client.nim @@ -60,7 +60,7 @@ proc getStoreMessagesV1*( # Optional cursor fields senderTime: string = "", storeTime: string = "", - messageHash: string = "", # base64-encoded digest + messageHash: string = "", # base64-encoded hash pageSize: string = "", ascending: string = "" diff --git a/waku/waku_api/rest/store/handlers.nim b/waku/waku_api/rest/store/handlers.nim index 8eaa3f1c8..220f26c53 100644 --- a/waku/waku_api/rest/store/handlers.nim +++ b/waku/waku_api/rest/store/handlers.nim @@ -89,23 +89,23 @@ proc parseCursor(parsedPubsubTopic: Option[string], if not parsedStoreTime.isOk(): return err(parsedStoreTime.error) - # Parse message digest - let parsedMsgDigest = parseMsgDigest(messageHash) - if not parsedMsgDigest.isOk(): - return err(parsedMsgDigest.error) + # Parse message hash + let parsedMsgHash = parseMsgDigest(messageHash) + if not parsedMsgHash.isOk(): + return err(parsedMsgHash.error) # Parse cursor information if parsedPubsubTopic.isSome() and parsedSenderTime.value.isSome() and parsedStoreTime.value.isSome() and - parsedMsgDigest.value.isSome(): + parsedMsgHash.value.isSome(): return ok(some( HistoryCursor( pubsubTopic: parsedPubsubTopic.get(), senderTime: parsedSenderTime.value.get(), storeTime: parsedStoreTime.value.get(), - messageHash: parsedMsgDigest.value.get()) + messageHash: parsedMsgHash.value.get()) )) else: return ok(none(HistoryCursor)) diff --git a/waku/waku_api/rest/store/types.nim b/waku/waku_api/rest/store/types.nim index 78b5a3d94..d8ac8c139 100644 --- a/waku/waku_api/rest/store/types.nim +++ b/waku/waku_api/rest/store/types.nim @@ -24,7 +24,7 @@ type pubsubTopic*: PubsubTopic senderTime*: Timestamp storeTime*: Timestamp - messageHash*: MessageDigest + messageHash*: MessageHash StoreRequestRest* = object # inspired by https://github.com/waku-org/nwaku/blob/f95147f5b7edfd45f914586f2d41cd18fb0e0d18/waku/v2//waku_store/common.nim#L52 @@ -53,37 +53,37 @@ type #### Type conversion -# Converts a URL-encoded-base64 string into a 'MessageDigest' +# Converts a URL-encoded-base64 string into a 'MessageHash' proc parseMsgDigest*(input: Option[string]): - Result[Option[MessageDigest], string] = + Result[Option[MessageHash], string] = if not input.isSome() or input.get() == "": - return ok(none(MessageDigest)) + return ok(none(MessageHash)) let decodedUrl = decodeUrl(input.get()) let base64Decoded = base64.decode(Base64String(decodedUrl)) - var messageDigest = MessageDigest() + var messageHash = MessageHash() if not base64Decoded.isOk(): return err(base64Decoded.error) let base64DecodedArr = base64Decoded.get() # Next snippet inspired by "nwaku/waku/waku_archive/archive.nim" - # TODO: Improve coherence of MessageDigest type - messageDigest = block: + # TODO: Improve coherence of MessageHash type + messageHash = block: var data: array[32, byte] for i in 0..