-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(store-archive): Remove duplicated code (#2234)
* Refactor utility functions for store and archive test.
- Loading branch information
1 parent
c301e88
commit 38e100e
Showing
13 changed files
with
205 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
{.used.} | ||
|
||
import | ||
std/options, | ||
chronos, | ||
chronicles, | ||
libp2p/crypto/crypto | ||
|
||
import | ||
../../../waku/[ | ||
node/peer_manager, | ||
waku_core, | ||
waku_archive, | ||
waku_archive/common, | ||
waku_archive/driver/sqlite_driver, | ||
common/databases/db_sqlite, | ||
waku_store | ||
], | ||
../testlib/[ | ||
common, | ||
wakucore | ||
] | ||
|
||
|
||
proc newSqliteDatabase*(): SqliteDatabase = | ||
SqliteDatabase.new(":memory:").tryGet() | ||
|
||
|
||
proc newSqliteArchiveDriver*(): ArchiveDriver = | ||
let database = newSqliteDatabase() | ||
SqliteDriver.new(database).tryGet() | ||
|
||
|
||
proc newWakuArchive*(driver: ArchiveDriver): WakuArchive = | ||
WakuArchive.new(driver).get() | ||
|
||
|
||
proc computeArchiveCursor*(pubsubTopic: PubsubTopic, message: WakuMessage): ArchiveCursor = | ||
ArchiveCursor( | ||
pubsubTopic: pubsubTopic, | ||
senderTime: message.timestamp, | ||
storeTime: message.timestamp, | ||
digest: waku_archive.computeDigest(message) | ||
) | ||
|
||
|
||
proc newArchiveDriverWithMessages*(pubsubTopic: PubSubTopic, msgList: seq[WakuMessage]): ArchiveDriver = | ||
let driver = newSqliteArchiveDriver() | ||
|
||
for msg in msgList: | ||
let | ||
msgDigest = waku_archive.computeDigest(msg) | ||
msgHash = computeMessageHash(pubsubTopic, msg) | ||
discard waitFor driver.put(pubsubTopic, msg, msgDigest, msgHash, msg.timestamp) | ||
|
||
return driver |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.