2021-03-23 08:04:51 +00:00
|
|
|
{.used.}
|
2020-11-16 08:38:52 +00:00
|
|
|
|
|
|
|
import
|
|
|
|
std/[unittest, options, tables, sets],
|
|
|
|
chronos, chronicles,
|
2021-03-25 08:37:11 +00:00
|
|
|
../../waku/v2/node/storage/message/waku_message_store,
|
2020-11-24 04:34:32 +00:00
|
|
|
../../waku/v2/protocol/waku_store/waku_store,
|
2021-01-22 09:39:16 +00:00
|
|
|
./utils
|
2020-11-16 08:38:52 +00:00
|
|
|
|
|
|
|
suite "Message Store":
|
|
|
|
test "set and get works":
|
|
|
|
let
|
2020-11-24 02:50:59 +00:00
|
|
|
database = SqliteDatabase.init("", inMemory = true)[]
|
2021-01-22 09:39:16 +00:00
|
|
|
store = WakuMessageStore.init(database)[]
|
2021-04-08 09:55:19 +00:00
|
|
|
topic = ContentTopic("/waku/2/default-content/proto")
|
2021-04-27 23:52:24 +00:00
|
|
|
pubsubTopic = "/waku/2/default-waku/proto"
|
2020-11-16 08:38:52 +00:00
|
|
|
|
|
|
|
var msgs = @[
|
2021-05-05 22:51:36 +00:00
|
|
|
WakuMessage(payload: @[byte 1, 2, 3], contentTopic: topic, version: uint32(0)),
|
|
|
|
WakuMessage(payload: @[byte 1, 2, 3, 4], contentTopic: topic, version: uint32(1)),
|
|
|
|
WakuMessage(payload: @[byte 1, 2, 3, 4, 5], contentTopic: topic, version: high(uint32)),
|
2020-11-16 08:38:52 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
defer: store.close()
|
|
|
|
|
|
|
|
for msg in msgs:
|
2021-04-27 23:52:24 +00:00
|
|
|
let output = store.put(computeIndex(msg), msg, pubsubTopic)
|
|
|
|
check output.isOk
|
2020-11-16 08:38:52 +00:00
|
|
|
|
2021-05-05 22:51:36 +00:00
|
|
|
var v0Flag, v1Flag, vMaxFlag: bool = false
|
2020-11-16 08:38:52 +00:00
|
|
|
var responseCount = 0
|
2021-04-27 23:52:24 +00:00
|
|
|
proc data(timestamp: uint64, msg: WakuMessage, psTopic: string) =
|
2020-11-16 08:38:52 +00:00
|
|
|
responseCount += 1
|
|
|
|
check msg in msgs
|
2021-04-27 23:52:24 +00:00
|
|
|
check psTopic == pubsubTopic
|
2021-05-05 22:51:36 +00:00
|
|
|
# check the correct retrieval of versions
|
|
|
|
if msg.version == uint32(0): v0Flag = true
|
|
|
|
if msg.version == uint32(1): v1Flag = true
|
|
|
|
# high(uint32) is the largest value that fits in uint32, this is to make sure there is no overflow in the storage
|
|
|
|
if msg.version == high(uint32): vMaxFlag = true
|
|
|
|
|
|
|
|
|
2020-11-16 08:38:52 +00:00
|
|
|
let res = store.getAll(data)
|
|
|
|
|
|
|
|
check:
|
|
|
|
res.isErr == false
|
|
|
|
responseCount == 3
|
2021-05-05 22:51:36 +00:00
|
|
|
v0Flag == true
|
|
|
|
v1Flag == true
|
|
|
|
vMaxFlag == true
|
|
|
|
|
|
|
|
|