2024-02-06 16:37:42 +00:00
|
|
|
{.used.}
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
import
|
2024-04-25 13:09:52 +00:00
|
|
|
std/[options, sequtils, algorithm, sets],
|
2023-12-19 14:38:43 +00:00
|
|
|
stew/shims/net as stewNet,
|
|
|
|
testutils/unittests,
|
|
|
|
chronos,
|
|
|
|
libp2p/crypto/crypto
|
|
|
|
|
|
|
|
import
|
|
|
|
../../../waku/[
|
2024-02-06 16:37:42 +00:00
|
|
|
common/paging,
|
2023-12-19 14:38:43 +00:00
|
|
|
node/waku_node,
|
|
|
|
node/peer_manager,
|
|
|
|
waku_core,
|
2024-04-25 13:09:52 +00:00
|
|
|
waku_core/message/digest,
|
2023-12-19 14:38:43 +00:00
|
|
|
waku_store,
|
|
|
|
waku_store/client,
|
|
|
|
waku_archive,
|
|
|
|
waku_archive/driver/sqlite_driver,
|
2024-03-15 23:08:47 +00:00
|
|
|
common/databases/db_sqlite,
|
2023-12-19 14:38:43 +00:00
|
|
|
],
|
|
|
|
../waku_store/store_utils,
|
|
|
|
../waku_archive/archive_utils,
|
2024-02-06 16:37:42 +00:00
|
|
|
../testlib/[common, wakucore, wakunode, testasync, futures, testutils]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
suite "Waku Store - End to End - Sorted Archive":
|
|
|
|
var pubsubTopic {.threadvar.}: PubsubTopic
|
|
|
|
var contentTopic {.threadvar.}: ContentTopic
|
|
|
|
var contentTopicSeq {.threadvar.}: seq[ContentTopic]
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
var archiveMessages {.threadvar.}: seq[WakuMessageKeyValue]
|
|
|
|
var storeQuery {.threadvar.}: StoreQueryRequest
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
var server {.threadvar.}: WakuNode
|
|
|
|
var client {.threadvar.}: WakuNode
|
|
|
|
|
|
|
|
var archiveDriver {.threadvar.}: ArchiveDriver
|
|
|
|
var serverRemotePeerInfo {.threadvar.}: RemotePeerInfo
|
2024-02-06 16:37:42 +00:00
|
|
|
var clientPeerId {.threadvar.}: PeerId
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncSetup:
|
|
|
|
pubsubTopic = DefaultPubsubTopic
|
|
|
|
contentTopic = DefaultContentTopic
|
|
|
|
contentTopicSeq = @[contentTopic]
|
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-04-25 13:09:52 +00:00
|
|
|
let messages =
|
2024-02-06 16:37:42 +00:00
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 00], ts = ts(00, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 01], ts = ts(10, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 02], ts = ts(20, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 03], ts = ts(30, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 04], ts = ts(40, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 05], ts = ts(50, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 06], ts = ts(60, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 07], ts = ts(70, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 08], ts = ts(80, timeOrigin)),
|
2024-03-15 23:08:47 +00:00
|
|
|
fakeWakuMessage(@[byte 09], ts = ts(90, timeOrigin)),
|
2024-02-06 16:37:42 +00:00
|
|
|
]
|
2024-04-25 13:09:52 +00:00
|
|
|
archiveMessages = messages.mapIt(
|
2024-05-01 18:47:06 +00:00
|
|
|
WakuMessageKeyValue(
|
2024-05-08 19:35:56 +00:00
|
|
|
messageHash: computeMessageHash(pubsubTopic, it),
|
|
|
|
message: some(it),
|
|
|
|
pubsubTopic: some(pubsubTopic),
|
2024-05-01 18:47:06 +00:00
|
|
|
)
|
2024-04-25 13:09:52 +00:00
|
|
|
)
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.Forward,
|
|
|
|
paginationLimit: some(uint64(5)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
serverKey = generateSecp256k1Key()
|
|
|
|
clientKey = generateSecp256k1Key()
|
|
|
|
|
|
|
|
server = newTestWakuNode(serverKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
client = newTestWakuNode(clientKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
archiveDriver = newArchiveDriverWithMessages(pubsubTopic, messages)
|
2023-12-19 14:38:43 +00:00
|
|
|
let mountArchiveResult = server.mountArchive(archiveDriver)
|
|
|
|
assert mountArchiveResult.isOk()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await server.mountStore()
|
2023-12-19 14:38:43 +00:00
|
|
|
client.mountStoreClient()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await allFutures(server.start(), client.start())
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()
|
|
|
|
clientPeerId = client.peerInfo.toRemotePeerInfo().peerId
|
|
|
|
|
|
|
|
asyncTeardown:
|
2024-05-10 12:13:58 +00:00
|
|
|
await allFutures(client.stop(), server.stop())
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
suite "Message Pagination":
|
|
|
|
asyncTest "Forward Pagination":
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse.get().messages == archiveMessages[0 ..< 5]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Given the next query
|
2024-04-25 13:09:52 +00:00
|
|
|
var otherHistoryQuery = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse.get().paginationCursor,
|
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(5)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
2024-03-15 23:08:47 +00:00
|
|
|
let otherQueryResponse =
|
|
|
|
await client.query(otherHistoryQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
otherQueryResponse.get().messages == archiveMessages[5 ..< 10]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Backward Pagination":
|
|
|
|
# Given the history query is backward
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.paginationForward = PagingDirection.BACKWARD
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse.get().messages == archiveMessages[5 ..< 10]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Given the next query
|
2024-04-25 13:09:52 +00:00
|
|
|
var nextHistoryQuery = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.BACKWARD,
|
|
|
|
paginationLimit: some(uint64(5)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
2024-03-15 23:08:47 +00:00
|
|
|
let otherQueryResponse =
|
|
|
|
await client.query(nextHistoryQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
otherQueryResponse.get().messages == archiveMessages[0 ..< 5]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
suite "Pagination with Differente Page Sizes":
|
|
|
|
asyncTest "Pagination with Small Page Size":
|
|
|
|
# Given the first query (1/5)
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.paginationLimit = some(uint64(2))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse1 = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse1.get().messages == archiveMessages[0 ..< 2]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Given the next query (2/5)
|
2024-04-25 13:09:52 +00:00
|
|
|
let historyQuery2 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse1.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(2)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse2 = await client.query(historyQuery2, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse2.get().messages == archiveMessages[2 ..< 4]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Given the next query (3/5)
|
2024-04-25 13:09:52 +00:00
|
|
|
let historyQuery3 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse2.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(2)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse3 = await client.query(historyQuery3, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse3.get().messages == archiveMessages[4 ..< 6]
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
# Given the next query (4/5)
|
2024-04-25 13:09:52 +00:00
|
|
|
let historyQuery4 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse3.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(2)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse4 = await client.query(historyQuery4, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse4.get().messages == archiveMessages[6 ..< 8]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Given the next query (5/5)
|
2024-04-25 13:09:52 +00:00
|
|
|
let historyQuery5 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse4.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(2)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse5 = await client.query(historyQuery5, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse5.get().messages == archiveMessages[8 ..< 10]
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
asyncTest "Pagination with Large Page Size":
|
|
|
|
# Given the first query (1/2)
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.paginationLimit = some(uint64(8))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse1 = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse1.get().messages == archiveMessages[0 ..< 8]
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
# Given the next query (2/2)
|
2024-04-25 13:09:52 +00:00
|
|
|
let historyQuery2 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse1.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(8)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse2 = await client.query(historyQuery2, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse2.get().messages == archiveMessages[8 ..< 10]
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
asyncTest "Pagination with Excessive Page Size":
|
|
|
|
# Given the first query (1/1)
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.paginationLimit = some(uint64(100))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse1 = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse1.get().messages == archiveMessages[0 ..< 10]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Pagination with Mixed Page Size":
|
|
|
|
# Given the first query (1/3)
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.paginationLimit = some(uint64(2))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse1 = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse1.get().messages == archiveMessages[0 ..< 2]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Given the next query (2/3)
|
2024-04-25 13:09:52 +00:00
|
|
|
let historyQuery2 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse1.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(4)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse2 = await client.query(historyQuery2, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse2.get().messages == archiveMessages[2 ..< 6]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Given the next query (3/3)
|
2024-04-25 13:09:52 +00:00
|
|
|
let historyQuery3 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse2.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(6)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse3 = await client.query(historyQuery3, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse3.get().messages == archiveMessages[6 ..< 10]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Pagination with Zero Page Size (Behaves as DefaultPageSize)":
|
|
|
|
# Given a message list of size higher than the default page size
|
|
|
|
let currentStoreLen = uint((await archiveDriver.getMessagesCount()).get())
|
2024-02-06 16:37:42 +00:00
|
|
|
assert archive.DefaultPageSize > currentStoreLen,
|
|
|
|
"This test requires a store with more than (DefaultPageSize) messages"
|
2023-12-19 14:38:43 +00:00
|
|
|
let missingMessagesAmount = archive.DefaultPageSize - currentStoreLen + 5
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
let lastMessageTimestamp =
|
2024-05-01 18:47:06 +00:00
|
|
|
archiveMessages[archiveMessages.len - 1].message.get().timestamp
|
2023-12-19 14:38:43 +00:00
|
|
|
var extraMessages: seq[WakuMessage] = @[]
|
2024-03-15 23:08:47 +00:00
|
|
|
for i in 0 ..< missingMessagesAmount:
|
2024-02-06 16:37:42 +00:00
|
|
|
let
|
|
|
|
timestampOffset = 10 * int(i + 1)
|
|
|
|
# + 1 to avoid collision with existing messages
|
|
|
|
message: WakuMessage =
|
|
|
|
fakeWakuMessage(@[byte i], ts = ts(timestampOffset, lastMessageTimestamp))
|
2023-12-19 14:38:43 +00:00
|
|
|
extraMessages.add(message)
|
|
|
|
discard archiveDriver.put(pubsubTopic, extraMessages)
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
let totalMessages =
|
|
|
|
archiveMessages &
|
|
|
|
extraMessages.mapIt(
|
|
|
|
WakuMessageKeyValue(
|
2024-05-08 19:35:56 +00:00
|
|
|
messageHash: computeMessageHash(pubsubTopic, it),
|
|
|
|
message: some(it),
|
|
|
|
pubsubTopic: some(pubsubTopic),
|
2024-04-25 13:09:52 +00:00
|
|
|
)
|
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Given the a query with zero page size (1/2)
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.paginationLimit = none(uint64)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse1 = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the archive.DefaultPageSize messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse1.get().messages == totalMessages[0 ..< archive.DefaultPageSize]
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
# Given the next query (2/2)
|
2024-04-25 13:09:52 +00:00
|
|
|
let historyQuery2 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse1.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: none(uint64),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse2 = await client.query(historyQuery2, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Then the response contains the remaining messages
|
|
|
|
check:
|
2024-02-06 16:37:42 +00:00
|
|
|
queryResponse2.get().messages ==
|
2024-03-15 23:08:47 +00:00
|
|
|
totalMessages[archive.DefaultPageSize ..< archive.DefaultPageSize + 5]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Pagination with Default Page Size":
|
|
|
|
# Given a message list of size higher than the default page size
|
|
|
|
let currentStoreLen = uint((await archiveDriver.getMessagesCount()).get())
|
2024-02-06 16:37:42 +00:00
|
|
|
assert archive.DefaultPageSize > currentStoreLen,
|
|
|
|
"This test requires a store with more than (DefaultPageSize) messages"
|
2023-12-19 14:38:43 +00:00
|
|
|
let missingMessagesAmount = archive.DefaultPageSize - currentStoreLen + 5
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
let lastMessageTimestamp =
|
2024-05-01 18:47:06 +00:00
|
|
|
archiveMessages[archiveMessages.len - 1].message.get().timestamp
|
2023-12-19 14:38:43 +00:00
|
|
|
var extraMessages: seq[WakuMessage] = @[]
|
2024-03-15 23:08:47 +00:00
|
|
|
for i in 0 ..< missingMessagesAmount:
|
2024-02-06 16:37:42 +00:00
|
|
|
let
|
|
|
|
timestampOffset = 10 * int(i + 1)
|
|
|
|
# + 1 to avoid collision with existing messages
|
|
|
|
message: WakuMessage =
|
|
|
|
fakeWakuMessage(@[byte i], ts = ts(timestampOffset, lastMessageTimestamp))
|
2023-12-19 14:38:43 +00:00
|
|
|
extraMessages.add(message)
|
|
|
|
discard archiveDriver.put(pubsubTopic, extraMessages)
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
let totalMessages =
|
|
|
|
archiveMessages &
|
|
|
|
extraMessages.mapIt(
|
|
|
|
WakuMessageKeyValue(
|
2024-05-08 19:35:56 +00:00
|
|
|
messageHash: computeMessageHash(pubsubTopic, it),
|
|
|
|
message: some(it),
|
|
|
|
pubsubTopic: some(pubsubTopic),
|
2024-04-25 13:09:52 +00:00
|
|
|
)
|
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Given a query with default page size (1/2)
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse.get().messages == totalMessages[0 ..< archive.DefaultPageSize]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Given the next query (2/2)
|
2024-04-25 13:09:52 +00:00
|
|
|
let historyQuery2 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse2 = await client.query(historyQuery2, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-02-06 16:37:42 +00:00
|
|
|
queryResponse2.get().messages ==
|
2024-03-15 23:08:47 +00:00
|
|
|
totalMessages[archive.DefaultPageSize ..< archive.DefaultPageSize + 5]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
suite "Pagination with Different Cursors":
|
|
|
|
asyncTest "Starting Cursor":
|
2024-04-25 13:09:52 +00:00
|
|
|
# Given a paginationCursor pointing to the first message
|
|
|
|
let paginationCursor = archiveMessages[0].messageHash
|
|
|
|
storeQuery.paginationCursor = some(paginationCursor)
|
|
|
|
storeQuery.paginationLimit = some(uint64(1))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the message
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse.get().messages == archiveMessages[1 ..< 2]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Middle Cursor":
|
2024-04-25 13:09:52 +00:00
|
|
|
# Given a paginationCursor pointing to the middle message1
|
|
|
|
let paginationCursor = archiveMessages[5].messageHash
|
|
|
|
storeQuery.paginationCursor = some(paginationCursor)
|
|
|
|
storeQuery.paginationLimit = some(uint64(1))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the message
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse.get().messages == archiveMessages[6 ..< 7]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Ending Cursor":
|
2024-04-25 13:09:52 +00:00
|
|
|
# Given a paginationCursor pointing to the last message
|
|
|
|
let paginationCursor = archiveMessages[9].messageHash
|
|
|
|
storeQuery.paginationCursor = some(paginationCursor)
|
|
|
|
storeQuery.paginationLimit = some(uint64(1))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains no messages
|
|
|
|
check:
|
|
|
|
queryResponse.get().messages.len == 0
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
suite "Message Sorting":
|
|
|
|
asyncTest "Cursor Reusability Across Nodes":
|
|
|
|
# Given a different server node with the same archive
|
|
|
|
let
|
2024-05-01 18:47:06 +00:00
|
|
|
otherArchiveDriverWithMessages = newArchiveDriverWithMessages(
|
|
|
|
pubsubTopic, archiveMessages.mapIt(it.message.get())
|
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
otherServerKey = generateSecp256k1Key()
|
2024-02-06 16:37:42 +00:00
|
|
|
otherServer =
|
|
|
|
newTestWakuNode(otherServerKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
mountOtherArchiveResult =
|
|
|
|
otherServer.mountArchive(otherArchiveDriverWithMessages)
|
2023-12-19 14:38:43 +00:00
|
|
|
assert mountOtherArchiveResult.isOk()
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await otherServer.mountStore()
|
2023-12-19 14:38:43 +00:00
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await otherServer.start()
|
2023-12-19 14:38:43 +00:00
|
|
|
let otherServerRemotePeerInfo = otherServer.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
# When making a history query to the first server node
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse.get().messages == archiveMessages[0 ..< 5]
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
# Given the paginationCursor from the first query
|
|
|
|
let paginationCursor = queryResponse.get().paginationCursor
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query to the second server node
|
2024-04-25 13:09:52 +00:00
|
|
|
let otherHistoryQuery = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(5)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
|
|
|
let otherQueryResponse =
|
|
|
|
await client.query(otherHistoryQuery, otherServerRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the remaining messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
otherQueryResponse.get().messages == archiveMessages[5 ..< 10]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Cleanup
|
2024-05-10 12:13:58 +00:00
|
|
|
await otherServer.stop()
|
2023-12-19 14:38:43 +00:00
|
|
|
|
2024-03-14 16:48:09 +00:00
|
|
|
suite "Waku Store - End to End - Unsorted Archive":
|
2023-12-19 14:38:43 +00:00
|
|
|
var pubsubTopic {.threadvar.}: PubsubTopic
|
|
|
|
var contentTopic {.threadvar.}: ContentTopic
|
|
|
|
var contentTopicSeq {.threadvar.}: seq[ContentTopic]
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
var storeQuery {.threadvar.}: StoreQueryRequest
|
|
|
|
var unsortedArchiveMessages {.threadvar.}: seq[WakuMessageKeyValue]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
var server {.threadvar.}: WakuNode
|
|
|
|
var client {.threadvar.}: WakuNode
|
|
|
|
|
|
|
|
var serverRemotePeerInfo {.threadvar.}: RemotePeerInfo
|
|
|
|
|
|
|
|
asyncSetup:
|
|
|
|
pubsubTopic = DefaultPubsubTopic
|
|
|
|
contentTopic = DefaultContentTopic
|
|
|
|
contentTopicSeq = @[contentTopic]
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(5)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-04-25 13:09:52 +00:00
|
|
|
let messages =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 00], ts = ts(00, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 03], ts = ts(00, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 08], ts = ts(00, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 07], ts = ts(10, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 02], ts = ts(10, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 09], ts = ts(10, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 06], ts = ts(20, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 01], ts = ts(20, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 04], ts = ts(20, timeOrigin)),
|
|
|
|
fakeWakuMessage(@[byte 05], ts = ts(20, timeOrigin)),
|
2024-02-06 16:37:42 +00:00
|
|
|
]
|
2024-04-25 13:09:52 +00:00
|
|
|
unsortedArchiveMessages = messages.mapIt(
|
2024-05-01 18:47:06 +00:00
|
|
|
WakuMessageKeyValue(
|
2024-05-08 19:35:56 +00:00
|
|
|
messageHash: computeMessageHash(pubsubTopic, it),
|
|
|
|
message: some(it),
|
|
|
|
pubsubTopic: some(pubsubTopic),
|
2024-05-01 18:47:06 +00:00
|
|
|
)
|
2024-04-25 13:09:52 +00:00
|
|
|
)
|
2024-02-06 16:37:42 +00:00
|
|
|
|
|
|
|
let
|
2023-12-19 14:38:43 +00:00
|
|
|
serverKey = generateSecp256k1Key()
|
|
|
|
clientKey = generateSecp256k1Key()
|
|
|
|
|
|
|
|
server = newTestWakuNode(serverKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
client = newTestWakuNode(clientKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
|
|
|
|
let
|
2024-02-06 16:37:42 +00:00
|
|
|
unsortedArchiveDriverWithMessages =
|
2024-04-25 13:09:52 +00:00
|
|
|
newArchiveDriverWithMessages(pubsubTopic, messages)
|
2024-02-06 16:37:42 +00:00
|
|
|
mountUnsortedArchiveResult =
|
|
|
|
server.mountArchive(unsortedArchiveDriverWithMessages)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
assert mountUnsortedArchiveResult.isOk()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await server.mountStore()
|
2023-12-19 14:38:43 +00:00
|
|
|
client.mountStoreClient()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await allFutures(server.start(), client.start())
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
asyncTeardown:
|
2024-05-10 12:13:58 +00:00
|
|
|
await allFutures(client.stop(), server.stop())
|
2023-12-19 14:38:43 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
asyncTest "Basic (Timestamp and Hash) Sorting Validation":
|
2023-12-19 14:38:43 +00:00
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
# Check the ordering
|
2023-12-19 14:38:43 +00:00
|
|
|
check:
|
2024-04-25 13:09:52 +00:00
|
|
|
queryResponse.get().messages.len == 5
|
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[0].message.get().timestamp ==
|
|
|
|
queryResponse.get().messages[1].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[1].message.get().timestamp ==
|
|
|
|
queryResponse.get().messages[2].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[2].message.get().timestamp <
|
|
|
|
queryResponse.get().messages[3].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[3].message.get().timestamp ==
|
|
|
|
queryResponse.get().messages[4].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
|
|
|
toHex(queryResponse.get().messages[0].messageHash) <
|
|
|
|
toHex(queryResponse.get().messages[1].messageHash)
|
|
|
|
|
|
|
|
toHex(queryResponse.get().messages[1].messageHash) <
|
|
|
|
toHex(queryResponse.get().messages[2].messageHash)
|
|
|
|
|
|
|
|
toHex(queryResponse.get().messages[3].messageHash) <
|
|
|
|
toHex(queryResponse.get().messages[4].messageHash)
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
# Given the next query
|
2024-04-25 13:09:52 +00:00
|
|
|
var historyQuery2 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(5)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse2 = await client.query(historyQuery2, serverRemotePeerInfo)
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
# Check the ordering
|
2023-12-19 14:38:43 +00:00
|
|
|
check:
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse2.get().messages[0].message.get().timestamp <
|
|
|
|
queryResponse2.get().messages[1].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse2.get().messages[1].message.get().timestamp ==
|
|
|
|
queryResponse2.get().messages[2].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse2.get().messages[2].message.get().timestamp ==
|
|
|
|
queryResponse2.get().messages[3].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse2.get().messages[3].message.get().timestamp ==
|
|
|
|
queryResponse2.get().messages[4].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
|
|
|
toHex(queryResponse2.get().messages[1].messageHash) <
|
|
|
|
toHex(queryResponse2.get().messages[2].messageHash)
|
|
|
|
|
|
|
|
toHex(queryResponse2.get().messages[2].messageHash) <
|
|
|
|
toHex(queryResponse2.get().messages[3].messageHash)
|
|
|
|
|
|
|
|
toHex(queryResponse2.get().messages[3].messageHash) <
|
|
|
|
toHex(queryResponse2.get().messages[4].messageHash)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Backward pagination with Ascending Sorting":
|
|
|
|
# Given a history query with backward pagination
|
2024-04-25 13:09:52 +00:00
|
|
|
|
|
|
|
# Pick the right cursor based on the ordering
|
|
|
|
var cursor = unsortedArchiveMessages[3].messageHash
|
|
|
|
if toHex(cursor) > toHex(unsortedArchiveMessages[4].messageHash):
|
|
|
|
cursor = unsortedArchiveMessages[4].messageHash
|
|
|
|
if toHex(cursor) > toHex(unsortedArchiveMessages[5].messageHash):
|
|
|
|
cursor = unsortedArchiveMessages[5].messageHash
|
|
|
|
|
|
|
|
storeQuery.paginationForward = PagingDirection.BACKWARD
|
|
|
|
storeQuery.paginationCursor = some(cursor)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
# Then check the response ordering
|
2023-12-19 14:38:43 +00:00
|
|
|
check:
|
2024-04-25 13:09:52 +00:00
|
|
|
queryResponse.get().messages.len == 3
|
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[0].message.get().timestamp ==
|
|
|
|
queryResponse.get().messages[1].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[1].message.get().timestamp ==
|
|
|
|
queryResponse.get().messages[2].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
|
|
|
toHex(queryResponse.get().messages[0].messageHash) <
|
|
|
|
toHex(queryResponse.get().messages[1].messageHash)
|
|
|
|
|
|
|
|
toHex(queryResponse.get().messages[1].messageHash) <
|
|
|
|
toHex(queryResponse.get().messages[2].messageHash)
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
asyncTest "Forward Pagination with Ascending Sorting":
|
|
|
|
# Given a history query with forward pagination
|
2024-04-25 13:09:52 +00:00
|
|
|
|
|
|
|
# Pick the right cursor based on the ordering
|
|
|
|
var cursor = unsortedArchiveMessages[3].messageHash
|
|
|
|
if toHex(cursor) > toHex(unsortedArchiveMessages[4].messageHash):
|
|
|
|
cursor = unsortedArchiveMessages[4].messageHash
|
|
|
|
if toHex(cursor) > toHex(unsortedArchiveMessages[5].messageHash):
|
|
|
|
cursor = unsortedArchiveMessages[5].messageHash
|
|
|
|
|
|
|
|
storeQuery.paginationForward = PagingDirection.FORWARD
|
|
|
|
storeQuery.paginationCursor = some(cursor)
|
|
|
|
storeQuery.paginationLimit = some(uint64(6))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
# Then check the response ordering
|
2023-12-19 14:38:43 +00:00
|
|
|
check:
|
2024-04-25 13:09:52 +00:00
|
|
|
queryResponse.get().messages.len == 6
|
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[0].message.get().timestamp ==
|
|
|
|
queryResponse.get().messages[1].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[1].message.get().timestamp <
|
|
|
|
queryResponse.get().messages[2].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[2].message.get().timestamp ==
|
|
|
|
queryResponse.get().messages[3].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[3].message.get().timestamp ==
|
|
|
|
queryResponse.get().messages[4].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[4].message.get().timestamp ==
|
|
|
|
queryResponse.get().messages[5].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
|
|
|
toHex(queryResponse.get().messages[0].messageHash) <
|
|
|
|
toHex(queryResponse.get().messages[1].messageHash)
|
|
|
|
|
|
|
|
toHex(queryResponse.get().messages[2].messageHash) <
|
|
|
|
toHex(queryResponse.get().messages[3].messageHash)
|
|
|
|
|
|
|
|
toHex(queryResponse.get().messages[3].messageHash) <
|
|
|
|
toHex(queryResponse.get().messages[4].messageHash)
|
|
|
|
|
|
|
|
toHex(queryResponse.get().messages[4].messageHash) <
|
|
|
|
toHex(queryResponse.get().messages[5].messageHash)
|
|
|
|
|
|
|
|
suite "Waku Store - End to End - Unsorted Archive without provided Timestamp":
|
|
|
|
var pubsubTopic {.threadvar.}: PubsubTopic
|
|
|
|
var contentTopic {.threadvar.}: ContentTopic
|
|
|
|
var contentTopicSeq {.threadvar.}: seq[ContentTopic]
|
|
|
|
|
|
|
|
var storeQuery {.threadvar.}: StoreQueryRequest
|
|
|
|
var unsortedArchiveMessages {.threadvar.}: seq[WakuMessageKeyValue]
|
|
|
|
|
|
|
|
var server {.threadvar.}: WakuNode
|
|
|
|
var client {.threadvar.}: WakuNode
|
|
|
|
|
|
|
|
var serverRemotePeerInfo {.threadvar.}: RemotePeerInfo
|
|
|
|
|
|
|
|
asyncSetup:
|
|
|
|
pubsubTopic = DefaultPubsubTopic
|
|
|
|
contentTopic = DefaultContentTopic
|
|
|
|
contentTopicSeq = @[contentTopic]
|
|
|
|
|
|
|
|
storeQuery = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(5)),
|
|
|
|
)
|
|
|
|
|
|
|
|
let messages =
|
|
|
|
@[ # Not providing explicit timestamp means it will be set in "arrive" order
|
|
|
|
fakeWakuMessage(@[byte 09]),
|
|
|
|
fakeWakuMessage(@[byte 07]),
|
|
|
|
fakeWakuMessage(@[byte 05]),
|
|
|
|
fakeWakuMessage(@[byte 03]),
|
|
|
|
fakeWakuMessage(@[byte 01]),
|
|
|
|
fakeWakuMessage(@[byte 00]),
|
|
|
|
fakeWakuMessage(@[byte 02]),
|
|
|
|
fakeWakuMessage(@[byte 04]),
|
|
|
|
fakeWakuMessage(@[byte 06]),
|
|
|
|
fakeWakuMessage(@[byte 08]),
|
|
|
|
]
|
|
|
|
unsortedArchiveMessages = messages.mapIt(
|
2024-05-01 18:47:06 +00:00
|
|
|
WakuMessageKeyValue(
|
2024-05-08 19:35:56 +00:00
|
|
|
messageHash: computeMessageHash(pubsubTopic, it),
|
|
|
|
message: some(it),
|
|
|
|
pubsubTopic: some(pubsubTopic),
|
2024-05-01 18:47:06 +00:00
|
|
|
)
|
2024-04-25 13:09:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
let
|
|
|
|
serverKey = generateSecp256k1Key()
|
|
|
|
clientKey = generateSecp256k1Key()
|
|
|
|
|
|
|
|
server = newTestWakuNode(serverKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
client = newTestWakuNode(clientKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
|
|
|
|
let
|
|
|
|
unsortedArchiveDriverWithMessages =
|
|
|
|
newArchiveDriverWithMessages(pubsubTopic, messages)
|
|
|
|
mountUnsortedArchiveResult =
|
|
|
|
server.mountArchive(unsortedArchiveDriverWithMessages)
|
|
|
|
|
|
|
|
assert mountUnsortedArchiveResult.isOk()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await server.mountStore()
|
2024-04-25 13:09:52 +00:00
|
|
|
client.mountStoreClient()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await allFutures(server.start(), client.start())
|
2024-04-25 13:09:52 +00:00
|
|
|
|
|
|
|
serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
asyncTeardown:
|
2024-05-10 12:13:58 +00:00
|
|
|
await allFutures(client.stop(), server.stop())
|
2024-04-25 13:09:52 +00:00
|
|
|
|
|
|
|
asyncTest "Sorting using receiverTime":
|
|
|
|
# When making a history query
|
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
check:
|
|
|
|
queryResponse.get().messages.len == 5
|
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[0].message.get().timestamp <=
|
|
|
|
queryResponse.get().messages[1].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[1].message.get().timestamp <=
|
|
|
|
queryResponse.get().messages[2].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[2].message.get().timestamp <=
|
|
|
|
queryResponse.get().messages[3].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse.get().messages[3].message.get().timestamp <=
|
|
|
|
queryResponse.get().messages[4].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
|
|
|
# Given the next query
|
|
|
|
var historyQuery2 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse.get().paginationCursor,
|
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(5)),
|
|
|
|
)
|
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse2 = await client.query(historyQuery2, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Timestamps are quite random in this case.
|
|
|
|
# Those are the only assumptions we can make in ALL cases.
|
|
|
|
let setA = toHashSet(queryResponse.get().messages)
|
|
|
|
let setB = toHashSet(queryResponse2.get().messages)
|
|
|
|
let setC = intersection(setA, setB)
|
|
|
|
|
|
|
|
check:
|
|
|
|
setC.len == 0
|
|
|
|
|
|
|
|
queryResponse2.get().messages.len == 5
|
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse2.get().messages[0].message.get().timestamp <=
|
|
|
|
queryResponse2.get().messages[1].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse2.get().messages[1].message.get().timestamp <=
|
|
|
|
queryResponse2.get().messages[2].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse2.get().messages[2].message.get().timestamp <=
|
|
|
|
queryResponse2.get().messages[3].message.get().timestamp
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
queryResponse2.get().messages[3].message.get().timestamp <=
|
|
|
|
queryResponse2.get().messages[4].message.get().timestamp
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
suite "Waku Store - End to End - Archive with Multiple Topics":
|
|
|
|
var pubsubTopic {.threadvar.}: PubsubTopic
|
|
|
|
var pubsubTopicB {.threadvar.}: PubsubTopic
|
|
|
|
var contentTopic {.threadvar.}: ContentTopic
|
|
|
|
var contentTopicB {.threadvar.}: ContentTopic
|
|
|
|
var contentTopicC {.threadvar.}: ContentTopic
|
|
|
|
var contentTopicSpecials {.threadvar.}: ContentTopic
|
|
|
|
var contentTopicSeq {.threadvar.}: seq[ContentTopic]
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
var storeQuery {.threadvar.}: StoreQueryRequest
|
2024-02-06 16:37:42 +00:00
|
|
|
var originTs {.threadvar.}: proc(offset: int): Timestamp {.gcsafe, raises: [].}
|
2024-04-25 13:09:52 +00:00
|
|
|
var archiveMessages {.threadvar.}: seq[WakuMessageKeyValue]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
var server {.threadvar.}: WakuNode
|
|
|
|
var client {.threadvar.}: WakuNode
|
|
|
|
|
|
|
|
var serverRemotePeerInfo {.threadvar.}: RemotePeerInfo
|
|
|
|
|
|
|
|
asyncSetup:
|
|
|
|
pubsubTopic = DefaultPubsubTopic
|
|
|
|
pubsubTopicB = "topicB"
|
|
|
|
contentTopic = DefaultContentTopic
|
|
|
|
contentTopicB = "topicB"
|
|
|
|
contentTopicC = "topicC"
|
|
|
|
contentTopicSpecials = "!@#$%^&*()_+"
|
2024-02-06 16:37:42 +00:00
|
|
|
contentTopicSeq =
|
|
|
|
@[contentTopic, contentTopicB, contentTopicC, contentTopicSpecials]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: some(pubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(5)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
originTs = proc(offset = 0): Timestamp {.gcsafe, raises: [].} =
|
|
|
|
ts(offset, timeOrigin)
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
let messages =
|
2024-02-06 16:37:42 +00:00
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 00], ts = originTs(00), contentTopic = contentTopic),
|
|
|
|
fakeWakuMessage(@[byte 01], ts = originTs(10), contentTopic = contentTopicB),
|
|
|
|
fakeWakuMessage(@[byte 02], ts = originTs(20), contentTopic = contentTopicC),
|
|
|
|
fakeWakuMessage(@[byte 03], ts = originTs(30), contentTopic = contentTopic),
|
|
|
|
fakeWakuMessage(@[byte 04], ts = originTs(40), contentTopic = contentTopicB),
|
|
|
|
fakeWakuMessage(@[byte 05], ts = originTs(50), contentTopic = contentTopicC),
|
|
|
|
fakeWakuMessage(@[byte 06], ts = originTs(60), contentTopic = contentTopic),
|
|
|
|
fakeWakuMessage(@[byte 07], ts = originTs(70), contentTopic = contentTopicB),
|
|
|
|
fakeWakuMessage(@[byte 08], ts = originTs(80), contentTopic = contentTopicC),
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 09], ts = originTs(90), contentTopic = contentTopicSpecials
|
2024-03-15 23:08:47 +00:00
|
|
|
),
|
2024-02-06 16:37:42 +00:00
|
|
|
]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
archiveMessages = messages.mapIt(
|
2024-05-01 18:47:06 +00:00
|
|
|
WakuMessageKeyValue(
|
2024-05-08 19:35:56 +00:00
|
|
|
messageHash: computeMessageHash(pubsubTopic, it),
|
|
|
|
message: some(it),
|
|
|
|
pubsubTopic: some(pubsubTopic),
|
2024-05-01 18:47:06 +00:00
|
|
|
)
|
2024-04-25 13:09:52 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
for i in 6 ..< 10:
|
|
|
|
archiveMessages[i].messagehash =
|
2024-05-01 18:47:06 +00:00
|
|
|
computeMessageHash(pubsubTopicB, archiveMessages[i].message.get())
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2024-05-08 19:35:56 +00:00
|
|
|
archiveMessages[i].pubsubTopic = some(pubsubTopicB)
|
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
let
|
|
|
|
serverKey = generateSecp256k1Key()
|
|
|
|
clientKey = generateSecp256k1Key()
|
|
|
|
|
|
|
|
server = newTestWakuNode(serverKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
client = newTestWakuNode(clientKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
let archiveDriver = newSqliteArchiveDriver().put(pubsubTopic, messages[0 ..< 6]).put(
|
|
|
|
pubsubTopicB, messages[6 ..< 10]
|
|
|
|
)
|
|
|
|
let mountUnsortedArchiveResult = server.mountArchive(archiveDriver)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
assert mountUnsortedArchiveResult.isOk()
|
2023-12-19 14:38:43 +00:00
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await server.mountStore()
|
2023-12-19 14:38:43 +00:00
|
|
|
client.mountStoreClient()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await allFutures(server.start(), client.start())
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
serverRemotePeerInfo = server.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
asyncTeardown:
|
2024-05-10 12:13:58 +00:00
|
|
|
await allFutures(client.stop(), server.stop())
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
suite "Validation of Content Filtering":
|
|
|
|
asyncTest "Basic Content Filtering":
|
|
|
|
# Given a history query with content filtering
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.contentTopics = @[contentTopic]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-02-06 16:37:42 +00:00
|
|
|
queryResponse.get().messages == @[archiveMessages[0], archiveMessages[3]]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Multiple Content Filters":
|
|
|
|
# Given a history query with multiple content filtering
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.contentTopics = @[contentTopic, contentTopicB]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-02-06 16:37:42 +00:00
|
|
|
queryResponse.get().messages ==
|
|
|
|
@[
|
|
|
|
archiveMessages[0],
|
|
|
|
archiveMessages[1],
|
|
|
|
archiveMessages[3],
|
2024-03-15 23:08:47 +00:00
|
|
|
archiveMessages[4],
|
2024-02-06 16:37:42 +00:00
|
|
|
]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Empty Content Filtering":
|
|
|
|
# Given a history query with empty content filtering
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.contentTopics = @[]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse.get().messages == archiveMessages[0 ..< 5]
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
# Given the next query
|
2024-04-25 13:09:52 +00:00
|
|
|
let historyQuery2 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: none(PubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(5)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse2 = await client.query(historyQuery2, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse2.get().messages == archiveMessages[5 ..< 10]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Non-Existent Content Topic":
|
|
|
|
# Given a history query with non-existent content filtering
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.contentTopics = @["non-existent-topic"]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains no messages
|
|
|
|
check:
|
|
|
|
queryResponse.get().messages.len == 0
|
|
|
|
|
|
|
|
asyncTest "Special Characters in Content Filtering":
|
|
|
|
# Given a history query with special characters in content filtering
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.pubsubTopic = some(pubsubTopicB)
|
|
|
|
storeQuery.contentTopics = @["!@#$%^&*()_+"]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains no messages
|
|
|
|
check:
|
|
|
|
queryResponse.get().messages == @[archiveMessages[9]]
|
|
|
|
|
|
|
|
asyncTest "PubsubTopic Specified":
|
|
|
|
# Given a history query with pubsub topic specified
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.pubsubTopic = some(pubsubTopicB)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-02-06 16:37:42 +00:00
|
|
|
queryResponse.get().messages ==
|
|
|
|
@[
|
|
|
|
archiveMessages[6],
|
|
|
|
archiveMessages[7],
|
|
|
|
archiveMessages[8],
|
2024-03-15 23:08:47 +00:00
|
|
|
archiveMessages[9],
|
2024-02-06 16:37:42 +00:00
|
|
|
]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "PubsubTopic Left Empty":
|
|
|
|
# Given a history query with pubsub topic left empty
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.pubsubTopic = none(PubsubTopic)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse.get().messages == archiveMessages[0 ..< 5]
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
# Given the next query
|
2024-04-25 13:09:52 +00:00
|
|
|
let historyQuery2 = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationCursor: queryResponse.get().paginationCursor,
|
2024-03-15 23:08:47 +00:00
|
|
|
pubsubTopic: none(PubsubTopic),
|
|
|
|
contentTopics: contentTopicSeq,
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(5)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making the next history query
|
|
|
|
let queryResponse2 = await client.query(historyQuery2, serverRemotePeerInfo)
|
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
queryResponse2.get().messages == archiveMessages[5 ..< 10]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
suite "Validation of Time-based Filtering":
|
|
|
|
asyncTest "Basic Time Filtering":
|
|
|
|
# Given a history query with start and end time
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.startTime = some(originTs(20))
|
|
|
|
storeQuery.endTime = some(originTs(40))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-02-06 16:37:42 +00:00
|
|
|
queryResponse.get().messages ==
|
|
|
|
@[archiveMessages[2], archiveMessages[3], archiveMessages[4]]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Only Start Time Specified":
|
|
|
|
# Given a history query with only start time
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.startTime = some(originTs(20))
|
|
|
|
storeQuery.endTime = none(Timestamp)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-02-06 16:37:42 +00:00
|
|
|
queryResponse.get().messages ==
|
|
|
|
@[
|
|
|
|
archiveMessages[2],
|
|
|
|
archiveMessages[3],
|
|
|
|
archiveMessages[4],
|
2024-03-15 23:08:47 +00:00
|
|
|
archiveMessages[5],
|
2024-02-06 16:37:42 +00:00
|
|
|
]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Only End Time Specified":
|
|
|
|
# Given a history query with only end time
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.startTime = none(Timestamp)
|
|
|
|
storeQuery.endTime = some(originTs(40))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains no messages
|
|
|
|
check:
|
2024-02-06 16:37:42 +00:00
|
|
|
queryResponse.get().messages ==
|
|
|
|
@[
|
|
|
|
archiveMessages[0],
|
|
|
|
archiveMessages[1],
|
|
|
|
archiveMessages[2],
|
|
|
|
archiveMessages[3],
|
2024-03-15 23:08:47 +00:00
|
|
|
archiveMessages[4],
|
2024-02-06 16:37:42 +00:00
|
|
|
]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Invalid Time Range":
|
|
|
|
# Given a history query with invalid time range
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.startTime = some(originTs(60))
|
|
|
|
storeQuery.endTime = some(originTs(40))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains no messages
|
|
|
|
check:
|
|
|
|
queryResponse.get().messages.len == 0
|
|
|
|
|
|
|
|
asyncTest "Time Filtering with Content Filtering":
|
|
|
|
# Given a history query with time and content filtering
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.startTime = some(originTs(20))
|
|
|
|
storeQuery.endTime = some(originTs(60))
|
|
|
|
storeQuery.contentTopics = @[contentTopicC]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-02-06 16:37:42 +00:00
|
|
|
queryResponse.get().messages == @[archiveMessages[2], archiveMessages[5]]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Messages Outside of Time Range":
|
|
|
|
# Given a history query with a valid time range which does not contain any messages
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.startTime = some(originTs(100))
|
|
|
|
storeQuery.endTime = some(originTs(200))
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains no messages
|
|
|
|
check:
|
|
|
|
queryResponse.get().messages.len == 0
|
|
|
|
|
|
|
|
suite "Ephemeral":
|
|
|
|
# TODO: Ephemeral value is not properly set for Sqlite
|
|
|
|
xasyncTest "Only ephemeral Messages:":
|
|
|
|
# Given an archive with only ephemeral messages
|
|
|
|
let
|
2024-02-06 16:37:42 +00:00
|
|
|
ephemeralMessages =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 00], ts = ts(00), ephemeral = true),
|
|
|
|
fakeWakuMessage(@[byte 01], ts = ts(10), ephemeral = true),
|
2024-03-15 23:08:47 +00:00
|
|
|
fakeWakuMessage(@[byte 02], ts = ts(20), ephemeral = true),
|
2024-02-06 16:37:42 +00:00
|
|
|
]
|
|
|
|
ephemeralArchiveDriver =
|
|
|
|
newSqliteArchiveDriver().put(pubsubTopic, ephemeralMessages)
|
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
# And a server node with the ephemeral archive
|
2024-02-06 16:37:42 +00:00
|
|
|
let
|
2023-12-19 14:38:43 +00:00
|
|
|
ephemeralServerKey = generateSecp256k1Key()
|
2024-02-06 16:37:42 +00:00
|
|
|
ephemeralServer =
|
|
|
|
newTestWakuNode(ephemeralServerKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
mountEphemeralArchiveResult =
|
|
|
|
ephemeralServer.mountArchive(ephemeralArchiveDriver)
|
2023-12-19 14:38:43 +00:00
|
|
|
assert mountEphemeralArchiveResult.isOk()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await ephemeralServer.mountStore()
|
|
|
|
await ephemeralServer.start()
|
2023-12-19 14:38:43 +00:00
|
|
|
let ephemeralServerRemotePeerInfo = ephemeralServer.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
# When making a history query to the server with only ephemeral messages
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, ephemeralServerRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains no messages
|
|
|
|
check:
|
|
|
|
queryResponse.get().messages.len == 0
|
|
|
|
|
|
|
|
# Cleanup
|
2024-05-10 12:13:58 +00:00
|
|
|
await ephemeralServer.stop()
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
xasyncTest "Mixed messages":
|
|
|
|
# Given an archive with both ephemeral and non-ephemeral messages
|
|
|
|
let
|
2024-02-06 16:37:42 +00:00
|
|
|
ephemeralMessages =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 00], ts = ts(00), ephemeral = true),
|
|
|
|
fakeWakuMessage(@[byte 01], ts = ts(10), ephemeral = true),
|
2024-03-15 23:08:47 +00:00
|
|
|
fakeWakuMessage(@[byte 02], ts = ts(20), ephemeral = true),
|
2024-02-06 16:37:42 +00:00
|
|
|
]
|
|
|
|
nonEphemeralMessages =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 03], ts = ts(30), ephemeral = false),
|
|
|
|
fakeWakuMessage(@[byte 04], ts = ts(40), ephemeral = false),
|
2024-03-15 23:08:47 +00:00
|
|
|
fakeWakuMessage(@[byte 05], ts = ts(50), ephemeral = false),
|
2024-02-06 16:37:42 +00:00
|
|
|
]
|
2024-03-15 23:08:47 +00:00
|
|
|
mixedArchiveDriver = newSqliteArchiveDriver()
|
|
|
|
.put(pubsubTopic, ephemeralMessages)
|
|
|
|
.put(pubsubTopic, nonEphemeralMessages)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# And a server node with the mixed archive
|
2024-02-06 16:37:42 +00:00
|
|
|
let
|
2023-12-19 14:38:43 +00:00
|
|
|
mixedServerKey = generateSecp256k1Key()
|
2024-02-06 16:37:42 +00:00
|
|
|
mixedServer =
|
|
|
|
newTestWakuNode(mixedServerKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
2023-12-19 14:38:43 +00:00
|
|
|
mountMixedArchiveResult = mixedServer.mountArchive(mixedArchiveDriver)
|
|
|
|
assert mountMixedArchiveResult.isOk()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await mixedServer.mountStore()
|
|
|
|
await mixedServer.start()
|
2023-12-19 14:38:43 +00:00
|
|
|
let mixedServerRemotePeerInfo = mixedServer.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
# When making a history query to the server with mixed messages
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, mixedServerRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the non-ephemeral messages
|
|
|
|
check:
|
|
|
|
queryResponse.get().messages == nonEphemeralMessages
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
# Cleanup
|
2024-05-10 12:13:58 +00:00
|
|
|
await mixedServer.stop()
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
suite "Edge Case Scenarios":
|
|
|
|
asyncTest "Empty Message Store":
|
|
|
|
# Given an empty archive
|
|
|
|
let emptyArchiveDriver = newSqliteArchiveDriver()
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
# And a server node with the empty archive
|
2024-02-06 16:37:42 +00:00
|
|
|
let
|
2023-12-19 14:38:43 +00:00
|
|
|
emptyServerKey = generateSecp256k1Key()
|
2024-02-06 16:37:42 +00:00
|
|
|
emptyServer =
|
|
|
|
newTestWakuNode(emptyServerKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
2023-12-19 14:38:43 +00:00
|
|
|
mountEmptyArchiveResult = emptyServer.mountArchive(emptyArchiveDriver)
|
|
|
|
assert mountEmptyArchiveResult.isOk()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await emptyServer.mountStore()
|
|
|
|
await emptyServer.start()
|
2023-12-19 14:38:43 +00:00
|
|
|
let emptyServerRemotePeerInfo = emptyServer.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
# When making a history query to the server with an empty archive
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, emptyServerRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains no messages
|
|
|
|
check:
|
|
|
|
queryResponse.get().messages.len == 0
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
# Cleanup
|
2024-05-10 12:13:58 +00:00
|
|
|
await emptyServer.stop()
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Voluminous Message Store":
|
|
|
|
# Given a voluminous archive (1M+ messages)
|
2024-04-25 13:09:52 +00:00
|
|
|
var messages: seq[WakuMessage] = @[]
|
2024-03-15 23:08:47 +00:00
|
|
|
for i in 0 ..< 100000:
|
2023-12-19 14:38:43 +00:00
|
|
|
let topic = "topic" & $i
|
2024-04-25 13:09:52 +00:00
|
|
|
messages.add(fakeWakuMessage(@[byte i], contentTopic = topic))
|
|
|
|
|
|
|
|
let voluminousArchiveMessages = messages.mapIt(
|
|
|
|
WakuMessageKeyValue(
|
2024-05-08 19:35:56 +00:00
|
|
|
messageHash: computeMessageHash(pubsubTopic, it),
|
|
|
|
message: some(it),
|
|
|
|
pubsubTopic: some(pubsubTopic),
|
2024-04-25 13:09:52 +00:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
let voluminousArchiveDriverWithMessages =
|
2024-04-25 13:09:52 +00:00
|
|
|
newArchiveDriverWithMessages(pubsubTopic, messages)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# And a server node with the voluminous archive
|
2024-02-06 16:37:42 +00:00
|
|
|
let
|
2023-12-19 14:38:43 +00:00
|
|
|
voluminousServerKey = generateSecp256k1Key()
|
2024-02-06 16:37:42 +00:00
|
|
|
voluminousServer =
|
|
|
|
newTestWakuNode(voluminousServerKey, ValidIpAddress.init("0.0.0.0"), Port(0))
|
|
|
|
mountVoluminousArchiveResult =
|
|
|
|
voluminousServer.mountArchive(voluminousArchiveDriverWithMessages)
|
2023-12-19 14:38:43 +00:00
|
|
|
assert mountVoluminousArchiveResult.isOk()
|
|
|
|
|
2024-05-10 12:13:58 +00:00
|
|
|
await voluminousServer.mountStore()
|
|
|
|
await voluminousServer.start()
|
2023-12-19 14:38:43 +00:00
|
|
|
let voluminousServerRemotePeerInfo = voluminousServer.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
# Given the following history query
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.contentTopics =
|
2024-02-06 16:37:42 +00:00
|
|
|
@["topic10000", "topic30000", "topic50000", "topic70000", "topic90000"]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# When making a history query to the server with a voluminous archive
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, voluminousServerRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response contains the messages
|
|
|
|
check:
|
2024-02-06 16:37:42 +00:00
|
|
|
queryResponse.get().messages ==
|
|
|
|
@[
|
|
|
|
voluminousArchiveMessages[10000],
|
|
|
|
voluminousArchiveMessages[30000],
|
|
|
|
voluminousArchiveMessages[50000],
|
|
|
|
voluminousArchiveMessages[70000],
|
2024-03-15 23:08:47 +00:00
|
|
|
voluminousArchiveMessages[90000],
|
2024-02-06 16:37:42 +00:00
|
|
|
]
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Cleanup
|
2024-05-10 12:13:58 +00:00
|
|
|
await voluminousServer.stop()
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
asyncTest "Large contentFilters Array":
|
|
|
|
# Given a history query with the max contentFilters len, 10
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.contentTopics = @[contentTopic]
|
2024-03-15 23:08:47 +00:00
|
|
|
for i in 0 ..< 9:
|
2023-12-19 14:38:43 +00:00
|
|
|
let topic = "topic" & $i
|
2024-04-25 13:09:52 +00:00
|
|
|
storeQuery.contentTopics.add(topic)
|
2024-02-06 16:37:42 +00:00
|
|
|
|
2023-12-19 14:38:43 +00:00
|
|
|
# When making a history query
|
2024-04-25 13:09:52 +00:00
|
|
|
let queryResponse = await client.query(storeQuery, serverRemotePeerInfo)
|
2023-12-19 14:38:43 +00:00
|
|
|
|
|
|
|
# Then the response should trigger no errors
|
|
|
|
check:
|
2024-02-06 16:37:42 +00:00
|
|
|
queryResponse.get().messages == @[archiveMessages[0], archiveMessages[3]]
|