|
1 | 1 | {.used.}
|
2 | 2 |
|
3 |
| -import std/sets, stew/[results, byteutils], testutils/unittests |
| 3 | +import std/[sets, random], stew/[results, byteutils], testutils/unittests |
4 | 4 | import ../../waku/waku_core, ../../waku/waku_api/message_cache, ./testlib/wakucore
|
5 | 5 |
|
| 6 | +randomize() |
| 7 | + |
6 | 8 | suite "MessageCache":
|
7 | 9 | setup:
|
8 | 10 | ## Given
|
@@ -209,3 +211,39 @@ suite "MessageCache":
|
209 | 211 |
|
210 | 212 | check:
|
211 | 213 | cache.messagesCount() == 2
|
| 214 | + |
| 215 | + test "fuzzing": |
| 216 | + let testContentTopic1 = "contentTopic1" |
| 217 | + let testContentTopic2 = "contentTopic2" |
| 218 | + |
| 219 | + let cache = MessageCache.init(50) |
| 220 | + |
| 221 | + cache.contentSubscribe(testContentTopic1) |
| 222 | + cache.contentSubscribe(testContentTopic2) |
| 223 | + |
| 224 | + for _ in 0 .. 10000: |
| 225 | + let numb = rand(1.0) |
| 226 | + |
| 227 | + if numb > 0.4: |
| 228 | + let topic = if rand(1.0) > 0.5: testContentTopic1 else: testContentTopic2 |
| 229 | + |
| 230 | + let testMessage = fakeWakuMessage(contentTopic = topic) |
| 231 | + |
| 232 | + cache.addMessage(DefaultPubsubTopic, testMessage) |
| 233 | + elif numb > 0.1: |
| 234 | + let topic = if rand(1.0) > 0.5: testContentTopic1 else: testContentTopic2 |
| 235 | + |
| 236 | + let clear = rand(1.0) > 0.5 |
| 237 | + discard cache.getAutoMessages(topic, clear) |
| 238 | + elif numb > 0.05: |
| 239 | + if rand(1.0) > 0.5: |
| 240 | + cache.pubsubUnsubscribe(DefaultPubsubTopic) |
| 241 | + else: |
| 242 | + cache.pubsubSubscribe(DefaultPubsubTopic) |
| 243 | + else: |
| 244 | + let topic = if rand(1.0) > 0.5: testContentTopic1 else: testContentTopic2 |
| 245 | + |
| 246 | + if rand(1.0) > 0.5: |
| 247 | + cache.contentUnsubscribe(topic) |
| 248 | + else: |
| 249 | + cache.contentSubscribe(topic) |
0 commit comments