implemented test case for sendBroadcast

This commit is contained in:
navjot 2020-09-25 21:47:14 +05:30
parent 1571176082
commit 72fbe124d2
No known key found for this signature in database
GPG Key ID: 9EE70AFD71357F1C

View File

@ -160,14 +160,28 @@ class TestAPI(TestAPIProto):
def test_send_broadcast(self): def test_send_broadcast(self):
"""API command 'sendBroadcast': ensure it returns ackData""" """API command 'sendBroadcast': ensure it returns ackData"""
addr = self._add_random_address('random_2') addr = self._add_random_address('random_2')
ack = self.api.sendBroadcast( msg = base64.encodestring('test message')
addr, base64.encodestring('test_subject'), ackdata = self.api.sendBroadcast(
base64.encodestring('test message') addr, base64.encodestring('test_subject'), msg)
)
try: try:
int(ack, 16) int(ackdata, 16)
status = self.api.getStatus(ackdata)
if status == 'notfound':
raise KeyError
self.assertIn(
status, ('broadcastqueued', 'broadcastsent', 'doingmsgpow'))
for m in json.loads(self.api.getAllSentMessages())['sentMessages']:
if m['ackData'] == ackdata:
sent_msg = m['message']
break
else:
raise KeyError
except ValueError: except ValueError:
self.fail('sendBroadcast returned error or ackData is not hex') self.fail('sendBroadcast returned error or ackData is not hex')
except KeyError:
self.fail('Could not find sent broadcast in sent messages')
else:
self.assertEqual(sent_msg, msg.strip())
finally: finally:
self.assertEqual(self.api.deleteAddress(addr), 'success') self.assertEqual(self.api.deleteAddress(addr), 'success')