2020-08-31 03:32:41 +00:00
|
|
|
{.used.}
|
2020-08-27 02:44:09 +00:00
|
|
|
|
2020-08-31 03:32:41 +00:00
|
|
|
import
|
2022-11-04 09:52:08 +00:00
|
|
|
std/[options, sequtils],
|
2022-11-08 15:10:23 +00:00
|
|
|
testutils/unittests,
|
2022-11-09 17:50:18 +00:00
|
|
|
chronos,
|
|
|
|
chronicles,
|
2022-08-02 11:14:13 +00:00
|
|
|
libp2p/crypto/crypto
|
2022-07-25 11:01:37 +00:00
|
|
|
import
|
2022-10-28 18:13:41 +00:00
|
|
|
../../waku/common/sqlite,
|
2022-11-08 15:10:23 +00:00
|
|
|
../../waku/v2/node/message_store/queue_store,
|
2022-11-04 18:48:22 +00:00
|
|
|
../../waku/v2/node/message_store/sqlite_store,
|
2021-03-26 08:49:51 +00:00
|
|
|
../../waku/v2/node/peer_manager/peer_manager,
|
2022-10-28 18:13:41 +00:00
|
|
|
../../waku/v2/protocol/waku_message,
|
|
|
|
../../waku/v2/protocol/waku_store,
|
|
|
|
../../waku/v2/protocol/waku_store/client,
|
2022-02-17 15:00:15 +00:00
|
|
|
../../waku/v2/utils/time,
|
2022-10-21 13:01:39 +00:00
|
|
|
./testlib/common,
|
|
|
|
./testlib/switch
|
2020-08-27 02:44:09 +00:00
|
|
|
|
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
proc newTestDatabase(): SqliteDatabase =
|
2022-10-28 18:13:41 +00:00
|
|
|
SqliteDatabase.new(":memory:").tryGet()
|
2020-09-24 02:16:25 +00:00
|
|
|
|
2022-10-05 15:58:24 +00:00
|
|
|
proc newTestMessageStore(): MessageStore =
|
2022-09-26 09:50:15 +00:00
|
|
|
let database = newTestDatabase()
|
|
|
|
SqliteStore.init(database).tryGet()
|
2020-08-27 02:44:09 +00:00
|
|
|
|
2022-10-20 16:09:40 +00:00
|
|
|
proc newTestWakuStore(switch: Switch, store=newTestMessageStore()): Future[WakuStore] {.async.} =
|
2022-09-13 10:37:06 +00:00
|
|
|
let
|
|
|
|
peerManager = PeerManager.new(switch)
|
|
|
|
rng = crypto.newRng()
|
2022-10-28 18:11:28 +00:00
|
|
|
proto = WakuStore.new(peerManager, rng, store)
|
2022-09-13 10:37:06 +00:00
|
|
|
|
2022-10-20 16:09:40 +00:00
|
|
|
await proto.start()
|
2022-09-13 10:37:06 +00:00
|
|
|
switch.mount(proto)
|
|
|
|
|
|
|
|
return proto
|
|
|
|
|
2022-11-21 10:16:57 +00:00
|
|
|
proc newTestWakuStore(switch: Switch, handler: HistoryQueryHandler): Future[WakuStore] {.async.} =
|
|
|
|
let
|
|
|
|
peerManager = PeerManager.new(switch)
|
|
|
|
rng = crypto.newRng()
|
|
|
|
proto = WakuStore.new(peerManager, rng, handler)
|
|
|
|
|
|
|
|
await proto.start()
|
|
|
|
switch.mount(proto)
|
|
|
|
|
|
|
|
return proto
|
|
|
|
|
2022-10-20 16:09:40 +00:00
|
|
|
proc newTestWakuStoreClient(switch: Switch, store: MessageStore = nil): WakuStoreClient =
|
|
|
|
let
|
|
|
|
peerManager = PeerManager.new(switch)
|
|
|
|
rng = crypto.newRng()
|
|
|
|
WakuStoreClient.new(peerManager, rng, store)
|
|
|
|
|
|
|
|
|
2022-11-21 10:16:57 +00:00
|
|
|
suite "Waku Store - query handler":
|
|
|
|
|
|
|
|
asyncTest "history query handler should be called":
|
|
|
|
## Setup
|
|
|
|
let
|
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
|
|
|
|
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
|
|
|
|
|
|
|
## Given
|
|
|
|
let serverPeerInfo = serverSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
let msg = fakeWakuMessage(contentTopic=DefaultContentTopic)
|
|
|
|
|
|
|
|
var queryHandlerFut = newFuture[(HistoryQuery)]()
|
|
|
|
let queryHandler = proc(req: HistoryQuery): HistoryResult =
|
|
|
|
queryHandlerFut.complete(req)
|
|
|
|
return ok(HistoryResponse(messages: @[msg]))
|
|
|
|
|
|
|
|
let
|
|
|
|
server = await newTestWakuStore(serverSwitch, handler=queryhandler)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
|
|
|
|
|
|
|
let req = HistoryQuery(contentTopics: @[DefaultContentTopic], ascending: true)
|
|
|
|
|
|
|
|
## When
|
|
|
|
let queryRes = await client.query(req, peer=serverPeerInfo)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
not queryHandlerFut.failed()
|
|
|
|
queryRes.isOk()
|
|
|
|
|
|
|
|
let request = queryHandlerFut.read()
|
|
|
|
check:
|
|
|
|
request == req
|
|
|
|
|
|
|
|
let response = queryRes.tryGet()
|
|
|
|
check:
|
|
|
|
response.messages.len == 1
|
|
|
|
response.messages == @[msg]
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await allFutures(serverSwitch.stop(), clientSwitch.stop())
|
|
|
|
|
|
|
|
asyncTest "history query handler should be called and return an error":
|
|
|
|
## Setup
|
|
|
|
let
|
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
|
|
|
|
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
|
|
|
|
|
|
|
## Given
|
|
|
|
let serverPeerInfo = serverSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
var queryHandlerFut = newFuture[(HistoryQuery)]()
|
|
|
|
let queryHandler = proc(req: HistoryQuery): HistoryResult =
|
|
|
|
queryHandlerFut.complete(req)
|
|
|
|
return err(HistoryError(kind: HistoryErrorKind.BAD_REQUEST))
|
|
|
|
|
|
|
|
let
|
|
|
|
server = await newTestWakuStore(serverSwitch, handler=queryhandler)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
|
|
|
|
|
|
|
let req = HistoryQuery(contentTopics: @[DefaultContentTopic], ascending: true)
|
|
|
|
|
|
|
|
## When
|
|
|
|
let queryRes = await client.query(req, peer=serverPeerInfo)
|
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
not queryHandlerFut.failed()
|
|
|
|
queryRes.isErr()
|
|
|
|
|
|
|
|
let request = queryHandlerFut.read()
|
|
|
|
check:
|
|
|
|
request == req
|
|
|
|
|
|
|
|
let error = queryRes.tryError()
|
|
|
|
check:
|
|
|
|
error.kind == HistoryErrorKind.BAD_REQUEST
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await allFutures(serverSwitch.stop(), clientSwitch.stop())
|
|
|
|
|
|
|
|
|
2022-10-05 15:58:24 +00:00
|
|
|
procSuite "Waku Store - history query":
|
|
|
|
## Fixtures
|
|
|
|
let storeA = block:
|
|
|
|
let store = newTestMessageStore()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-10-05 15:58:24 +00:00
|
|
|
let msgList = @[
|
|
|
|
fakeWakuMessage(contentTopic=ContentTopic("2"), ts=Timestamp(0)),
|
|
|
|
fakeWakuMessage(contentTopic=ContentTopic("1"), ts=Timestamp(1)),
|
|
|
|
fakeWakuMessage(contentTopic=ContentTopic("2"), ts=Timestamp(2)),
|
|
|
|
fakeWakuMessage(contentTopic=ContentTopic("1"), ts=Timestamp(3)),
|
|
|
|
fakeWakuMessage(contentTopic=ContentTopic("2"), ts=Timestamp(4)),
|
|
|
|
fakeWakuMessage(contentTopic=ContentTopic("1"), ts=Timestamp(5)),
|
|
|
|
fakeWakuMessage(contentTopic=ContentTopic("2"), ts=Timestamp(6)),
|
|
|
|
fakeWakuMessage(contentTopic=ContentTopic("1"), ts=Timestamp(7)),
|
|
|
|
fakeWakuMessage(contentTopic=ContentTopic("2"), ts=Timestamp(8)),
|
|
|
|
fakeWakuMessage(contentTopic=ContentTopic("1"), ts=Timestamp(9))
|
|
|
|
]
|
|
|
|
|
|
|
|
for msg in msgList:
|
|
|
|
require store.put(DefaultPubsubTopic, msg, computeDigest(msg), msg.timestamp).isOk()
|
|
|
|
|
|
|
|
store
|
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
asyncTest "handle query":
|
|
|
|
## Setup
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
2022-11-21 10:16:57 +00:00
|
|
|
|
|
|
|
let
|
2022-10-20 16:09:40 +00:00
|
|
|
server = await newTestWakuStore(serverSwitch)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
2021-04-19 17:38:30 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Given
|
|
|
|
let topic = ContentTopic("1")
|
2021-04-19 17:38:30 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
msg1 = fakeWakuMessage(contentTopic=topic)
|
|
|
|
msg2 = fakeWakuMessage()
|
2021-04-19 17:38:30 +00:00
|
|
|
|
2022-10-20 16:09:40 +00:00
|
|
|
server.handleMessage("foo", msg1)
|
|
|
|
server.handleMessage("foo", msg2)
|
2021-04-19 17:38:30 +00:00
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
let serverPeerInfo =serverSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## When
|
2022-11-09 17:50:18 +00:00
|
|
|
let req = HistoryQuery(contentTopics: @[topic])
|
|
|
|
let queryRes = await client.query(req, peer=serverPeerInfo)
|
2021-04-19 17:38:30 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Then
|
|
|
|
check:
|
2022-11-09 17:50:18 +00:00
|
|
|
queryRes.isOk()
|
2021-04-19 17:38:30 +00:00
|
|
|
|
2022-11-21 10:16:57 +00:00
|
|
|
let response = queryRes.tryGet()
|
2020-08-27 02:44:09 +00:00
|
|
|
check:
|
2022-08-02 11:14:13 +00:00
|
|
|
response.messages.len == 1
|
2022-10-20 16:09:40 +00:00
|
|
|
response.messages == @[msg1]
|
2022-01-25 02:31:14 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Cleanup
|
|
|
|
await allFutures(serverSwitch.stop(), clientSwitch.stop())
|
2021-04-27 23:52:24 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
asyncTest "handle query with multiple content filters":
|
|
|
|
## Setup
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
2022-11-21 10:16:57 +00:00
|
|
|
|
|
|
|
let
|
2022-10-20 16:09:40 +00:00
|
|
|
server = await newTestWakuStore(serverSwitch)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
2021-04-27 23:52:24 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Given
|
2021-04-27 23:52:24 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
topic1 = ContentTopic("1")
|
|
|
|
topic2 = ContentTopic("2")
|
|
|
|
topic3 = ContentTopic("3")
|
2021-04-27 23:52:24 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
let
|
|
|
|
msg1 = fakeWakuMessage(contentTopic=topic1)
|
|
|
|
msg2 = fakeWakuMessage(contentTopic=topic2)
|
|
|
|
msg3 = fakeWakuMessage(contentTopic=topic3)
|
2021-04-27 23:52:24 +00:00
|
|
|
|
2022-10-20 16:09:40 +00:00
|
|
|
server.handleMessage("foo", msg1)
|
|
|
|
server.handleMessage("foo", msg2)
|
|
|
|
server.handleMessage("foo", msg3)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
let serverPeerInfo =serverSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## When
|
2022-11-09 17:50:18 +00:00
|
|
|
let req = HistoryQuery(contentTopics: @[topic1, topic3])
|
|
|
|
let queryRes = await client.query(req, peer=serverPeerInfo)
|
2022-08-02 11:14:13 +00:00
|
|
|
|
|
|
|
## Then
|
2021-04-27 23:52:24 +00:00
|
|
|
check:
|
2022-11-09 17:50:18 +00:00
|
|
|
queryRes.isOk()
|
2021-04-27 23:52:24 +00:00
|
|
|
|
2022-11-21 10:16:57 +00:00
|
|
|
let response = queryRes.tryGet()
|
2022-08-02 11:14:13 +00:00
|
|
|
check:
|
|
|
|
response.messages.len() == 2
|
|
|
|
response.messages.anyIt(it == msg1)
|
|
|
|
response.messages.anyIt(it == msg3)
|
2021-04-27 23:52:24 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Cleanup
|
|
|
|
await allFutures(clientSwitch.stop(), serverSwitch.stop())
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
asyncTest "handle query with pubsub topic filter":
|
|
|
|
## Setup
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
2022-11-21 10:16:57 +00:00
|
|
|
|
|
|
|
let
|
2022-10-20 16:09:40 +00:00
|
|
|
server = await newTestWakuStore(serverSwitch)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
2021-04-27 23:52:24 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Given
|
2021-04-27 23:52:24 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
pubsubTopic1 = "queried-topic"
|
|
|
|
pubsubTopic2 = "non-queried-topic"
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2021-04-27 23:52:24 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
contentTopic1 = ContentTopic("1")
|
|
|
|
contentTopic2 = ContentTopic("2")
|
|
|
|
contentTopic3 = ContentTopic("3")
|
2021-04-27 23:52:24 +00:00
|
|
|
|
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
msg1 = fakeWakuMessage(contentTopic=contentTopic1)
|
|
|
|
msg2 = fakeWakuMessage(contentTopic=contentTopic2)
|
|
|
|
msg3 = fakeWakuMessage(contentTopic=contentTopic3)
|
2021-04-27 23:52:24 +00:00
|
|
|
|
2022-10-20 16:09:40 +00:00
|
|
|
server.handleMessage(pubsubtopic1, msg1)
|
|
|
|
server.handleMessage(pubsubtopic2, msg2)
|
|
|
|
server.handleMessage(pubsubtopic2, msg3)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
let serverPeerInfo =serverSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## When
|
2022-11-21 10:16:57 +00:00
|
|
|
# this query targets: pubsubtopic1 AND (contentTopic1 OR contentTopic3)
|
2022-11-09 17:50:18 +00:00
|
|
|
let req = HistoryQuery(
|
|
|
|
pubsubTopic: some(pubsubTopic1),
|
2022-11-21 10:16:57 +00:00
|
|
|
contentTopics: @[contentTopic1, contentTopic3]
|
2022-08-02 11:14:13 +00:00
|
|
|
)
|
2022-11-09 17:50:18 +00:00
|
|
|
let queryRes = await client.query(req, peer=serverPeerInfo)
|
2022-08-02 11:14:13 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
2022-11-09 17:50:18 +00:00
|
|
|
queryRes.isOk()
|
2021-04-27 23:52:24 +00:00
|
|
|
|
2022-11-21 10:16:57 +00:00
|
|
|
let response = queryRes.tryGet()
|
2021-04-27 23:52:24 +00:00
|
|
|
check:
|
2022-08-02 11:14:13 +00:00
|
|
|
response.messages.len() == 1
|
|
|
|
response.messages.anyIt(it == msg1)
|
2020-11-16 08:38:52 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Cleanup
|
|
|
|
await allFutures(clientSwitch.stop(), serverSwitch.stop())
|
2022-01-25 02:31:14 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
asyncTest "handle query with pubsub topic filter - no match":
|
|
|
|
## Setup
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
2022-11-21 10:16:57 +00:00
|
|
|
|
|
|
|
let
|
2022-10-20 16:09:40 +00:00
|
|
|
server = await newTestWakuStore(serverSwitch)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
2020-11-16 08:38:52 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Given
|
2020-11-16 08:38:52 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
pubsubtopic1 = "queried-topic"
|
|
|
|
pubsubtopic2 = "non-queried-topic"
|
2020-11-16 08:38:52 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
let
|
|
|
|
msg1 = fakeWakuMessage()
|
|
|
|
msg2 = fakeWakuMessage()
|
|
|
|
msg3 = fakeWakuMessage()
|
2020-11-16 08:38:52 +00:00
|
|
|
|
2022-10-20 16:09:40 +00:00
|
|
|
server.handleMessage(pubsubtopic2, msg1)
|
|
|
|
server.handleMessage(pubsubtopic2, msg2)
|
|
|
|
server.handleMessage(pubsubtopic2, msg3)
|
2020-11-16 08:38:52 +00:00
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
let serverPeerInfo =serverSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## When
|
2022-11-09 17:50:18 +00:00
|
|
|
let req = HistoryQuery(pubsubTopic: some(pubsubTopic1))
|
|
|
|
let res = await client.query(req, peer=serverPeerInfo)
|
2020-11-16 08:38:52 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Then
|
2020-11-16 08:38:52 +00:00
|
|
|
check:
|
2022-08-02 11:14:13 +00:00
|
|
|
res.isOk()
|
2020-11-16 08:38:52 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
let response = res.tryGet()
|
|
|
|
check:
|
|
|
|
response.messages.len() == 0
|
2020-11-16 08:38:52 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Cleanup
|
|
|
|
await allFutures(clientSwitch.stop(), serverSwitch.stop())
|
2020-11-16 08:38:52 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
asyncTest "handle query with pubsub topic filter - match the entire stored messages":
|
|
|
|
## Setup
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
2022-11-21 10:16:57 +00:00
|
|
|
|
|
|
|
let
|
2022-10-20 16:09:40 +00:00
|
|
|
server = await newTestWakuStore(serverSwitch)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Given
|
|
|
|
let pubsubTopic = "queried-topic"
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2020-11-09 04:48:09 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
msg1 = fakeWakuMessage(payload="TEST-1")
|
|
|
|
msg2 = fakeWakuMessage(payload="TEST-2")
|
|
|
|
msg3 = fakeWakuMessage(payload="TEST-3")
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-10-20 16:09:40 +00:00
|
|
|
server.handleMessage(pubsubTopic, msg1)
|
|
|
|
server.handleMessage(pubsubTopic, msg2)
|
|
|
|
server.handleMessage(pubsubTopic, msg3)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
let serverPeerInfo =serverSwitch.peerInfo.toRemotePeerInfo()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## When
|
2022-11-09 17:50:18 +00:00
|
|
|
let req = HistoryQuery(pubsubTopic: some(pubsubTopic))
|
|
|
|
let res = await client.query(req, peer=serverPeerInfo)
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
let response = res.tryGet()
|
|
|
|
check:
|
|
|
|
response.messages.len() == 3
|
|
|
|
response.messages.anyIt(it == msg1)
|
|
|
|
response.messages.anyIt(it == msg2)
|
|
|
|
response.messages.anyIt(it == msg3)
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Cleanup
|
|
|
|
await allFutures(clientSwitch.stop(), serverSwitch.stop())
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
asyncTest "handle query with forward pagination":
|
|
|
|
## Setup
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
2022-11-21 10:16:57 +00:00
|
|
|
|
|
|
|
let
|
2022-10-20 16:09:40 +00:00
|
|
|
server = await newTestWakuStore(serverSwitch)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
2022-08-02 11:14:13 +00:00
|
|
|
|
|
|
|
## Given
|
2022-10-21 13:01:39 +00:00
|
|
|
let currentTime = now()
|
2022-08-02 11:14:13 +00:00
|
|
|
let msgList = @[
|
2022-10-20 10:24:40 +00:00
|
|
|
WakuMessage(payload: @[byte 0], contentTopic: ContentTopic("2"), timestamp: currentTime - 9),
|
|
|
|
WakuMessage(payload: @[byte 1], contentTopic: DefaultContentTopic, timestamp: currentTime - 8),
|
|
|
|
WakuMessage(payload: @[byte 2], contentTopic: DefaultContentTopic, timestamp: currentTime - 7),
|
|
|
|
WakuMessage(payload: @[byte 3], contentTopic: DefaultContentTopic, timestamp: currentTime - 6),
|
|
|
|
WakuMessage(payload: @[byte 4], contentTopic: DefaultContentTopic, timestamp: currentTime - 5),
|
|
|
|
WakuMessage(payload: @[byte 5], contentTopic: DefaultContentTopic, timestamp: currentTime - 4),
|
|
|
|
WakuMessage(payload: @[byte 6], contentTopic: DefaultContentTopic, timestamp: currentTime - 3),
|
|
|
|
WakuMessage(payload: @[byte 7], contentTopic: DefaultContentTopic, timestamp: currentTime - 2),
|
2022-11-21 10:16:57 +00:00
|
|
|
WakuMessage(payload: @[byte 8], contentTopic: DefaultContentTopic, timestamp: currentTime - 1),
|
2022-10-20 10:24:40 +00:00
|
|
|
WakuMessage(payload: @[byte 9], contentTopic: ContentTopic("2"), timestamp: currentTime)
|
2022-08-02 11:14:13 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for msg in msgList:
|
2022-10-20 16:09:40 +00:00
|
|
|
require server.store.put(DefaultPubsubTopic, msg).isOk()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
let serverPeerInfo =serverSwitch.peerInfo.toRemotePeerInfo()
|
2022-08-02 11:14:13 +00:00
|
|
|
|
|
|
|
## When
|
2022-11-09 17:50:18 +00:00
|
|
|
var req = HistoryQuery(
|
|
|
|
contentTopics: @[DefaultContentTopic],
|
2022-11-21 10:16:57 +00:00
|
|
|
pageSize: 2,
|
2022-11-09 17:50:18 +00:00
|
|
|
ascending: true
|
2022-10-20 16:09:40 +00:00
|
|
|
)
|
2022-11-09 17:50:18 +00:00
|
|
|
var res = await client.query(req, peer=serverPeerInfo)
|
2022-10-20 10:24:40 +00:00
|
|
|
require res.isOk()
|
|
|
|
|
|
|
|
var
|
|
|
|
response = res.tryGet()
|
|
|
|
totalMessages = response.messages.len()
|
|
|
|
totalQueries = 1
|
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
while response.cursor.isSome():
|
2022-10-20 10:24:40 +00:00
|
|
|
require:
|
|
|
|
totalQueries <= 4 # Sanity check here and guarantee that the test will not run forever
|
|
|
|
response.messages.len() == 2
|
2022-11-21 10:16:57 +00:00
|
|
|
response.pageSize == 2
|
2022-11-09 17:50:18 +00:00
|
|
|
response.ascending == true
|
2022-10-20 10:24:40 +00:00
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
req.cursor = response.cursor
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-10-20 10:24:40 +00:00
|
|
|
# Continue querying
|
2022-11-09 17:50:18 +00:00
|
|
|
res = await client.query(req, peer=serverPeerInfo)
|
2022-10-20 10:24:40 +00:00
|
|
|
require res.isOk()
|
|
|
|
response = res.tryGet()
|
|
|
|
totalMessages += response.messages.len()
|
|
|
|
totalQueries += 1
|
2022-08-02 11:14:13 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
2022-10-20 10:24:40 +00:00
|
|
|
totalQueries == 4 # 4 queries of pageSize 2
|
|
|
|
totalMessages == 8 # 8 messages in total
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Cleanup
|
|
|
|
await allFutures(clientSwitch.stop(), serverSwitch.stop())
|
2022-01-25 02:31:14 +00:00
|
|
|
|
2020-11-09 04:48:09 +00:00
|
|
|
asyncTest "handle query with backward pagination":
|
2022-08-02 11:14:13 +00:00
|
|
|
## Setup
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
2022-11-21 10:16:57 +00:00
|
|
|
|
|
|
|
let
|
2022-10-20 16:09:40 +00:00
|
|
|
server = await newTestWakuStore(serverSwitch)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
2022-08-02 11:14:13 +00:00
|
|
|
|
|
|
|
## Given
|
2022-10-21 13:01:39 +00:00
|
|
|
let currentTime = now()
|
2022-08-02 11:14:13 +00:00
|
|
|
let msgList = @[
|
2022-10-20 10:24:40 +00:00
|
|
|
WakuMessage(payload: @[byte 0], contentTopic: ContentTopic("2"), timestamp: currentTime - 9),
|
|
|
|
WakuMessage(payload: @[byte 1], contentTopic: DefaultContentTopic, timestamp: currentTime - 8),
|
|
|
|
WakuMessage(payload: @[byte 2], contentTopic: DefaultContentTopic, timestamp: currentTime - 7),
|
|
|
|
WakuMessage(payload: @[byte 3], contentTopic: DefaultContentTopic, timestamp: currentTime - 6),
|
|
|
|
WakuMessage(payload: @[byte 4], contentTopic: DefaultContentTopic, timestamp: currentTime - 5),
|
|
|
|
WakuMessage(payload: @[byte 5], contentTopic: DefaultContentTopic, timestamp: currentTime - 4),
|
|
|
|
WakuMessage(payload: @[byte 6], contentTopic: DefaultContentTopic, timestamp: currentTime - 3),
|
|
|
|
WakuMessage(payload: @[byte 7], contentTopic: DefaultContentTopic, timestamp: currentTime - 2),
|
2022-11-21 10:16:57 +00:00
|
|
|
WakuMessage(payload: @[byte 8], contentTopic: DefaultContentTopic, timestamp: currentTime - 1),
|
2022-10-20 10:24:40 +00:00
|
|
|
WakuMessage(payload: @[byte 9], contentTopic: ContentTopic("2"), timestamp: currentTime)
|
2022-08-02 11:14:13 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
for msg in msgList:
|
2022-10-20 16:09:40 +00:00
|
|
|
require server.store.put(DefaultPubsubTopic, msg).isOk()
|
2022-08-02 11:14:13 +00:00
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
let serverPeerInfo =serverSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## When
|
2022-11-09 17:50:18 +00:00
|
|
|
var req = HistoryQuery(
|
|
|
|
contentTopics: @[DefaultContentTopic],
|
2022-11-21 10:16:57 +00:00
|
|
|
pageSize: 2,
|
2022-11-09 17:50:18 +00:00
|
|
|
ascending: false
|
2022-10-20 16:09:40 +00:00
|
|
|
)
|
2022-11-09 17:50:18 +00:00
|
|
|
var res = await client.query(req, peer=serverPeerInfo)
|
2022-10-20 10:24:40 +00:00
|
|
|
require res.isOk()
|
2022-10-20 16:09:40 +00:00
|
|
|
|
2022-10-20 10:24:40 +00:00
|
|
|
var
|
|
|
|
response = res.tryGet()
|
|
|
|
totalMessages = response.messages.len()
|
|
|
|
totalQueries = 1
|
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
while response.cursor.isSome():
|
2022-10-20 10:24:40 +00:00
|
|
|
require:
|
|
|
|
totalQueries <= 4 # Sanity check here and guarantee that the test will not run forever
|
|
|
|
response.messages.len() == 2
|
2022-11-21 10:16:57 +00:00
|
|
|
response.pageSize == 2
|
2022-11-09 17:50:18 +00:00
|
|
|
response.ascending == false
|
2022-10-20 10:24:40 +00:00
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
req.cursor = response.cursor
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-10-20 10:24:40 +00:00
|
|
|
# Continue querying
|
2022-11-09 17:50:18 +00:00
|
|
|
res = await client.query(req, peer=serverPeerInfo)
|
2022-10-20 10:24:40 +00:00
|
|
|
require res.isOk()
|
|
|
|
response = res.tryGet()
|
|
|
|
totalMessages += response.messages.len()
|
|
|
|
totalQueries += 1
|
2022-08-02 11:14:13 +00:00
|
|
|
|
|
|
|
## Then
|
2020-11-09 04:48:09 +00:00
|
|
|
check:
|
2022-10-20 10:24:40 +00:00
|
|
|
totalQueries == 4 # 4 queries of pageSize 2
|
|
|
|
totalMessages == 8 # 8 messages in total
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Cleanup
|
|
|
|
await allFutures(clientSwitch.stop(), serverSwitch.stop())
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
asyncTest "handle query with no paging info - auto-pagination":
|
|
|
|
## Setup
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-08-02 11:14:13 +00:00
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
2022-11-21 10:16:57 +00:00
|
|
|
|
|
|
|
let
|
2022-10-20 16:09:40 +00:00
|
|
|
server = await newTestWakuStore(serverSwitch)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
2022-08-02 11:14:13 +00:00
|
|
|
|
|
|
|
## Given
|
|
|
|
let msgList = @[
|
|
|
|
WakuMessage(payload: @[byte 0], contentTopic: ContentTopic("2")),
|
|
|
|
WakuMessage(payload: @[byte 1], contentTopic: DefaultContentTopic),
|
|
|
|
WakuMessage(payload: @[byte 2], contentTopic: DefaultContentTopic),
|
|
|
|
WakuMessage(payload: @[byte 3], contentTopic: DefaultContentTopic),
|
|
|
|
WakuMessage(payload: @[byte 4], contentTopic: DefaultContentTopic),
|
|
|
|
WakuMessage(payload: @[byte 5], contentTopic: DefaultContentTopic),
|
|
|
|
WakuMessage(payload: @[byte 6], contentTopic: DefaultContentTopic),
|
|
|
|
WakuMessage(payload: @[byte 7], contentTopic: DefaultContentTopic),
|
2022-11-21 10:16:57 +00:00
|
|
|
WakuMessage(payload: @[byte 8], contentTopic: DefaultContentTopic),
|
2022-08-02 11:14:13 +00:00
|
|
|
WakuMessage(payload: @[byte 9], contentTopic: ContentTopic("2"))
|
|
|
|
]
|
|
|
|
|
|
|
|
for msg in msgList:
|
2022-10-20 16:09:40 +00:00
|
|
|
require server.store.put(DefaultPubsubTopic, msg).isOk()
|
2022-08-02 11:14:13 +00:00
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
let serverPeerInfo =serverSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## When
|
2022-11-09 17:50:18 +00:00
|
|
|
let req = HistoryQuery(contentTopics: @[DefaultContentTopic])
|
|
|
|
let res = await client.query(req, peer=serverPeerInfo)
|
2022-08-02 11:14:13 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
res.isOk()
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
let response = res.tryGet()
|
|
|
|
check:
|
|
|
|
## No pagination specified. Response will be auto-paginated with
|
|
|
|
## up to MaxPageSize messages per page.
|
|
|
|
response.messages.len() == 8
|
2022-11-09 17:50:18 +00:00
|
|
|
response.cursor.isNone()
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-08-02 11:14:13 +00:00
|
|
|
## Cleanup
|
|
|
|
await allFutures(clientSwitch.stop(), serverSwitch.stop())
|
2020-11-09 04:48:09 +00:00
|
|
|
|
2022-10-05 15:58:24 +00:00
|
|
|
asyncTest "handle temporal history query with a valid time window":
|
|
|
|
## Setup
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-10-05 15:58:24 +00:00
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-10-05 15:58:24 +00:00
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
|
|
|
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-10-05 15:58:24 +00:00
|
|
|
server = newTestWakuStore(serverSwitch, store=storeA)
|
2022-10-20 16:09:40 +00:00
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
2022-10-05 15:58:24 +00:00
|
|
|
|
|
|
|
## Given
|
2022-11-09 17:50:18 +00:00
|
|
|
let req = HistoryQuery(
|
2022-11-21 10:16:57 +00:00
|
|
|
contentTopics: @[ContentTopic("1")],
|
|
|
|
startTime: some(Timestamp(2)),
|
2022-11-09 17:50:18 +00:00
|
|
|
endTime: some(Timestamp(5))
|
2022-10-05 15:58:24 +00:00
|
|
|
)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
let serverPeerInfo =serverSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
|
2022-10-05 15:58:24 +00:00
|
|
|
## When
|
2022-11-09 17:50:18 +00:00
|
|
|
let res = await client.query(req, peer=serverPeerInfo)
|
2022-10-05 15:58:24 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check res.isOk()
|
|
|
|
|
|
|
|
let response = res.tryGet()
|
|
|
|
check:
|
|
|
|
response.messages.len() == 2
|
|
|
|
response.messages.anyIt(it.timestamp == Timestamp(3))
|
|
|
|
response.messages.anyIt(it.timestamp == Timestamp(5))
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await allFutures(clientSwitch.stop(), serverSwitch.stop())
|
2022-10-20 16:09:40 +00:00
|
|
|
|
2022-10-05 15:58:24 +00:00
|
|
|
asyncTest "handle temporal history query with a zero-size time window":
|
|
|
|
# a zero-size window results in an empty list of history messages
|
|
|
|
## Setup
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-10-05 15:58:24 +00:00
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-10-05 15:58:24 +00:00
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
|
|
|
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-10-20 16:09:40 +00:00
|
|
|
server = await newTestWakuStore(serverSwitch, store=storeA)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
2022-10-05 15:58:24 +00:00
|
|
|
|
|
|
|
## Given
|
2022-11-09 17:50:18 +00:00
|
|
|
let req = HistoryQuery(
|
2022-11-21 10:16:57 +00:00
|
|
|
contentTopics: @[ContentTopic("1")],
|
|
|
|
startTime: some(Timestamp(2)),
|
2022-11-09 17:50:18 +00:00
|
|
|
endTime: some(Timestamp(2))
|
2022-10-05 15:58:24 +00:00
|
|
|
)
|
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
let serverPeerInfo =serverSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
|
2022-10-05 15:58:24 +00:00
|
|
|
## When
|
2022-11-09 17:50:18 +00:00
|
|
|
let res = await client.query(req, peer=serverPeerInfo)
|
2022-10-05 15:58:24 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check res.isOk()
|
|
|
|
|
|
|
|
let response = res.tryGet()
|
|
|
|
check:
|
|
|
|
response.messages.len == 0
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await allFutures(clientSwitch.stop(), serverSwitch.stop())
|
|
|
|
|
|
|
|
asyncTest "handle temporal history query with an invalid time window":
|
|
|
|
# A history query with an invalid time range results in an empty list of history messages
|
|
|
|
## Setup
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-10-05 15:58:24 +00:00
|
|
|
serverSwitch = newTestSwitch()
|
|
|
|
clientSwitch = newTestSwitch()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-10-05 15:58:24 +00:00
|
|
|
await allFutures(serverSwitch.start(), clientSwitch.start())
|
|
|
|
|
2022-11-21 10:16:57 +00:00
|
|
|
let
|
2022-10-20 16:09:40 +00:00
|
|
|
server = await newTestWakuStore(serverSwitch, store=storeA)
|
|
|
|
client = newTestWakuStoreClient(clientSwitch)
|
2022-10-05 15:58:24 +00:00
|
|
|
|
|
|
|
## Given
|
2022-11-09 17:50:18 +00:00
|
|
|
let req = HistoryQuery(
|
2022-11-21 10:16:57 +00:00
|
|
|
contentTopics: @[ContentTopic("1")],
|
|
|
|
startTime: some(Timestamp(5)),
|
2022-11-09 17:50:18 +00:00
|
|
|
endTime: some(Timestamp(2))
|
2022-10-05 15:58:24 +00:00
|
|
|
)
|
|
|
|
|
2022-11-09 17:50:18 +00:00
|
|
|
let serverPeerInfo = serverSwitch.peerInfo.toRemotePeerInfo()
|
2022-10-28 18:11:28 +00:00
|
|
|
|
2022-10-05 15:58:24 +00:00
|
|
|
## When
|
2022-11-09 17:50:18 +00:00
|
|
|
let res = await client.query(req, peer=serverPeerInfo)
|
2022-10-05 15:58:24 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check res.isOk()
|
|
|
|
|
|
|
|
let response = res.tryGet()
|
|
|
|
check:
|
|
|
|
response.messages.len == 0
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await allFutures(clientSwitch.stop(), serverSwitch.stop())
|
|
|
|
|
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
suite "Message Store - message handling":
|
2022-09-26 09:50:15 +00:00
|
|
|
|
|
|
|
asyncTest "it should store a valid and non-ephemeral message":
|
|
|
|
## Setup
|
|
|
|
let store = StoreQueueRef.new(5)
|
|
|
|
let switch = newTestSwitch()
|
2022-10-20 16:09:40 +00:00
|
|
|
let proto = await newTestWakuStore(switch, store)
|
2022-09-26 09:50:15 +00:00
|
|
|
|
|
|
|
## Given
|
|
|
|
let validSenderTime = now()
|
|
|
|
let message = fakeWakuMessage(ephemeral=false, ts=validSenderTime)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## When
|
|
|
|
proto.handleMessage(DefaultPubSubTopic, message)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
store.getMessagesCount().tryGet() == 1
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await switch.stop()
|
|
|
|
|
|
|
|
asyncTest "it should not store an ephemeral message":
|
2022-09-13 10:37:06 +00:00
|
|
|
## Setup
|
|
|
|
let store = StoreQueueRef.new(10)
|
|
|
|
let switch = newTestSwitch()
|
2022-10-20 16:09:40 +00:00
|
|
|
let proto = await newTestWakuStore(switch, store)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## Given
|
2022-11-21 10:16:57 +00:00
|
|
|
let msgList = @[
|
2022-09-13 10:37:06 +00:00
|
|
|
fakeWakuMessage(ephemeral = false, payload = "1"),
|
|
|
|
fakeWakuMessage(ephemeral = true, payload = "2"),
|
|
|
|
fakeWakuMessage(ephemeral = true, payload = "3"),
|
|
|
|
fakeWakuMessage(ephemeral = true, payload = "4"),
|
|
|
|
fakeWakuMessage(ephemeral = false, payload = "5"),
|
|
|
|
]
|
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## When
|
2022-09-13 10:37:06 +00:00
|
|
|
for msg in msgList:
|
2022-09-21 09:32:59 +00:00
|
|
|
proto.handleMessage(DefaultPubsubTopic, msg)
|
2022-09-13 10:37:06 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## Then
|
2022-11-21 10:16:57 +00:00
|
|
|
check:
|
2022-09-13 10:37:06 +00:00
|
|
|
store.len == 2
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await switch.stop()
|
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
asyncTest "it should store a message with no sender timestamp":
|
|
|
|
## Setup
|
|
|
|
let store = StoreQueueRef.new(5)
|
|
|
|
let switch = newTestSwitch()
|
2022-10-20 16:09:40 +00:00
|
|
|
let proto = await newTestWakuStore(switch, store)
|
2022-09-26 09:50:15 +00:00
|
|
|
|
|
|
|
## Given
|
|
|
|
let invalidSenderTime = 0
|
|
|
|
let message = fakeWakuMessage(ts=invalidSenderTime)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## When
|
|
|
|
proto.handleMessage(DefaultPubSubTopic, message)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
store.getMessagesCount().tryGet() == 1
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await switch.stop()
|
|
|
|
|
|
|
|
asyncTest "it should not store a message with a sender time variance greater than max time variance (future)":
|
|
|
|
## Setup
|
|
|
|
let store = StoreQueueRef.new(5)
|
|
|
|
let switch = newTestSwitch()
|
2022-10-20 16:09:40 +00:00
|
|
|
let proto = await newTestWakuStore(switch, store)
|
2022-09-26 09:50:15 +00:00
|
|
|
|
|
|
|
## Given
|
|
|
|
let
|
2022-10-21 13:01:39 +00:00
|
|
|
now = now()
|
2022-09-26 09:50:15 +00:00
|
|
|
invalidSenderTime = now + MaxMessageTimestampVariance + 1
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
let message = fakeWakuMessage(ts=invalidSenderTime)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## When
|
|
|
|
proto.handleMessage(DefaultPubSubTopic, message)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
store.getMessagesCount().tryGet() == 0
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## Cleanup
|
|
|
|
await switch.stop()
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
asyncTest "it should not store a message with a sender time variance greater than max time variance (past)":
|
|
|
|
## Setup
|
|
|
|
let store = StoreQueueRef.new(5)
|
|
|
|
let switch = newTestSwitch()
|
2022-10-20 16:09:40 +00:00
|
|
|
let proto = await newTestWakuStore(switch, store)
|
2022-09-26 09:50:15 +00:00
|
|
|
|
|
|
|
## Given
|
|
|
|
let
|
2022-10-21 13:01:39 +00:00
|
|
|
now = now()
|
2022-09-26 09:50:15 +00:00
|
|
|
invalidSenderTime = now - MaxMessageTimestampVariance - 1
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
let message = fakeWakuMessage(ts=invalidSenderTime)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## When
|
|
|
|
proto.handleMessage(DefaultPubSubTopic, message)
|
2022-11-21 10:16:57 +00:00
|
|
|
|
2022-09-26 09:50:15 +00:00
|
|
|
## Then
|
|
|
|
check:
|
|
|
|
store.getMessagesCount().tryGet() == 0
|
|
|
|
|
|
|
|
## Cleanup
|
|
|
|
await switch.stop()
|