2022-11-22 18:40:24 +00:00
|
|
|
{.used.}
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
import std/sequtils, testutils/unittests, chronos
|
2022-11-22 18:40:24 +00:00
|
|
|
import
|
2023-06-22 09:27:40 +00:00
|
|
|
../../../waku/common/databases/db_sqlite,
|
2023-08-09 17:11:50 +00:00
|
|
|
../../../waku/waku_archive,
|
|
|
|
../../../waku/waku_archive/driver/sqlite_driver,
|
|
|
|
../../../waku/waku_core,
|
2023-11-27 17:33:27 +00:00
|
|
|
../waku_archive/archive_utils,
|
2023-02-13 10:43:49 +00:00
|
|
|
../testlib/common,
|
2023-04-05 14:01:51 +00:00
|
|
|
../testlib/wakucore
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
suite "SQLite driver":
|
|
|
|
test "init driver and database":
|
|
|
|
## Given
|
2023-11-27 17:33:27 +00:00
|
|
|
let database = newSqliteDatabase()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
|
|
|
let driverRes = SqliteDriver.new(database)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
driverRes.isOk()
|
|
|
|
|
|
|
|
let driver: ArchiveDriver = driverRes.tryGet()
|
|
|
|
check:
|
|
|
|
not driver.isNil()
|
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
test "insert a message":
|
|
|
|
## Given
|
|
|
|
const contentTopic = "test-content-topic"
|
|
|
|
|
2023-11-27 17:33:27 +00:00
|
|
|
let driver = newSqliteArchiveDriver()
|
2022-11-22 18:40:24 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let msg = fakeWakuMessage(contentTopic = contentTopic)
|
2024-03-12 11:51:03 +00:00
|
|
|
let msgHash = computeMessageHash(DefaultPubsubTopic, msg)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## When
|
2024-03-15 23:08:47 +00:00
|
|
|
let putRes = waitFor driver.put(
|
|
|
|
DefaultPubsubTopic, msg, computeDigest(msg), msgHash, msg.timestamp
|
|
|
|
)
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
putRes.isOk()
|
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
let storedMsg = (waitFor driver.getAllMessages()).tryGet()
|
2022-11-22 18:40:24 +00:00
|
|
|
check:
|
|
|
|
storedMsg.len == 1
|
2024-03-15 23:08:47 +00:00
|
|
|
storedMsg.all do(item: auto) -> bool:
|
2024-03-12 11:51:03 +00:00
|
|
|
let (pubsubTopic, msg, _, _, hash) = item
|
2024-03-15 23:08:47 +00:00
|
|
|
msg.contentTopic == contentTopic and pubsubTopic == DefaultPubsubTopic and
|
|
|
|
hash == msgHash
|
2022-11-22 18:40:24 +00:00
|
|
|
|
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
(waitFor driver.close()).expect("driver to close")
|