2022-09-09 13:54:16 +00:00
|
|
|
{.used.}
|
|
|
|
|
|
|
|
import
|
2024-04-25 13:09:52 +00:00
|
|
|
std/sequtils,
|
2022-11-23 09:08:00 +00:00
|
|
|
stew/shims/net as stewNet,
|
2022-09-09 13:54:16 +00:00
|
|
|
testutils/unittests,
|
2022-11-23 09:08:00 +00:00
|
|
|
chronicles,
|
|
|
|
chronos,
|
2022-09-09 13:54:16 +00:00
|
|
|
libp2p/crypto/crypto,
|
|
|
|
libp2p/peerid,
|
|
|
|
libp2p/multiaddress,
|
|
|
|
libp2p/switch,
|
|
|
|
libp2p/protocols/pubsub/rpc/messages,
|
|
|
|
libp2p/protocols/pubsub/pubsub,
|
2022-09-20 09:39:52 +00:00
|
|
|
libp2p/protocols/pubsub/gossipsub
|
2022-09-09 13:54:16 +00:00
|
|
|
import
|
2024-07-05 22:03:38 +00:00
|
|
|
waku/[
|
|
|
|
common/paging,
|
|
|
|
waku_core,
|
|
|
|
waku_core/message/digest,
|
|
|
|
waku_core/subscription,
|
|
|
|
node/peer_manager,
|
|
|
|
waku_archive,
|
|
|
|
waku_archive/driver/sqlite_driver,
|
|
|
|
waku_filter_v2,
|
|
|
|
waku_filter_v2/client,
|
|
|
|
waku_store,
|
|
|
|
waku_node,
|
|
|
|
],
|
2023-11-27 17:33:27 +00:00
|
|
|
../waku_store/store_utils,
|
|
|
|
../waku_archive/archive_utils,
|
2023-04-05 14:01:51 +00:00
|
|
|
../testlib/wakucore,
|
|
|
|
../testlib/wakunode
|
2022-09-09 13:54:16 +00:00
|
|
|
|
|
|
|
procSuite "WakuNode - Store":
|
2023-01-30 14:21:51 +00:00
|
|
|
## Fixtures
|
|
|
|
let timeOrigin = now()
|
2024-03-15 23:08:47 +00:00
|
|
|
let msgListA =
|
|
|
|
@[
|
|
|
|
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-01-30 14:21:51 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
let hashes = msgListA.mapIt(computeMessageHash(DefaultPubsubTopic, it))
|
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
let kvs = zip(hashes, msgListA).mapIt(
|
2024-05-08 19:35:56 +00:00
|
|
|
WakuMessageKeyValue(
|
|
|
|
messageHash: it[0], message: some(it[1]), pubsubTopic: some(DefaultPubsubTopic)
|
|
|
|
)
|
2024-05-01 18:47:06 +00:00
|
|
|
)
|
2024-04-25 13:09:52 +00:00
|
|
|
|
2023-01-30 14:21:51 +00:00
|
|
|
let archiveA = block:
|
2023-11-27 17:33:27 +00:00
|
|
|
let driver = newSqliteArchiveDriver()
|
2023-01-30 14:21:51 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
for kv in kvs:
|
2024-05-01 18:47:06 +00:00
|
|
|
let message = kv.message.get()
|
2024-07-12 16:19:12 +00:00
|
|
|
require (waitFor driver.put(kv.messageHash, DefaultPubsubTopic, message)).isOk()
|
2023-01-30 14:21:51 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
driver
|
2023-01-30 14:21:51 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
test "Store protocol returns expected messages":
|
2022-09-21 16:27:40 +00:00
|
|
|
## Setup
|
2022-09-09 13:54:16 +00:00
|
|
|
let
|
2023-02-13 10:43:49 +00:00
|
|
|
serverKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
server = newTestWakuNode(serverKey, parseIpAddress("0.0.0.0"), Port(0))
|
2023-02-13 10:43:49 +00:00
|
|
|
clientKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0))
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor allFutures(client.start(), server.start())
|
2022-11-23 09:08:00 +00:00
|
|
|
|
2023-06-27 11:24:31 +00:00
|
|
|
let mountArchiveRes = server.mountArchive(archiveA)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor server.mountStore()
|
2022-11-23 09:08:00 +00:00
|
|
|
|
2022-10-28 18:11:28 +00:00
|
|
|
client.mountStoreClient()
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
## Given
|
2024-05-01 18:47:06 +00:00
|
|
|
let req =
|
|
|
|
StoreQueryRequest(includeData: true, contentTopics: @[DefaultContentTopic])
|
2022-10-28 18:11:28 +00:00
|
|
|
let serverPeer = server.peerInfo.toRemotePeerInfo()
|
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
## When
|
2024-03-15 23:08:47 +00:00
|
|
|
let queryRes = waitFor client.query(req, peer = serverPeer)
|
2022-11-23 09:08:00 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
## Then
|
|
|
|
check queryRes.isOk()
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
let response = queryRes.get()
|
2022-09-09 13:54:16 +00:00
|
|
|
check:
|
2024-04-25 13:09:52 +00:00
|
|
|
response.messages == kvs
|
2023-01-30 14:21:51 +00:00
|
|
|
|
|
|
|
# Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor allFutures(client.stop(), server.stop())
|
2023-01-30 14:21:51 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
test "Store node history response - forward pagination":
|
2023-01-30 14:21:51 +00:00
|
|
|
## Setup
|
|
|
|
let
|
2023-02-13 10:43:49 +00:00
|
|
|
serverKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
server = newTestWakuNode(serverKey, parseIpAddress("0.0.0.0"), Port(0))
|
2023-02-13 10:43:49 +00:00
|
|
|
clientKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0))
|
2023-01-30 14:21:51 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor allFutures(client.start(), server.start())
|
2023-01-30 14:21:51 +00:00
|
|
|
|
2023-06-27 11:24:31 +00:00
|
|
|
let mountArchiveRes = server.mountArchive(archiveA)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor server.mountStore()
|
2023-01-30 14:21:51 +00:00
|
|
|
|
|
|
|
client.mountStoreClient()
|
|
|
|
|
|
|
|
## Given
|
2024-04-25 13:09:52 +00:00
|
|
|
let req = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-03-15 23:08:47 +00:00
|
|
|
contentTopics: @[DefaultContentTopic],
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationForward: PagingDirection.FORWARD,
|
|
|
|
paginationLimit: some(uint64(7)),
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-01-30 14:21:51 +00:00
|
|
|
let serverPeer = server.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
## When
|
|
|
|
var nextReq = req # copy
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
var pages = newSeq[seq[WakuMessageKeyValue]](2)
|
|
|
|
var cursors = newSeq[Option[WakuMessageHash]](2)
|
2023-01-30 14:21:51 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
for i in 0 ..< 2:
|
|
|
|
let res = waitFor client.query(nextReq, peer = serverPeer)
|
2023-01-30 14:21:51 +00:00
|
|
|
require res.isOk()
|
|
|
|
|
|
|
|
# Keep query response content
|
|
|
|
let response = res.get()
|
|
|
|
pages[i] = response.messages
|
2024-04-25 13:09:52 +00:00
|
|
|
cursors[i] = response.paginationCursor
|
2023-01-30 14:21:51 +00:00
|
|
|
|
|
|
|
# Set/update the request cursor
|
2024-04-25 13:09:52 +00:00
|
|
|
nextReq.paginationCursor = cursors[i]
|
2023-01-30 14:21:51 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
2024-04-25 13:09:52 +00:00
|
|
|
cursors[0] == some(kvs[6].messageHash)
|
|
|
|
cursors[1] == none(WakuMessageHash)
|
2023-01-30 14:21:51 +00:00
|
|
|
|
|
|
|
check:
|
2024-04-25 13:09:52 +00:00
|
|
|
pages[0] == kvs[0 .. 6]
|
|
|
|
pages[1] == kvs[7 .. 9]
|
2023-01-30 14:21:51 +00:00
|
|
|
|
|
|
|
# Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor allFutures(client.stop(), server.stop())
|
2023-01-30 14:21:51 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
test "Store node history response - backward pagination":
|
2023-01-30 14:21:51 +00:00
|
|
|
## Setup
|
|
|
|
let
|
2023-02-13 10:43:49 +00:00
|
|
|
serverKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
server = newTestWakuNode(serverKey, parseIpAddress("0.0.0.0"), Port(0))
|
2023-02-13 10:43:49 +00:00
|
|
|
clientKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0))
|
2023-01-30 14:21:51 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor allFutures(client.start(), server.start())
|
2023-01-30 14:21:51 +00:00
|
|
|
|
2023-06-27 11:24:31 +00:00
|
|
|
let mountArchiveRes = server.mountArchive(archiveA)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor server.mountStore()
|
2023-01-30 14:21:51 +00:00
|
|
|
|
|
|
|
client.mountStoreClient()
|
|
|
|
|
|
|
|
## Given
|
2024-04-25 13:09:52 +00:00
|
|
|
let req = StoreQueryRequest(
|
2024-05-01 18:47:06 +00:00
|
|
|
includeData: true,
|
2024-03-15 23:08:47 +00:00
|
|
|
contentTopics: @[DefaultContentTopic],
|
2024-04-25 13:09:52 +00:00
|
|
|
paginationLimit: some(uint64(7)),
|
|
|
|
paginationForward: PagingDirection.BACKWARD,
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2023-01-30 14:21:51 +00:00
|
|
|
let serverPeer = server.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
## When
|
|
|
|
var nextReq = req # copy
|
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
var pages = newSeq[seq[WakuMessageKeyValue]](2)
|
|
|
|
var cursors = newSeq[Option[WakuMessageHash]](2)
|
2023-01-30 14:21:51 +00:00
|
|
|
|
2024-03-15 23:08:47 +00:00
|
|
|
for i in 0 ..< 2:
|
|
|
|
let res = waitFor client.query(nextReq, peer = serverPeer)
|
2023-01-30 14:21:51 +00:00
|
|
|
require res.isOk()
|
|
|
|
|
|
|
|
# Keep query response content
|
|
|
|
let response = res.get()
|
|
|
|
pages[i] = response.messages
|
2024-04-25 13:09:52 +00:00
|
|
|
cursors[i] = response.paginationCursor
|
2023-01-30 14:21:51 +00:00
|
|
|
|
|
|
|
# Set/update the request cursor
|
2024-04-25 13:09:52 +00:00
|
|
|
nextReq.paginationCursor = cursors[i]
|
2023-01-30 14:21:51 +00:00
|
|
|
|
|
|
|
## Then
|
|
|
|
check:
|
2024-04-25 13:09:52 +00:00
|
|
|
cursors[0] == some(kvs[3].messageHash)
|
|
|
|
cursors[1] == none(WakuMessageHash)
|
2023-01-30 14:21:51 +00:00
|
|
|
|
|
|
|
check:
|
2024-04-25 13:09:52 +00:00
|
|
|
pages[0] == kvs[3 .. 9]
|
|
|
|
pages[1] == kvs[0 .. 2]
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
# Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor allFutures(client.stop(), server.stop())
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
test "Store protocol returns expected message when relay is disabled and filter enabled":
|
2022-09-21 16:27:40 +00:00
|
|
|
## See nwaku issue #937: 'Store: ability to decouple store from relay'
|
|
|
|
## Setup
|
2022-09-09 13:54:16 +00:00
|
|
|
let
|
2023-02-13 10:43:49 +00:00
|
|
|
filterSourceKey = generateSecp256k1Key()
|
2024-03-15 23:08:47 +00:00
|
|
|
filterSource =
|
|
|
|
newTestWakuNode(filterSourceKey, parseIpAddress("0.0.0.0"), Port(0))
|
2023-02-13 10:43:49 +00:00
|
|
|
serverKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
server = newTestWakuNode(serverKey, parseIpAddress("0.0.0.0"), Port(0))
|
2023-02-13 10:43:49 +00:00
|
|
|
clientKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0))
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor allFutures(client.start(), server.start(), filterSource.start())
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor filterSource.mountFilter()
|
2023-11-27 17:33:27 +00:00
|
|
|
let driver = newSqliteArchiveDriver()
|
2023-06-27 11:24:31 +00:00
|
|
|
|
|
|
|
let mountArchiveRes = server.mountArchive(driver)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
2023-09-14 19:28:57 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor server.mountStore()
|
|
|
|
waitFor server.mountFilterClient()
|
2022-10-28 18:11:28 +00:00
|
|
|
client.mountStoreClient()
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
## Given
|
|
|
|
let message = fakeWakuMessage()
|
2024-04-25 13:09:52 +00:00
|
|
|
let hash = computeMessageHash(DefaultPubSubTopic, message)
|
2022-11-23 09:08:00 +00:00
|
|
|
let
|
2022-11-02 10:59:58 +00:00
|
|
|
serverPeer = server.peerInfo.toRemotePeerInfo()
|
|
|
|
filterSourcePeer = filterSource.peerInfo.toRemotePeerInfo()
|
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
## Then
|
2022-11-02 10:59:58 +00:00
|
|
|
let filterFut = newFuture[(PubsubTopic, WakuMessage)]()
|
2024-03-15 23:08:47 +00:00
|
|
|
proc filterHandler(
|
|
|
|
pubsubTopic: PubsubTopic, msg: WakuMessage
|
|
|
|
) {.async, gcsafe, closure.} =
|
2024-03-25 18:07:56 +00:00
|
|
|
await server.wakuArchive.handleMessage(pubsubTopic, msg)
|
2022-11-02 10:59:58 +00:00
|
|
|
filterFut.complete((pubsubTopic, msg))
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2024-03-25 18:07:56 +00:00
|
|
|
server.wakuFilterClient.registerPushHandler(filterHandler)
|
|
|
|
let resp = waitFor server.filterSubscribe(
|
2024-04-15 13:28:35 +00:00
|
|
|
some(DefaultPubsubTopic), DefaultContentTopic, peer = filterSourcePeer
|
2024-03-15 23:08:47 +00:00
|
|
|
)
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor sleepAsync(100.millis)
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2024-03-25 18:07:56 +00:00
|
|
|
waitFor filterSource.wakuFilter.handleMessage(DefaultPubsubTopic, message)
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
# Wait for the server filter to receive the push message
|
2023-05-25 15:34:34 +00:00
|
|
|
require waitFor filterFut.withTimeout(5.seconds)
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2024-05-01 18:47:06 +00:00
|
|
|
let req =
|
|
|
|
StoreQueryRequest(includeData: true, contentTopics: @[DefaultContentTopic])
|
2024-04-25 13:09:52 +00:00
|
|
|
let res = waitFor client.query(req, serverPeer)
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
## Then
|
|
|
|
check res.isOk()
|
2022-09-09 13:54:16 +00:00
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
let response = res.get()
|
2022-09-09 13:54:16 +00:00
|
|
|
check:
|
2022-09-21 16:27:40 +00:00
|
|
|
response.messages.len == 1
|
2024-05-01 18:47:06 +00:00
|
|
|
response.messages[0] ==
|
2024-05-08 19:35:56 +00:00
|
|
|
WakuMessageKeyValue(
|
|
|
|
messageHash: hash,
|
|
|
|
message: some(message),
|
|
|
|
pubsubTopic: some(DefaultPubSubTopic),
|
|
|
|
)
|
2022-09-21 16:27:40 +00:00
|
|
|
|
2022-11-02 10:59:58 +00:00
|
|
|
let (handledPubsubTopic, handledMsg) = filterFut.read()
|
|
|
|
check:
|
|
|
|
handledPubsubTopic == DefaultPubsubTopic
|
|
|
|
handledMsg == message
|
|
|
|
|
2022-09-21 16:27:40 +00:00
|
|
|
## Cleanup
|
2023-05-25 15:34:34 +00:00
|
|
|
waitFor allFutures(client.stop(), server.stop(), filterSource.stop())
|
2023-11-22 08:32:39 +00:00
|
|
|
|
|
|
|
test "history query should return INVALID_CURSOR if the cursor has empty data in the request":
|
|
|
|
## Setup
|
|
|
|
let
|
|
|
|
serverKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
server = newTestWakuNode(serverKey, parseIpAddress("0.0.0.0"), Port(0))
|
2023-11-22 08:32:39 +00:00
|
|
|
clientKey = generateSecp256k1Key()
|
2023-12-14 06:16:39 +00:00
|
|
|
client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0))
|
2023-11-22 08:32:39 +00:00
|
|
|
|
|
|
|
waitFor allFutures(client.start(), server.start())
|
|
|
|
|
|
|
|
let mountArchiveRes = server.mountArchive(archiveA)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
|
|
|
waitFor server.mountStore()
|
|
|
|
|
|
|
|
client.mountStoreClient()
|
|
|
|
|
|
|
|
## Forcing a bad cursor with empty digest data
|
2024-04-25 13:09:52 +00:00
|
|
|
var cursor: WakuMessageHash = [
|
2024-03-15 23:08:47 +00:00
|
|
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
|
|
|
0, 0, 0, 0, 0,
|
|
|
|
]
|
2023-11-22 08:32:39 +00:00
|
|
|
|
|
|
|
## Given
|
2024-04-25 13:09:52 +00:00
|
|
|
let req = StoreQueryRequest(
|
|
|
|
contentTopics: @[DefaultContentTopic], paginationCursor: some(cursor)
|
|
|
|
)
|
2023-11-22 08:32:39 +00:00
|
|
|
let serverPeer = server.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
## When
|
2024-03-15 23:08:47 +00:00
|
|
|
let queryRes = waitFor client.query(req, peer = serverPeer)
|
2023-11-22 08:32:39 +00:00
|
|
|
|
|
|
|
## Then
|
2024-04-25 13:09:52 +00:00
|
|
|
check queryRes.isOk()
|
2023-11-22 08:32:39 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
let response = queryRes.get()
|
|
|
|
|
|
|
|
check response.statusCode == 400
|
|
|
|
check response.statusDesc == "BAD_REQUEST: invalid cursor"
|
2023-11-22 08:32:39 +00:00
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
waitFor allFutures(client.stop(), server.stop())
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
test "Store protocol queries does not violate request rate limitation":
|
|
|
|
## Setup
|
|
|
|
let
|
|
|
|
serverKey = generateSecp256k1Key()
|
|
|
|
server = newTestWakuNode(serverKey, parseIpAddress("0.0.0.0"), Port(0))
|
|
|
|
clientKey = generateSecp256k1Key()
|
|
|
|
client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0))
|
|
|
|
|
|
|
|
waitFor allFutures(client.start(), server.start())
|
|
|
|
|
|
|
|
let mountArchiveRes = server.mountArchive(archiveA)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
|
|
|
waitFor server.mountStore((4, 500.millis))
|
|
|
|
|
|
|
|
client.mountStoreClient()
|
|
|
|
|
|
|
|
## Given
|
2024-05-01 18:47:06 +00:00
|
|
|
let req =
|
|
|
|
StoreQueryRequest(includeData: true, contentTopics: @[DefaultContentTopic])
|
2024-04-15 13:28:35 +00:00
|
|
|
let serverPeer = server.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
let requestProc = proc() {.async.} =
|
2024-05-10 12:13:58 +00:00
|
|
|
let queryRes = await client.query(req, peer = serverPeer)
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
assert queryRes.isOk(), queryRes.error
|
|
|
|
|
|
|
|
let response = queryRes.get()
|
|
|
|
check:
|
2024-05-01 18:47:06 +00:00
|
|
|
response.messages.mapIt(it.message.get()) == msgListA
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
for count in 0 ..< 4:
|
|
|
|
waitFor requestProc()
|
|
|
|
waitFor sleepAsync(20.millis)
|
|
|
|
|
|
|
|
waitFor sleepAsync(500.millis)
|
|
|
|
|
|
|
|
for count in 0 ..< 4:
|
|
|
|
waitFor requestProc()
|
|
|
|
waitFor sleepAsync(20.millis)
|
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
waitFor allFutures(client.stop(), server.stop())
|
|
|
|
|
|
|
|
test "Store protocol queries overrun request rate limitation":
|
|
|
|
## Setup
|
|
|
|
let
|
|
|
|
serverKey = generateSecp256k1Key()
|
|
|
|
server = newTestWakuNode(serverKey, parseIpAddress("0.0.0.0"), Port(0))
|
|
|
|
clientKey = generateSecp256k1Key()
|
|
|
|
client = newTestWakuNode(clientKey, parseIpAddress("0.0.0.0"), Port(0))
|
|
|
|
|
|
|
|
waitFor allFutures(client.start(), server.start())
|
|
|
|
|
|
|
|
let mountArchiveRes = server.mountArchive(archiveA)
|
|
|
|
assert mountArchiveRes.isOk(), mountArchiveRes.error
|
|
|
|
|
|
|
|
waitFor server.mountStore((3, 500.millis))
|
|
|
|
|
|
|
|
client.mountStoreClient()
|
|
|
|
|
|
|
|
## Given
|
2024-05-01 18:47:06 +00:00
|
|
|
let req =
|
|
|
|
StoreQueryRequest(includeData: true, contentTopics: @[DefaultContentTopic])
|
2024-04-15 13:28:35 +00:00
|
|
|
let serverPeer = server.peerInfo.toRemotePeerInfo()
|
|
|
|
|
|
|
|
let successProc = proc() {.async.} =
|
2024-05-10 12:13:58 +00:00
|
|
|
let queryRes = await client.query(req, peer = serverPeer)
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
check queryRes.isOk()
|
|
|
|
let response = queryRes.get()
|
|
|
|
check:
|
2024-05-01 18:47:06 +00:00
|
|
|
response.messages.mapIt(it.message.get()) == msgListA
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
let failsProc = proc() {.async.} =
|
2024-05-10 12:13:58 +00:00
|
|
|
let queryRes = await client.query(req, peer = serverPeer)
|
2024-04-15 13:28:35 +00:00
|
|
|
|
2024-04-25 13:09:52 +00:00
|
|
|
check queryRes.isOk()
|
|
|
|
let response = queryRes.get()
|
|
|
|
|
|
|
|
check response.statusCode == 429
|
2024-04-15 13:28:35 +00:00
|
|
|
|
|
|
|
for count in 0 ..< 3:
|
|
|
|
waitFor successProc()
|
|
|
|
waitFor sleepAsync(20.millis)
|
|
|
|
|
|
|
|
waitFor failsProc()
|
|
|
|
|
|
|
|
waitFor sleepAsync(500.millis)
|
|
|
|
|
|
|
|
for count in 0 ..< 3:
|
|
|
|
waitFor successProc()
|
|
|
|
waitFor sleepAsync(20.millis)
|
|
|
|
|
|
|
|
# Cleanup
|
|
|
|
waitFor allFutures(client.stop(), server.stop())
|