Merge pull request #166 from libp2p/peer-id

Full-length Peer ID
This commit is contained in:
stuckinaboot 2019-05-22 12:58:45 -04:00 committed by GitHub
commit b001256f5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 7 deletions

View File

@ -27,9 +27,7 @@ class ID:
def __str__(self):
pid = self.pretty()
if len(pid) <= 10:
return "<peer.ID %s>" % pid
return "<peer.ID %s*%s>" % (pid[:2], pid[len(pid)-6:])
return pid
__repr__ = __str__

View File

@ -36,7 +36,7 @@ def test_str_less_than_10():
for _ in range(5):
random_id_string += random.SystemRandom().choice(ALPHABETS)
pid = base58.b58encode(random_id_string).decode()
expected = "<peer.ID " + pid + ">"
expected = pid
actual = ID(random_id_string).__str__()
assert actual == expected
@ -46,9 +46,7 @@ def test_str_more_than_10():
for _ in range(10):
random_id_string += random.SystemRandom().choice(ALPHABETS)
pid = base58.b58encode(random_id_string).decode()
part_1, part_2 = pid[:2], pid[len(pid)-6:]
expected = "<peer.ID " + part_1 + "*" + part_2 + ">"
expected = pid
actual = ID(random_id_string).__str__()
assert actual == expected