mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
feat: Add neighbours_max_ipv4 test (#836)
This commit is contained in:
@ -93,6 +93,7 @@ const MAX_NODES_PING: usize = 2 * MAX_NODES_PER_BUCKET;
|
||||
/// fit in one datagram. The safe number of nodes that always fit in a datagram is 12, with worst
|
||||
/// case all of them being IPv6 nodes. This is calculated by `(MAX_PACKET_SIZE - (header + expire +
|
||||
/// rlp overhead) / size(rlp(Node_IPv6))`
|
||||
/// Even in the best case where all nodes are IPv4, only 14 nodes fit into one packet.
|
||||
const SAFE_MAX_DATAGRAM_NEIGHBOUR_RECORDS: usize = (MAX_PACKET_SIZE - 109) / 91;
|
||||
|
||||
/// The timeout used to identify expired nodes, 24h
|
||||
|
||||
@ -563,6 +563,20 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn neighbours_max_ipv4() {
|
||||
let mut rng = thread_rng();
|
||||
let msg = Message::Neighbours(Neighbours {
|
||||
nodes: std::iter::repeat_with(|| rng_ipv4_record(&mut rng)).take(16).collect(),
|
||||
expire: rng.gen(),
|
||||
});
|
||||
let (secret_key, _) = SECP256K1.generate_keypair(&mut rng);
|
||||
|
||||
let (encoded, _) = msg.encode(&secret_key);
|
||||
// Assret that 16 nodes never fit into one packet
|
||||
assert!(encoded.len() > MAX_PACKET_SIZE, "{} {msg:?}", encoded.len());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn neighbours_max_nodes() {
|
||||
let mut rng = thread_rng();
|
||||
|
||||
Reference in New Issue
Block a user