mirror of
https://github.com/varun-r-mallya/py-libp2p.git
synced 2026-02-09 22:50:54 +00:00
Merge branch 'main' into improve-error-message
This commit is contained in:
@ -3,9 +3,11 @@ from collections.abc import (
|
|||||||
)
|
)
|
||||||
from typing import (
|
from typing import (
|
||||||
Any,
|
Any,
|
||||||
|
cast,
|
||||||
)
|
)
|
||||||
|
|
||||||
import multiaddr
|
import multiaddr
|
||||||
|
from multiaddr.protocols import Protocol
|
||||||
|
|
||||||
from .id import (
|
from .id import (
|
||||||
ID,
|
ID,
|
||||||
@ -42,7 +44,8 @@ def info_from_p2p_addr(addr: multiaddr.Multiaddr) -> PeerInfo:
|
|||||||
p2p_protocols = p2p_part.protocols()
|
p2p_protocols = p2p_part.protocols()
|
||||||
if not p2p_protocols:
|
if not p2p_protocols:
|
||||||
raise InvalidAddrError("The last part of the address has no 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:
|
if last_protocol is None:
|
||||||
raise InvalidAddrError("The last protocol is None")
|
raise InvalidAddrError("The last protocol is None")
|
||||||
|
|
||||||
|
|||||||
1
newsfragments/757.bugfix.rst
Normal file
1
newsfragments/757.bugfix.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
fixed malformed PeerId in test_peerinfo
|
||||||
1
newsfragments/757.internal.rst
Normal file
1
newsfragments/757.internal.rst
Normal file
@ -0,0 +1 @@
|
|||||||
|
fixed a typecheck error using cast in peerinfo.py
|
||||||
@ -13,7 +13,9 @@ from libp2p.peer.peerinfo import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
ALPHABETS = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
|
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_():
|
def test_init_():
|
||||||
@ -50,9 +52,6 @@ def test_info_from_p2p_addr_invalid(addr):
|
|||||||
def test_info_from_p2p_addr_valid():
|
def test_info_from_p2p_addr_valid():
|
||||||
m_addr = multiaddr.Multiaddr(VALID_MULTI_ADDR_STR)
|
m_addr = multiaddr.Multiaddr(VALID_MULTI_ADDR_STR)
|
||||||
info = info_from_p2p_addr(m_addr)
|
info = info_from_p2p_addr(m_addr)
|
||||||
assert (
|
assert info.peer_id.pretty() == "QmWQqHcMi6Cay5M6KWSNVYSDnxzfqWb1aGFQFSRzBNe49t"
|
||||||
info.peer_id.pretty()
|
|
||||||
== "3YgLAeMKSAPcGqZkAt8mREqhQXmJT8SN8VCMN4T6ih4GNX9wvK8mWJnWZ1qA2mLdCQ"
|
|
||||||
)
|
|
||||||
assert len(info.addrs) == 1
|
assert len(info.addrs) == 1
|
||||||
assert str(info.addrs[0]) == "/ip4/127.0.0.1/tcp/8000"
|
assert str(info.addrs[0]) == "/ip4/127.0.0.1/tcp/8000"
|
||||||
|
|||||||
Reference in New Issue
Block a user