Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Couple of changes to tests to support python3 #1749

Closed
wants to merge 2 commits into from
Closed
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
48 changes: 35 additions & 13 deletions src/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ def test_shutdown(self):

class TestAPI(TestAPIProto):
"""Main API test case"""
_seed = base64.encodestring(
'TIGER, tiger, burning bright. In the forests of the night'
)
try:
_seed = base64.encodestring(
'TIGER, tiger, burning bright. In the forests of the night'
)
except TypeError:
_seed = base64.encodestring(
b'TIGER, tiger, burning bright. In the forests of the night'
)


def _add_random_address(self, label):
return self.api.createRandomAddress(base64.encodestring(label))
Expand Down Expand Up @@ -172,10 +178,16 @@ def test_addressbook(self):
[]
)
# Add known address
self.api.addAddressBookEntry(
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK',
base64.encodestring('tiger_4')
)
try:
self.api.addAddressBookEntry(
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK',
base64.encodestring('tiger_4')
)
except TypeError:
self.api.addAddressBookEntry(
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK',
base64.encodestring(b'tiger_4')
)
# Check addressbook entry
entries = json.loads(
self.api.listAddressBookEntries()).get('addresses')[0]
Expand Down Expand Up @@ -216,8 +228,12 @@ def test_send(self):
"""Test message sending"""
# self.api.createDeterministicAddresses(self._seed, 1, 4)
addr = self._add_random_address('random_2')
msg = base64.encodestring('test message')
msg_subject = base64.encodestring('test_subject')
try:
msg = base64.encodestring('test message')
msg_subject = base64.encodestring('test_subject')
except TypeError:
msg = base64.encodestring(b'test message')
msg_subject = base64.encodestring(b'test_subject')
ackdata = self.api.sendMessage(
'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK', addr, msg_subject, msg)
try:
Expand Down Expand Up @@ -274,10 +290,16 @@ def test_send(self):

def test_send_broadcast(self):
"""Test broadcast sending"""
addr = self._add_random_address('random_2')
msg = base64.encodestring('test broadcast')
ackdata = self.api.sendBroadcast(
addr, base64.encodestring('test_subject'), msg)
try:
addr = self._add_random_address('random_2')
msg = base64.encodestring('test broadcast')
ackdata = self.api.sendBroadcast(
addr, base64.encodestring('test_subject'), msg)
except TypeError:
addr = self._add_random_address(b'random_2')
msg = base64.encodestring(b'test broadcast')
ackdata = self.api.sendBroadcast(
addr, base64.encodestring(b'test_subject'), msg)
try:
int(ackdata, 16)
status = self.api.getStatus(ackdata)
Expand Down
3 changes: 2 additions & 1 deletion src/tests/test_crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ class TestCrypto(RIPEMD160TestCase, unittest.TestCase):
"""RIPEMD160 test case for Crypto"""
@staticmethod
def _hashdigest(data):
return RIPEMD.RIPEMD160Hash(data).digest()
from pybitmessage.fallback import RIPEMD160Hash
return RIPEMD160Hash(data).digest()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You didn't get it. This part of the test should use pycrypto or pycryptodome, not fallback. Because it's the test for fallback itself.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment stating this would've been helpful.



class TestAddresses(unittest.TestCase):
Expand Down