mirror of https://github.com/waku-org/nwaku.git
feat(archive): respond with error on more than 10 content topics query
This commit is contained in:
parent
982cd28265
commit
3ee87d1848
|
@ -214,6 +214,29 @@ procSuite "Waku Archive - find messages":
|
|||
response.messages.anyIt(it == msg1)
|
||||
response.messages.anyIt(it == msg3)
|
||||
|
||||
test "handle query with more than 10 content filters":
|
||||
## Setup
|
||||
let
|
||||
driver = newTestArchiveDriver()
|
||||
archive = newTestWakuArchive(driver)
|
||||
|
||||
let queryTopics = toSeq(1..15).mapIt(ContentTopic($it))
|
||||
|
||||
## Given
|
||||
let req = ArchiveQuery(contentTopics: queryTopics)
|
||||
|
||||
## When
|
||||
let queryRes = archive.findMessages(req)
|
||||
|
||||
## Then
|
||||
check:
|
||||
queryRes.isErr()
|
||||
|
||||
let error = queryRes.tryError()
|
||||
check:
|
||||
error.kind == ArchiveErrorKind.INVALID_QUERY
|
||||
error.cause == "too many content topics"
|
||||
|
||||
test "handle query with pubsub topic filter":
|
||||
## Setup
|
||||
let
|
||||
|
|
|
@ -126,6 +126,8 @@ proc findMessages*(w: WakuArchive, query: ArchiveQuery): ArchiveResult {.gcsafe.
|
|||
else: min(query.pageSize, MaxPageSize)
|
||||
qAscendingOrder = query.ascending
|
||||
|
||||
if qContentTopics.len > 10:
|
||||
return err(ArchiveError.invalidQuery("too many content topics"))
|
||||
|
||||
let queryStartTime = getTime().toUnixFloat()
|
||||
|
||||
|
|
|
@ -85,3 +85,6 @@ proc `$`*(err: ArchiveError): string =
|
|||
"INVALID_QUERY: " & err.cause
|
||||
of ArchiveErrorKind.UNKNOWN:
|
||||
"UNKNOWN"
|
||||
|
||||
proc invalidQuery*(T: type ArchiveError, cause: string): T =
|
||||
ArchiveError(kind: ArchiveErrorKind.INVALID_QUERY, cause: cause)
|
||||
|
|
Loading…
Reference in New Issue