mirror of
https://github.com/waku-org/nwaku.git
synced 2025-02-27 14:31:01 +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[])[]
|
||||
|
@ -4,13 +4,14 @@ import
|
||||
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,7 +7,8 @@ import
|
||||
import
|
||||
../../waku/v2/protocol/waku_message,
|
||||
../../waku/v2/node/message_cache,
|
||||
./testlib/common
|
||||
./testlib/common,
|
||||
./testlib/waku2
|
||||
|
||||
|
||||
type TestMessageCache = MessageCache[(PubsubTopic, ContentTopic)]
|
||||
|
@ -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,7 +7,7 @@ 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":
|
||||
@ -19,7 +19,7 @@ suite "Peer Storage":
|
||||
|
||||
# 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())
|
||||
|
@ -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()
|
||||
privkey = generateSecp256k1Key()
|
||||
bindIp = ValidIpAddress.init("0.0.0.0")
|
||||
extIp = ValidIpAddress.init("127.0.0.1")
|
||||
port = Port(9000)
|
||||
|
@ -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)
|
||||
|
@ -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,9 +14,10 @@ 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
|
||||
@ -24,13 +25,13 @@ procSuite "Waku DNS Discovery":
|
||||
# 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
|
||||
|
||||
@ -44,7 +45,7 @@ procSuite "Waku DNS Discovery":
|
||||
@[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:
|
||||
@ -65,7 +66,7 @@ procSuite "Waku DNS Discovery":
|
||||
# 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()
|
||||
|
@ -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()
|
||||
|
@ -15,22 +15,21 @@ import
|
||||
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:
|
||||
|
@ -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)
|
||||
@ -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)
|
||||
|
@ -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
|
||||
@ -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 = [
|
||||
%*{
|
||||
|
@ -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)
|
||||
|
||||
|
||||
|
@ -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()])
|
||||
|
@ -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()
|
||||
|
||||
|
@ -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
|
||||
@ -385,7 +384,7 @@ procSuite "Waku-rln-relay":
|
||||
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()
|
||||
|
||||
@ -453,7 +452,7 @@ procSuite "Waku-rln-relay":
|
||||
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()
|
||||
|
||||
@ -568,12 +567,12 @@ 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()
|
||||
|
||||
|
@ -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()])
|
||||
|
@ -11,18 +11,18 @@ import
|
||||
../../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())
|
||||
|
@ -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())
|
||||
@ -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