Skip to content

Commit 719246c

Browse files
authored
Merge pull request #764 from acul71/fix/issue-757-test-peerinfo-valid-cid
fix: added valid CID and fix typecheck
2 parents 5fcfc67 + e013e80 commit 719246c

File tree

4 files changed

+10
-6
lines changed

4 files changed

+10
-6
lines changed

libp2p/peer/peerinfo.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
)
44
from typing import (
55
Any,
6+
cast,
67
)
78

89
import multiaddr
10+
from multiaddr.protocols import Protocol
911

1012
from .id import (
1113
ID,
@@ -42,7 +44,8 @@ def info_from_p2p_addr(addr: multiaddr.Multiaddr) -> PeerInfo:
4244
p2p_protocols = p2p_part.protocols()
4345
if not p2p_protocols:
4446
raise InvalidAddrError("The last part of the address has no protocols")
45-
last_protocol = p2p_protocols[0]
47+
last_protocol = cast(Protocol, p2p_part.protocols()[0])
48+
4649
if last_protocol is None:
4750
raise InvalidAddrError("The last protocol is None")
4851

newsfragments/757.bugfix.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fixed malformed PeerId in test_peerinfo

newsfragments/757.internal.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fixed a typecheck error using cast in peerinfo.py

tests/core/peer/test_peerinfo.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
)
1414

1515
ALPHABETS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
16-
VALID_MULTI_ADDR_STR = "/ip4/127.0.0.1/tcp/8000/p2p/3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ" # noqa: E501
16+
VALID_MULTI_ADDR_STR = (
17+
"/ip4/127.0.0.1/tcp/8000/p2p/QmWQqHcMi6Cay5M6KWSNVYSDnxzfqWb1aGFQFSRzBNe49t"
18+
)
1719

1820

1921
def test_init_():
@@ -50,9 +52,6 @@ def test_info_from_p2p_addr_invalid(addr):
5052
def test_info_from_p2p_addr_valid():
5153
m_addr = multiaddr.Multiaddr(VALID_MULTI_ADDR_STR)
5254
info = info_from_p2p_addr(m_addr)
53-
assert (
54-
info.peer_id.pretty()
55-
== "3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ"
56-
)
55+
assert info.peer_id.pretty() == "QmWQqHcMi6Cay5M6KWSNVYSDnxzfqWb1aGFQFSRzBNe49t"
5756
assert len(info.addrs) == 1
5857
assert str(info.addrs[0]) == "/ip4/127.0.0.1/tcp/8000"

0 commit comments

Comments
 (0)