Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed mock IPv6 address generation #1256

Merged
merged 2 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/pr-comment-validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ jobs:
python-version: ${{ matrix.version }}
- run: python -m pip install -r requirements.txt
- run: python run_all_tests.py -a
env:
TEST_IPV8_WITH_IPV6: 0
- run: python run_all_tests.py -a
env:
TEST_IPV8_WITH_IPV6: 1
6 changes: 5 additions & 1 deletion ipv8/test/mocking/endpoint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import ipaddress
import os
import random
from asyncio import get_running_loop
Expand Down Expand Up @@ -173,7 +174,10 @@ def _generate_address(self) -> UDPv4Address | UDPv6Address:
b7 = random.randint(0, 65535)
port = random.randint(0, 65535)

return UDPv6Address(f"{b0:02x}:{b1:02x}:{b2:02x}:{b3:02x}:{b4:02x}:{b5:02x}:{b6:02x}:{b7:02x}", port)
exploded_ip = f"{b0:02x}:{b1:02x}:{b2:02x}:{b3:02x}:{b4:02x}:{b5:02x}:{b6:02x}:{b7:02x}"
# Our tests assume that the valid (exploded) ip is formatted using `ip_address`.
# You will get random failures if you fail to normalize (see https://github.com/Tribler/py-ipv8/issues/1243).
return UDPv6Address(str(ipaddress.ip_address(exploded_ip)), port)

def _is_lan(self, address: Address) -> bool:
"""
Expand Down