2023-04-06 09:43:19 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2024-05-27 14:54:10 +00:00
|
|
|
std/[options, sugar],
|
2023-04-06 09:43:19 +00:00
|
|
|
stew/shims/net as stewNet,
|
|
|
|
chronicles,
|
2024-05-27 14:54:10 +00:00
|
|
|
chronos/timer,
|
2023-04-06 09:43:19 +00:00
|
|
|
testutils/unittests,
|
|
|
|
eth/keys,
|
2024-03-15 23:08:47 +00:00
|
|
|
presto,
|
|
|
|
presto/client as presto_client,
|
2023-04-06 09:43:19 +00:00
|
|
|
libp2p/crypto/crypto
|
|
|
|
import
|
2024-07-05 22:03:38 +00:00
|
|
|
waku/[
|
|
|
|
waku_core/message,
|
|
|
|
waku_core/message/digest,
|
|
|
|
waku_core/topics,
|
|
|
|
waku_core/time,
|
|
|
|
waku_node,
|
|
|
|
node/peer_manager,
|
|
|
|
waku_api/rest/server,
|
|
|
|
waku_api/rest/client,
|
|
|
|
waku_api/rest/responses,
|
|
|
|
waku_api/rest/store/handlers as store_api,
|
|
|
|
waku_api/rest/store/client as store_api_client,
|
|
|
|
waku_api/rest/store/types,
|
|
|
|
waku_archive,
|
|
|
|
waku_archive/driver/queue_driver,
|
|
|
|
waku_archive/driver/sqlite_driver,
|
|
|
|
common/databases/db_sqlite,
|
|
|
|
waku_archive/driver/postgres_driver,
|
|
|
|
waku_store as waku_store,
|
|
|
|
],
|
2023-08-09 17:11:50 +00:00
|
|
|
../testlib/wakucore,
|
|
|
|
../testlib/wakunode
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
logScope:
|
|
|
|
topics = "waku node rest store_api test"
|
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
proc put(
|
|
|
|
store: ArchiveDriver, pubsubTopic: PubsubTopic, message: WakuMessage
|
|
|
|
): Future[Result[void, string]] =
|
2024-07-12 16:19:12 +00:00
|
|
|
let msgHash = computeMessageHash(pubsubTopic, message)
|
2023-04-06 09:43:19 +00:00
|
|
|
|
2024-07-12 16:19:12 +00:00
|
|
|
store.put(msgHash, pubsubTopic, message)
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
# Creates a new WakuNode
|
|
|
|
proc testWakuNode(): WakuNode =
|
|
|
|
let
|
|
|
|
privkey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
bindIp = parseIpAddress("0.0.0.0")
|
|
|
|
extIp = parseIpAddress("127.0.0.1")
|
2023-04-06 09:43:19 +00:00
|
|
|
port = Port(0)
|
|
|
|
|
|
|
|
return newTestWakuNode(privkey, bindIp, port, some(extIp), some(port))
|
|
|
|
|
|
|
|
################################################################################
|
|
|
|
# Beginning of the tests
|
|
|
|
################################################################################
|
2024-04-25 13:09:52 +00:00
|
|
|
procSuite "Waku Rest API - Store v3":
|
|
|
|
asyncTest "MessageHash <-> string conversions":
|
|
|
|
# Validate MessageHash conversion from a WakuMessage obj
|
2023-04-06 09:43:19 +00:00
|
|
|
let wakuMsg = WakuMessage(
|
2024-03-15 23:08:47 +00:00
|
|
|
contentTopic: "Test content topic", payload: @[byte('H'), byte('i'), byte('!')]
|
2023-04-06 09:43:19 +00:00
|
|
|
)
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
let messageHash = computeMessageHash(DefaultPubsubTopic, wakuMsg)
|
|
|
|
let restMsgHash = some(messageHash.toRestStringWakuMessageHash())
|
|
|
|
|
|
|
|
let parsedMsgHashRes = parseHash(restMsgHash)
|
|
|
|
assert parsedMsgHashRes.isOk(), $parsedMsgHashRes.error
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
check:
|
2024-04-25 13:09:52 +00:00
|
|
|
messageHash == parsedMsgHashRes.get().get()
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
# Random validation. Obtained the raw values manually
|
2024-04-25 13:09:52 +00:00
|
|
|
let expected = some("f6za9OzG1xSiEZagZc2b3litRbkd3zRl61rezDd3pgQ%3D")
|
|
|
|
|
|
|
|
let msgHashRes = parseHash(expected)
|
|
|
|
assert msgHashRes.isOk(), $msgHashRes.error
|
|
|
|
|
2023-04-06 09:43:19 +00:00
|
|
|
check:
|
2024-04-25 13:09:52 +00:00
|
|
|
expected.get() == msgHashRes.get().get().toRestStringWakuMessageHash()
|
2023-04-06 09:43:19 +00:00
|
|
|
|
2024-05-27 14:54:10 +00:00
|
|
|
asyncTest "invalid cursor":
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2024-05-27 14:54:10 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-05-27 14:54:10 +00:00
|
|
|
|
|
|
|
installStoreApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# WakuStore setup
|
|
|
|
let db: SqliteDatabase =
|
|
|
|
SqliteDatabase.new(string.none().get(":memory:")).expect("valid DB")
|
|
|
|
let driver: ArchiveDriver = SqliteDriver.new(db).expect("valid driver")
|
|
|
|
let mountArchiveRes = node.mountArchive(driver)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
|
|
|
await node.mountStore()
|
|
|
|
node.mountStoreClient()
|
|
|
|
|
|
|
|
let key = generateEcdsaKey()
|
|
|
|
var peerSwitch = newStandardSwitch(some(key))
|
|
|
|
await peerSwitch.start()
|
|
|
|
|
|
|
|
peerSwitch.mount(node.wakuStore)
|
|
|
|
|
|
|
|
await sleepAsync(1.seconds())
|
|
|
|
|
|
|
|
# Now prime it with some history before tests
|
|
|
|
let msgList =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = ContentTopic("ct1"), ts = 0),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 1),
|
|
|
|
fakeWakuMessage(@[byte 1, byte 2], ts = 2),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 3),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 4),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 5),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 6),
|
|
|
|
fakeWakuMessage(@[byte 9], contentTopic = ContentTopic("c2"), ts = 9),
|
|
|
|
]
|
|
|
|
for msg in msgList:
|
|
|
|
require (await driver.put(DefaultPubsubTopic, msg)).isOk()
|
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
let remotePeerInfo = peerSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
let fullAddr = $remotePeerInfo.addrs[0] & "/p2p/" & $remotePeerInfo.peerId
|
|
|
|
|
|
|
|
await sleepAsync(1.seconds())
|
|
|
|
|
|
|
|
let fakeCursor = computeMessageHash(DefaultPubsubTopic, fakeWakuMessage())
|
|
|
|
let encodedCursor = fakeCursor.toRestStringWakuMessageHash()
|
|
|
|
|
|
|
|
# Apply filter by start and end timestamps
|
|
|
|
var response = await client.getStoreMessagesV3(
|
|
|
|
encodeUrl(fullAddr),
|
|
|
|
"true", # include data
|
|
|
|
"", # pubsub topic
|
|
|
|
"ct1,c2", # empty content topics.
|
|
|
|
"", # start time
|
|
|
|
"", # end time
|
|
|
|
"", # hashes
|
|
|
|
encodedCursor, # base64-encoded hash
|
|
|
|
"true", # ascending
|
|
|
|
"5", # empty implies default page size
|
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 0
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
2023-04-06 09:43:19 +00:00
|
|
|
asyncTest "Filter by start and end time":
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2023-12-14 06:16:39 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 08:48:14 +00:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
installStoreApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# WakuStore setup
|
|
|
|
let driver: ArchiveDriver = QueueDriver.new()
|
2023-06-27 11:24:31 +00:00
|
|
|
let mountArchiveRes = node.mountArchive(driver)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
2023-04-06 09:43:19 +00:00
|
|
|
await node.mountStore()
|
|
|
|
node.mountStoreClient()
|
|
|
|
|
|
|
|
let key = generateEcdsaKey()
|
|
|
|
var peerSwitch = newStandardSwitch(some(key))
|
|
|
|
await peerSwitch.start()
|
|
|
|
|
|
|
|
peerSwitch.mount(node.wakuStore)
|
|
|
|
|
|
|
|
# Now prime it with some history before tests
|
2024-03-15 23:08:47 +00:00
|
|
|
let msgList =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = ContentTopic("ct1"), ts = 0),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 1),
|
|
|
|
fakeWakuMessage(@[byte 1, byte 2], ts = 2),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 3),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 4),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 5),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 6),
|
|
|
|
fakeWakuMessage(@[byte 9], contentTopic = ContentTopic("c2"), ts = 9),
|
|
|
|
]
|
2023-04-06 09:43:19 +00:00
|
|
|
for msg in msgList:
|
2024-05-10 12:13:58 +00:00
|
|
|
require (await driver.put(DefaultPubsubTopic, msg)).isOk()
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
let remotePeerInfo = peerSwitch.peerInfo.toRemotePeerInfo()
|
2024-03-15 23:08:47 +00:00
|
|
|
let fullAddr = $remotePeerInfo.addrs[0] & "/p2p/" & $remotePeerInfo.peerId
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
# Apply filter by start and end timestamps
|
2024-04-25 13:09:52 +00:00
|
|
|
var response = await client.getStoreMessagesV3(
|
2024-03-15 23:08:47 +00:00
|
|
|
encodeUrl(fullAddr),
|
2024-04-25 13:09:52 +00:00
|
|
|
"true", # include data
|
2024-03-15 23:08:47 +00:00
|
|
|
encodeUrl(DefaultPubsubTopic),
|
|
|
|
"", # empty content topics. Don't filter by this field
|
|
|
|
"3", # start time
|
|
|
|
"6", # end time
|
2024-04-25 13:09:52 +00:00
|
|
|
"", # hashes
|
|
|
|
"", # base64-encoded hash
|
2024-03-15 23:08:47 +00:00
|
|
|
"true", # ascending
|
2024-04-25 13:09:52 +00:00
|
|
|
"", # empty implies default page size
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 4
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
asyncTest "Store node history response - forward pagination":
|
|
|
|
# Test adapted from the analogous present at waku_store/test_wakunode_store.nim
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2023-12-14 06:16:39 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 08:48:14 +00:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
installStoreApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# WakuStore setup
|
|
|
|
let driver: ArchiveDriver = QueueDriver.new()
|
2023-06-27 11:24:31 +00:00
|
|
|
let mountArchiveRes = node.mountArchive(driver)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
2023-04-06 09:43:19 +00:00
|
|
|
await node.mountStore()
|
|
|
|
node.mountStoreClient()
|
|
|
|
|
|
|
|
let key = generateEcdsaKey()
|
|
|
|
var peerSwitch = newStandardSwitch(some(key))
|
|
|
|
await peerSwitch.start()
|
|
|
|
|
|
|
|
peerSwitch.mount(node.wakuStore)
|
|
|
|
|
|
|
|
# Now prime it with some history before tests
|
2023-04-19 14:39:52 +00:00
|
|
|
let timeOrigin = wakucore.now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let msgList =
|
|
|
|
@[
|
|
|
|
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)),
|
|
|
|
fakeWakuMessage(@[byte 09], ts = ts(90, timeOrigin)),
|
|
|
|
]
|
2023-04-06 09:43:19 +00:00
|
|
|
for msg in msgList:
|
2024-05-10 12:13:58 +00:00
|
|
|
require (await driver.put(DefaultPubsubTopic, msg)).isOk()
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
let remotePeerInfo = peerSwitch.peerInfo.toRemotePeerInfo()
|
2024-03-15 23:08:47 +00:00
|
|
|
let fullAddr = $remotePeerInfo.addrs[0] & "/p2p/" & $remotePeerInfo.peerId
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
var pages = newSeq[seq[WakuMessage]](2)
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
var reqHash = none(WakuMessageHash)
|
2023-04-06 09:43:19 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
for i in 0 ..< 2:
|
2024-04-25 13:09:52 +00:00
|
|
|
let response = await client.getStoreMessagesV3(
|
2024-03-15 23:08:47 +00:00
|
|
|
encodeUrl(fullAddr),
|
2024-04-25 13:09:52 +00:00
|
|
|
"true", # include data
|
|
|
|
encodeUrl(DefaultPubsubTopic),
|
2024-03-15 23:08:47 +00:00
|
|
|
"", # content topics. Empty ignores the field.
|
|
|
|
"", # start time. Empty ignores the field.
|
|
|
|
"", # end time. Empty ignores the field.
|
2024-04-25 13:09:52 +00:00
|
|
|
"", # hashes
|
|
|
|
if reqHash.isSome():
|
|
|
|
reqHash.get().toRestStringWakuMessageHash()
|
|
|
|
else:
|
2024-09-11 01:51:42 +00:00
|
|
|
"", # base64-encoded digest. Empty ignores the field.
|
2024-03-15 23:08:47 +00:00
|
|
|
"true", # ascending
|
2024-04-25 13:09:52 +00:00
|
|
|
"7", # page size. Empty implies default page size.
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-04-06 09:43:19 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
let wakuMessages = collect(newSeq):
|
|
|
|
for element in response.data.messages:
|
|
|
|
if element.message.isSome():
|
|
|
|
element.message.get()
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
pages[i] = wakuMessages
|
|
|
|
|
|
|
|
# populate the cursor for next page
|
2024-04-25 13:09:52 +00:00
|
|
|
if response.data.paginationCursor.isSome():
|
|
|
|
reqHash = some(response.data.paginationCursor.get())
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
|
|
|
|
check:
|
2024-03-15 23:08:47 +00:00
|
|
|
pages[0] == msgList[0 .. 6]
|
|
|
|
pages[1] == msgList[7 .. 9]
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
asyncTest "query a node and retrieve historical messages filtered by pubsub topic":
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2023-12-14 06:16:39 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 08:48:14 +00:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
installStoreApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# WakuStore setup
|
|
|
|
let driver: ArchiveDriver = QueueDriver.new()
|
2023-06-27 11:24:31 +00:00
|
|
|
let mountArchiveRes = node.mountArchive(driver)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
2023-04-06 09:43:19 +00:00
|
|
|
await node.mountStore()
|
|
|
|
node.mountStoreClient()
|
|
|
|
|
|
|
|
let key = generateEcdsaKey()
|
|
|
|
var peerSwitch = newStandardSwitch(some(key))
|
|
|
|
await peerSwitch.start()
|
|
|
|
|
|
|
|
peerSwitch.mount(node.wakuStore)
|
|
|
|
|
|
|
|
# Now prime it with some history before tests
|
2024-03-15 23:08:47 +00:00
|
|
|
let msgList =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = ContentTopic("2"), ts = 0),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 1),
|
|
|
|
fakeWakuMessage(@[byte 9], contentTopic = ContentTopic("2"), ts = 9),
|
|
|
|
]
|
2023-04-06 09:43:19 +00:00
|
|
|
for msg in msgList:
|
2024-05-10 12:13:58 +00:00
|
|
|
require (await driver.put(DefaultPubsubTopic, msg)).isOk()
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
let remotePeerInfo = peerSwitch.peerInfo.toRemotePeerInfo()
|
2024-03-15 23:08:47 +00:00
|
|
|
let fullAddr = $remotePeerInfo.addrs[0] & "/p2p/" & $remotePeerInfo.peerId
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
# Filtering by a known pubsub topic
|
2024-04-25 13:09:52 +00:00
|
|
|
var response = await client.getStoreMessagesV3(
|
|
|
|
encodeUrl($fullAddr), "true", encodeUrl(DefaultPubsubTopic)
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 3
|
|
|
|
|
|
|
|
# Get all the messages by specifying an empty pubsub topic
|
2024-04-25 13:09:52 +00:00
|
|
|
response = await client.getStoreMessagesV3(encodeUrl($fullAddr), "true")
|
2023-04-06 09:43:19 +00:00
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 3
|
|
|
|
|
|
|
|
# Receiving no messages by filtering with a random pubsub topic
|
2024-04-25 13:09:52 +00:00
|
|
|
response = await client.getStoreMessagesV3(
|
|
|
|
encodeUrl($fullAddr), "true", encodeUrl("random pubsub topic")
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-04-06 09:43:19 +00:00
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 0
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
asyncTest "retrieve historical messages from a provided store node address":
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2023-12-14 06:16:39 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 08:48:14 +00:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
installStoreApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# WakuStore setup
|
|
|
|
let driver: ArchiveDriver = QueueDriver.new()
|
2023-06-27 11:24:31 +00:00
|
|
|
let mountArchiveRes = node.mountArchive(driver)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
2023-04-06 09:43:19 +00:00
|
|
|
await node.mountStore()
|
|
|
|
node.mountStoreClient()
|
|
|
|
|
|
|
|
let key = generateEcdsaKey()
|
|
|
|
var peerSwitch = newStandardSwitch(some(key))
|
|
|
|
await peerSwitch.start()
|
|
|
|
|
|
|
|
peerSwitch.mount(node.wakuStore)
|
|
|
|
|
|
|
|
# Now prime it with some history before tests
|
2024-03-15 23:08:47 +00:00
|
|
|
let msgList =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = ContentTopic("ct1"), ts = 0),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 1),
|
|
|
|
fakeWakuMessage(@[byte 9], contentTopic = ContentTopic("ct2"), ts = 9),
|
|
|
|
]
|
2023-04-06 09:43:19 +00:00
|
|
|
for msg in msgList:
|
2024-05-10 12:13:58 +00:00
|
|
|
require (await driver.put(DefaultPubsubTopic, msg)).isOk()
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
let remotePeerInfo = peerSwitch.peerInfo.toRemotePeerInfo()
|
2024-03-15 23:08:47 +00:00
|
|
|
let fullAddr = $remotePeerInfo.addrs[0] & "/p2p/" & $remotePeerInfo.peerId
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
# Filtering by a known pubsub topic.
|
|
|
|
# We also pass the store-node address in the request.
|
2024-04-25 13:09:52 +00:00
|
|
|
var response = await client.getStoreMessagesV3(
|
|
|
|
encodeUrl(fullAddr), "true", encodeUrl(DefaultPubsubTopic)
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-04-06 09:43:19 +00:00
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 3
|
|
|
|
|
|
|
|
# Get all the messages by specifying an empty pubsub topic
|
|
|
|
# We also pass the store-node address in the request.
|
2024-04-25 13:09:52 +00:00
|
|
|
response =
|
|
|
|
await client.getStoreMessagesV3(encodeUrl(fullAddr), "true", encodeUrl(""))
|
2023-04-06 09:43:19 +00:00
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 3
|
|
|
|
|
|
|
|
# Receiving no messages by filtering with a random pubsub topic
|
|
|
|
# We also pass the store-node address in the request.
|
2024-04-25 13:09:52 +00:00
|
|
|
response = await client.getStoreMessagesV3(
|
|
|
|
encodeUrl(fullAddr), "true", encodeUrl("random pubsub topic")
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-04-06 09:43:19 +00:00
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 0
|
|
|
|
|
|
|
|
# Receiving 400 response if setting wrong store-node address
|
2024-04-25 13:09:52 +00:00
|
|
|
response = await client.getStoreMessagesV3(
|
|
|
|
encodeUrl("incorrect multi address format"),
|
|
|
|
"true",
|
|
|
|
encodeUrl("random pubsub topic"),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-04-06 09:43:19 +00:00
|
|
|
check:
|
|
|
|
response.status == 400
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
|
|
response.data.messages.len == 0
|
2024-04-25 13:09:52 +00:00
|
|
|
response.data.statusDesc ==
|
2023-04-12 09:29:11 +00:00
|
|
|
"Failed parsing remote peer info [MultiAddress.init [multiaddress: Invalid MultiAddress, must start with `/`]]"
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
asyncTest "filter historical messages by content topic":
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2023-12-14 06:16:39 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 08:48:14 +00:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
installStoreApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# WakuStore setup
|
|
|
|
let driver: ArchiveDriver = QueueDriver.new()
|
2023-06-27 11:24:31 +00:00
|
|
|
let mountArchiveRes = node.mountArchive(driver)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
2023-04-06 09:43:19 +00:00
|
|
|
await node.mountStore()
|
|
|
|
node.mountStoreClient()
|
|
|
|
|
|
|
|
let key = generateEcdsaKey()
|
|
|
|
var peerSwitch = newStandardSwitch(some(key))
|
|
|
|
await peerSwitch.start()
|
|
|
|
|
|
|
|
peerSwitch.mount(node.wakuStore)
|
|
|
|
|
|
|
|
# Now prime it with some history before tests
|
2024-03-15 23:08:47 +00:00
|
|
|
let msgList =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = ContentTopic("ct1"), ts = 0),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 1),
|
|
|
|
fakeWakuMessage(@[byte 9], contentTopic = ContentTopic("ct2"), ts = 9),
|
|
|
|
]
|
2023-04-06 09:43:19 +00:00
|
|
|
for msg in msgList:
|
2024-05-10 12:13:58 +00:00
|
|
|
require (await driver.put(DefaultPubsubTopic, msg)).isOk()
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
let remotePeerInfo = peerSwitch.peerInfo.toRemotePeerInfo()
|
2024-03-15 23:08:47 +00:00
|
|
|
let fullAddr = $remotePeerInfo.addrs[0] & "/p2p/" & $remotePeerInfo.peerId
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
# Filtering by content topic
|
2024-04-25 13:09:52 +00:00
|
|
|
let response = await client.getStoreMessagesV3(
|
|
|
|
encodeUrl(fullAddr), "true", encodeUrl(DefaultPubsubTopic), encodeUrl("ct1,ct2")
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-04-06 09:43:19 +00:00
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 2
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
|
|
|
|
|
|
|
asyncTest "precondition failed":
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
await node.mountRelay()
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2023-12-14 06:16:39 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 08:48:14 +00:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
installStoreApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
node.mountStoreClient()
|
|
|
|
|
|
|
|
let key = generateEcdsaKey()
|
|
|
|
var peerSwitch = newStandardSwitch(some(key))
|
|
|
|
await peerSwitch.start()
|
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
let remotePeerInfo = peerSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
# Sending no peer-store node address
|
2024-04-25 13:09:52 +00:00
|
|
|
var response = await client.getStoreMessagesV3(
|
|
|
|
encodeUrl(""), "true", encodeUrl(DefaultPubsubTopic)
|
|
|
|
)
|
2023-04-06 09:43:19 +00:00
|
|
|
check:
|
|
|
|
response.status == 412
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
|
|
|
response.data.messages.len == 0
|
2024-04-25 13:09:52 +00:00
|
|
|
response.data.statusDesc == NoPeerNoDiscError.errobj.message
|
2023-04-06 09:43:19 +00:00
|
|
|
|
|
|
|
# Now add the storenode from "config"
|
2024-03-15 23:08:47 +00:00
|
|
|
node.peerManager.addServicePeer(remotePeerInfo, WakuStoreCodec)
|
2023-04-06 09:43:19 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
# WakuStore setup
|
|
|
|
let driver: ArchiveDriver = QueueDriver.new()
|
|
|
|
let mountArchiveRes = node.mountArchive(driver)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
|
|
|
await node.mountStore()
|
|
|
|
|
|
|
|
# Now prime it with some history before tests
|
|
|
|
let msgList =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(@[byte 0], contentTopic = ContentTopic("ct1"), ts = 0),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 1),
|
|
|
|
fakeWakuMessage(@[byte 9], contentTopic = ContentTopic("ct2"), ts = 9),
|
|
|
|
]
|
|
|
|
for msg in msgList:
|
2024-05-10 12:13:58 +00:00
|
|
|
require (await driver.put(DefaultPubsubTopic, msg)).isOk()
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2023-04-06 09:43:19 +00:00
|
|
|
# Sending no peer-store node address
|
2024-04-25 13:09:52 +00:00
|
|
|
response = await client.getStoreMessagesV3(
|
|
|
|
encodeUrl(""), "true", encodeUrl(DefaultPubsubTopic)
|
|
|
|
)
|
2023-04-06 09:43:19 +00:00
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 3
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|
2024-01-31 16:43:59 +00:00
|
|
|
|
|
|
|
asyncTest "retrieve historical messages from a self-store-node":
|
|
|
|
## This test aims to validate the correct message retrieval for a store-node which exposes
|
|
|
|
## a REST server.
|
|
|
|
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2024-01-31 16:43:59 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 08:48:14 +00:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-01-31 16:43:59 +00:00
|
|
|
|
|
|
|
installStoreApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# WakuStore setup
|
|
|
|
let driver: ArchiveDriver = QueueDriver.new()
|
|
|
|
let mountArchiveRes = node.mountArchive(driver)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
|
|
|
await node.mountStore()
|
|
|
|
|
|
|
|
# Now prime it with some history before tests
|
2024-03-15 23:08:47 +00:00
|
|
|
let msgList =
|
|
|
|
@[
|
|
|
|
fakeWakuMessage(
|
|
|
|
@[byte 0], contentTopic = ContentTopic("ct1"), ts = 0, meta = (@[byte 8])
|
|
|
|
),
|
|
|
|
fakeWakuMessage(@[byte 1], ts = 1),
|
|
|
|
fakeWakuMessage(@[byte 9], contentTopic = ContentTopic("ct2"), ts = 9),
|
|
|
|
]
|
2024-01-31 16:43:59 +00:00
|
|
|
for msg in msgList:
|
2024-05-10 12:13:58 +00:00
|
|
|
require (await driver.put(DefaultPubsubTopic, msg)).isOk()
|
2024-01-31 16:43:59 +00:00
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
# Filtering by a known pubsub topic.
|
2024-04-25 13:09:52 +00:00
|
|
|
var response = await client.getStoreMessagesV3(
|
|
|
|
includeData = "true", pubsubTopic = encodeUrl(DefaultPubsubTopic)
|
|
|
|
)
|
2024-02-14 15:29:59 +00:00
|
|
|
|
2024-01-31 16:43:59 +00:00
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 3
|
|
|
|
|
|
|
|
# Get all the messages by specifying an empty pubsub topic
|
2024-04-25 13:09:52 +00:00
|
|
|
response =
|
|
|
|
await client.getStoreMessagesV3(includeData = "true", pubsubTopic = encodeUrl(""))
|
2024-01-31 16:43:59 +00:00
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 3
|
|
|
|
|
|
|
|
# Receiving no messages by filtering with a random pubsub topic
|
2024-04-25 13:09:52 +00:00
|
|
|
response = await client.getStoreMessagesV3(
|
|
|
|
includeData = "true", pubsubTopic = encodeUrl("random pubsub topic")
|
|
|
|
)
|
2024-01-31 16:43:59 +00:00
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 0
|
2024-02-14 15:29:59 +00:00
|
|
|
|
|
|
|
asyncTest "correct message fields are returned":
|
|
|
|
# Given
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
|
|
|
|
var restPort = Port(0)
|
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
2024-02-29 08:48:14 +00:00
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-02-14 15:29:59 +00:00
|
|
|
|
|
|
|
installStoreApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# WakuStore setup
|
|
|
|
let driver: ArchiveDriver = QueueDriver.new()
|
|
|
|
let mountArchiveRes = node.mountArchive(driver)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
|
|
|
await node.mountStore()
|
|
|
|
|
|
|
|
# Now prime it with some history before tests
|
2024-03-15 23:08:47 +00:00
|
|
|
let msg = fakeWakuMessage(
|
|
|
|
@[byte 0], contentTopic = ContentTopic("ct1"), ts = 0, meta = (@[byte 8])
|
|
|
|
)
|
2024-05-10 12:13:58 +00:00
|
|
|
require (await driver.put(DefaultPubsubTopic, msg)).isOk()
|
2024-02-14 15:29:59 +00:00
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
# Filtering by a known pubsub topic.
|
2024-05-01 18:47:06 +00:00
|
|
|
var response = await client.getStoreMessagesV3(
|
|
|
|
includeData = "true", pubsubTopic = encodeUrl(DefaultPubsubTopic)
|
|
|
|
)
|
2024-02-14 15:29:59 +00:00
|
|
|
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
response.data.messages.len == 1
|
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
let storeMessage = response.data.messages[0].message.get()
|
2024-02-14 15:29:59 +00:00
|
|
|
|
|
|
|
check:
|
2024-04-25 13:09:52 +00:00
|
|
|
storeMessage.payload == msg.payload
|
|
|
|
storeMessage.contentTopic == msg.contentTopic
|
|
|
|
storeMessage.version == msg.version
|
|
|
|
storeMessage.timestamp == msg.timestamp
|
|
|
|
storeMessage.ephemeral == msg.ephemeral
|
|
|
|
storeMessage.meta == msg.meta
|
|
|
|
|
|
|
|
asyncTest "Rate limit store node store query":
|
2024-04-15 13:28:35 +00:00
|
|
|
# Test adapted from the analogous present at waku_store/test_wakunode_store.nim
|
|
|
|
let node = testWakuNode()
|
|
|
|
await node.start()
|
|
|
|
|
2024-06-12 13:07:33 +00:00
|
|
|
var restPort = Port(0)
|
2024-04-15 13:28:35 +00:00
|
|
|
let restAddress = parseIpAddress("0.0.0.0")
|
|
|
|
let restServer = WakuRestServerRef.init(restAddress, restPort).tryGet()
|
2024-06-12 13:07:33 +00:00
|
|
|
restPort = restServer.httpServer.address.port # update with bound port for client use
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
installStoreApiHandlers(restServer.router, node)
|
|
|
|
restServer.start()
|
|
|
|
|
|
|
|
# WakuStore setup
|
|
|
|
let driver: ArchiveDriver = QueueDriver.new()
|
|
|
|
let mountArchiveRes = node.mountArchive(driver)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
|
|
|
await node.mountStore((2, 500.millis))
|
|
|
|
node.mountStoreClient()
|
|
|
|
|
|
|
|
let key = generateEcdsaKey()
|
|
|
|
var peerSwitch = newStandardSwitch(some(key))
|
|
|
|
await peerSwitch.start()
|
|
|
|
|
|
|
|
peerSwitch.mount(node.wakuStore)
|
|
|
|
|
|
|
|
# Now prime it with some history before tests
|
|
|
|
let timeOrigin = wakucore.now()
|
|
|
|
let msgList =
|
|
|
|
@[
|
|
|
|
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)),
|
|
|
|
fakeWakuMessage(@[byte 09], ts = ts(90, timeOrigin)),
|
|
|
|
]
|
|
|
|
for msg in msgList:
|
2024-05-10 12:13:58 +00:00
|
|
|
require (await driver.put(DefaultPubsubTopic, msg)).isOk()
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
let client = newRestHttpClient(initTAddress(restAddress, restPort))
|
|
|
|
|
|
|
|
let remotePeerInfo = peerSwitch.peerInfo.toRemotePeerInfo()
|
|
|
|
let fullAddr = $remotePeerInfo.addrs[0] & "/p2p/" & $remotePeerInfo.peerId
|
|
|
|
|
|
|
|
var pages = newSeq[seq[WakuMessage]](2)
|
|
|
|
|
|
|
|
var reqPubsubTopic = DefaultPubsubTopic
|
2024-04-25 13:09:52 +00:00
|
|
|
var reqHash = none(WakuMessageHash)
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
for i in 0 ..< 2:
|
2024-04-25 13:09:52 +00:00
|
|
|
let response = await client.getStoreMessagesV3(
|
2024-04-15 13:28:35 +00:00
|
|
|
encodeUrl(fullAddr),
|
2024-04-25 13:09:52 +00:00
|
|
|
"true", # include data
|
2024-04-15 13:28:35 +00:00
|
|
|
encodeUrl(reqPubsubTopic),
|
|
|
|
"", # content topics. Empty ignores the field.
|
|
|
|
"", # start time. Empty ignores the field.
|
|
|
|
"", # end time. Empty ignores the field.
|
2024-04-25 13:09:52 +00:00
|
|
|
"", # hashes
|
|
|
|
if reqHash.isSome():
|
|
|
|
reqHash.get().toRestStringWakuMessageHash()
|
|
|
|
else:
|
2024-09-11 01:51:42 +00:00
|
|
|
"", # base64-encoded digest. Empty ignores the field.
|
2024-04-15 13:28:35 +00:00
|
|
|
"true", # ascending
|
2024-04-25 13:09:52 +00:00
|
|
|
"3", # page size. Empty implies default page size.
|
2024-04-15 13:28:35 +00:00
|
|
|
)
|
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
let wakuMessages = collect(newSeq):
|
|
|
|
for element in response.data.messages:
|
|
|
|
if element.message.isSome():
|
|
|
|
element.message.get()
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
pages[i] = wakuMessages
|
|
|
|
|
|
|
|
# populate the cursor for next page
|
2024-04-25 13:09:52 +00:00
|
|
|
if response.data.paginationCursor.isSome():
|
|
|
|
reqHash = response.data.paginationCursor
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
|
|
|
|
check:
|
|
|
|
pages[0] == msgList[0 .. 2]
|
|
|
|
pages[1] == msgList[3 .. 5]
|
|
|
|
|
|
|
|
# request last third will lead to rate limit rejection
|
2024-04-25 13:09:52 +00:00
|
|
|
var response = await client.getStoreMessagesV3(
|
2024-04-15 13:28:35 +00:00
|
|
|
encodeUrl(fullAddr),
|
2024-04-25 13:09:52 +00:00
|
|
|
"true", # include data
|
2024-04-15 13:28:35 +00:00
|
|
|
encodeUrl(reqPubsubTopic),
|
|
|
|
"", # content topics. Empty ignores the field.
|
|
|
|
"", # start time. Empty ignores the field.
|
|
|
|
"", # end time. Empty ignores the field.
|
2024-04-25 13:09:52 +00:00
|
|
|
"", # hashes
|
|
|
|
if reqHash.isSome():
|
|
|
|
reqHash.get().toRestStringWakuMessageHash()
|
|
|
|
else:
|
2024-09-11 01:51:42 +00:00
|
|
|
"", # base64-encoded digest. Empty ignores the field.
|
2024-04-15 13:28:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
response.status == 429
|
|
|
|
$response.contentType == $MIMETYPE_TEXT
|
2024-04-25 13:09:52 +00:00
|
|
|
response.data.statusDesc == "Request rate limit reached"
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
await sleepAsync(500.millis)
|
|
|
|
|
|
|
|
# retry after respective amount of time shall succeed
|
2024-04-25 13:09:52 +00:00
|
|
|
response = await client.getStoreMessagesV3(
|
2024-04-15 13:28:35 +00:00
|
|
|
encodeUrl(fullAddr),
|
2024-04-25 13:09:52 +00:00
|
|
|
"true", # include data
|
2024-04-15 13:28:35 +00:00
|
|
|
encodeUrl(reqPubsubTopic),
|
|
|
|
"", # content topics. Empty ignores the field.
|
|
|
|
"", # start time. Empty ignores the field.
|
|
|
|
"", # end time. Empty ignores the field.
|
2024-04-25 13:09:52 +00:00
|
|
|
"", # hashes
|
|
|
|
if reqHash.isSome():
|
|
|
|
reqHash.get().toRestStringWakuMessageHash()
|
|
|
|
else:
|
2024-09-11 01:51:42 +00:00
|
|
|
"", # base64-encoded digest. Empty ignores the field.
|
2024-04-15 13:28:35 +00:00
|
|
|
"true", # ascending
|
2024-04-25 13:09:52 +00:00
|
|
|
"5", # page size. Empty implies default page size.
|
2024-04-15 13:28:35 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
check:
|
|
|
|
response.status == 200
|
|
|
|
$response.contentType == $MIMETYPE_JSON
|
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
let wakuMessages = collect(newSeq):
|
|
|
|
for element in response.data.messages:
|
|
|
|
if element.message.isSome():
|
|
|
|
element.message.get()
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
check wakuMessages == msgList[6 .. 9]
|
|
|
|
|
|
|
|
await restServer.stop()
|
|
|
|
await restServer.closeWait()
|
|
|
|
await node.stop()
|