Skip to content
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: 4 additions & 1 deletion libp2p/peer/peerinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
)
from typing import (
Any,
cast,
)

import multiaddr
from multiaddr.protocols import Protocol

from .id import (
ID,
Expand Down Expand Up @@ -42,7 +44,8 @@ def info_from_p2p_addr(addr: multiaddr.Multiaddr) -> PeerInfo:
p2p_protocols = p2p_part.protocols()
if not p2p_protocols:
raise InvalidAddrError("The last part of the address has no protocols")
last_protocol = p2p_protocols[0]
last_protocol = cast(Protocol, p2p_part.protocols()[0])

if last_protocol is None:
raise InvalidAddrError("The last protocol is None")

Expand Down
1 change: 1 addition & 0 deletions newsfragments/757.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixed malformed PeerId in test_peerinfo
1 change: 1 addition & 0 deletions newsfragments/757.internal.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fixed a typecheck error using cast in peerinfo.py
9 changes: 4 additions & 5 deletions tests/core/peer/test_peerinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
)

ALPHABETS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
VALID_MULTI_ADDR_STR = "/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ" # noqa: E501
VALID_MULTI_ADDR_STR = (
"/ip4/127.0.0.1/tcp/8000/p2p/QmWQqHcMi6Cay5M6KWSNVYSDnxzfqWb1aGFQFSRzBNe49t"
)


def test_init_():
Expand Down Expand Up @@ -50,9 +52,6 @@ def test_info_from_p2p_addr_invalid(addr):
def test_info_from_p2p_addr_valid():
m_addr = multiaddr.Multiaddr(VALID_MULTI_ADDR_STR)
info = info_from_p2p_addr(m_addr)
assert (
info.peer_id.pretty()
== "3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ"
)
assert info.peer_id.pretty() == "QmWQqHcMi6Cay5M6KWSNVYSDnxzfqWb1aGFQFSRzBNe49t"
assert len(info.addrs) == 1
assert str(info.addrs[0]) == "/ip4/127.0.0.1/tcp/8000"