import unittest, chronos, sequtils, chronicles, tables, stint, nimcrypto, eth/[keys, rlp], eth/p2p/enode, eth/trie/db, eth/p2p/discoveryv5/[discovery_db, enr, node, types, routing_table, encoding], eth/p2p/discoveryv5/protocol as discv5_protocol, ./p2p_test_helper proc initDiscoveryNode*(privKey: PrivateKey, address: Address, bootstrapRecords: openarray[Record] = []): discv5_protocol.Protocol = var db = DiscoveryDB.init(newMemoryDB()) result = newProtocol(privKey, db, some(parseIpAddress("127.0.0.1")), address.tcpPort, address.udpPort, bootstrapRecords = bootstrapRecords) result.open() proc nodeIdInNodes(id: NodeId, nodes: openarray[Node]): bool = for n in nodes: if id == n.id: return true # Creating a random packet with specific nodeid each time proc randomPacket(tag: PacketTag): seq[byte] = var authTag: AuthTag msg: array[44, byte] require randomBytes(authTag) == authTag.len require randomBytes(msg) == msg.len result.add(tag) result.add(rlp.encode(authTag)) result.add(msg) proc generateNode(privKey = PrivateKey.random()[], port: int = 20302): Node = let port = Port(port) let enr = enr.Record.init(1, privKey, some(parseIpAddress("127.0.0.1")), port, port).expect("Properly intialized private key") result = newNode(enr) proc nodeAtDistance(n: Node, d: uint32): Node = while true: let node = generateNode() if logDist(n.id, node.id) == d: return node proc nodesAtDistance(n: Node, d: uint32, amount: int): seq[Node] = for i in 0..