Skip to content

Commit

Permalink
Merge pull request #1256 from qstokkink/fix_mock_ipv6addr_gen
Browse files Browse the repository at this point in the history
Fixed mock IPv6 address generation
  • Loading branch information
qstokkink authored Jan 10, 2024
2 parents b8edffe + d2d31ee commit d51ea1e
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit d51ea1e

Please sign in to comment.