mirror of
https://github.com/waku-org/nwaku.git
synced 2025-01-09 14:26:27 +00:00
9518322198
* Change folder structure to {v1,v2,common}/... Addresses https://github.com/status-im/nim-waku/issues/261 * Update waku.nimble paths * Flatten paths * Fix import paths * Pull out utils folder for nat * Pull out waku_types to top level for v2 * Fix test import paths * Remove old READMEs and replace with one liner * Update README and split v1 and v2 * Skeleton READMEs * Update README.md Co-authored-by: Kim De Mey <kim.demey@gmail.com> * Update README.md Co-authored-by: Kim De Mey <kim.demey@gmail.com> Co-authored-by: Kim De Mey <kim.demey@gmail.com>
66 lines
2.2 KiB
Nim
66 lines
2.2 KiB
Nim
#
|
|
# Waku
|
|
# (c) Copyright 2020
|
|
# Status Research & Development GmbH
|
|
#
|
|
# Licensed under either of
|
|
# Apache License, version 2.0, (LICENSE-APACHEv2)
|
|
# MIT license (LICENSE-MIT)
|
|
{.used.}
|
|
|
|
import
|
|
std/[sequtils, options, unittest, times],
|
|
../../waku/v1/protocol/waku_protocol
|
|
|
|
suite "Waku envelope validation":
|
|
test "should validate and allow envelope according to config":
|
|
let ttl = 1'u32
|
|
let topic = [byte 1, 2, 3, 4]
|
|
let config = WakuConfig(powRequirement: 0, bloom: some(topic.topicBloom()),
|
|
isLightNode: false, maxMsgSize: defaultMaxMsgSize)
|
|
|
|
let env = Envelope(expiry:epochTime().uint32 + ttl, ttl: ttl, topic: topic,
|
|
data: repeat(byte 9, 256), nonce: 0)
|
|
check env.valid()
|
|
|
|
let msg = initMessage(env)
|
|
check msg.allowed(config)
|
|
|
|
test "should invalidate envelope due to ttl 0":
|
|
let ttl = 0'u32
|
|
let topic = [byte 1, 2, 3, 4]
|
|
|
|
let env = Envelope(expiry:epochTime().uint32 + ttl, ttl: ttl, topic: topic,
|
|
data: repeat(byte 9, 256), nonce: 0)
|
|
check env.valid() == false
|
|
|
|
test "should invalidate envelope due to expired":
|
|
let ttl = 1'u32
|
|
let topic = [byte 1, 2, 3, 4]
|
|
|
|
let env = Envelope(expiry:epochTime().uint32, ttl: ttl, topic: topic,
|
|
data: repeat(byte 9, 256), nonce: 0)
|
|
check env.valid() == false
|
|
|
|
test "should invalidate envelope due to in the future":
|
|
let ttl = 1'u32
|
|
let topic = [byte 1, 2, 3, 4]
|
|
|
|
# there is currently a 2 second tolerance, hence the + 3
|
|
let env = Envelope(expiry:epochTime().uint32 + ttl + 3, ttl: ttl,
|
|
topic: topic, data: repeat(byte 9, 256), nonce: 0)
|
|
check env.valid() == false
|
|
|
|
test "should not allow envelope due to bloom filter":
|
|
let topic = [byte 1, 2, 3, 4]
|
|
let wrongTopic = [byte 9, 8, 7, 6]
|
|
let config = WakuConfig(powRequirement: 0,
|
|
bloom: some(wrongTopic.topicBloom()),
|
|
isLightNode: false, maxMsgSize: defaultMaxMsgSize)
|
|
|
|
let env = Envelope(expiry:100000 , ttl: 30, topic: topic,
|
|
data: repeat(byte 9, 256), nonce: 0)
|
|
|
|
let msg = initMessage(env)
|
|
check msg.allowed(config) == false
|