mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-27 06:20:54 +00:00
feat(testlib): added global tests rng and waku2 sub-module
This commit is contained in:
parent
a7f0a7f704
commit
6782398989
@ -43,6 +43,3 @@ proc getRng(): ref rand.HmacDrbgContext =
|
||||
|
||||
template rng*(): ref rand.HmacDrbgContext =
|
||||
getRng()
|
||||
|
||||
proc generateKey*(): crypto.PrivateKey =
|
||||
return crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
|
@ -1,16 +1,17 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/[options,sequtils],
|
||||
std/[options, sequtils],
|
||||
chronos,
|
||||
stew/byteutils,
|
||||
testutils/unittests,
|
||||
testutils/unittests
|
||||
import
|
||||
../../waku/v2/utils/wakuenr,
|
||||
../test_helpers
|
||||
./testlib/waku2
|
||||
|
||||
procSuite "ENR utils":
|
||||
|
||||
asyncTest "Parse multiaddr field":
|
||||
test "Parse multiaddr field":
|
||||
let
|
||||
reasonable = "0x000A047F0000010601BADD03".hexToSeqByte()
|
||||
reasonableDns4 = ("0x002F36286E6F64652D30312E646F2D616D73332E77616B7576322E746" &
|
||||
@ -39,12 +40,12 @@ procSuite "ENR utils":
|
||||
# Empty
|
||||
empty.toMultiAddresses().len() == 0
|
||||
|
||||
asyncTest "Init ENR for Waku Usage":
|
||||
test "Init ENR for Waku Usage":
|
||||
# Tests RFC31 encoding "happy path"
|
||||
let
|
||||
enrIp = ValidIpAddress.init("127.0.0.1")
|
||||
enrTcpPort, enrUdpPort = Port(61101)
|
||||
enrKey = wakuenr.crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
enrKey = generateSecp256k1Key()
|
||||
wakuFlags = initWakuFlags(false, true, false, true)
|
||||
multiaddrs = @[MultiAddress.init("/ip4/127.0.0.1/tcp/442/ws")[],
|
||||
MultiAddress.init("/ip4/127.0.0.1/tcp/443/wss")[]]
|
||||
@ -72,12 +73,12 @@ procSuite "ENR utils":
|
||||
decodedAddrs.contains(MultiAddress.init("/ip4/127.0.0.1/tcp/442/ws")[])
|
||||
decodedAddrs.contains(MultiAddress.init("/ip4/127.0.0.1/tcp/443/wss")[])
|
||||
|
||||
asyncTest "Strip multiaddr peerId":
|
||||
test "Strip multiaddr peerId":
|
||||
# Tests that peerId is stripped of multiaddrs as per RFC31
|
||||
let
|
||||
enrIp = ValidIpAddress.init("127.0.0.1")
|
||||
enrTcpPort, enrUdpPort = Port(61102)
|
||||
enrKey = wakuenr.crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
enrKey = generateSecp256k1Key()
|
||||
multiaddrs = @[MultiAddress.init("/ip4/127.0.0.1/tcp/443/wss/p2p/16Uiu2HAm4v86W3bmT1BiH6oSPzcsSr31iDQpSN5Qa882BCjjwgrD")[]]
|
||||
|
||||
let
|
||||
@ -92,7 +93,7 @@ procSuite "ENR utils":
|
||||
|
||||
check decodedAddrs.contains(MultiAddress.init("/ip4/127.0.0.1/tcp/443/wss")[]) # Peer Id has been stripped
|
||||
|
||||
asyncTest "Decode ENR with multiaddrs field":
|
||||
test "Decode ENR with multiaddrs field":
|
||||
let
|
||||
# Known values correspond to shared test vectors with other Waku implementations
|
||||
knownIp = ValidIpAddress.init("18.223.219.100")
|
||||
@ -126,11 +127,11 @@ procSuite "ENR utils":
|
||||
for knownMultiaddr in knownMultiaddrs:
|
||||
check decodedAddrs.contains(knownMultiaddr)
|
||||
|
||||
asyncTest "Supports specific capabilities encoded in the ENR":
|
||||
test "Supports specific capabilities encoded in the ENR":
|
||||
let
|
||||
enrIp = ValidIpAddress.init("127.0.0.1")
|
||||
enrTcpPort, enrUdpPort = Port(60000)
|
||||
enrKey = wakuenr.crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
enrKey = generateSecp256k1Key()
|
||||
multiaddrs = @[MultiAddress.init("/ip4/127.0.0.1/tcp/442/ws")[]]
|
||||
|
||||
# TODO: Refactor enr.Record.init, provide enums as inputs enr.Record.init(capabilites=[Store,Filter])
|
||||
@ -166,11 +167,11 @@ procSuite "ENR utils":
|
||||
for j, capability in @[Lightpush, Filter, Store, Relay]:
|
||||
check expectedCapabilities[i][j] == record.supportsCapability(capability)
|
||||
|
||||
asyncTest "Get all supported capabilities encoded in the ENR":
|
||||
test "Get all supported capabilities encoded in the ENR":
|
||||
let
|
||||
enrIp = ValidIpAddress.init("127.0.0.1")
|
||||
enrTcpPort, enrUdpPort = Port(60000)
|
||||
enrKey = wakuenr.crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
enrKey = generateSecp256k1Key()
|
||||
multiaddrs = @[MultiAddress.init("/ip4/127.0.0.1/tcp/442/ws")[]]
|
||||
|
||||
records = @[0b0000_0000'u8,
|
||||
@ -196,7 +197,7 @@ procSuite "ENR utils":
|
||||
for i, actualExpetedTuple in zip(records, expectedCapabilities):
|
||||
check actualExpetedTuple[0].getCapabilities() == actualExpetedTuple[1]
|
||||
|
||||
asyncTest "Get supported capabilities of a non waku node":
|
||||
test "Get supported capabilities of a non waku node":
|
||||
|
||||
# non waku enr, i.e. Ethereum one
|
||||
let nonWakuEnr = "enr:-KG4QOtcP9X1FbIMOe17QNMKqDxCpm14jcX5tiOE4_TyMrFqbmhPZHK_ZPG2G"&
|
||||
|
@ -7,13 +7,14 @@ import
|
||||
import
|
||||
../../waku/v2/protocol/waku_message,
|
||||
../../waku/v2/node/message_cache,
|
||||
./testlib/common
|
||||
./testlib/common,
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
type TestMessageCache = MessageCache[(PubsubTopic, ContentTopic)]
|
||||
|
||||
suite "MessageCache":
|
||||
test "subscribe to topic":
|
||||
test "subscribe to topic":
|
||||
## Given
|
||||
let testTopic = (PubsubTopic("test-pubsub-topic"), ContentTopic("test-content-topic"))
|
||||
let cache = TestMessageCache.init()
|
||||
@ -26,7 +27,7 @@ suite "MessageCache":
|
||||
cache.isSubscribed(testTopic)
|
||||
|
||||
|
||||
test "unsubscribe from topic":
|
||||
test "unsubscribe from topic":
|
||||
## Given
|
||||
let testTopic = (PubsubTopic("test-pubsub-topic"), ContentTopic("test-content-topic"))
|
||||
let cache = TestMessageCache.init()
|
||||
@ -40,13 +41,13 @@ suite "MessageCache":
|
||||
## Then
|
||||
check:
|
||||
not cache.isSubscribed(testTopic)
|
||||
|
||||
|
||||
|
||||
test "get messages of a subscribed topic":
|
||||
## Given
|
||||
let testTopic = (PubsubTopic("test-pubsub-topic"), ContentTopic("test-content-topic"))
|
||||
let testMessage = fakeWakuMessage()
|
||||
let cache = TestMessageCache.init()
|
||||
let cache = TestMessageCache.init()
|
||||
|
||||
# Init cache content
|
||||
cache.subscribe(testTopic)
|
||||
@ -65,7 +66,7 @@ suite "MessageCache":
|
||||
## Given
|
||||
let testTopic = (PubsubTopic("test-pubsub-topic"), ContentTopic("test-content-topic"))
|
||||
let testMessage = fakeWakuMessage()
|
||||
let cache = TestMessageCache.init()
|
||||
let cache = TestMessageCache.init()
|
||||
|
||||
# Init cache content
|
||||
cache.subscribe(testTopic)
|
||||
@ -81,7 +82,7 @@ suite "MessageCache":
|
||||
check:
|
||||
res.isOk()
|
||||
res.get().len == 0
|
||||
|
||||
|
||||
|
||||
test "get messages of a non-subscribed topic":
|
||||
## Given
|
||||
@ -105,7 +106,7 @@ suite "MessageCache":
|
||||
|
||||
cache.subscribe(testTopic)
|
||||
|
||||
## When
|
||||
## When
|
||||
cache.addMessage(testTopic, testMessage)
|
||||
|
||||
## Then
|
||||
@ -120,7 +121,7 @@ suite "MessageCache":
|
||||
let testMessage = fakeWakuMessage()
|
||||
let cache = TestMessageCache.init()
|
||||
|
||||
## When
|
||||
## When
|
||||
cache.addMessage(testTopic, testMessage)
|
||||
|
||||
## Then
|
||||
@ -129,7 +130,7 @@ suite "MessageCache":
|
||||
res.isErr()
|
||||
res.error() == "Not subscribed to topic"
|
||||
|
||||
|
||||
|
||||
test "add messages beyond the capacity":
|
||||
## Given
|
||||
let testTopic = (PubsubTopic("test-pubsub-topic"), ContentTopic("test-content-topic"))
|
||||
@ -142,11 +143,11 @@ suite "MessageCache":
|
||||
let cache = TestMessageCache.init(capacity = 2)
|
||||
cache.subscribe(testTopic)
|
||||
|
||||
## When
|
||||
## When
|
||||
for msg in testMessages:
|
||||
cache.addMessage(testTopic, msg)
|
||||
|
||||
## Then
|
||||
let messages = cache.getMessages(testTopic).tryGet()
|
||||
let messages = cache.getMessages(testTopic).tryGet()
|
||||
check:
|
||||
messages == testMessages[1..2]
|
||||
|
@ -12,8 +12,7 @@ import
|
||||
import
|
||||
../../waku/v2/node/waku_node,
|
||||
../../waku/v2/utils/peers,
|
||||
../test_helpers,
|
||||
./testlib/common
|
||||
./testlib/waku2
|
||||
|
||||
procSuite "Peer Exchange":
|
||||
asyncTest "GossipSub (relay) peer exchange":
|
||||
@ -22,11 +21,11 @@ procSuite "Peer Exchange":
|
||||
# Create nodes and ENR. These will be added to the discoverable list
|
||||
let
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, bindIp, Port(61100))
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, bindIp, Port(61102), sendSignedPeerRecord = true)
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
node3 = WakuNode.new(nodeKey3, bindIp, Port(61103), sendSignedPeerRecord = true)
|
||||
|
||||
var
|
||||
|
@ -28,13 +28,14 @@ import
|
||||
../../waku/v2/protocol/waku_lightpush,
|
||||
../../waku/v2/protocol/waku_peer_exchange,
|
||||
../../waku/v2/protocol/waku_swap/waku_swap,
|
||||
../test_helpers,
|
||||
./testlib/testutils
|
||||
./testlib/common,
|
||||
./testlib/testutils,
|
||||
./testlib/waku2
|
||||
|
||||
procSuite "Peer Manager":
|
||||
asyncTest "Peer dialing works":
|
||||
# Create 2 nodes
|
||||
let nodes = toSeq(0..<2).mapIt(WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
let nodes = toSeq(0..<2).mapIt(WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
|
||||
await allFutures(nodes.mapIt(it.start()))
|
||||
await allFutures(nodes.mapIt(it.mountRelay()))
|
||||
@ -59,7 +60,7 @@ procSuite "Peer Manager":
|
||||
|
||||
asyncTest "Dialing fails gracefully":
|
||||
# Create 2 nodes
|
||||
let nodes = toSeq(0..<2).mapIt(WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
let nodes = toSeq(0..<2).mapIt(WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
|
||||
await nodes[0].start()
|
||||
await nodes[0].mountRelay()
|
||||
@ -77,19 +78,17 @@ procSuite "Peer Manager":
|
||||
|
||||
asyncTest "Adding, selecting and filtering peers work":
|
||||
let
|
||||
node = WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
|
||||
# Create filter peer
|
||||
filterLoc = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet()
|
||||
filterKey = crypto.PrivateKey.random(ECDSA, rng[]).get()
|
||||
filterPeer = PeerInfo.new(filterKey, @[filterLoc])
|
||||
filterPeer = PeerInfo.new(generateEcdsaKey(), @[filterLoc])
|
||||
# Create swap peer
|
||||
swapLoc = MultiAddress.init("/ip4/127.0.0.2/tcp/2").tryGet()
|
||||
swapKey = crypto.PrivateKey.random(ECDSA, rng[]).get()
|
||||
swapPeer = PeerInfo.new(swapKey, @[swapLoc])
|
||||
swapPeer = PeerInfo.new(generateEcdsaKey(), @[swapLoc])
|
||||
# Create store peer
|
||||
storeLoc = MultiAddress.init("/ip4/127.0.0.3/tcp/4").tryGet()
|
||||
storeKey = crypto.PrivateKey.random(ECDSA, rng[]).get()
|
||||
storePeer = PeerInfo.new(storeKey, @[storeLoc])
|
||||
storePeer = PeerInfo.new(generateEcdsaKey(), @[storeLoc])
|
||||
|
||||
await node.start()
|
||||
|
||||
@ -120,7 +119,7 @@ procSuite "Peer Manager":
|
||||
|
||||
asyncTest "Peer manager keeps track of connections":
|
||||
# Create 2 nodes
|
||||
let nodes = toSeq(0..<2).mapIt(WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
let nodes = toSeq(0..<2).mapIt(WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
|
||||
await nodes[0].start()
|
||||
# Do not start node2
|
||||
@ -157,7 +156,7 @@ procSuite "Peer Manager":
|
||||
|
||||
asyncTest "Peer manager updates failed peers correctly":
|
||||
# Create 2 nodes
|
||||
let nodes = toSeq(0..<2).mapIt(WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
let nodes = toSeq(0..<2).mapIt(WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
|
||||
await nodes[0].start()
|
||||
await nodes[0].mountRelay()
|
||||
@ -209,10 +208,8 @@ procSuite "Peer Manager":
|
||||
let
|
||||
database = SqliteDatabase.new(":memory:")[]
|
||||
storage = WakuPeerStorage.new(database)[]
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(0), peerStorage = storage)
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node1 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0), peerStorage = storage)
|
||||
node2 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
peerInfo2 = node2.switch.peerInfo
|
||||
|
||||
await node1.start()
|
||||
@ -230,8 +227,7 @@ procSuite "Peer Manager":
|
||||
|
||||
# Simulate restart by initialising a new node using the same storage
|
||||
let
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node3 = WakuNode.new(nodeKey3, ValidIpAddress.init("0.0.0.0"), Port(0), peerStorage = storage)
|
||||
node3 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0), peerStorage = storage)
|
||||
|
||||
await node3.start()
|
||||
check:
|
||||
@ -255,10 +251,8 @@ procSuite "Peer Manager":
|
||||
let
|
||||
database = SqliteDatabase.new(":memory:")[]
|
||||
storage = WakuPeerStorage.new(database)[]
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(0), peerStorage = storage)
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node1 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0), peerStorage = storage)
|
||||
node2 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
peerInfo2 = node2.switch.peerInfo
|
||||
betaCodec = "/vac/waku/relay/2.0.0-beta2"
|
||||
stableCodec = "/vac/waku/relay/2.0.0"
|
||||
@ -281,8 +275,7 @@ procSuite "Peer Manager":
|
||||
|
||||
# Simulate restart by initialising a new node using the same storage
|
||||
let
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node3 = WakuNode.new(nodeKey3, ValidIpAddress.init("0.0.0.0"), Port(0), peerStorage = storage)
|
||||
node3 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0), peerStorage = storage)
|
||||
|
||||
await node3.mountRelay()
|
||||
node3.wakuRelay.codec = stableCodec
|
||||
@ -310,7 +303,7 @@ procSuite "Peer Manager":
|
||||
|
||||
asyncTest "Peer manager connects to all peers supporting a given protocol":
|
||||
# Create 4 nodes
|
||||
let nodes = toSeq(0..<4).mapIt(WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
let nodes = toSeq(0..<4).mapIt(WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
|
||||
# Start them
|
||||
await allFutures(nodes.mapIt(it.start()))
|
||||
@ -350,7 +343,7 @@ procSuite "Peer Manager":
|
||||
|
||||
asyncTest "Peer store keeps track of incoming connections":
|
||||
# Create 4 nodes
|
||||
let nodes = toSeq(0..<4).mapIt(WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
let nodes = toSeq(0..<4).mapIt(WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
|
||||
# Start them
|
||||
await allFutures(nodes.mapIt(it.start()))
|
||||
@ -410,8 +403,7 @@ procSuite "Peer Manager":
|
||||
let basePeerId = "16Uiu2HAm7QGEZKujdSbbo1aaQyfDPQ6Bw3ybQnj6fruH5Dxwd7D"
|
||||
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node = WakuNode.new(nodeKey, ValidIpAddress.init("0.0.0.0"), Port(60932))
|
||||
node = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(60932))
|
||||
peer1 = parseRemotePeerInfo("/ip4/0.0.0.0/tcp/30300/p2p/" & basePeerId & "1")
|
||||
peer2 = parseRemotePeerInfo("/ip4/0.0.0.0/tcp/30301/p2p/" & basePeerId & "2")
|
||||
peer3 = parseRemotePeerInfo("/ip4/0.0.0.0/tcp/30302/p2p/" & basePeerId & "3")
|
||||
|
@ -7,31 +7,31 @@ import
|
||||
../../waku/common/sqlite,
|
||||
../../waku/v2/node/peer_manager/peer_manager,
|
||||
../../waku/v2/node/peer_manager/peer_store/waku_peer_storage,
|
||||
../test_helpers
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
suite "Peer Storage":
|
||||
|
||||
test "Store, replace and retrieve from persistent peer storage":
|
||||
let
|
||||
let
|
||||
database = SqliteDatabase.new(":memory:").tryGet()
|
||||
storage = WakuPeerStorage.new(database)[]
|
||||
|
||||
# Test Peer
|
||||
peerLoc = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet()
|
||||
peerKey = crypto.PrivateKey.random(ECDSA, rng[]).get()
|
||||
peerKey = generateEcdsaKey()
|
||||
peer = PeerInfo.new(peerKey, @[peerLoc])
|
||||
peerProto = "/waku/2/default-waku/codec"
|
||||
stored = StoredInfo(peerId: peer.peerId, addrs: @[peerLoc], protos: @[peerProto], publicKey: peerKey.getPublicKey().tryGet())
|
||||
conn = Connectedness.CanConnect
|
||||
disconn = 999999
|
||||
|
||||
|
||||
defer: storage.close()
|
||||
|
||||
|
||||
# Test insert and retrieve
|
||||
|
||||
discard storage.put(peer.peerId, stored, conn, disconn)
|
||||
|
||||
|
||||
var responseCount = 0
|
||||
# flags to check data matches what was stored (default true)
|
||||
var peerIdFlag, storedInfoFlag, connectednessFlag, disconnectFlag: bool
|
||||
@ -39,7 +39,7 @@ suite "Peer Storage":
|
||||
proc data(peerId: PeerID, storedInfo: StoredInfo,
|
||||
connectedness: Connectedness, disconnectTime: int64) {.raises: [Defect].} =
|
||||
responseCount += 1
|
||||
|
||||
|
||||
# Note: cannot use `check` within `{.raises: [Defect].}` block
|
||||
# @TODO: /Nim/lib/pure/unittest.nim(577, 16) Error: can raise an unlisted exception: Exception
|
||||
# These flags are checked outside this block.
|
||||
@ -47,9 +47,9 @@ suite "Peer Storage":
|
||||
storedInfoFlag = storedInfo == stored
|
||||
connectednessFlag = connectedness == conn
|
||||
disconnectFlag = disconnectTime == disconn
|
||||
|
||||
|
||||
let res = storage.getAll(data)
|
||||
|
||||
|
||||
check:
|
||||
res.isErr == false
|
||||
responseCount == 1
|
||||
@ -57,15 +57,15 @@ suite "Peer Storage":
|
||||
storedInfoFlag
|
||||
connectednessFlag
|
||||
disconnectFlag
|
||||
|
||||
|
||||
# Test replace and retrieve (update an existing entry)
|
||||
discard storage.put(peer.peerId, stored, Connectedness.CannotConnect, disconn + 10)
|
||||
|
||||
|
||||
responseCount = 0
|
||||
proc replacedData(peerId: PeerID, storedInfo: StoredInfo,
|
||||
connectedness: Connectedness, disconnectTime: int64) {.raises: [Defect].} =
|
||||
responseCount += 1
|
||||
|
||||
|
||||
# Note: cannot use `check` within `{.raises: [Defect].}` block
|
||||
# @TODO: /Nim/lib/pure/unittest.nim(577, 16) Error: can raise an unlisted exception: Exception
|
||||
# These flags are checked outside this block.
|
||||
@ -75,7 +75,7 @@ suite "Peer Storage":
|
||||
disconnectFlag = disconnectTime == disconn + 10
|
||||
|
||||
let repRes = storage.getAll(replacedData)
|
||||
|
||||
|
||||
check:
|
||||
repRes.isErr == false
|
||||
responseCount == 1
|
||||
|
@ -1,7 +1,7 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/[options,sequtils, times],
|
||||
std/[sequtils, times],
|
||||
chronos,
|
||||
libp2p/crypto/crypto,
|
||||
libp2p/peerid,
|
||||
@ -12,7 +12,7 @@ import
|
||||
../../waku/v2/node/peer_manager/peer_manager,
|
||||
../../waku/v2/node/peer_manager/waku_peer_store,
|
||||
../../waku/v2/node/waku_node,
|
||||
../test_helpers
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
suite "Extended nim-libp2p Peer Store":
|
||||
@ -39,7 +39,7 @@ suite "Extended nim-libp2p Peer Store":
|
||||
# Peer1: Connected
|
||||
peerStore[AddressBook][p1] = @[MultiAddress.init("/ip4/127.0.0.1/tcp/1").tryGet()]
|
||||
peerStore[ProtoBook][p1] = @["/vac/waku/relay/2.0.0-beta1", "/vac/waku/store/2.0.0"]
|
||||
peerStore[KeyBook][p1] = KeyPair.random(ECDSA, rng[]).tryGet().pubkey
|
||||
peerStore[KeyBook][p1] = generateEcdsaKeyPair().pubkey
|
||||
peerStore[AgentBook][p1] = "nwaku"
|
||||
peerStore[ProtoVersionBook][p1] = "protoVersion1"
|
||||
peerStore[ConnectionBook][p1] = Connected
|
||||
@ -52,7 +52,7 @@ suite "Extended nim-libp2p Peer Store":
|
||||
# Peer2: Connected
|
||||
peerStore[AddressBook][p2] = @[MultiAddress.init("/ip4/127.0.0.1/tcp/2").tryGet()]
|
||||
peerStore[ProtoBook][p2] = @["/vac/waku/relay/2.0.0", "/vac/waku/store/2.0.0"]
|
||||
peerStore[KeyBook][p2] = KeyPair.random(ECDSA, rng[]).tryGet().pubkey
|
||||
peerStore[KeyBook][p2] = generateEcdsaKeyPair().pubkey
|
||||
peerStore[AgentBook][p2] = "nwaku"
|
||||
peerStore[ProtoVersionBook][p2] = "protoVersion2"
|
||||
peerStore[ConnectionBook][p2] = Connected
|
||||
@ -65,7 +65,7 @@ suite "Extended nim-libp2p Peer Store":
|
||||
# Peer3: Connected
|
||||
peerStore[AddressBook][p3] = @[MultiAddress.init("/ip4/127.0.0.1/tcp/3").tryGet()]
|
||||
peerStore[ProtoBook][p3] = @["/vac/waku/lightpush/2.0.0", "/vac/waku/store/2.0.0-beta1"]
|
||||
peerStore[KeyBook][p3] = KeyPair.random(ECDSA, rng[]).tryGet().pubkey
|
||||
peerStore[KeyBook][p3] = generateEcdsaKeyPair().pubkey
|
||||
peerStore[AgentBook][p3] = "gowaku"
|
||||
peerStore[ProtoVersionBook][p3] = "protoVersion3"
|
||||
peerStore[ConnectionBook][p3] = Connected
|
||||
@ -78,7 +78,7 @@ suite "Extended nim-libp2p Peer Store":
|
||||
# Peer4: Added but never connected
|
||||
peerStore[AddressBook][p4] = @[MultiAddress.init("/ip4/127.0.0.1/tcp/4").tryGet()]
|
||||
# unknown: peerStore[ProtoBook][p4]
|
||||
peerStore[KeyBook][p4] = KeyPair.random(ECDSA, rng[]).tryGet().pubkey
|
||||
peerStore[KeyBook][p4] = generateEcdsaKeyPair().pubkey
|
||||
# unknown: peerStore[AgentBook][p4]
|
||||
# unknown: peerStore[ProtoVersionBook][p4]
|
||||
peerStore[ConnectionBook][p4] = NotConnected
|
||||
@ -91,7 +91,7 @@ suite "Extended nim-libp2p Peer Store":
|
||||
# Peer5: Connecteed in the past
|
||||
peerStore[AddressBook][p5] = @[MultiAddress.init("/ip4/127.0.0.1/tcp/5").tryGet()]
|
||||
peerStore[ProtoBook][p5] = @["/vac/waku/swap/2.0.0", "/vac/waku/store/2.0.0-beta2"]
|
||||
peerStore[KeyBook][p5] = KeyPair.random(ECDSA, rng[]).tryGet().pubkey
|
||||
peerStore[KeyBook][p5] = generateEcdsaKeyPair().pubkey
|
||||
peerStore[AgentBook][p5] = "gowaku"
|
||||
peerStore[ProtoVersionBook][p5] = "protoVersion5"
|
||||
peerStore[ConnectionBook][p5] = CanConnect
|
||||
@ -295,7 +295,7 @@ suite "Extended nim-libp2p Peer Store":
|
||||
require p1.init("QmeuZJbXrszW2jdT7GdduSjQskPU3S7vvGWKtKgDfkDvW" & "1")
|
||||
peerStore[AddressBook][p1] = @[MultiAddress.init("/ip4/127.0.0.1/tcp/1").tryGet()]
|
||||
peerStore[ProtoBook][p1] = @["proto"]
|
||||
peerStore[KeyBook][p1] = KeyPair.random(ECDSA, rng[]).tryGet().pubkey
|
||||
peerStore[KeyBook][p1] = generateEcdsaKeyPair().pubkey
|
||||
peerStore[AgentBook][p1] = "agent"
|
||||
peerStore[ProtoVersionBook][p1] = "version"
|
||||
peerStore[LastFailedConnBook][p1] = Moment.init(getTime().toUnix, Second)
|
||||
|
@ -10,13 +10,13 @@ import
|
||||
import
|
||||
../../waku/v2/node/waku_node,
|
||||
../../waku/v2/node/rest/[server, client, utils],
|
||||
../../waku/v2/node/rest/debug/debug_api
|
||||
../../waku/v2/node/rest/debug/debug_api,
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
proc testWakuNode(): WakuNode =
|
||||
let
|
||||
rng = crypto.newRng()
|
||||
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
||||
proc testWakuNode(): WakuNode =
|
||||
let
|
||||
privkey = generateSecp256k1Key()
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
extIp = ValidIpAddress.init("127.0.0.1")
|
||||
port = Port(9000)
|
||||
@ -25,7 +25,7 @@ proc testWakuNode(): WakuNode =
|
||||
|
||||
|
||||
suite "REST API - Debug":
|
||||
asyncTest "Get node info - GET /debug/v1/info":
|
||||
asyncTest "Get node info - GET /debug/v1/info":
|
||||
# Given
|
||||
let node = testWakuNode()
|
||||
await node.start()
|
||||
@ -50,4 +50,4 @@ suite "REST API - Debug":
|
||||
|
||||
await restServer.stop()
|
||||
await restServer.closeWait()
|
||||
await node.stop()
|
||||
await node.stop()
|
||||
|
@ -14,13 +14,12 @@ import
|
||||
../../waku/v2/node/rest/relay/[api_types, relay_api, topic_cache],
|
||||
../../waku/v2/protocol/waku_relay,
|
||||
../../waku/v2/utils/time,
|
||||
./testlib/common
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
proc testWakuNode(): WakuNode =
|
||||
let
|
||||
rng = crypto.newRng()
|
||||
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
||||
privkey = generateSecp256k1Key()
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
extIp = ValidIpAddress.init("127.0.0.1")
|
||||
port = Port(9000)
|
||||
|
@ -5,7 +5,7 @@ import
|
||||
chronicles,
|
||||
unittest2,
|
||||
json_serialization
|
||||
import
|
||||
import
|
||||
../../waku/v2/node/rest/serdes,
|
||||
../../waku/v2/node/rest/base64,
|
||||
../../waku/v2/node/rest/relay/api_types,
|
||||
|
@ -4,23 +4,25 @@ else:
|
||||
{.push raises: [].}
|
||||
|
||||
import
|
||||
testutils/unittests,
|
||||
std/[options, osproc, streams, strutils, sequtils],
|
||||
stew/results,
|
||||
options,
|
||||
stew/shims/net as stewNet,
|
||||
testutils/unittests,
|
||||
chronos,
|
||||
chronicles,
|
||||
stint,
|
||||
web3,
|
||||
json,
|
||||
libp2p/crypto/crypto,
|
||||
eth/keys
|
||||
import
|
||||
../../waku/v2/protocol/waku_rln_relay/protocol_types,
|
||||
../../waku/v2/protocol/waku_rln_relay/constants,
|
||||
../../waku/v2/protocol/waku_rln_relay/contract,
|
||||
../../waku/v2/protocol/waku_rln_relay/rln,
|
||||
../../waku/v2/protocol/waku_rln_relay/conversion_utils,
|
||||
../../waku/v2/protocol/waku_rln_relay/group_manager/on_chain/group_manager
|
||||
|
||||
import
|
||||
std/[osproc, streams, strutils, sequtils],
|
||||
chronos, chronicles, stint, web3, json,
|
||||
stew/shims/net as stewNet,
|
||||
libp2p/crypto/crypto,
|
||||
eth/keys,
|
||||
../test_helpers,
|
||||
../../waku/v2/protocol/waku_rln_relay/group_manager/on_chain/group_manager,
|
||||
./testlib/common,
|
||||
./test_utils
|
||||
|
||||
from posix import kill, SIGINT
|
||||
@ -88,14 +90,12 @@ proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
|
||||
|
||||
|
||||
proc createEthAccount(): Future[(keys.PrivateKey, Address)] {.async.} =
|
||||
let theRNG = keys.newRng()
|
||||
|
||||
let web3 = await newWeb3(EthClient)
|
||||
let accounts = await web3.provider.eth_accounts()
|
||||
let gasPrice = int(await web3.provider.eth_gasPrice())
|
||||
web3.defaultAccount = accounts[0]
|
||||
|
||||
let pk = keys.PrivateKey.random(theRNG[])
|
||||
let pk = keys.PrivateKey.random(rng[])
|
||||
let acc = Address(toCanonicalAddress(pk.toPublicKey()))
|
||||
|
||||
var tx:EthSend
|
||||
|
@ -5,10 +5,10 @@ import
|
||||
import
|
||||
../../waku/v2/protocol/waku_message,
|
||||
../../waku/v2/utils/compat,
|
||||
../../waku/v2/utils/time
|
||||
../../waku/v2/utils/time,
|
||||
./testlib/common
|
||||
|
||||
procSuite "Waku Payload":
|
||||
let rng = newRng()
|
||||
suite "Waku Payload":
|
||||
|
||||
test "Encode/Decode without encryption (version 0)":
|
||||
## This would be the usual way when no encryption is done or when it is done
|
||||
|
@ -13,7 +13,8 @@ import
|
||||
../../waku/v2/protocol/waku_message,
|
||||
../../waku/v2/node/discv5/waku_discv5,
|
||||
../../waku/v2/node/waku_node,
|
||||
../test_helpers
|
||||
./testlib/common,
|
||||
./testlib/waku2
|
||||
|
||||
procSuite "Waku Discovery v5":
|
||||
asyncTest "Waku Discovery v5 end-to-end":
|
||||
@ -22,17 +23,17 @@ procSuite "Waku Discovery v5":
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
extIp = ValidIpAddress.init("127.0.0.1")
|
||||
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
nodeTcpPort1 = Port(61500)
|
||||
nodeUdpPort1 = Port(9000)
|
||||
node1 = WakuNode.new(nodeKey1, bindIp, nodeTcpPort1)
|
||||
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
nodeTcpPort2 = Port(61502)
|
||||
nodeUdpPort2 = Port(9002)
|
||||
node2 = WakuNode.new(nodeKey2, bindIp, nodeTcpPort2)
|
||||
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
nodeTcpPort3 = Port(61504)
|
||||
nodeUdpPort3 = Port(9004)
|
||||
node3 = WakuNode.new(nodeKey3, bindIp, nodeTcpPort3)
|
||||
@ -134,7 +135,7 @@ procSuite "Waku Discovery v5":
|
||||
|
||||
nodeTcpPort1 = Port(9010)
|
||||
nodeUdpPort1 = Port(9012)
|
||||
node1Key = generateKey()
|
||||
node1Key = generateSecp256k1Key()
|
||||
node1NetConfig = NetConfig.init(bindIp = bindIp,
|
||||
extIp = some(extIp),
|
||||
extPort = some(nodeTcpPort1),
|
||||
@ -159,7 +160,7 @@ procSuite "Waku Discovery v5":
|
||||
|
||||
nodeTcpPort2 = Port(9014)
|
||||
nodeUdpPort2 = Port(9016)
|
||||
node2Key = generateKey()
|
||||
node2Key = generateSecp256k1Key()
|
||||
node2NetConfig = NetConfig.init(bindIp = bindIp,
|
||||
extIp = some(extIp),
|
||||
extPort = some(nodeTcpPort2),
|
||||
|
@ -14,37 +14,38 @@ import
|
||||
../../waku/v2/node/peer_manager,
|
||||
../../waku/v2/node/dnsdisc/waku_dnsdisc,
|
||||
../../waku/v2/node/waku_node,
|
||||
../test_helpers
|
||||
./testlib/common,
|
||||
./testlib/waku2
|
||||
|
||||
procSuite "Waku DNS Discovery":
|
||||
suite "Waku DNS Discovery":
|
||||
asyncTest "Waku DNS Discovery end-to-end":
|
||||
## Tests integrated DNS discovery, from building
|
||||
## the tree to connecting to discovered nodes
|
||||
|
||||
|
||||
# Create nodes and ENR. These will be added to the discoverable list
|
||||
let
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, bindIp, Port(63500))
|
||||
enr1 = node1.enr
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, bindIp, Port(63502))
|
||||
enr2 = node2.enr
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
node3 = WakuNode.new(nodeKey3, bindIp, Port(63503))
|
||||
enr3 = node3.enr
|
||||
|
||||
|
||||
await node1.mountRelay()
|
||||
await node2.mountRelay()
|
||||
await node3.mountRelay()
|
||||
await allFutures([node1.start(), node2.start(), node3.start()])
|
||||
|
||||
|
||||
# Build and sign tree
|
||||
var tree = buildTree(1, # Seq no
|
||||
@[enr1, enr2, enr3], # ENR entries
|
||||
@[]).get() # No link entries
|
||||
|
||||
let treeKeys = keys.KeyPair.random(keys.newRng()[])
|
||||
let treeKeys = keys.KeyPair.random(rng[])
|
||||
|
||||
# Sign tree
|
||||
check:
|
||||
@ -56,21 +57,21 @@ procSuite "Waku DNS Discovery":
|
||||
zoneTxts = tree.buildTXT(domain).get()
|
||||
username = Base32.encode(treeKeys.pubkey().toRawCompressed())
|
||||
location = LinkPrefix & username & "@" & domain # See EIP-1459: https://eips.ethereum.org/EIPS/eip-1459
|
||||
|
||||
|
||||
# Create a resolver for the domain
|
||||
|
||||
proc resolver(domain: string): Future[string] {.async, gcsafe.} =
|
||||
return zoneTxts[domain]
|
||||
|
||||
|
||||
# Create Waku DNS discovery client on a new Waku v2 node using the resolver
|
||||
|
||||
let
|
||||
nodeKey4 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey4 = generateSecp256k1Key()
|
||||
node4 = WakuNode.new(nodeKey4, bindIp, Port(63504))
|
||||
|
||||
|
||||
await node4.mountRelay()
|
||||
await node4.start()
|
||||
|
||||
|
||||
var wakuDnsDisc = WakuDnsDiscovery.init(location, resolver).get()
|
||||
|
||||
let res = wakuDnsDisc.findPeers()
|
||||
@ -82,7 +83,7 @@ procSuite "Waku DNS Discovery":
|
||||
res[].mapIt(it.peerId).contains(node1.switch.peerInfo.peerId)
|
||||
res[].mapIt(it.peerId).contains(node2.switch.peerInfo.peerId)
|
||||
res[].mapIt(it.peerId).contains(node3.switch.peerInfo.peerId)
|
||||
|
||||
|
||||
# Connect to discovered nodes
|
||||
await node4.connectToNodes(res[])
|
||||
|
||||
|
@ -11,15 +11,13 @@ import
|
||||
../../waku/v2/protocol/waku_message,
|
||||
../../waku/v2/protocol/waku_filter,
|
||||
../../waku/v2/protocol/waku_filter/client,
|
||||
./utils,
|
||||
./testlib/common,
|
||||
./testlib/switch
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
proc newTestWakuFilterNode(switch: Switch, timeout: Duration = 2.hours): Future[WakuFilter] {.async.} =
|
||||
let
|
||||
peerManager = PeerManager.new(switch)
|
||||
rng = crypto.newRng()
|
||||
proto = WakuFilter.new(peerManager, rng, timeout)
|
||||
|
||||
await proto.start()
|
||||
@ -30,7 +28,6 @@ proc newTestWakuFilterNode(switch: Switch, timeout: Duration = 2.hours): Future[
|
||||
proc newTestWakuFilterClient(switch: Switch): Future[WakuFilterClient] {.async.} =
|
||||
let
|
||||
peerManager = PeerManager.new(switch)
|
||||
rng = crypto.newRng()
|
||||
proto = WakuFilterClient.new(peerManager, rng)
|
||||
|
||||
await proto.start()
|
||||
|
@ -3,34 +3,33 @@
|
||||
import
|
||||
std/options,
|
||||
stew/shims/net as stewNet,
|
||||
testutils/unittests,
|
||||
chronos,
|
||||
testutils/unittests,
|
||||
chronos,
|
||||
chronicles,
|
||||
libp2p/switch,
|
||||
libp2p/protobuf/minprotobuf,
|
||||
libp2p/protocols/ping,
|
||||
libp2p/stream/bufferstream,
|
||||
libp2p/stream/bufferstream,
|
||||
libp2p/stream/connection,
|
||||
libp2p/crypto/crypto
|
||||
import
|
||||
../../waku/v2/node/waku_node,
|
||||
../../waku/v2/utils/peers,
|
||||
../test_helpers,
|
||||
./utils
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
procSuite "Waku Keepalive":
|
||||
suite "Waku Keepalive":
|
||||
|
||||
asyncTest "handle ping keepalives":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(63010))
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(63012))
|
||||
|
||||
var completionFut = newFuture[bool]()
|
||||
|
||||
proc pingHandler(peerId: PeerID) {.async, gcsafe, raises: [Defect].} =
|
||||
proc pingHandler(peerId: PeerID) {.async, gcsafe.} =
|
||||
debug "Ping received"
|
||||
|
||||
check:
|
||||
@ -44,7 +43,7 @@ procSuite "Waku Keepalive":
|
||||
|
||||
await node2.start()
|
||||
await node2.mountRelay()
|
||||
|
||||
|
||||
let pingProto = Ping.new(handler = pingHandler)
|
||||
await pingProto.start()
|
||||
node2.switch.mount(pingProto)
|
||||
|
@ -2,19 +2,18 @@
|
||||
|
||||
import
|
||||
std/[algorithm, json, options, os],
|
||||
testutils/unittests, chronos, stint,
|
||||
testutils/unittests, chronos, stint
|
||||
import
|
||||
../../waku/v2/protocol/waku_keystore,
|
||||
../test_helpers
|
||||
./testlib/common
|
||||
|
||||
from ../../waku/v2/protocol/waku_noise/noise_utils import randomSeqByte
|
||||
|
||||
procSuite "Credentials test suite":
|
||||
|
||||
# We initialize the RNG in test_helpers
|
||||
let rng = rng()
|
||||
let testAppInfo = AppInfo(application: "test", appIdentifier: "1234", version: "0.1")
|
||||
|
||||
asyncTest "Create keystore":
|
||||
test "Create keystore":
|
||||
|
||||
let filepath = "./testAppKeystore.txt"
|
||||
defer: removeFile(filepath)
|
||||
@ -25,7 +24,7 @@ procSuite "Credentials test suite":
|
||||
check:
|
||||
keystoreRes.isOk()
|
||||
|
||||
asyncTest "Load keystore":
|
||||
test "Load keystore":
|
||||
|
||||
let filepath = "./testAppKeystore.txt"
|
||||
defer: removeFile(filepath)
|
||||
@ -47,7 +46,7 @@ procSuite "Credentials test suite":
|
||||
# We assume the loaded keystore to not have credentials set (previous tests delete the keystore at filepath)
|
||||
keystore["credentials"].getElems().len() == 0
|
||||
|
||||
asyncTest "Add credentials to keystore":
|
||||
test "Add credentials to keystore":
|
||||
|
||||
let filepath = "./testAppKeystore.txt"
|
||||
defer: removeFile(filepath)
|
||||
@ -83,7 +82,7 @@ procSuite "Credentials test suite":
|
||||
membershipGroups: @[membershipGroup2])
|
||||
|
||||
let password = "%m0um0ucoW%"
|
||||
|
||||
|
||||
let keystoreRes = addMembershipCredentials(path = filepath,
|
||||
credentials = @[membershipCredentials1, membershipCredentials2],
|
||||
password = password,
|
||||
@ -92,7 +91,7 @@ procSuite "Credentials test suite":
|
||||
check:
|
||||
keystoreRes.isOk()
|
||||
|
||||
asyncTest "Add/retrieve credentials in keystore":
|
||||
test "Add/retrieve credentials in keystore":
|
||||
|
||||
let filepath = "./testAppKeystore.txt"
|
||||
defer: removeFile(filepath)
|
||||
@ -104,14 +103,14 @@ procSuite "Credentials test suite":
|
||||
idSecretHash1 = randomSeqByte(rng[], 32)
|
||||
idCommitment1 = randomSeqByte(rng[], 32)
|
||||
idCredential1 = IdentityCredential(idTrapdoor: idTrapdoor1, idNullifier: idNullifier1, idSecretHash: idSecretHash1, idCommitment: idCommitment1)
|
||||
|
||||
|
||||
var
|
||||
idTrapdoor2 = randomSeqByte(rng[], 32)
|
||||
idNullifier2 = randomSeqByte(rng[], 32)
|
||||
idSecretHash2 = randomSeqByte(rng[], 32)
|
||||
idCommitment2 = randomSeqByte(rng[], 32)
|
||||
idCredential2 = IdentityCredential(idTrapdoor: idTrapdoor2, idNullifier: idNullifier2, idSecretHash: idSecretHash2, idCommitment: idCommitment2)
|
||||
|
||||
|
||||
# We generate two distinct membership groups
|
||||
var contract1 = MembershipContract(chainId: "5", address: "0x0123456789012345678901234567890123456789")
|
||||
var index1 = MembershipIndex(1)
|
||||
@ -136,7 +135,7 @@ procSuite "Credentials test suite":
|
||||
membershipGroups: @[membershipGroup2])
|
||||
|
||||
let password = "%m0um0ucoW%"
|
||||
|
||||
|
||||
# We add credentials to the keystore. Note that only 3 credentials should be effectively added, since rlnMembershipCredentials3 is equal to membershipCredentials2
|
||||
let keystoreRes = addMembershipCredentials(path = filepath,
|
||||
credentials = @[membershipCredentials1, membershipCredentials2, membershipCredentials3, membershipCredentials4],
|
||||
@ -147,13 +146,13 @@ procSuite "Credentials test suite":
|
||||
keystoreRes.isOk()
|
||||
|
||||
# We test retrieval of credentials.
|
||||
var expectedMembershipGroups1 = @[membershipGroup1, membershipGroup2]
|
||||
var expectedMembershipGroups1 = @[membershipGroup1, membershipGroup2]
|
||||
expectedMembershipGroups1.sort(sortMembershipGroup)
|
||||
let expectedCredential1 = MembershipCredentials(identityCredential: idCredential1,
|
||||
membershipGroups: expectedMembershipGroups1)
|
||||
|
||||
|
||||
var expectedMembershipGroups2 = @[membershipGroup2]
|
||||
var expectedMembershipGroups2 = @[membershipGroup2]
|
||||
expectedMembershipGroups2.sort(sortMembershipGroup)
|
||||
let expectedCredential2 = MembershipCredentials(identityCredential: idCredential2,
|
||||
membershipGroups: expectedMembershipGroups2)
|
||||
@ -185,7 +184,7 @@ procSuite "Credentials test suite":
|
||||
filterIdentityCredentials = @[idCredential1, idCredential2],
|
||||
appInfo = testAppInfo)
|
||||
|
||||
check:
|
||||
check:
|
||||
recoveredCredentialsRes.isOk()
|
||||
recoveredCredentialsRes.get() == @[expectedCredential1, expectedCredential2]
|
||||
|
||||
|
@ -6,14 +6,13 @@ import
|
||||
testutils/unittests, chronos,
|
||||
eth/keys
|
||||
import
|
||||
../../waku/v2/protocol/waku_keystore
|
||||
../../waku/v2/protocol/waku_keystore,
|
||||
./testlib/common
|
||||
|
||||
from ../../waku/v2/protocol/waku_noise/noise_utils import randomSeqByte
|
||||
|
||||
suite "KeyFile test suite":
|
||||
|
||||
let rng = newRng()
|
||||
|
||||
test "Create/Save/Load single keyfile":
|
||||
|
||||
# The password we use to encrypt our secret
|
||||
@ -54,7 +53,7 @@ suite "KeyFile test suite":
|
||||
let password1 = string.fromBytes(randomSeqByte(rng[], 20))
|
||||
let password2 = ""
|
||||
let password3 = string.fromBytes(randomSeqByte(rng[], 20))
|
||||
var keyfile: KfResult[JsonNode]
|
||||
var keyfile: KfResult[JsonNode]
|
||||
|
||||
let filepath = "./test.keyfile"
|
||||
defer: removeFile(filepath)
|
||||
@ -101,7 +100,7 @@ suite "KeyFile test suite":
|
||||
saveKeyFile(filepath, keyfile.get()).isOk()
|
||||
|
||||
# Now there are 6 keyfiles stored in filepath encrypted with 3 different passwords
|
||||
# We decrypt the keyfiles using the respective passwords and we check that the number of
|
||||
# We decrypt the keyfiles using the respective passwords and we check that the number of
|
||||
# successful decryptions corresponds to the number of secrets encrypted under that password
|
||||
|
||||
var decodedKeyfilesPassword1 = loadKeyFiles(filepath, password1)
|
||||
@ -121,7 +120,7 @@ suite "KeyFile test suite":
|
||||
decodedKeyfilesPassword3.isOk()
|
||||
decodedKeyfilesPassword3.get().len == 2
|
||||
var decodedSecretsPassword3 = decodedKeyfilesPassword3.get()
|
||||
|
||||
|
||||
# We check if the corresponding secrets are correct
|
||||
check:
|
||||
# Secrets encrypted with password 1
|
||||
@ -140,8 +139,6 @@ suite "KeyFile test suite":
|
||||
# Note: the original nim-eth "Create/Save/Load test" is redefined and expanded above in "KeyFile test suite"
|
||||
suite "KeyFile test suite (adapted from nim-eth keyfile tests)":
|
||||
|
||||
let rng = newRng()
|
||||
|
||||
# Testvectors originally from https://github.com/status-im/nim-eth/blob/fef47331c37ee8abb8608037222658737ff498a6/tests/keyfile/test_keyfile.nim#L22-L168
|
||||
let TestVectors = [
|
||||
%*{
|
||||
@ -307,7 +304,7 @@ suite "KeyFile test suite (adapted from nim-eth keyfile tests)":
|
||||
secret.isOk()
|
||||
secret.get() == expectedSecret
|
||||
|
||||
# Decryption with wrong password
|
||||
# Decryption with wrong password
|
||||
secret = decodeKeyFileJson(TestVectors[i].getOrDefault("keyfile"), "wrongpassword")
|
||||
|
||||
check:
|
||||
@ -316,7 +313,7 @@ suite "KeyFile test suite (adapted from nim-eth keyfile tests)":
|
||||
|
||||
test "Wrong mac in keyfile":
|
||||
|
||||
# This keyfile is the same as the first one in TestVectors,
|
||||
# This keyfile is the same as the first one in TestVectors,
|
||||
# but the last byte of mac is changed to 00.
|
||||
# While ciphertext is the correct encryption of priv under password,
|
||||
# mac verfication should fail and nothing will be decrypted
|
||||
@ -357,7 +354,7 @@ suite "KeyFile test suite (adapted from nim-eth keyfile tests)":
|
||||
expectedSecret = randomSeqByte(rng[], 300)
|
||||
password = "miawmiawcat"
|
||||
|
||||
# By default, keyfiles' encryption key is derived from password using PBKDF2.
|
||||
# By default, keyfiles' encryption key is derived from password using PBKDF2.
|
||||
# Here we test keyfiles encypted with a key derived from password using scrypt
|
||||
jsonKeyfile = createKeyFileJson(expectedSecret, password, 3, AES128CTR, SCRYPT)
|
||||
|
||||
@ -374,4 +371,4 @@ suite "KeyFile test suite (adapted from nim-eth keyfile tests)":
|
||||
|
||||
check:
|
||||
loadKeyFiles("nonexistant.keyfile", "password").error ==
|
||||
KeyFileError.KeyfileDoesNotExist
|
||||
KeyFileError.KeyfileDoesNotExist
|
||||
|
@ -1,9 +1,9 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
testutils/unittests,
|
||||
testutils/unittests,
|
||||
chronicles,
|
||||
chronos,
|
||||
chronos,
|
||||
libp2p/crypto/crypto
|
||||
import
|
||||
../../waku/v2/node/peer_manager,
|
||||
@ -11,13 +11,12 @@ import
|
||||
../../waku/v2/protocol/waku_lightpush,
|
||||
../../waku/v2/protocol/waku_lightpush/client,
|
||||
./testlib/common,
|
||||
./testlib/switch
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
proc newTestWakuLightpushNode(switch: Switch, handler: PushMessageHandler): Future[WakuLightPush] {.async.} =
|
||||
let
|
||||
peerManager = PeerManager.new(switch)
|
||||
rng = crypto.newRng()
|
||||
proto = WakuLightPush.new(peerManager, rng, handler)
|
||||
|
||||
await proto.start()
|
||||
@ -28,7 +27,6 @@ proc newTestWakuLightpushNode(switch: Switch, handler: PushMessageHandler): Futu
|
||||
proc newTestWakuLightpushClient(switch: Switch): WakuLightPushClient =
|
||||
let
|
||||
peerManager = PeerManager.new(switch)
|
||||
rng = crypto.newRng()
|
||||
WakuLightPushClient.new(peerManager, rng)
|
||||
|
||||
|
||||
@ -36,7 +34,7 @@ suite "Waku Lightpush":
|
||||
|
||||
asyncTest "push message to pubsub topic is successful":
|
||||
## Setup
|
||||
let
|
||||
let
|
||||
serverSwitch = newTestSwitch()
|
||||
clientSwitch = newTestSwitch()
|
||||
|
||||
@ -44,7 +42,7 @@ suite "Waku Lightpush":
|
||||
|
||||
## Given
|
||||
let handlerFuture = newFuture[(string, WakuMessage)]()
|
||||
let handler = proc(peer: PeerId, pubsubTopic: PubsubTopic, message: WakuMessage): Future[WakuLightPushResult[void]] {.async.} =
|
||||
let handler = proc(peer: PeerId, pubsubTopic: PubsubTopic, message: WakuMessage): Future[WakuLightPushResult[void]] {.async.} =
|
||||
handlerFuture.complete((pubsubTopic, message))
|
||||
return ok()
|
||||
|
||||
@ -78,7 +76,7 @@ suite "Waku Lightpush":
|
||||
|
||||
asyncTest "push message to pubsub topic should fail":
|
||||
## Setup
|
||||
let
|
||||
let
|
||||
serverSwitch = newTestSwitch()
|
||||
clientSwitch = newTestSwitch()
|
||||
|
||||
@ -86,9 +84,9 @@ suite "Waku Lightpush":
|
||||
|
||||
## Given
|
||||
let error = "test_failure"
|
||||
|
||||
|
||||
let handlerFuture = newFuture[void]()
|
||||
let handler = proc(peer: PeerId, pubsubTopic: PubsubTopic, message: WakuMessage): Future[WakuLightPushResult[void]] {.async.} =
|
||||
let handler = proc(peer: PeerId, pubsubTopic: PubsubTopic, message: WakuMessage): Future[WakuLightPushResult[void]] {.async.} =
|
||||
handlerFuture.complete()
|
||||
return err(error)
|
||||
|
||||
@ -115,6 +113,6 @@ suite "Waku Lightpush":
|
||||
let requestError = requestRes.error
|
||||
check:
|
||||
requestError == error
|
||||
|
||||
|
||||
## Cleanup
|
||||
await allFutures(clientSwitch.stop(), serverSwitch.stop())
|
||||
|
@ -5,24 +5,21 @@ import
|
||||
std/random,
|
||||
std/tables,
|
||||
stew/byteutils,
|
||||
libp2p/crypto/chacha20poly1305,
|
||||
libp2p/protobuf/minprotobuf,
|
||||
stew/endians2
|
||||
import
|
||||
../../waku/v2/utils/noise as waku_message_utils,
|
||||
../../waku/v2/protocol/waku_noise/noise_types,
|
||||
../../waku/v2/protocol/waku_noise/noise_utils,
|
||||
../../waku/v2/protocol/waku_noise/noise,
|
||||
../../waku/v2/protocol/waku_noise/noise_handshake_processing,
|
||||
../../waku/v2/protocol/waku_message,
|
||||
../test_helpers,
|
||||
libp2p/crypto/chacha20poly1305,
|
||||
libp2p/protobuf/minprotobuf,
|
||||
stew/endians2
|
||||
./testlib/common
|
||||
|
||||
|
||||
procSuite "Waku Noise":
|
||||
|
||||
# We initialize the RNG in test_helpers
|
||||
let rng = rng()
|
||||
# We initialize the RNG in std/random
|
||||
randomize()
|
||||
common.randomize()
|
||||
|
||||
test "PKCS#7 Padding/Unpadding":
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/[random, tables],
|
||||
std/tables,
|
||||
stew/[results, byteutils],
|
||||
testutils/unittests,
|
||||
libp2p/protobuf/minprotobuf
|
||||
@ -11,13 +11,9 @@ import
|
||||
../../waku/v2/protocol/waku_noise/noise_utils,
|
||||
../../waku/v2/protocol/waku_noise/noise_handshake_processing,
|
||||
../../waku/v2/protocol/waku_message,
|
||||
../test_helpers
|
||||
./testlib/common
|
||||
|
||||
procSuite "Waku Noise Sessions":
|
||||
|
||||
# We initialize the RNG in test_helpers
|
||||
let rng = rng()
|
||||
# We initialize the RNG in std/random
|
||||
randomize()
|
||||
|
||||
# This test implements the Device pairing and Secure Transfers with Noise
|
||||
|
@ -18,9 +18,7 @@ import
|
||||
../../waku/v2/protocol/waku_peer_exchange,
|
||||
../../waku/v2/protocol/waku_peer_exchange/rpc,
|
||||
../../waku/v2/protocol/waku_peer_exchange/rpc_codec,
|
||||
../test_helpers,
|
||||
./utils,
|
||||
./testlib/testutils
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
# TODO: Extend test coverage
|
||||
@ -75,17 +73,17 @@ procSuite "Waku Peer Exchange":
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
extIp = ValidIpAddress.init("127.0.0.1")
|
||||
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
nodeTcpPort1 = Port(64010)
|
||||
nodeUdpPort1 = Port(9000)
|
||||
node1 = WakuNode.new(nodeKey1, bindIp, nodeTcpPort1)
|
||||
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
nodeTcpPort2 = Port(64012)
|
||||
nodeUdpPort2 = Port(9002)
|
||||
node2 = WakuNode.new(nodeKey2, bindIp, nodeTcpPort2)
|
||||
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
nodeTcpPort3 = Port(64014)
|
||||
nodeUdpPort3 = Port(9004)
|
||||
node3 = WakuNode.new(nodeKey3, bindIp, nodeTcpPort3)
|
||||
@ -154,8 +152,8 @@ procSuite "Waku Peer Exchange":
|
||||
|
||||
asyncTest "peer exchange request functions returns some discovered peers":
|
||||
let
|
||||
node1 = WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node2 = WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node1 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node2 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
|
||||
# Start and mount peer exchange
|
||||
await allFutures([node1.start(), node2.start()])
|
||||
@ -198,8 +196,8 @@ procSuite "Waku Peer Exchange":
|
||||
|
||||
asyncTest "peer exchange handler works as expected":
|
||||
let
|
||||
node1 = WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node2 = WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node1 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node2 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
|
||||
# Start and mount peer exchange
|
||||
await allFutures([node1.start(), node2.start()])
|
||||
@ -234,8 +232,8 @@ procSuite "Waku Peer Exchange":
|
||||
|
||||
asyncTest "peer exchange request fails gracefully":
|
||||
let
|
||||
node1 = WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node2 = WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node1 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node2 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
|
||||
# Start and mount peer exchange
|
||||
await allFutures([node1.start(), node2.start()])
|
||||
|
@ -3,11 +3,11 @@
|
||||
|
||||
import
|
||||
std/[options, os, sequtils, times],
|
||||
stew/byteutils,
|
||||
stew/byteutils,
|
||||
stew/shims/net as stewNet,
|
||||
testutils/unittests,
|
||||
chronos,
|
||||
chronicles,
|
||||
testutils/unittests,
|
||||
chronos,
|
||||
chronicles,
|
||||
stint,
|
||||
libp2p/crypto/crypto
|
||||
import
|
||||
@ -15,16 +15,17 @@ import
|
||||
../../waku/v2/protocol/waku_message,
|
||||
../../waku/v2/protocol/waku_rln_relay,
|
||||
../../waku/v2/protocol/waku_keystore,
|
||||
../test_helpers
|
||||
./testlib/waku2
|
||||
|
||||
const RlnRelayPubsubTopic = "waku/2/rlnrelay/proto"
|
||||
const RlnRelayContentTopic = "waku/2/rlnrelay/proto"
|
||||
|
||||
procSuite "Waku rln relay":
|
||||
|
||||
suite "Waku rln relay":
|
||||
|
||||
asyncTest "mount waku-rln-relay in the off-chain mode":
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey = generateSecp256k1Key()
|
||||
node = WakuNode.new(nodeKey, ValidIpAddress.init("0.0.0.0"), Port(60200))
|
||||
await node.start()
|
||||
|
||||
@ -43,8 +44,8 @@ procSuite "Waku rln relay":
|
||||
groupIdCredentialsRes = groupCredentials.toIdentityCredentials()
|
||||
require:
|
||||
groupIdCredentialsRes.isOk()
|
||||
|
||||
let
|
||||
|
||||
let
|
||||
groupIdCredentials = groupIdCredentialsRes.get()
|
||||
# extract the id commitments
|
||||
groupIDCommitments = groupIdCredentials.mapIt(it.idCommitment)
|
||||
@ -199,7 +200,7 @@ suite "Waku rln relay":
|
||||
let idCredentialRes = membershipKeyGen(rln)
|
||||
require:
|
||||
idCredentialRes.isOk()
|
||||
|
||||
|
||||
let idCredential = idCredentialRes.get()
|
||||
let pkBuffer = toBuffer(idCredential.idCommitment)
|
||||
let pkBufferPtr = unsafeAddr(pkBuffer)
|
||||
@ -277,7 +278,7 @@ suite "Waku rln relay":
|
||||
let idCredentialRes = membershipKeyGen(rln)
|
||||
require:
|
||||
idCredentialRes.isOk()
|
||||
|
||||
|
||||
let idCredential = idCredentialRes.get()
|
||||
let pkBuffer = toBuffer(idCredential.idCommitment)
|
||||
let pkBufferPtr = unsafeAddr(pkBuffer)
|
||||
@ -324,7 +325,7 @@ suite "Waku rln relay":
|
||||
debug "The root after deletion", rootHex3
|
||||
|
||||
# the root must change after the insertion
|
||||
check:
|
||||
check:
|
||||
not(rootHex1 == rootHex2)
|
||||
|
||||
## The initial root of the tree (empty tree) must be identical to
|
||||
@ -407,7 +408,7 @@ suite "Waku rln relay":
|
||||
require:
|
||||
hashSuccess
|
||||
let outputArr = cast[ptr array[32, byte]](outputBuffer.`ptr`)[]
|
||||
|
||||
|
||||
check:
|
||||
"1e32b3ab545c07c8b4a7ab1ca4f46bc31e4fdc29ac3b240ef1d54b4017a26e4c" ==
|
||||
outputArr.inHex()
|
||||
@ -458,7 +459,7 @@ suite "Waku rln relay":
|
||||
let groupIdCredentialsRes = groupKeys.toIdentityCredentials()
|
||||
require:
|
||||
groupIdCredentialsRes.isOk()
|
||||
|
||||
|
||||
let groupIdCredentials = groupIdCredentialsRes.get()
|
||||
# extract the id commitments
|
||||
let groupIDCommitments = groupIdCredentials.mapIt(it.idCommitment)
|
||||
@ -529,7 +530,7 @@ suite "Waku rln relay":
|
||||
|
||||
require:
|
||||
idCredentialRes.isOk()
|
||||
|
||||
|
||||
let idCredential = idCredentialRes.get()
|
||||
|
||||
var members = newSeq[IDCommitment]()
|
||||
@ -641,7 +642,7 @@ suite "Waku rln relay":
|
||||
verified.value() == false
|
||||
|
||||
test "validate roots which are part of the acceptable window":
|
||||
# Setup:
|
||||
# Setup:
|
||||
# This step consists of creating the rln instance and waku-rln-relay,
|
||||
# Inserting members, and creating a valid proof with the merkle root
|
||||
# create an RLN instance
|
||||
@ -653,14 +654,14 @@ suite "Waku rln relay":
|
||||
let rlnRelay = WakuRLNRelay(rlnInstance:rln)
|
||||
|
||||
let
|
||||
# peer's index in the Merkle Tree.
|
||||
# peer's index in the Merkle Tree.
|
||||
index = 5'u
|
||||
# create an identity credential
|
||||
idCredentialRes = membershipKeyGen(rlnRelay.rlnInstance)
|
||||
|
||||
require:
|
||||
idCredentialRes.isOk()
|
||||
|
||||
|
||||
let idCredential = idCredentialRes.get()
|
||||
|
||||
let membershipCount: uint = AcceptableRootWindowSize + 5'u
|
||||
@ -678,13 +679,13 @@ suite "Waku rln relay":
|
||||
require:
|
||||
idCredentialRes.isOk()
|
||||
members.add(idCredentialRes.get())
|
||||
|
||||
|
||||
# Batch inserts into the tree
|
||||
let insertedRes = rlnRelay.insertMembers(0, members.mapIt(it.idCommitment))
|
||||
require:
|
||||
insertedRes.isOk()
|
||||
|
||||
# Given:
|
||||
|
||||
# Given:
|
||||
# This step includes constructing a valid message with the latest merkle root
|
||||
# prepare the message
|
||||
let messageBytes = "Hello".toBytes()
|
||||
@ -708,7 +709,7 @@ suite "Waku rln relay":
|
||||
require:
|
||||
verified == true
|
||||
|
||||
# When:
|
||||
# When:
|
||||
# This test depends on the local merkle tree root being part of a
|
||||
# acceptable set of roots, which is denoted by AcceptableRootWindowSize
|
||||
# The following action is equivalent to a member being removed upon listening to the events emitted by the contract
|
||||
@ -724,7 +725,7 @@ suite "Waku rln relay":
|
||||
currentMerkleRoot.isOk()
|
||||
currentMerkleRoot.value() != validProof.merkleRoot
|
||||
|
||||
# Then:
|
||||
# Then:
|
||||
# we try to verify a root against this window,
|
||||
# which should return true
|
||||
let olderRootVerified = rlnRelay.validateRoot(validProof.merkleRoot)
|
||||
@ -733,13 +734,13 @@ suite "Waku rln relay":
|
||||
olderRootVerified == true
|
||||
|
||||
test "invalidate roots which are not part of the acceptable window":
|
||||
# Setup:
|
||||
# Setup:
|
||||
# This step consists of creating the rln instance and waku-rln-relay,
|
||||
# Inserting members, and creating a valid proof with the merkle root
|
||||
|
||||
|
||||
require:
|
||||
AcceptableRootWindowSize < 10
|
||||
|
||||
|
||||
# create an RLN instance
|
||||
let rlnInstance = createRLNInstance()
|
||||
require:
|
||||
@ -749,7 +750,7 @@ suite "Waku rln relay":
|
||||
let rlnRelay = WakuRLNRelay(rlnInstance:rln)
|
||||
|
||||
let
|
||||
# peer's index in the Merkle Tree.
|
||||
# peer's index in the Merkle Tree.
|
||||
index = 6'u
|
||||
# create an identity credential
|
||||
idCredentialRes = membershipKeyGen(rlnRelay.rlnInstance)
|
||||
@ -759,7 +760,7 @@ suite "Waku rln relay":
|
||||
|
||||
let idCredential = idCredentialRes.get()
|
||||
|
||||
let membershipCount: uint = AcceptableRootWindowSize + 5'u
|
||||
let membershipCount: uint = AcceptableRootWindowSize + 5'u
|
||||
|
||||
# Create a Merkle tree with random members
|
||||
for i in 0'u..membershipCount:
|
||||
@ -777,7 +778,7 @@ suite "Waku rln relay":
|
||||
require:
|
||||
memberIsAdded.isOk()
|
||||
|
||||
# Given:
|
||||
# Given:
|
||||
# This step includes constructing a valid message with the latest merkle root
|
||||
# prepare the message
|
||||
let messageBytes = "Hello".toBytes()
|
||||
@ -801,7 +802,7 @@ suite "Waku rln relay":
|
||||
require:
|
||||
verified == true
|
||||
|
||||
# When:
|
||||
# When:
|
||||
# This test depends on the local merkle tree root being part of a
|
||||
# acceptable set of roots, which is denoted by AcceptableRootWindowSize
|
||||
# The following action is equivalent to a member being removed upon listening to the events emitted by the contract
|
||||
@ -815,7 +816,7 @@ suite "Waku rln relay":
|
||||
currentMerkleRoot.isOk()
|
||||
currentMerkleRoot.value() != validProof.merkleRoot
|
||||
|
||||
# Then:
|
||||
# Then:
|
||||
# we try to verify a proof against this window,
|
||||
# which should return false
|
||||
let olderRootVerified = rlnRelay.validateRoot(validProof.merkleRoot)
|
||||
@ -873,16 +874,16 @@ suite "Waku rln relay":
|
||||
|
||||
let
|
||||
wm1 = WakuMessage(proof: RateLimitProof(epoch: epoch,
|
||||
nullifier: nullifier1,
|
||||
shareX: shareX1,
|
||||
nullifier: nullifier1,
|
||||
shareX: shareX1,
|
||||
shareY: shareY1).encodeAndGetBuf())
|
||||
wm2 = WakuMessage(proof: RateLimitProof(epoch: epoch,
|
||||
nullifier: nullifier2,
|
||||
shareX: shareX2,
|
||||
nullifier: nullifier2,
|
||||
shareX: shareX2,
|
||||
shareY: shareY2).encodeAndGetBuf())
|
||||
wm3 = WakuMessage(proof: RateLimitProof(epoch: epoch,
|
||||
nullifier: nullifier3,
|
||||
shareX: shareX3,
|
||||
nullifier: nullifier3,
|
||||
shareX: shareX3,
|
||||
shareY: shareY3).encodeAndGetBuf())
|
||||
|
||||
# check whether hasDuplicate correctly finds records with the same nullifiers but different secret shares
|
||||
@ -917,10 +918,10 @@ suite "Waku rln relay":
|
||||
|
||||
# create a group of 100 membership keys
|
||||
let memListRes = createMembershipList(100)
|
||||
|
||||
|
||||
require:
|
||||
memListRes.isOk()
|
||||
let
|
||||
let
|
||||
(groupKeys, _) = memListRes.get()
|
||||
# convert the keys to IdentityCredential structs
|
||||
groupIdCredentialsRes = groupKeys.toIdentityCredentials()
|
||||
@ -1002,7 +1003,7 @@ suite "Waku rln relay":
|
||||
rlnInstance.isOk()
|
||||
|
||||
let rln = rlnInstance.get()
|
||||
|
||||
|
||||
# create an idendity credential
|
||||
let idCredentialRes = rln.membershipKeyGen()
|
||||
require:
|
||||
@ -1060,7 +1061,7 @@ suite "Waku rln relay":
|
||||
credentials = @[rlnMembershipCredentials],
|
||||
password = password,
|
||||
appInfo = RLNAppInfo).isOk()
|
||||
|
||||
|
||||
let readCredentialsResult = getMembershipCredentials(path = filepath,
|
||||
password = password,
|
||||
filterMembershipContracts = @[rlnMembershipContract],
|
||||
@ -1071,7 +1072,7 @@ suite "Waku rln relay":
|
||||
|
||||
# getMembershipCredentials returns all credentials in keystore as sequence matching the filter
|
||||
let allMatchingCredentials = readCredentialsResult.get()
|
||||
# if any is found, we return the first credential, otherwise credentials is none
|
||||
# if any is found, we return the first credential, otherwise credentials is none
|
||||
var credentials = none(MembershipCredentials)
|
||||
if allMatchingCredentials.len() > 0:
|
||||
credentials = some(allMatchingCredentials[0])
|
||||
|
@ -11,7 +11,8 @@ import
|
||||
../../waku/v2/protocol/waku_keystore,
|
||||
../../waku/v2/protocol/waku_rln_relay,
|
||||
../../waku/v2/node/waku_node,
|
||||
../test_helpers,
|
||||
./testlib/common,
|
||||
./testlib/waku2,
|
||||
./test_utils
|
||||
|
||||
from posix import kill, SIGINT
|
||||
@ -80,14 +81,12 @@ proc uploadRLNContract*(ethClientAddress: string): Future[Address] {.async.} =
|
||||
|
||||
|
||||
proc createEthAccount(): Future[(keys.PrivateKey, Address)] {.async.} =
|
||||
let theRNG = keys.newRng()
|
||||
|
||||
let web3 = await newWeb3(EthClient)
|
||||
let accounts = await web3.provider.eth_accounts()
|
||||
let gasPrice = int(await web3.provider.eth_gasPrice())
|
||||
web3.defaultAccount = accounts[0]
|
||||
|
||||
let pk = keys.PrivateKey.random(theRNG[])
|
||||
let pk = keys.PrivateKey.random(rng[])
|
||||
let acc = Address(toCanonicalAddress(pk.toPublicKey()))
|
||||
|
||||
var tx:EthSend
|
||||
@ -106,7 +105,7 @@ proc createEthAccount(): Future[(keys.PrivateKey, Address)] {.async.} =
|
||||
|
||||
# Installs Ganache Daemon
|
||||
proc installGanache() =
|
||||
# We install Ganache.
|
||||
# We install Ganache.
|
||||
# Packages will be installed to the ./build folder through the --prefix option
|
||||
let installGanache = startProcess("npm", args = ["install", "ganache", "--prefix", "./build"], options = {poUsePath})
|
||||
let returnCode = installGanache.waitForExit()
|
||||
@ -125,7 +124,7 @@ proc uninstallGanache() =
|
||||
|
||||
# Runs Ganache daemon
|
||||
proc runGanache(): Process =
|
||||
# We run directly "node node_modules/ganache/dist/node/cli.js" rather than using "npx ganache", so that the daemon does not spawn in a new child process.
|
||||
# We run directly "node node_modules/ganache/dist/node/cli.js" rather than using "npx ganache", so that the daemon does not spawn in a new child process.
|
||||
# In this way, we can directly send a SIGINT signal to the corresponding PID to gracefully terminate Ganache without dealing with multiple processes.
|
||||
# Passed options are
|
||||
# --port Port to listen on.
|
||||
@ -193,11 +192,11 @@ procSuite "Waku-rln-relay":
|
||||
|
||||
# create an RLN instance
|
||||
let rlnInstance = createRLNInstance()
|
||||
require:
|
||||
rlnInstance.isOk()
|
||||
require:
|
||||
rlnInstance.isOk()
|
||||
# generate the membership keys
|
||||
let identityCredentialRes = membershipKeyGen(rlnInstance.get())
|
||||
require:
|
||||
require:
|
||||
identityCredentialRes.isOk()
|
||||
let identityCredential = identityCredentialRes.get()
|
||||
let pk = identityCredential.idCommitment.toUInt256()
|
||||
@ -249,12 +248,12 @@ procSuite "Waku-rln-relay":
|
||||
# test ------------------------------
|
||||
# create an RLN instance
|
||||
let rlnInstance = createRLNInstance()
|
||||
require:
|
||||
require:
|
||||
rlnInstance.isOk()
|
||||
let rln = rlnInstance.get()
|
||||
|
||||
let idCredentialRes = rln.membershipKeyGen()
|
||||
require:
|
||||
require:
|
||||
idCredentialRes.isOk()
|
||||
let idCredential = idCredentialRes.get()
|
||||
let pk = idCredential.idCommitment.toUInt256()
|
||||
@ -270,7 +269,7 @@ procSuite "Waku-rln-relay":
|
||||
|
||||
# generate another identity credential
|
||||
let idCredential2Res = rln.membershipKeyGen()
|
||||
require:
|
||||
require:
|
||||
idCredential2Res.isOk()
|
||||
let idCredential2 = idCredential2Res.get()
|
||||
let pk2 = idCredential2.idCommitment.toUInt256()
|
||||
@ -279,7 +278,7 @@ procSuite "Waku-rln-relay":
|
||||
let events = [newFuture[void](), newFuture[void]()]
|
||||
var futIndex = 0
|
||||
var handler: GroupUpdateHandler
|
||||
handler = proc (blockNumber: BlockNumber,
|
||||
handler = proc (blockNumber: BlockNumber,
|
||||
members: seq[MembershipTuple]): RlnRelayResult[void] =
|
||||
debug "handler is called", members = members
|
||||
events[futIndex].complete()
|
||||
@ -289,7 +288,7 @@ procSuite "Waku-rln-relay":
|
||||
check:
|
||||
insertRes.isOk()
|
||||
return ok()
|
||||
|
||||
|
||||
# mount the handler for listening to the contract events
|
||||
await subscribeToGroupEvents(ethClientUri = EthClient,
|
||||
ethAccountAddress = some(accounts[0]),
|
||||
@ -332,7 +331,7 @@ procSuite "Waku-rln-relay":
|
||||
# send takes the following parameters, c: ContractCallBase, value = 0.u256, gas = 3000000'u64 gasPrice = 0
|
||||
# should use send proc for the contract functions that update the state of the contract
|
||||
let tx = await sender.register(20.u256).send(value = MembershipFee) # value is the membership fee
|
||||
debug "The hash of registration tx: ", tx
|
||||
debug "The hash of registration tx: ", tx
|
||||
|
||||
# let members: array[2, uint256] = [20.u256, 21.u256]
|
||||
# debug "This is the batch registration result ", await sender.registerBatch(members).send(value = (members.len * MembershipFee)) # value is the membership fee
|
||||
@ -355,16 +354,16 @@ procSuite "Waku-rln-relay":
|
||||
|
||||
# create an RLN instance
|
||||
let rlnInstance = createRLNInstance()
|
||||
require:
|
||||
require:
|
||||
rlnInstance.isOk()
|
||||
|
||||
# generate the membership keys
|
||||
let identityCredentialRes = membershipKeyGen(rlnInstance.get())
|
||||
require:
|
||||
require:
|
||||
identityCredentialRes.isOk()
|
||||
let identityCredential = identityCredentialRes.get()
|
||||
|
||||
# create an Ethereum private key and the corresponding account
|
||||
# create an Ethereum private key and the corresponding account
|
||||
let (ethPrivKey, ethacc) = await createEthAccount()
|
||||
|
||||
# test ------------------------------
|
||||
@ -378,14 +377,14 @@ procSuite "Waku-rln-relay":
|
||||
|
||||
# register the rln-relay peer to the membership contract
|
||||
let isSuccessful = await rlnPeer.register()
|
||||
check:
|
||||
check:
|
||||
isSuccessful.isOk()
|
||||
|
||||
|
||||
asyncTest "mounting waku rln-relay: check correct Merkle tree construction in the static/off-chain group management":
|
||||
# preparation ------------------------------
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey = generateSecp256k1Key()
|
||||
node = WakuNode.new(nodeKey, ValidIpAddress.init("0.0.0.0"), Port(60110))
|
||||
await node.start()
|
||||
|
||||
@ -436,7 +435,7 @@ procSuite "Waku-rln-relay":
|
||||
memIndex = index,
|
||||
pubsubTopic = RlnRelayPubsubTopic,
|
||||
contentTopic = RlnRelayContentTopic)
|
||||
|
||||
|
||||
require:
|
||||
mountRes.isOk()
|
||||
|
||||
@ -449,11 +448,11 @@ procSuite "Waku-rln-relay":
|
||||
expectedRoot == calculatedRoot
|
||||
|
||||
await node.stop()
|
||||
|
||||
|
||||
asyncTest "mounting waku rln-relay: check correct Merkle tree construction in the dynamic/onchain group management":
|
||||
# preparation ------------------------------
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey = generateSecp256k1Key()
|
||||
node = WakuNode.new(nodeKey, ValidIpAddress.init("0.0.0.0"), Port(60111))
|
||||
await node.start()
|
||||
|
||||
@ -467,8 +466,8 @@ procSuite "Waku-rln-relay":
|
||||
# choose one of the existing accounts for the rln-relay peer
|
||||
ethAccountAddress = accounts[0]
|
||||
web3.defaultAccount = accounts[0]
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# create an rln instance
|
||||
let rlnInstance = createRLNInstance()
|
||||
@ -477,18 +476,18 @@ procSuite "Waku-rln-relay":
|
||||
let rln = rlnInstance.get()
|
||||
|
||||
# create two identity credentials
|
||||
let
|
||||
let
|
||||
idCredential1Res = rln.membershipKeyGen()
|
||||
idCredential2Res = rln.membershipKeyGen()
|
||||
require:
|
||||
require:
|
||||
idCredential1Res.isOk()
|
||||
idCredential2Res.isOk()
|
||||
|
||||
let
|
||||
idCredential1 = idCredential1Res.get()
|
||||
idCredential2 = idCredential2Res.get()
|
||||
pk1 = idCredential1.idCommitment.toUInt256()
|
||||
pk2 = idCredential2.idCommitment.toUInt256()
|
||||
pk1 = idCredential1.idCommitment.toUInt256()
|
||||
pk2 = idCredential2.idCommitment.toUInt256()
|
||||
debug "member key1", key = idCredential1.idCommitment.inHex
|
||||
debug "member key2", key = idCredential2.idCommitment.inHex
|
||||
|
||||
@ -496,14 +495,14 @@ procSuite "Waku-rln-relay":
|
||||
let
|
||||
memberIsAdded1 = rln.insertMembers(0, @[idCredential1.idCommitment])
|
||||
memberIsAdded2 = rln.insertMembers(1, @[idCredential2.idCommitment])
|
||||
|
||||
|
||||
require:
|
||||
memberIsAdded1
|
||||
memberIsAdded2
|
||||
|
||||
|
||||
# get the Merkle root
|
||||
let expectedRoot = rln.getMerkleRoot().value().inHex
|
||||
|
||||
|
||||
# prepare a contract sender to interact with it
|
||||
let contractObj = web3.contractSender(MembershipContract,
|
||||
contractAddress) # creates a Sender object with a web3 field and contract address of type Address
|
||||
@ -516,7 +515,7 @@ procSuite "Waku-rln-relay":
|
||||
let tx2Hash = await contractObj.register(pk2).send(value = MembershipFee)
|
||||
debug "a member is registered", tx2 = tx2Hash
|
||||
|
||||
# create an Ethereum private key and the corresponding account
|
||||
# create an Ethereum private key and the corresponding account
|
||||
let (ethPrivKey, ethacc) = await createEthAccount()
|
||||
|
||||
|
||||
@ -527,7 +526,7 @@ procSuite "Waku-rln-relay":
|
||||
ethClientAddr = EthClient,
|
||||
ethAccountAddress = some(ethacc),
|
||||
ethAccountPrivKeyOpt = some(ethPrivKey),
|
||||
memContractAddr = contractAddress,
|
||||
memContractAddr = contractAddress,
|
||||
memIdCredential = some(idCredential1),
|
||||
memIndex = some(MembershipIndex(0)),
|
||||
pubsubTopic = RlnRelayPubsubTopic,
|
||||
@ -537,7 +536,7 @@ procSuite "Waku-rln-relay":
|
||||
mountRes.isOk()
|
||||
|
||||
let wakuRlnRelay = mountRes.get()
|
||||
|
||||
|
||||
await sleepAsync(2000.milliseconds()) # wait for the event to reach the group handler
|
||||
|
||||
# rln pks are inserted into the rln peer's Merkle tree and the resulting root
|
||||
@ -547,7 +546,7 @@ procSuite "Waku-rln-relay":
|
||||
debug "expected root ", expectedRoot=expectedRoot
|
||||
|
||||
check:
|
||||
expectedRoot == calculatedRoot
|
||||
expectedRoot == calculatedRoot
|
||||
|
||||
|
||||
await web3.close()
|
||||
@ -568,16 +567,16 @@ procSuite "Waku-rln-relay":
|
||||
|
||||
# prepare two nodes
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey = generateSecp256k1Key()
|
||||
node = WakuNode.new(nodeKey, ValidIpAddress.init("0.0.0.0"), Port(60112))
|
||||
await node.start()
|
||||
|
||||
let
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(60113))
|
||||
await node2.start()
|
||||
|
||||
# create an Ethereum private key and the corresponding account
|
||||
# create an Ethereum private key and the corresponding account
|
||||
let (ethPrivKey, ethacc) = await createEthAccount()
|
||||
|
||||
# start rln-relay on the first node, leave rln-relay credentials empty
|
||||
@ -586,7 +585,7 @@ procSuite "Waku-rln-relay":
|
||||
ethClientAddr = EthClient,
|
||||
ethAccountAddress = some(ethacc),
|
||||
ethAccountPrivKeyOpt = some(ethPrivKey),
|
||||
memContractAddr = contractAddress,
|
||||
memContractAddr = contractAddress,
|
||||
memIdCredential = none(IdentityCredential),
|
||||
memIndex = none(MembershipIndex),
|
||||
pubsubTopic = RlnRelayPubsubTopic,
|
||||
@ -603,7 +602,7 @@ procSuite "Waku-rln-relay":
|
||||
ethClientAddr = EthClient,
|
||||
ethAccountAddress = some(ethacc),
|
||||
ethAccountPrivKeyOpt = some(ethPrivKey),
|
||||
memContractAddr = contractAddress,
|
||||
memContractAddr = contractAddress,
|
||||
memIdCredential = none(IdentityCredential),
|
||||
memIndex = none(MembershipIndex),
|
||||
pubsubTopic = RlnRelayPubsubTopic,
|
||||
@ -614,7 +613,7 @@ procSuite "Waku-rln-relay":
|
||||
|
||||
let wakuRlnRelay2 = mountRes2.get()
|
||||
|
||||
# the two nodes should be registered into the contract
|
||||
# the two nodes should be registered into the contract
|
||||
# since nodes are spun up sequentially
|
||||
# the first node has index 0 whereas the second node gets index 1
|
||||
check:
|
||||
@ -632,4 +631,4 @@ procSuite "Waku-rln-relay":
|
||||
stopGanache(runGanache)
|
||||
|
||||
# We uninstall Ganache
|
||||
uninstallGanache()
|
||||
uninstallGanache()
|
||||
|
@ -1,7 +1,6 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
std/tables,
|
||||
stew/shims/net as stewNet,
|
||||
testutils/unittests,
|
||||
chronos,
|
||||
@ -14,12 +13,7 @@ import
|
||||
libp2p/crypto/secp,
|
||||
eth/keys
|
||||
import
|
||||
../../waku/v2/node/waku_node,
|
||||
../../waku/v2/protocol/waku_swap/waku_swap,
|
||||
../../waku/v2/utils/peers,
|
||||
../test_helpers,
|
||||
./utils,
|
||||
./testlib/common
|
||||
../../waku/v2/protocol/waku_swap/waku_swap
|
||||
|
||||
|
||||
procSuite "Waku SWAP Accounting":
|
||||
|
@ -1,15 +1,18 @@
|
||||
# Tests of Swap contracts via external module
|
||||
#
|
||||
import
|
||||
std/[unittest, options, tables, sets, osproc, strutils, strformat, json],
|
||||
chronicles,
|
||||
../test_helpers, ./utils,
|
||||
std/[options, osproc, strutils, json],
|
||||
testutils/unittests,
|
||||
chronicles
|
||||
import
|
||||
../../waku/v2/protocol/waku_swap/waku_swap_contracts
|
||||
|
||||
|
||||
procSuite "Basic balance test":
|
||||
var aliceSwapAddress = ""
|
||||
var signature = ""
|
||||
var erc20address = ""
|
||||
|
||||
test "Get pwd of swap module":
|
||||
let (output, errC) = osproc.execCmdEx("(cd ../swap-contracts-module && pwd)")
|
||||
debug "output", output
|
||||
|
@ -10,12 +10,12 @@ import
|
||||
stew/byteutils
|
||||
import
|
||||
../../waku/v2/node/wakuswitch,
|
||||
../test_helpers,
|
||||
./testlib/switch
|
||||
./testlib/common,
|
||||
./testlib/waku2
|
||||
|
||||
proc newCircuitRelayClientSwitch(relayClient: RelayClient): Switch =
|
||||
SwitchBuilder.new()
|
||||
.withRng(newRng())
|
||||
.withRng(rng())
|
||||
.withAddresses(@[MultiAddress.init("/ip4/0.0.0.0/tcp/0").tryGet()])
|
||||
.withTcpTransport()
|
||||
.withMplex()
|
||||
@ -23,7 +23,7 @@ proc newCircuitRelayClientSwitch(relayClient: RelayClient): Switch =
|
||||
.withCircuitRelay(relayClient)
|
||||
.build()
|
||||
|
||||
procSuite "Waku Switch":
|
||||
suite "Waku Switch":
|
||||
|
||||
asyncTest "Waku Switch works with AutoNat":
|
||||
## Given
|
||||
|
@ -23,18 +23,16 @@ import
|
||||
../../waku/v2/protocol/waku_relay,
|
||||
../../waku/v2/protocol/waku_peer_exchange,
|
||||
../../waku/v2/utils/peers,
|
||||
./testlib/testutils,
|
||||
../test_helpers
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
procSuite "WakuNode":
|
||||
let rng = crypto.newRng()
|
||||
suite "WakuNode":
|
||||
|
||||
asyncTest "Protocol matcher works as expected":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(61000))
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(61002))
|
||||
pubSubTopic = "/waku/2/default-waku/proto"
|
||||
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
||||
@ -89,9 +87,9 @@ procSuite "WakuNode":
|
||||
resolver.ipResponses[("localhost", false)] = @["127.0.0.1"]
|
||||
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(61020), nameResolver = resolver)
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(61022))
|
||||
|
||||
# Construct DNS multiaddr for node2
|
||||
@ -114,13 +112,13 @@ procSuite "WakuNode":
|
||||
asyncTest "Maximum connections can be configured":
|
||||
let
|
||||
maxConnections = 2
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"),
|
||||
Port(60010), maxConnections = maxConnections)
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"),
|
||||
Port(60012))
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
node3 = WakuNode.new(nodeKey3, ValidIpAddress.init("0.0.0.0"),
|
||||
Port(60013))
|
||||
|
||||
@ -153,7 +151,7 @@ procSuite "WakuNode":
|
||||
|
||||
asyncTest "Messages fails with wrong key path":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
|
||||
expect IOError:
|
||||
# gibberish
|
||||
@ -165,7 +163,7 @@ procSuite "WakuNode":
|
||||
|
||||
asyncTest "Peer info updates with correct announced addresses":
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey = generateSecp256k1Key()
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
bindPort = Port(61006)
|
||||
extIp = some(ValidIpAddress.init("127.0.0.1"))
|
||||
@ -204,7 +202,7 @@ procSuite "WakuNode":
|
||||
|
||||
asyncTest "Node can use dns4 in announced addresses":
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey = generateSecp256k1Key()
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
bindPort = Port(61010)
|
||||
extIp = some(ValidIpAddress.init("127.0.0.1"))
|
||||
@ -231,12 +229,12 @@ procSuite "WakuNode":
|
||||
expectedAgentString2 = "nim-libp2p/0.0.1"
|
||||
let
|
||||
# node with custom agent string
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(61014),
|
||||
agentString = some(expectedAgentString1))
|
||||
|
||||
# node with default agent string from libp2p
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(61016))
|
||||
|
||||
await node1.start()
|
||||
@ -266,12 +264,12 @@ procSuite "WakuNode":
|
||||
# have two nodes to check that the multiaddress is advertised correctly
|
||||
let
|
||||
# node with custom multiaddress
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(61018),
|
||||
extMultiAddrs = @[expectedMultiaddress1])
|
||||
|
||||
# node with default multiaddress
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(61020))
|
||||
|
||||
await node1.start()
|
||||
@ -292,8 +290,8 @@ procSuite "WakuNode":
|
||||
|
||||
asyncTest "Function fetchPeerExchangePeers succesfully exchanges px peers":
|
||||
let
|
||||
node1 = WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node2 = WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node1 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
node2 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0))
|
||||
|
||||
# Start and mount peer exchange
|
||||
await allFutures([node1.start(), node2.start()])
|
||||
|
@ -1,33 +1,33 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
stew/shims/net as stewNet,
|
||||
stew/shims/net as stewNet,
|
||||
testutils/unittests,
|
||||
chronicles,
|
||||
chronos,
|
||||
chronos,
|
||||
libp2p/crypto/crypto
|
||||
import
|
||||
../../waku/v2/node/peer_manager,
|
||||
../../waku/v2/node/waku_node,
|
||||
../../waku/v2/protocol/waku_message,
|
||||
../../waku/v2/utils/peers,
|
||||
./testlib/common
|
||||
./testlib/common,
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
suite "WakuNode - Filter":
|
||||
|
||||
|
||||
asyncTest "subscriber should receive the message handled by the publisher":
|
||||
## Setup
|
||||
let rng = crypto.newRng()
|
||||
let
|
||||
serverKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
serverKey = generateSecp256k1Key()
|
||||
server = WakuNode.new(serverKey, ValidIpAddress.init("0.0.0.0"), Port(60110))
|
||||
clientKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
clientKey = generateSecp256k1Key()
|
||||
client = WakuNode.new(clientKey, ValidIpAddress.init("0.0.0.0"), Port(60111))
|
||||
|
||||
await allFutures(server.start(), client.start())
|
||||
|
||||
await server.mountFilter()
|
||||
await server.mountFilter()
|
||||
await client.mountFilterClient()
|
||||
|
||||
## Given
|
||||
|
@ -1,10 +1,10 @@
|
||||
{.used.}
|
||||
|
||||
import
|
||||
stew/shims/net as stewNet,
|
||||
stew/shims/net as stewNet,
|
||||
testutils/unittests,
|
||||
chronicles,
|
||||
chronos,
|
||||
chronos,
|
||||
libp2p/crypto/crypto,
|
||||
libp2p/switch
|
||||
import
|
||||
@ -13,20 +13,19 @@ import
|
||||
../../waku/v2/node/peer_manager,
|
||||
../../waku/v2/utils/peers,
|
||||
../../waku/v2/node/waku_node,
|
||||
./testlib/common
|
||||
./testlib/common,
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
procSuite "WakuNode - Lightpush":
|
||||
let rng = crypto.newRng()
|
||||
|
||||
asyncTest "Lightpush message return success":
|
||||
## Setup
|
||||
let
|
||||
lightNodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
lightNodeKey = generateSecp256k1Key()
|
||||
lightNode = WakuNode.new(lightNodeKey, ValidIpAddress.init("0.0.0.0"), Port(60010))
|
||||
bridgeNodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
bridgeNodeKey = generateSecp256k1Key()
|
||||
bridgeNode = WakuNode.new(bridgeNodeKey, ValidIpAddress.init("0.0.0.0"), Port(60012))
|
||||
destNodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
destNodeKey = generateSecp256k1Key()
|
||||
destNode = WakuNode.new(destNodeKey, ValidIpAddress.init("0.0.0.0"), Port(60013))
|
||||
|
||||
await allFutures(destNode.start(), bridgeNode.start(), lightNode.start())
|
||||
@ -35,7 +34,7 @@ procSuite "WakuNode - Lightpush":
|
||||
await bridgeNode.mountRelay(@[DefaultPubsubTopic])
|
||||
await bridgeNode.mountLightPush()
|
||||
lightNode.mountLightPushClient()
|
||||
|
||||
|
||||
discard await lightNode.peerManager.dialPeer(bridgeNode.peerInfo.toRemotePeerInfo(), WakuLightPushCodec)
|
||||
await sleepAsync(100.milliseconds)
|
||||
await destNode.connectToNodes(@[bridgeNode.peerInfo.toRemotePeerInfo()])
|
||||
@ -63,4 +62,3 @@ procSuite "WakuNode - Lightpush":
|
||||
|
||||
## Cleanup
|
||||
await allFutures(lightNode.stop(), bridgeNode.stop(), destNode.stop())
|
||||
|
@ -18,7 +18,8 @@ import
|
||||
../../waku/v2/protocol/waku_message,
|
||||
../../waku/v2/protocol/waku_rln_relay,
|
||||
../../waku/v2/protocol/waku_keystore,
|
||||
../../waku/v2/utils/peers
|
||||
../../waku/v2/utils/peers,
|
||||
./testlib/waku2
|
||||
|
||||
from std/times import epochTime
|
||||
|
||||
@ -27,19 +28,17 @@ from std/times import epochTime
|
||||
const RlnRelayPubsubTopic = "waku/2/rlnrelay/proto"
|
||||
|
||||
procSuite "WakuNode - RLN relay":
|
||||
let rng = keys.newRng()
|
||||
|
||||
asyncTest "testing rln-relay with valid proof":
|
||||
|
||||
let
|
||||
# publisher node
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(60300))
|
||||
# Relay node
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(60302))
|
||||
# Subscriber
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
node3 = WakuNode.new(nodeKey3, ValidIpAddress.init("0.0.0.0"), Port(60303))
|
||||
|
||||
rlnRelayPubSubTopic = RlnRelayPubsubTopic
|
||||
@ -117,16 +116,17 @@ procSuite "WakuNode - RLN relay":
|
||||
await node1.stop()
|
||||
await node2.stop()
|
||||
await node3.stop()
|
||||
|
||||
asyncTest "testing rln-relay with invalid proof":
|
||||
let
|
||||
# publisher node
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(60310))
|
||||
# Relay node
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(60312))
|
||||
# Subscriber
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
node3 = WakuNode.new(nodeKey3, ValidIpAddress.init("0.0.0.0"), Port(60313))
|
||||
|
||||
rlnRelayPubSubTopic = RlnRelayPubsubTopic
|
||||
@ -229,13 +229,13 @@ procSuite "WakuNode - RLN relay":
|
||||
|
||||
let
|
||||
# publisher node
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(60320))
|
||||
# Relay node
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(60322))
|
||||
# Subscriber
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
node3 = WakuNode.new(nodeKey3, ValidIpAddress.init("0.0.0.0"), Port(60323))
|
||||
|
||||
rlnRelayPubSubTopic = RlnRelayPubsubTopic
|
||||
|
@ -1,14 +1,12 @@
|
||||
import
|
||||
std/[times, random],
|
||||
stew/byteutils
|
||||
bearssl/rand,
|
||||
libp2p/crypto/crypto
|
||||
import
|
||||
../../../waku/v2/protocol/waku_message,
|
||||
../../../waku/v2/utils/time
|
||||
|
||||
export
|
||||
waku_message.DefaultPubsubTopic,
|
||||
waku_message.DefaultContentTopic
|
||||
|
||||
# Time
|
||||
|
||||
proc now*(): Timestamp =
|
||||
getNanosecondTime(getTime().toUnixFloat())
|
||||
@ -17,31 +15,34 @@ 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
|
||||
)
|
||||
|
||||
|
||||
# Randomization
|
||||
## Randomization
|
||||
|
||||
proc randomize*() =
|
||||
## Initializes the default random number generator with the given seed.
|
||||
## From: https://nim-lang.org/docs/random.html#randomize,int64
|
||||
let now = getTime()
|
||||
randomize(now.toUnix() * 1_000_000_000 + now.nanosecond)
|
||||
|
||||
|
||||
## RNG
|
||||
# Copied from here: https://github.com/status-im/nim-libp2p/blob/d522537b19a532bc4af94fcd146f779c1f23bad0/tests/helpers.nim#L28
|
||||
|
||||
type Rng = object
|
||||
rng: ref HmacDrbgContext
|
||||
|
||||
# Typically having a module variable is considered bad design. This case should
|
||||
# be considered as an exception and it should be used only in the tests.
|
||||
var rngVar: Rng
|
||||
|
||||
proc getRng(): ref HmacDrbgContext =
|
||||
# TODO: if `rngVar` is a threadvar like it should be, there are random and
|
||||
# spurious compile failures on mac - this is not gcsafe but for the
|
||||
# purpose of the tests, it's ok as long as we only use a single thread
|
||||
{.gcsafe.}:
|
||||
if rngVar.rng.isNil():
|
||||
rngVar.rng = crypto.newRng()
|
||||
|
||||
rngVar.rng
|
||||
|
||||
|
||||
template rng*(): ref HmacDrbgContext = getRng()
|
||||
|
@ -1,14 +0,0 @@
|
||||
import
|
||||
std/options,
|
||||
libp2p/switch,
|
||||
libp2p/builders
|
||||
import
|
||||
../../test_helpers
|
||||
|
||||
export switch
|
||||
|
||||
|
||||
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)
|
56
tests/v2/testlib/waku2.nim
Normal file
56
tests/v2/testlib/waku2.nim
Normal file
@ -0,0 +1,56 @@
|
||||
import
|
||||
std/options,
|
||||
stew/byteutils,
|
||||
libp2p/switch,
|
||||
libp2p/builders
|
||||
import
|
||||
../../../waku/v2/protocol/waku_message,
|
||||
./common
|
||||
|
||||
export switch
|
||||
|
||||
|
||||
# Switch
|
||||
|
||||
proc generateEcdsaKey*(): PrivateKey =
|
||||
PrivateKey.random(ECDSA, rng[]).get()
|
||||
|
||||
proc generateEcdsaKeyPair*(): KeyPair =
|
||||
KeyPair.random(ECDSA, rng[]).get()
|
||||
|
||||
proc generateSecp256k1Key*(): PrivateKey =
|
||||
PrivateKey.random(Secp256k1, rng[]).get()
|
||||
|
||||
|
||||
proc newTestSwitch*(key=none(PrivateKey), address=none(MultiAddress)): Switch =
|
||||
let peerKey = key.get(generateSecp256k1Key())
|
||||
let peerAddr = address.get(MultiAddress.init("/ip4/127.0.0.1/tcp/0").get())
|
||||
return newStandardSwitch(some(peerKey), addrs=peerAddr)
|
||||
|
||||
|
||||
# Waku message
|
||||
|
||||
export
|
||||
waku_message.DefaultPubsubTopic,
|
||||
waku_message.DefaultContentTopic
|
||||
|
||||
|
||||
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
|
||||
)
|
@ -1,72 +0,0 @@
|
||||
# compile time options here
|
||||
const
|
||||
libp2p_pubsub_sign {.booldefine.} = true
|
||||
libp2p_pubsub_verify {.booldefine.} = true
|
||||
|
||||
import random
|
||||
import chronos
|
||||
import libp2p/[builders,
|
||||
protocols/pubsub/pubsub,
|
||||
protocols/secure/secure]
|
||||
import ../../waku/v2/protocol/waku_relay
|
||||
|
||||
export builders
|
||||
|
||||
randomize()
|
||||
|
||||
proc generateNodes*(
|
||||
num: Natural,
|
||||
secureManagers: openarray[SecureProtocol] = [
|
||||
# array cos order matters
|
||||
SecureProtocol.Secio,
|
||||
SecureProtocol.Noise,
|
||||
],
|
||||
msgIdProvider: MsgIdProvider = nil,
|
||||
gossip: bool = false,
|
||||
triggerSelf: bool = false,
|
||||
verifySignature: bool = libp2p_pubsub_verify,
|
||||
sign: bool = libp2p_pubsub_sign): seq[PubSub] =
|
||||
|
||||
for i in 0..<num:
|
||||
let switch = newStandardSwitch(secureManagers = secureManagers)
|
||||
let wakuRelay = WakuRelay.init(
|
||||
switch = switch,
|
||||
triggerSelf = triggerSelf,
|
||||
verifySignature = verifySignature,
|
||||
sign = sign,
|
||||
# XXX unclear why including this causes a compiler error, it is part of WakuRelay type
|
||||
msgIdProvider = msgIdProvider).PubSub
|
||||
|
||||
switch.mount(wakuRelay)
|
||||
result.add(wakuRelay)
|
||||
|
||||
proc subscribeNodes*(nodes: seq[PubSub]) {.async.} =
|
||||
for dialer in nodes:
|
||||
for node in nodes:
|
||||
if dialer.switch.peerInfo.peerId != node.switch.peerInfo.peerId:
|
||||
await dialer.switch.connect(node.switch.peerInfo.peerId, node.switch.peerInfo.addrs)
|
||||
dialer.subscribePeer(node.switch.peerInfo.peerId)
|
||||
|
||||
proc subscribeSparseNodes*(nodes: seq[PubSub], degree: int = 2) {.async.} =
|
||||
if nodes.len < degree:
|
||||
raise (ref CatchableError)(msg: "nodes count needs to be greater or equal to degree!")
|
||||
|
||||
for i, dialer in nodes:
|
||||
if (i mod degree) != 0:
|
||||
continue
|
||||
|
||||
for node in nodes:
|
||||
if dialer.switch.peerInfo.peerId != node.switch.peerInfo.peerId:
|
||||
await dialer.switch.connect(node.switch.peerInfo.peerId, node.switch.peerInfo.addrs)
|
||||
dialer.subscribePeer(node.switch.peerInfo.peerId)
|
||||
|
||||
proc subscribeRandom*(nodes: seq[PubSub]) {.async.} =
|
||||
for dialer in nodes:
|
||||
var dialed: seq[PeerID]
|
||||
while dialed.len < nodes.len - 1:
|
||||
let node = sample(nodes)
|
||||
if node.switch.peerInfo.peerId notin dialed:
|
||||
if dialer.switch.peerInfo.peerId != node.switch.peerInfo.peerId:
|
||||
await dialer.switch.connect(node.switch.peerInfo.peerId, node.switch.peerInfo.addrs)
|
||||
dialer.subscribePeer(node.switch.peerInfo.peerId)
|
||||
dialed.add(node.switch.peerInfo.peerId)
|
@ -8,8 +8,7 @@ import
|
||||
import
|
||||
../../../waku/v2/protocol/waku_message,
|
||||
../../../waku/v2/protocol/waku_archive/driver/queue_driver/index,
|
||||
../../../waku/v2/utils/time,
|
||||
../testlib/common
|
||||
../../../waku/v2/utils/time
|
||||
|
||||
|
||||
## Helpers
|
||||
|
@ -10,7 +10,8 @@ import
|
||||
../../../waku/v2/protocol/waku_archive/driver/queue_driver/index,
|
||||
../../../waku/v2/protocol/waku_message,
|
||||
../../../waku/v2/utils/time,
|
||||
../testlib/common
|
||||
../testlib/common,
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
proc getTestQueueDriver(numMessages: int): QueueDriver =
|
||||
|
@ -9,8 +9,8 @@ import
|
||||
../../../waku/v2/protocol/waku_archive,
|
||||
../../../waku/v2/protocol/waku_archive/driver/queue_driver,
|
||||
../../../waku/v2/protocol/waku_message,
|
||||
../utils,
|
||||
../testlib/common
|
||||
../testlib/common,
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
logScope:
|
||||
|
@ -9,8 +9,8 @@ import
|
||||
../../../waku/v2/protocol/waku_archive,
|
||||
../../../waku/v2/protocol/waku_archive/driver/sqlite_driver,
|
||||
../../../waku/v2/protocol/waku_message,
|
||||
../utils,
|
||||
../testlib/common
|
||||
../testlib/common,
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
proc newTestDatabase(): SqliteDatabase =
|
||||
|
@ -10,8 +10,8 @@ import
|
||||
../../../waku/v2/protocol/waku_archive,
|
||||
../../../waku/v2/protocol/waku_archive/driver/sqlite_driver,
|
||||
../../../waku/v2/protocol/waku_message,
|
||||
../utils,
|
||||
../testlib/common
|
||||
../testlib/common,
|
||||
../testlib/waku2
|
||||
|
||||
logScope:
|
||||
topics = "test archive _driver"
|
||||
|
@ -13,8 +13,8 @@ import
|
||||
../../../waku/v2/protocol/waku_archive/retention_policy/retention_policy_capacity,
|
||||
../../../waku/v2/protocol/waku_message,
|
||||
../../../waku/v2/utils/time,
|
||||
../utils,
|
||||
../testlib/common
|
||||
../testlib/common,
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
proc newTestDatabase(): SqliteDatabase =
|
||||
|
@ -11,7 +11,8 @@ import
|
||||
../../../waku/v2/protocol/waku_archive/driver/sqlite_driver,
|
||||
../../../waku/v2/protocol/waku_archive,
|
||||
../../../waku/v2/utils/time,
|
||||
../testlib/common
|
||||
../testlib/common,
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
proc newTestDatabase(): SqliteDatabase =
|
||||
|
@ -13,8 +13,8 @@ import
|
||||
../../../waku/v2/node/peer_manager,
|
||||
../../../waku/v2/protocol/waku_message,
|
||||
../../../waku/v2/protocol/waku_relay,
|
||||
../testlib/switch,
|
||||
../testlib/common
|
||||
../testlib/common,
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
proc noopRawHandler(): PubsubRawHandler =
|
||||
|
@ -21,20 +21,18 @@ import
|
||||
../../waku/v2/utils/peers,
|
||||
../../waku/v2/node/waku_node,
|
||||
../../waku/v2/protocol/waku_relay,
|
||||
../../test_helpers,
|
||||
../testlib/common,
|
||||
../testlib/testutils
|
||||
../testlib/testutils,
|
||||
../testlib/waku2
|
||||
|
||||
template sourceDir: string = currentSourcePath.parentDir()
|
||||
const KEY_PATH = sourceDir / "resources/test_key.pem"
|
||||
const CERT_PATH = sourceDir / "resources/test_cert.pem"
|
||||
|
||||
procSuite "WakuNode - Relay":
|
||||
let rng = crypto.newRng()
|
||||
suite "WakuNode - Relay":
|
||||
|
||||
asyncTest "Relay protocol is started correctly":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(60400))
|
||||
|
||||
# Relay protocol starts if mounted after node start
|
||||
@ -48,7 +46,7 @@ procSuite "WakuNode - Relay":
|
||||
# Relay protocol starts if mounted before node start
|
||||
|
||||
let
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(60402))
|
||||
|
||||
await node2.mountRelay()
|
||||
@ -67,11 +65,11 @@ procSuite "WakuNode - Relay":
|
||||
|
||||
asyncTest "Messages are correctly relayed":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(60410))
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(60412))
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
node3 = WakuNode.new(nodeKey3, ValidIpAddress.init("0.0.0.0"), Port(60413))
|
||||
pubSubTopic = "test"
|
||||
contentTopic = ContentTopic("/waku/2/default-content/proto")
|
||||
@ -125,13 +123,13 @@ procSuite "WakuNode - Relay":
|
||||
|
||||
let
|
||||
# publisher node
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(60420))
|
||||
# Relay node
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(60422))
|
||||
# Subscriber
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
node3 = WakuNode.new(nodeKey3, ValidIpAddress.init("0.0.0.0"), Port(60423))
|
||||
|
||||
pubSubTopic = "test"
|
||||
@ -216,7 +214,7 @@ procSuite "WakuNode - Relay":
|
||||
# TODO: Add a function to validate the WakuMessage integrity
|
||||
xasyncTest "Stats of peer sending wrong WakuMessages are updated":
|
||||
# Create 2 nodes
|
||||
let nodes = toSeq(0..1).mapIt(WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
let nodes = toSeq(0..1).mapIt(WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(0)))
|
||||
|
||||
# Start all the nodes and mount relay with
|
||||
await allFutures(nodes.mapIt(it.start()))
|
||||
@ -247,10 +245,10 @@ procSuite "WakuNode - Relay":
|
||||
|
||||
asyncTest "Messages are relayed between two websocket nodes":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"),
|
||||
bindPort = Port(60510), wsBindPort = Port(8001), wsEnabled = true)
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"),
|
||||
bindPort = Port(60512), wsBindPort = Port(8101), wsEnabled = true)
|
||||
pubSubTopic = "test"
|
||||
@ -291,10 +289,10 @@ procSuite "WakuNode - Relay":
|
||||
|
||||
asyncTest "Messages are relayed between nodes with multiple transports (TCP and Websockets)":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"),
|
||||
bindPort = Port(60520), wsBindPort = Port(8002), wsEnabled = true)
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"),
|
||||
bindPort = Port(60522))
|
||||
pubSubTopic = "test"
|
||||
@ -335,10 +333,10 @@ procSuite "WakuNode - Relay":
|
||||
|
||||
asyncTest "Messages relaying fails with non-overlapping transports (TCP or Websockets)":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"),
|
||||
bindPort = Port(60530))
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"),
|
||||
bindPort = Port(60532), wsBindPort = Port(8103), wsEnabled = true)
|
||||
pubSubTopic = "test"
|
||||
@ -382,10 +380,10 @@ procSuite "WakuNode - Relay":
|
||||
|
||||
asyncTest "Messages are relayed between nodes with multiple transports (TCP and secure Websockets)":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"),
|
||||
bindPort = Port(60540), wsBindPort = Port(8004), wssEnabled = true, secureKey = KEY_PATH, secureCert = CERT_PATH)
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"),
|
||||
bindPort = Port(60542))
|
||||
pubSubTopic = "test"
|
||||
@ -425,9 +423,9 @@ procSuite "WakuNode - Relay":
|
||||
|
||||
asyncTest "Messages are relayed between nodes with multiple transports (websocket and secure Websockets)":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), bindPort = Port(60550), wsBindPort = Port(8005), wssEnabled = true, secureKey = KEY_PATH, secureCert = CERT_PATH)
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), bindPort = Port(60552),wsBindPort = Port(8105), wsEnabled = true )
|
||||
|
||||
let
|
||||
|
@ -27,7 +27,6 @@ proc newTestArchiveDriver(): ArchiveDriver =
|
||||
proc newTestWakuStore(switch: Switch, store=newTestMessageStore()): Future[WakuStore] {.async.} =
|
||||
let
|
||||
peerManager = PeerManager.new(switch)
|
||||
rng = crypto.newRng()
|
||||
proto = WakuStore.init(peerManager, rng, store)
|
||||
|
||||
await proto.start()
|
||||
@ -38,7 +37,6 @@ proc newTestWakuStore(switch: Switch, store=newTestMessageStore()): Future[WakuS
|
||||
proc newTestWakuStoreClient(switch: Switch, store: MessageStore = nil): WakuStoreClient =
|
||||
let
|
||||
peerManager = PeerManager.new(switch)
|
||||
rng = crypto.newRng()
|
||||
WakuStoreClient.new(peerManager, rng, store)
|
||||
|
||||
|
||||
@ -215,9 +213,9 @@ suite "WakuNode - waku store":
|
||||
asyncTest "Resume proc fetches the history":
|
||||
## Setup
|
||||
let
|
||||
serverKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
serverKey = generateSecp256k1Key()
|
||||
server = WakuNode.new(serverKey, ValidIpAddress.init("0.0.0.0"), Port(60412))
|
||||
clientKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
clientKey = generateSecp256k1Key()
|
||||
client = WakuNode.new(clientKey, ValidIpAddress.init("0.0.0.0"), Port(60410))
|
||||
|
||||
await allFutures(client.start(), server.start())
|
||||
@ -249,9 +247,9 @@ suite "WakuNode - waku store":
|
||||
asyncTest "Resume proc discards duplicate messages":
|
||||
## Setup
|
||||
let
|
||||
serverKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
serverKey = generateSecp256k1Key()
|
||||
server = WakuNode.new(serverKey, ValidIpAddress.init("0.0.0.0"), Port(60422))
|
||||
clientKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
clientKey = generateSecp256k1Key()
|
||||
client = WakuNode.new(clientKey, ValidIpAddress.init("0.0.0.0"), Port(60420))
|
||||
|
||||
await allFutures(server.start(), client.start())
|
||||
|
@ -9,7 +9,9 @@ import
|
||||
../../../waku/v2/protocol/waku_store/rpc,
|
||||
../../../waku/v2/protocol/waku_store/rpc_codec,
|
||||
../../../waku/v2/utils/time,
|
||||
../testlib/common
|
||||
../testlib/common,
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
|
||||
procSuite "Waku Store - RPC codec":
|
||||
|
@ -12,14 +12,13 @@ import
|
||||
../../../waku/v2/protocol/waku_store,
|
||||
../../../waku/v2/protocol/waku_store/client,
|
||||
../testlib/common,
|
||||
../testlib/switch
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
|
||||
proc newTestWakuStore(switch: Switch, handler: HistoryQueryHandler): Future[WakuStore] {.async.} =
|
||||
let
|
||||
peerManager = PeerManager.new(switch)
|
||||
rng = crypto.newRng()
|
||||
proto = WakuStore.new(peerManager, rng, handler)
|
||||
|
||||
await proto.start()
|
||||
@ -30,7 +29,6 @@ proc newTestWakuStore(switch: Switch, handler: HistoryQueryHandler): Future[Waku
|
||||
proc newTestWakuStoreClient(switch: Switch): WakuStoreClient =
|
||||
let
|
||||
peerManager = PeerManager.new(switch)
|
||||
rng = crypto.newRng()
|
||||
WakuStoreClient.new(peerManager, rng)
|
||||
|
||||
|
||||
|
@ -22,7 +22,8 @@ import
|
||||
../../../waku/v2/protocol/waku_filter,
|
||||
../../../waku/v2/utils/peers,
|
||||
../../../waku/v2/node/waku_node,
|
||||
../testlib/common
|
||||
../testlib/common,
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
proc newTestArchiveDriver(): ArchiveDriver =
|
||||
@ -39,8 +40,6 @@ proc computeTestCursor(pubsubTopic: PubsubTopic, message: WakuMessage): HistoryC
|
||||
|
||||
procSuite "WakuNode - Store":
|
||||
## Fixtures
|
||||
let rng = crypto.newRng()
|
||||
|
||||
let timeOrigin = now()
|
||||
let msgListA = @[
|
||||
fakeWakuMessage(@[byte 00], ts=ts(00, timeOrigin)),
|
||||
@ -67,9 +66,9 @@ procSuite "WakuNode - Store":
|
||||
asyncTest "Store protocol returns expected messages":
|
||||
## Setup
|
||||
let
|
||||
serverKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
serverKey = generateSecp256k1Key()
|
||||
server = WakuNode.new(serverKey, ValidIpAddress.init("0.0.0.0"), Port(60422))
|
||||
clientKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
clientKey = generateSecp256k1Key()
|
||||
client = WakuNode.new(clientKey, ValidIpAddress.init("0.0.0.0"), Port(60420))
|
||||
|
||||
await allFutures(client.start(), server.start())
|
||||
@ -99,9 +98,9 @@ procSuite "WakuNode - Store":
|
||||
asyncTest "Store node history response - forward pagination":
|
||||
## Setup
|
||||
let
|
||||
serverKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
serverKey = generateSecp256k1Key()
|
||||
server = WakuNode.new(serverKey, ValidIpAddress.init("0.0.0.0"), Port(60432))
|
||||
clientKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
clientKey = generateSecp256k1Key()
|
||||
client = WakuNode.new(clientKey, ValidIpAddress.init("0.0.0.0"), Port(60430))
|
||||
|
||||
await allFutures(client.start(), server.start())
|
||||
@ -148,9 +147,9 @@ procSuite "WakuNode - Store":
|
||||
asyncTest "Store node history response - backward pagination":
|
||||
## Setup
|
||||
let
|
||||
serverKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
serverKey = generateSecp256k1Key()
|
||||
server = WakuNode.new(serverKey, ValidIpAddress.init("0.0.0.0"), Port(60432))
|
||||
clientKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
clientKey = generateSecp256k1Key()
|
||||
client = WakuNode.new(clientKey, ValidIpAddress.init("0.0.0.0"), Port(60430))
|
||||
|
||||
await allFutures(client.start(), server.start())
|
||||
@ -198,11 +197,11 @@ procSuite "WakuNode - Store":
|
||||
## See nwaku issue #937: 'Store: ability to decouple store from relay'
|
||||
## Setup
|
||||
let
|
||||
filterSourceKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
filterSourceKey = generateSecp256k1Key()
|
||||
filterSource = WakuNode.new(filterSourceKey, ValidIpAddress.init("0.0.0.0"), Port(60404))
|
||||
serverKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
serverKey = generateSecp256k1Key()
|
||||
server = WakuNode.new(serverKey, ValidIpAddress.init("0.0.0.0"), Port(60402))
|
||||
clientKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
clientKey = generateSecp256k1Key()
|
||||
client = WakuNode.new(clientKey, ValidIpAddress.init("0.0.0.0"), Port(60400))
|
||||
|
||||
await allFutures(client.start(), server.start(), filterSource.start())
|
||||
|
@ -20,24 +20,20 @@ import
|
||||
../../../waku/v2/protocol/waku_store,
|
||||
../../../waku/v2/protocol/waku_filter,
|
||||
../../../waku/v2/utils/peers,
|
||||
../../test_helpers
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
procSuite "Waku v2 JSON-RPC API - Admin":
|
||||
let
|
||||
rng = crypto.newRng()
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
|
||||
asyncTest "connect to ad-hoc peers":
|
||||
# Create a couple of nodes
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node1 = WakuNode.new(nodeKey1, ValidIpAddress.init("0.0.0.0"), Port(60600))
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node2 = WakuNode.new(nodeKey2, ValidIpAddress.init("0.0.0.0"), Port(60602))
|
||||
node1 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(60600))
|
||||
node2 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(60602))
|
||||
peerInfo2 = node2.switch.peerInfo
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node3 = WakuNode.new(nodeKey3, ValidIpAddress.init("0.0.0.0"), Port(60604))
|
||||
node3 = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(60604))
|
||||
peerInfo3 = node3.switch.peerInfo
|
||||
|
||||
await allFutures([node1.start(), node2.start(), node3.start()])
|
||||
@ -93,7 +89,7 @@ procSuite "Waku v2 JSON-RPC API - Admin":
|
||||
|
||||
asyncTest "get managed peer information":
|
||||
# Create 3 nodes and start them with relay
|
||||
let nodes = toSeq(0..<3).mapIt(WakuNode.new(generateKey(), ValidIpAddress.init("0.0.0.0"), Port(60220+it*2)))
|
||||
let nodes = toSeq(0..<3).mapIt(WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(60220+it*2)))
|
||||
await allFutures(nodes.mapIt(it.start()))
|
||||
await allFutures(nodes.mapIt(it.mountRelay()))
|
||||
|
||||
@ -140,9 +136,7 @@ procSuite "Waku v2 JSON-RPC API - Admin":
|
||||
await allFutures(nodes.mapIt(it.stop()))
|
||||
|
||||
asyncTest "get unmanaged peer information":
|
||||
let
|
||||
nodeKey = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
node = WakuNode.new(nodeKey, ValidIpAddress.init("0.0.0.0"), Port(60523))
|
||||
let node = WakuNode.new(generateSecp256k1Key(), ValidIpAddress.init("0.0.0.0"), Port(60523))
|
||||
|
||||
await node.start()
|
||||
|
||||
@ -170,11 +164,8 @@ procSuite "Waku v2 JSON-RPC API - Admin":
|
||||
let
|
||||
locationAddr = MultiAddress.init("/ip4/127.0.0.1/tcp/0").tryGet()
|
||||
|
||||
filterKey = crypto.PrivateKey.random(ECDSA, rng[]).get()
|
||||
filterPeer = PeerInfo.new(filterKey, @[locationAddr])
|
||||
|
||||
storeKey = crypto.PrivateKey.random(ECDSA, rng[]).get()
|
||||
storePeer = PeerInfo.new(storeKey, @[locationAddr])
|
||||
filterPeer = PeerInfo.new(generateEcdsaKey(), @[locationAddr])
|
||||
storePeer = PeerInfo.new(generateEcdsaKey(), @[locationAddr])
|
||||
|
||||
node.setStorePeer(storePeer.toRemotePeerInfo())
|
||||
node.setFilterPeer(filterPeer.toRemotePeerInfo())
|
||||
|
@ -13,13 +13,13 @@ import
|
||||
../../../waku/v2/node/peer_manager,
|
||||
../../../waku/v2/node/waku_node,
|
||||
../../../waku/v2/node/jsonrpc/debug/handlers as debug_api,
|
||||
../../../waku/v2/node/jsonrpc/debug/client as debug_api_client
|
||||
../../../waku/v2/node/jsonrpc/debug/client as debug_api_client,
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
procSuite "Waku v2 JSON-RPC API - Debug":
|
||||
let
|
||||
rng = crypto.newRng()
|
||||
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
||||
privkey = generateSecp256k1Key()
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
extIp = ValidIpAddress.init("127.0.0.1")
|
||||
port = Port(9000)
|
||||
|
@ -17,7 +17,8 @@ import
|
||||
../../../waku/v2/protocol/waku_message,
|
||||
../../../waku/v2/protocol/waku_filter/rpc,
|
||||
../../../waku/v2/protocol/waku_filter/client,
|
||||
../../../waku/v2/utils/peers
|
||||
../../../waku/v2/utils/peers,
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
proc newTestMessageCache(): filter_api.MessageCache =
|
||||
@ -26,14 +27,13 @@ proc newTestMessageCache(): filter_api.MessageCache =
|
||||
|
||||
procSuite "Waku v2 JSON-RPC API - Filter":
|
||||
let
|
||||
rng = crypto.newRng()
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
|
||||
asyncTest "subscribe and unsubscribe":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, bindIp, Port(60390))
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, bindIp, Port(60392))
|
||||
|
||||
await allFutures(node1.start(), node2.start())
|
||||
|
@ -19,7 +19,8 @@ import
|
||||
../../../waku/v2/protocol/waku_relay,
|
||||
../../../waku/v2/utils/compat,
|
||||
../../../waku/v2/utils/peers,
|
||||
../../../waku/v2/utils/time
|
||||
../../../waku/v2/utils/time,
|
||||
../testlib/waku2
|
||||
|
||||
|
||||
proc newTestMessageCache(): relay_api.MessageCache =
|
||||
@ -28,8 +29,7 @@ proc newTestMessageCache(): relay_api.MessageCache =
|
||||
|
||||
procSuite "Waku v2 JSON-RPC API - Relay":
|
||||
let
|
||||
rng = crypto.newRng()
|
||||
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
||||
privkey = generateSecp256k1Key()
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
extIp = ValidIpAddress.init("127.0.0.1")
|
||||
port = Port(9000)
|
||||
@ -87,11 +87,11 @@ procSuite "Waku v2 JSON-RPC API - Relay":
|
||||
|
||||
asyncTest "get latest messages":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, bindIp, Port(60300))
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, bindIp, Port(60302))
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
node3 = WakuNode.new(nodeKey3, bindIp, Port(60303), some(extIp), some(port))
|
||||
pubSubTopic = "polling"
|
||||
contentTopic = DefaultContentTopic
|
||||
@ -178,11 +178,11 @@ procSuite "Waku v2 JSON-RPC API - Relay":
|
||||
|
||||
asyncTest "generate asymmetric keys and encrypt/decrypt communication":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, bindIp, Port(62001))
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, bindIp, Port(62002))
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
node3 = WakuNode.new(nodeKey3, bindIp, Port(62003), some(extIp), some(port))
|
||||
pubSubTopic = "polling"
|
||||
contentTopic = DefaultContentTopic
|
||||
@ -269,11 +269,11 @@ procSuite "Waku v2 JSON-RPC API - Relay":
|
||||
|
||||
asyncTest "generate symmetric keys and encrypt/decrypt communication":
|
||||
let
|
||||
nodeKey1 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey1 = generateSecp256k1Key()
|
||||
node1 = WakuNode.new(nodeKey1, bindIp, Port(62100))
|
||||
nodeKey2 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey2 = generateSecp256k1Key()
|
||||
node2 = WakuNode.new(nodeKey2, bindIp, Port(62102))
|
||||
nodeKey3 = crypto.PrivateKey.random(Secp256k1, rng[])[]
|
||||
nodeKey3 = generateSecp256k1Key()
|
||||
node3 = WakuNode.new(nodeKey3, bindIp, Port(62103), some(extIp), some(port))
|
||||
pubSubTopic = "polling"
|
||||
contentTopic = DefaultContentTopic
|
||||
|
@ -19,7 +19,8 @@ import
|
||||
../../../waku/v2/protocol/waku_store/rpc,
|
||||
../../../waku/v2/utils/peers,
|
||||
../../../waku/v2/utils/time,
|
||||
../../v2/testlib/common
|
||||
../../v2/testlib/common,
|
||||
../../v2/testlib/waku2
|
||||
|
||||
|
||||
proc put(store: ArchiveDriver, pubsubTopic: PubsubTopic, message: WakuMessage): Result[void, string] =
|
||||
@ -32,8 +33,7 @@ proc put(store: ArchiveDriver, pubsubTopic: PubsubTopic, message: WakuMessage):
|
||||
|
||||
procSuite "Waku v2 JSON-RPC API - Store":
|
||||
let
|
||||
rng = crypto.newRng()
|
||||
privkey = crypto.PrivateKey.random(Secp256k1, rng[]).tryGet()
|
||||
privkey = generateSecp256k1Key()
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
extIp = ValidIpAddress.init("127.0.0.1")
|
||||
port = Port(9000)
|
||||
@ -55,7 +55,7 @@ procSuite "Waku v2 JSON-RPC API - Store":
|
||||
|
||||
# WakuStore setup
|
||||
let
|
||||
key = crypto.PrivateKey.random(ECDSA, rng[]).get()
|
||||
key = generateEcdsaKey()
|
||||
peer = PeerInfo.new(key)
|
||||
|
||||
let driver: ArchiveDriver = QueueDriver.new()
|
||||
|
Loading…
x
Reference in New Issue
Block a user