missing asyncio and change unittest (#24)
* missing asyincio * - change unittest twisted using builtin unittest - fix bytes parameter in hashlib
This commit is contained in:
parent
125abe7415
commit
55594096d1
@ -1,4 +1,5 @@
|
||||
import random
|
||||
import asyncio
|
||||
from logging import getLogger
|
||||
|
||||
from rpcudp.protocol import RPCProtocol
|
||||
|
@ -1,7 +1,7 @@
|
||||
import unittest
|
||||
import random
|
||||
import hashlib
|
||||
|
||||
from twisted.trial import unittest
|
||||
|
||||
from kademlia.node import Node, NodeHeap
|
||||
from kademlia.tests.utils import mknode
|
||||
@ -9,15 +9,15 @@ from kademlia.tests.utils import mknode
|
||||
|
||||
class NodeTest(unittest.TestCase):
|
||||
def test_longID(self):
|
||||
rid = hashlib.sha1(str(random.getrandbits(255))).digest()
|
||||
rid = hashlib.sha1(str(random.getrandbits(255)).encode()).digest()
|
||||
n = Node(rid)
|
||||
self.assertEqual(n.long_id, long(rid.encode('hex'), 16))
|
||||
self.assertEqual(n.long_id, int(rid.hex(), 16))
|
||||
|
||||
def test_distanceCalculation(self):
|
||||
ridone = hashlib.sha1(str(random.getrandbits(255)))
|
||||
ridtwo = hashlib.sha1(str(random.getrandbits(255)))
|
||||
ridone = hashlib.sha1(str(random.getrandbits(255)).encode())
|
||||
ridtwo = hashlib.sha1(str(random.getrandbits(255)).encode())
|
||||
|
||||
shouldbe = long(ridone.hexdigest(), 16) ^ long(ridtwo.hexdigest(), 16)
|
||||
shouldbe = int(ridone.hexdigest(), 16) ^ int(ridtwo.hexdigest(), 16)
|
||||
none = Node(ridone.digest())
|
||||
ntwo = Node(ridtwo.digest())
|
||||
self.assertEqual(none.distanceTo(ntwo), shouldbe)
|
||||
|
@ -1,4 +1,4 @@
|
||||
from twisted.trial import unittest
|
||||
import unittest
|
||||
|
||||
from kademlia.routing import KBucket
|
||||
from kademlia.tests.utils import mknode, FakeProtocol
|
||||
|
@ -1,16 +1,15 @@
|
||||
import hashlib
|
||||
|
||||
from twisted.trial import unittest
|
||||
import unittest
|
||||
|
||||
from kademlia.utils import digest, sharedPrefix, OrderedSet
|
||||
|
||||
|
||||
class UtilsTest(unittest.TestCase):
|
||||
def test_digest(self):
|
||||
d = hashlib.sha1('1').digest()
|
||||
d = hashlib.sha1(b'1').digest()
|
||||
self.assertEqual(d, digest(1))
|
||||
|
||||
d = hashlib.sha1('another').digest()
|
||||
d = hashlib.sha1(b'another').digest()
|
||||
self.assertEqual(d, digest('another'))
|
||||
|
||||
def test_sharedPrefix(self):
|
||||
|
@ -15,7 +15,7 @@ def mknode(id=None, ip=None, port=None, intid=None):
|
||||
"""
|
||||
if intid is not None:
|
||||
id = pack('>l', intid)
|
||||
id = id or hashlib.sha1(str(random.getrandbits(255))).digest()
|
||||
id = id or hashlib.sha1(str(random.getrandbits(255)).encode()).digest()
|
||||
return Node(id, ip, port)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user