chore: extract test procedures and constants into a common module

This commit is contained in:
Lorenzo Delgado 2022-10-21 15:01:39 +02:00 committed by GitHub
parent c19081b6ce
commit 9b59052bcd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
19 changed files with 120 additions and 318 deletions

View File

@ -6,16 +6,10 @@ import
chronicles
import
../../waku/v2/protocol/waku_message,
../../waku/v2/node/message_cache
../../waku/v2/node/message_cache,
./testlib/common
proc fakeWakuMessage(payload = toBytes("TEST"), contentTopic = "test"): WakuMessage =
WakuMessage(
payload: payload,
contentTopic: contentTopic,
version: 1,
timestamp: 2022
)
type PubsubTopicString = string

View File

@ -8,12 +8,8 @@ import
import
../../waku/v2/protocol/waku_message,
../../waku/v2/utils/time,
../../waku/v2/node/storage/message/queue_store/index
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
../../waku/v2/node/storage/message/queue_store/index,
./testlib/common
## Helpers

View File

@ -1,7 +1,7 @@
{.used.}
import
std/[options, sequtils, times, algorithm],
std/[options, sequtils, algorithm],
testutils/unittests,
nimcrypto/sha2,
libp2p/protobuf/minprotobuf
@ -9,12 +9,8 @@ import
../../waku/v2/node/storage/message/waku_store_queue,
../../waku/v2/protocol/waku_store,
../../waku/v2/protocol/waku_message,
../../waku/v2/utils/time
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
../../waku/v2/utils/time,
./testlib/common
proc getTestStoreQueue(numMessages: int): StoreQueueRef =
@ -36,12 +32,6 @@ proc getTestStoreQueue(numMessages: int): StoreQueueRef =
return testStoreQueue
proc now(): Timestamp =
getNanosecondTime(getTime().toUnixFloat())
proc ts(offset=0, origin=now()): Timestamp =
origin + getNanosecondTime(offset)
suite "Queue store - pagination":
test "Forward pagination test":

View File

@ -13,35 +13,13 @@ import
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_store/pagination,
../../waku/v2/utils/time,
./utils
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
./utils,
./testlib/common
proc newTestDatabase(): SqliteDatabase =
SqliteDatabase.init("", inMemory = true).tryGet()
proc now(): Timestamp =
getNanosecondTime(getTime().toUnixFloat())
proc ts(offset=0, origin=now()): Timestamp =
origin + getNanosecondTime(offset)
proc fakeWakuMessage(
payload = "TEST-PAYLOAD",
contentTopic = DefaultContentTopic,
ts = now()
): WakuMessage =
WakuMessage(
payload: toBytes(payload),
contentTopic: contentTopic,
version: 1,
timestamp: ts
)
suite "SQLite message store - init store":
test "init store":

View File

@ -1,45 +1,23 @@
{.used.}
import
std/[options, tables, sets, times, strutils, sequtils, algorithm],
stew/byteutils,
std/[options, tables, sets, strutils, sequtils, algorithm],
unittest2,
chronos,
chronicles,
chronicles
import
../../waku/v2/node/storage/message/sqlite_store,
../../waku/v2/node/storage/sqlite,
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_store/pagination,
../../waku/v2/utils/time,
./utils
./utils,
./testlib/common
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
proc now(): Timestamp =
getNanosecondTime(getTime().toUnixFloat())
proc ts(offset=0, origin=now()): Timestamp =
origin + getNanosecondTime(offset)
proc newTestDatabase(): SqliteDatabase =
SqliteDatabase.init("", inMemory = true).tryGet()
proc fakeWakuMessage(
payload = "TEST-PAYLOAD",
contentTopic = DefaultContentTopic,
ts = now()
): WakuMessage =
WakuMessage(
payload: toBytes(payload),
contentTopic: contentTopic,
version: 1,
timestamp: ts
)
suite "message store - history query":
@ -477,7 +455,7 @@ suite "message store - history query":
test "single content topic and valid time range":
## Given
const contentTopic = "test-content-topic"
let timeOrigin = getNanosecondTime(epochTime())
let timeOrigin = now()
let
database = newTestDatabase()
@ -522,7 +500,7 @@ suite "message store - history query":
test "single content topic and invalid time range - no results":
## Given
const contentTopic = "test-content-topic"
let timeOrigin = getNanosecondTime(epochTime())
let timeOrigin = now()
let
database = newTestDatabase()
@ -561,7 +539,7 @@ suite "message store - history query":
test "single content topic and only time range start":
## Given
const contentTopic = "test-content-topic"
let timeOrigin = getNanosecondTime(epochTime())
let timeOrigin = now()
let
database = newTestDatabase()
@ -602,7 +580,7 @@ suite "message store - history query":
test "single content topic, cursor and only time range start":
## Given
const contentTopic = "test-content-topic"
let timeOrigin = getNanosecondTime(epochTime())
let timeOrigin = now()
let
database = newTestDatabase()

View File

@ -13,7 +13,9 @@ import
../../waku/v2/protocol/waku_message,
../../waku/v2/node/waku_node,
../../waku/v2/node/rest/[server, client, base64, utils],
../../waku/v2/node/rest/relay/[api_types, relay_api, topic_cache]
../../waku/v2/node/rest/relay/[api_types, relay_api, topic_cache],
../../waku/v2/utils/time,
./testlib/common
proc testWakuNode(): WakuNode =
@ -26,14 +28,6 @@ proc testWakuNode(): WakuNode =
WakuNode.new(privkey, bindIp, port, some(extIp), some(port))
proc fakeWakuMessage(payload = toBytes("TEST"), contentTopic = "test"): WakuMessage =
WakuMessage(
payload: payload,
contentTopic: contentTopic,
version: 1,
timestamp: 2022
)
suite "REST API - Relay":
asyncTest "Subscribe a node to an array of topics - POST /relay/v1/subscriptions":
@ -167,8 +161,8 @@ suite "REST API - Relay":
response.data.all do (msg: RelayWakuMessage) -> bool:
msg.payload == Base64String.encode("TEST-1") and
msg.contentTopic.get().string == "content-topic-x" and
msg.version.get() == Natural(1) and
msg.timestamp.get() == int64(2022)
msg.version.get() == 2 and
msg.timestamp.get() != Timestamp(0)
check:

View File

@ -5,7 +5,6 @@ import
testutils/unittests,
chronos,
chronicles,
libp2p/switch,
libp2p/crypto/crypto,
libp2p/multistream
import
@ -13,20 +12,13 @@ import
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_filter,
../test_helpers,
./utils
./utils,
./testlib/common,
./testlib/switch
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
const dummyHandler = proc(requestId: string, msg: MessagePush) {.async, gcsafe, closure.} = discard
proc newTestSwitch(key=none(PrivateKey), address=none(MultiAddress)): Switch =
let peerKey = key.get(PrivateKey.random(ECDSA, rng[]).get())
let peerAddr = address.get(MultiAddress.init("/ip4/127.0.0.1/tcp/0").get())
return newStandardSwitch(some(peerKey), addrs=peerAddr)
# TODO: Extend test coverage
procSuite "Waku Filter":

View File

@ -11,12 +11,8 @@ import
../../waku/v2/node/peer_manager/peer_manager,
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_lightpush,
../test_helpers
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
../test_helpers,
./testlib/common
# TODO: Extend lightpush protocol test coverage

View File

@ -6,7 +6,8 @@ import
testutils/unittests, chronos, chronicles, stint,
stew/byteutils, stew/shims/net as stewNet,
libp2p/crypto/crypto,
json,
json
import
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_rln_relay/[rln,
waku_rln_relay_utils,

View File

@ -1,12 +1,11 @@
{.used.}
import
std/[options, tables, sets, sequtils, times],
std/[options, tables, sets, sequtils],
stew/byteutils,
testutils/unittests,
chronos,
chronicles,
libp2p/switch,
libp2p/crypto/crypto
import
../../waku/v2/protocol/waku_message,
@ -17,39 +16,13 @@ import
../../waku/v2/node/storage/message/sqlite_store,
../../waku/v2/node/peer_manager/peer_manager,
../../waku/v2/utils/time,
../test_helpers
./testlib/common,
./testlib/switch
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
proc now(): Timestamp =
getNanosecondTime(getTime().toUnixFloat())
proc newTestDatabase(): SqliteDatabase =
SqliteDatabase.init("", inMemory = true).tryGet()
proc fakeWakuMessage(
payload = "TEST-PAYLOAD",
contentTopic = DefaultContentTopic,
ts = getNanosecondTime(epochTime()),
ephemeral = false,
): WakuMessage =
WakuMessage(
payload: toBytes(payload),
contentTopic: contentTopic,
version: 1,
timestamp: ts,
ephemeral: ephemeral,
)
proc newTestSwitch(key=none(PrivateKey), address=none(MultiAddress)): Switch =
let peerKey = key.get(PrivateKey.random(ECDSA, rng[]).get())
let peerAddr = address.get(MultiAddress.init("/ip4/127.0.0.1/tcp/0").get())
return newStandardSwitch(some(peerKey), addrs=peerAddr)
proc newTestMessageStore(): MessageStore =
let database = newTestDatabase()
SqliteStore.init(database).tryGet()
@ -340,7 +313,7 @@ procSuite "Waku Store - history query":
client.setPeer(serverSwitch.peerInfo.toRemotePeerInfo())
## Given
let currentTime = getNanosecondTime(getTime().toUnixFloat())
let currentTime = now()
let msgList = @[
WakuMessage(payload: @[byte 0], contentTopic: ContentTopic("2"), timestamp: currentTime - 9),
WakuMessage(payload: @[byte 1], contentTopic: DefaultContentTopic, timestamp: currentTime - 8),
@ -409,7 +382,7 @@ procSuite "Waku Store - history query":
client.setPeer(serverSwitch.peerInfo.toRemotePeerInfo())
## Given
let currentTime = getNanosecondTime(getTime().toUnixFloat())
let currentTime = now()
let msgList = @[
WakuMessage(payload: @[byte 0], contentTopic: ContentTopic("2"), timestamp: currentTime - 9),
WakuMessage(payload: @[byte 1], contentTopic: DefaultContentTopic, timestamp: currentTime - 8),
@ -695,7 +668,7 @@ suite "Waku Store - message handling":
## Given
let
now = getNanoSecondTime(getTime().toUnixFloat())
now = now()
invalidSenderTime = now + MaxMessageTimestampVariance + 1
let message = fakeWakuMessage(ts=invalidSenderTime)
@ -718,7 +691,7 @@ suite "Waku Store - message handling":
## Given
let
now = getNanoSecondTime(getTime().toUnixFloat())
now = now()
invalidSenderTime = now - MaxMessageTimestampVariance - 1
let message = fakeWakuMessage(ts=invalidSenderTime)

View File

@ -1,12 +1,10 @@
{.used.}
import
std/[options, tables, sets, times],
stew/byteutils,
std/[options, tables, sets],
testutils/unittests,
chronos,
chronicles,
libp2p/switch,
libp2p/crypto/crypto
import
../../waku/v2/protocol/waku_message,
@ -16,51 +14,24 @@ import
../../waku/v2/node/storage/sqlite,
../../waku/v2/node/storage/message/sqlite_store,
../../waku/v2/node/peer_manager/peer_manager,
../../waku/v2/utils/time,
../test_helpers
./testlib/common,
./testlib/switch
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
proc now(): Timestamp =
getNanosecondTime(getTime().toUnixFloat())
proc newTestDatabase(): SqliteDatabase =
SqliteDatabase.init("", inMemory = true).tryGet()
proc fakeWakuMessage(
payload = toBytes("TEST-PAYLOAD"),
contentTopic = DefaultContentTopic,
ts = now(),
ephemeral = false,
): WakuMessage =
WakuMessage(
payload: payload,
contentTopic: contentTopic,
version: 1,
timestamp: ts,
ephemeral: ephemeral,
)
proc newTestSwitch(key=none(PrivateKey), address=none(MultiAddress)): Switch =
let peerKey = key.get(PrivateKey.random(ECDSA, rng[]).get())
let peerAddr = address.get(MultiAddress.init("/ip4/127.0.0.1/tcp/0").get())
return newStandardSwitch(some(peerKey), addrs=peerAddr)
proc newTestStore(): MessageStore =
let database = newTestDatabase()
SqliteStore.init(database).tryGet()
proc newTestWakuStore(switch: Switch, store=newTestStore()): WakuStore =
proc newTestWakuStore(switch: Switch, store=newTestStore()): Future[WakuStore] {.async.} =
let
peerManager = PeerManager.new(switch)
rng = crypto.newRng()
proto = WakuStore.init(peerManager, rng, store)
waitFor proto.start()
await proto.start()
switch.mount(proto)
return proto
@ -107,7 +78,7 @@ procSuite "Waku Store Client":
await allFutures(serverSwitch.start(), clientSwitch.start())
let
server = newTestWakuStore(serverSwitch, store=testStore)
server = await newTestWakuStore(serverSwitch, store=testStore)
client = newTestWakuStoreClient(clientSwitch)
## Given
@ -143,7 +114,7 @@ procSuite "Waku Store Client":
await allFutures(serverSwitch.start(), clientSwitch.start())
let
server = newTestWakuStore(serverSwitch, store=testStore)
server = await newTestWakuStore(serverSwitch, store=testStore)
client = newTestWakuStoreClient(clientSwitch)
## Given
@ -177,8 +148,8 @@ procSuite "Waku Store Client":
await allFutures(serverSwitchA.start(), serverSwitchB.start(), clientSwitch.start())
let
serverA = newTestWakuStore(serverSwitchA, store=testStore)
serverB = newTestWakuStore(serverSwitchB, store=testStore)
serverA = await newTestWakuStore(serverSwitchA, store=testStore)
serverB = await newTestWakuStore(serverSwitchB, store=testStore)
client = newTestWakuStoreClient(clientSwitch)
## Given
@ -214,7 +185,7 @@ procSuite "Waku Store Client":
await allFutures(serverSwitch.start(), clientSwitch.start())
let
server = newTestWakuStore(serverSwitch, store=testStore)
server = await newTestWakuStore(serverSwitch, store=testStore)
client = newTestWakuStoreClient(clientSwitch)
## Given
@ -243,7 +214,7 @@ procSuite "Waku Store Client":
await allFutures(serverSwitch.start(), clientSwitch.start())
let
server = newTestWakuStore(serverSwitch, store=testStore)
server = await newTestWakuStore(serverSwitch, store=testStore)
client = newTestWakuStoreClient(clientSwitch)
## Given

View File

@ -1,12 +1,10 @@
{.used.}
import
std/[options, tables, sets, times],
stew/byteutils,
std/[options, tables, sets],
testutils/unittests,
chronos,
chronicles,
libp2p/switch,
libp2p/crypto/crypto
import
../../waku/v2/protocol/waku_message,
@ -14,54 +12,24 @@ import
../../waku/v2/node/storage/sqlite,
../../waku/v2/node/storage/message/sqlite_store,
../../waku/v2/node/peer_manager/peer_manager,
../../waku/v2/utils/time,
../test_helpers
./testlib/common,
./testlib/switch
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
proc now(): Timestamp =
getNanosecondTime(getTime().toUnixFloat())
proc ts(offset=0, origin=now()): Timestamp =
origin + getNanosecondTime(offset)
proc newTestDatabase(): SqliteDatabase =
SqliteDatabase.init("", inMemory = true).tryGet()
proc fakeWakuMessage(
payload = toBytes("TEST-PAYLOAD"),
contentTopic = DefaultContentTopic,
ts = now(),
ephemeral = false,
): WakuMessage =
WakuMessage(
payload: payload,
contentTopic: contentTopic,
version: 1,
timestamp: ts,
ephemeral: ephemeral,
)
proc newTestSwitch(key=none(PrivateKey), address=none(MultiAddress)): Switch =
let peerKey = key.get(PrivateKey.random(ECDSA, rng[]).get())
let peerAddr = address.get(MultiAddress.init("/ip4/127.0.0.1/tcp/0").get())
return newStandardSwitch(some(peerKey), addrs=peerAddr)
proc newTestMessageStore(): MessageStore =
let database = newTestDatabase()
SqliteStore.init(database).tryGet()
proc newTestWakuStore(switch: Switch, store=newTestMessageStore()): WakuStore =
proc newTestWakuStore(switch: Switch, store=newTestMessageStore()): Future[WakuStore] {.async.} =
let
peerManager = PeerManager.new(switch)
rng = crypto.newRng()
proto = WakuStore.init(peerManager, rng, store)
waitFor proto.start()
await proto.start()
switch.mount(proto)
return proto
@ -71,7 +39,6 @@ procSuite "Waku Store - resume store":
## Fixtures
let storeA = block:
let store = newTestMessageStore()
let msgList = @[
fakeWakuMessage(payload= @[byte 0], contentTopic=ContentTopic("2"), ts=ts(0)),
fakeWakuMessage(payload= @[byte 1], contentTopic=ContentTopic("1"), ts=ts(1)),
@ -118,8 +85,8 @@ procSuite "Waku Store - resume store":
await allFutures(serverSwitch.start(), clientSwitch.start())
let
_ = newTestWakuStore(serverSwitch, store=storeA)
client = newTestWakuStore(clientSwitch)
server = await newTestWakuStore(serverSwitch, store=storeA)
client = await newTestWakuStore(clientSwitch)
client.setPeer(serverSwitch.peerInfo.toRemotePeerInfo())
@ -146,7 +113,7 @@ procSuite "Waku Store - resume store":
await clientSwitch.start()
let client = newTestWakuStore(clientSwitch)
let client = await newTestWakuStore(clientSwitch)
## Given
let peers = @[offlineSwitch.peerInfo.toRemotePeerInfo()]
@ -171,9 +138,9 @@ procSuite "Waku Store - resume store":
await allFutures(serverASwitch.start(), serverBSwitch.start(), clientSwitch.start())
let
serverA = newTestWakuStore(serverASwitch, store=storeA)
serverB = newTestWakuStore(serverBSwitch, store=storeB)
client = newTestWakuStore(clientSwitch)
serverA = await newTestWakuStore(serverASwitch, store=storeA)
serverB = await newTestWakuStore(serverBSwitch, store=storeB)
client = await newTestWakuStore(clientSwitch)
## Given
let peers = @[

View File

@ -9,24 +9,8 @@ import
import
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_store,
../../waku/v2/utils/time
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
proc fakeWakuMessage(
payload = "TEST-PAYLOAD",
contentTopic = DefaultContentTopic,
ts = getNanosecondTime(epochTime())
): WakuMessage =
WakuMessage(
payload: toBytes(payload),
contentTopic: contentTopic,
version: 1,
timestamp: ts
)
../../waku/v2/utils/time,
./testlib/common
procSuite "Waku Store - RPC codec":

View File

@ -22,28 +22,8 @@ import
../../waku/v2/utils/peers,
../../waku/v2/utils/time,
../test_helpers,
./utils
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
proc now(): Timestamp =
getNanosecondTime(getTime().toUnixFloat())
proc fakeWakuMessage(
payload = "TEST-PAYLOAD",
contentTopic = DefaultContentTopic,
ts = now()
): WakuMessage =
WakuMessage(
payload: toBytes(payload),
contentTopic: contentTopic,
version: 1,
timestamp: ts
)
./utils,
./testlib/common
procSuite "Waku SWAP Accounting":

View File

@ -7,35 +7,14 @@ import
chronicles,
chronos,
libp2p/crypto/crypto,
libp2p/switch,
libp2p/switch
import
../../waku/v2/protocol/waku_message,
../../waku/v2/protocol/waku_lightpush,
../../waku/v2/node/peer_manager/peer_manager,
../../waku/v2/utils/peers,
../../waku/v2/utils/time,
../../waku/v2/node/waku_node
from std/times import getTime, toUnixFloat
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
proc now(): Timestamp =
getNanosecondTime(getTime().toUnixFloat())
proc fakeWakuMessage(
payload = "TEST-PAYLOAD",
contentTopic = DefaultContentTopic,
ts = now()
): WakuMessage =
WakuMessage(
payload: toBytes(payload),
contentTopic: contentTopic,
version: 1,
timestamp: ts
)
../../waku/v2/node/waku_node,
./testlib/common
procSuite "WakuNode - Lightpush":

View File

@ -16,7 +16,7 @@ import
libp2p/protocols/pubsub/pubsub,
libp2p/protocols/pubsub/gossipsub
import
../../waku/v2/protocol/[waku_relay, waku_message],
../../waku/v2/protocol/waku_message,
../../waku/v2/node/peer_manager/peer_manager,
../../waku/v2/utils/peers,
../../waku/v2/node/waku_node

View File

@ -23,34 +23,14 @@ import
../../waku/v2/node/peer_manager/peer_manager,
../../waku/v2/utils/peers,
../../waku/v2/utils/time,
../../waku/v2/node/waku_node
../../waku/v2/node/waku_node,
./testlib/common
from std/times import getTime, toUnixFloat
const
DefaultPubsubTopic = "/waku/2/default-waku/proto"
DefaultContentTopic = ContentTopic("/waku/2/default-content/proto")
proc now(): Timestamp =
getNanosecondTime(getTime().toUnixFloat())
proc newTestMessageStore(): MessageStore =
let database = SqliteDatabase.init("", inMemory = true)[]
SqliteStore.init(database).tryGet()
proc fakeWakuMessage(
payload = "TEST-PAYLOAD",
contentTopic = DefaultContentTopic,
ts = now()
): WakuMessage =
WakuMessage(
payload: toBytes(payload),
contentTopic: contentTopic,
version: 1,
timestamp: ts
)
procSuite "WakuNode - Store":
let rng = crypto.newRng()
@ -199,7 +179,7 @@ procSuite "WakuNode - Store":
# Insert the same message in both node's store
let
receivedTime3 = getNanosecondTime(getTime().toUnixFloat() + 10.float)
receivedTime3 = now() + getNanosecondTime(10)
digest3 = computeDigest(msg3)
require server.wakuStore.store.put(DefaultTopic, msg3, digest3, receivedTime3).isOk()
require client.wakuStore.store.put(DefaultTopic, msg3, digest3, receivedTime3).isOk()

View File

@ -0,0 +1,38 @@
import
std/times
import
../../../waku/v2/protocol/waku_message,
../../../waku/v2/utils/time
const
DefaultPubsubTopic* = "/waku/2/default-waku/proto"
DefaultContentTopic* = ContentTopic("/waku/2/default-content/proto")
proc now*(): Timestamp =
getNanosecondTime(getTime().toUnixFloat())
proc ts*(offset=0, origin=now()): Timestamp =
origin + getNanosecondTime(offset)
proc fakeWakuMessage*(
payload: string|seq[byte] = "TEST-PAYLOAD",
contentTopic = DefaultContentTopic,
ts = now(),
ephemeral = false
): WakuMessage =
var payloadBytes: seq[byte]
when payload is string:
payloadBytes = toBytes(payload)
else:
payloadBytes = payload
WakuMessage(
payload: payloadBytes,
contentTopic: contentTopic,
version: 2,
timestamp: ts,
ephemeral: ephemeral
)

View File

@ -0,0 +1,11 @@
import
std/options,
libp2p/switch,
libp2p/builders
import
../../test_helpers
proc newTestSwitch*(key=none(PrivateKey), address=none(MultiAddress)): Switch =
let peerKey = key.get(PrivateKey.random(ECDSA, rng[]).get())
let peerAddr = address.get(MultiAddress.init("/ip4/127.0.0.1/tcp/0").get())
return newStandardSwitch(some(peerKey), addrs=peerAddr)