Merge branch 'api' into testing

This commit is contained in:
Dmitri Bogomolov 2021-12-15 22:21:19 +02:00
commit 1f7ab287fd
Signed by untrusted user: g1itch
GPG Key ID: 720A756F18DEED13
3 changed files with 29 additions and 28 deletions

View File

@ -1119,10 +1119,8 @@ class BMRPCDispatcher(object):
toAddress = addBMIfNotPresent(toAddress) toAddress = addBMIfNotPresent(toAddress)
fromAddress = addBMIfNotPresent(fromAddress) fromAddress = addBMIfNotPresent(fromAddress)
self._verifyAddress(fromAddress) self._verifyAddress(fromAddress)
try: fromAddressEnabled = self.config.safeGetBoolean(fromAddress, 'enabled')
fromAddressEnabled = self.config.getboolean( if fromAddressEnabled is None:
fromAddress, 'enabled')
except BaseException:
raise APIError( raise APIError(
13, 'Could not find your fromAddress in the keys.dat file.') 13, 'Could not find your fromAddress in the keys.dat file.')
if not fromAddressEnabled: if not fromAddressEnabled:
@ -1165,9 +1163,7 @@ class BMRPCDispatcher(object):
TTL = 28 * 24 * 60 * 60 TTL = 28 * 24 * 60 * 60
fromAddress = addBMIfNotPresent(fromAddress) fromAddress = addBMIfNotPresent(fromAddress)
self._verifyAddress(fromAddress) self._verifyAddress(fromAddress)
try: if not self.config.safeGetBoolean(fromAddress, 'enabled'):
self.config.getboolean(fromAddress, 'enabled')
except BaseException:
raise APIError( raise APIError(
13, 'Could not find your fromAddress in the keys.dat file.') 13, 'Could not find your fromAddress in the keys.dat file.')
toAddress = str_broadcast_subscribers toAddress = str_broadcast_subscribers

View File

@ -26,7 +26,8 @@ sample_ripe = b'003cd097eb7f35c87b5dc8b4538c22cb55312a9f'
# stream: 1, version: 2 # stream: 1, version: 2
sample_address = 'BM-onkVu1KKL2UaUss5Upg9vXmqd3esTmV79' sample_address = 'BM-onkVu1KKL2UaUss5Upg9vXmqd3esTmV79'
sample_factor = 66858749573256452658262553961707680376751171096153613379801854825275240965733 sample_factor = \
66858749573256452658262553961707680376751171096153613379801854825275240965733
# G * sample_factor # G * sample_factor
sample_point = ( sample_point = (
33567437183004486938355437500683826356288335339807546987348409590129959362313, 33567437183004486938355437500683826356288335339807546987348409590129959362313,
@ -47,7 +48,7 @@ sample_inbox_msg_ids = [
'27e644765a3e4b2e973ee7ccf958ea20', '51fc5531-3989-4d69-bbb5-68d64b756f5b', '27e644765a3e4b2e973ee7ccf958ea20', '51fc5531-3989-4d69-bbb5-68d64b756f5b',
'2c975c515f8b414db5eea60ba57ba455', 'bc1f2d8a-681c-4cc0-9a12-6067c7e1ac24'] '2c975c515f8b414db5eea60ba57ba455', 'bc1f2d8a-681c-4cc0-9a12-6067c7e1ac24']
# second address in sample_subscription_addresses # second address in sample_subscription_addresses
# is for the announcement broadcast # is for the announcement broadcast, but is it matter?
sample_subscription_addresses = [ sample_subscription_addresses = [
'BM-2cWQLCBGorT9pUGkYSuGGVr9LzE4mRnQaq', 'BM-2cWQLCBGorT9pUGkYSuGGVr9LzE4mRnQaq',
'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw'] 'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw']

View File

@ -12,10 +12,9 @@ from six.moves import xmlrpc_client # nosec
import psutil import psutil
from .samples import ( from .samples import (
sample_seed, sample_deterministic_addr3, sample_deterministic_addr4, sample_deterministic_addr3, sample_deterministic_addr4, sample_seed,
sample_statusbar_msg, sample_inbox_msg_ids, sample_subscription_addresses, sample_inbox_msg_ids, sample_statusbar_msg, sample_subscription_name,
sample_subscription_name sample_subscription_addresses)
)
from .test_process import TestProcessProto from .test_process import TestProcessProto
@ -116,19 +115,22 @@ class TestAPI(TestAPIProto):
) )
self.assertEqual( self.assertEqual(
len(json.loads( len(json.loads(
self.api.getInboxMessageById(hexlify(sample_inbox_msg_ids[2])))["inboxMessage"]), self.api.getInboxMessageById(
hexlify(sample_inbox_msg_ids[2])))["inboxMessage"]),
1 1
) )
self.assertEqual( self.assertEqual(
len(json.loads( len(json.loads(
self.api.getInboxMessagesByReceiver(sample_deterministic_addr4))["inboxMessages"]), self.api.getInboxMessagesByReceiver(
sample_deterministic_addr4))["inboxMessages"]),
4 4
) )
def test_message_trash(self): def test_message_trash(self):
"""Test message inbox methods""" """Test message inbox methods"""
messages_before_delete = len(json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"]) messages_before_delete = len(
json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"])
self.assertEqual( self.assertEqual(
self.api.trashMessage(hexlify(sample_inbox_msg_ids[0])), self.api.trashMessage(hexlify(sample_inbox_msg_ids[0])),
'Trashed message (assuming message existed).' 'Trashed message (assuming message existed).'
@ -138,8 +140,8 @@ class TestAPI(TestAPIProto):
'Trashed inbox message (assuming message existed).' 'Trashed inbox message (assuming message existed).'
) )
self.assertEqual( self.assertEqual(
len(json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"]), messages_before_delete - 2,
messages_before_delete - 2 len(json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"])
) )
self.assertEqual( self.assertEqual(
self.api.undeleteMessage(hexlify(sample_inbox_msg_ids[0])), self.api.undeleteMessage(hexlify(sample_inbox_msg_ids[0])),
@ -150,8 +152,8 @@ class TestAPI(TestAPIProto):
'Undeleted message' 'Undeleted message'
) )
self.assertEqual( self.assertEqual(
len(json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"]), messages_before_delete,
messages_before_delete len(json.loads(self.api.getAllInboxMessageIds())["inboxMessageIds"])
) )
def test_clientstatus_consistency(self): def test_clientstatus_consistency(self):
@ -278,6 +280,9 @@ class TestAPI(TestAPIProto):
# special address, added when sqlThread starts # special address, added when sqlThread starts
if sub['address'] == sample_subscription_addresses[0]: if sub['address'] == sample_subscription_addresses[0]:
added_subscription = sub added_subscription = sub
self.assertEqual(
base64.decodestring(sub['label']), sample_subscription_name)
self.assertTrue(sub['enabled'])
break break
self.assertEqual( self.assertEqual(
@ -309,7 +314,6 @@ class TestAPI(TestAPIProto):
def test_send(self): def test_send(self):
"""Test message sending""" """Test message sending"""
# self.api.createDeterministicAddresses(self._seed, 1, 4)
addr = self._add_random_address('random_2') addr = self._add_random_address('random_2')
msg = base64.encodestring('test message') msg = base64.encodestring('test message')
msg_subject = base64.encodestring('test_subject') msg_subject = base64.encodestring('test_subject')
@ -334,13 +338,6 @@ class TestAPI(TestAPIProto):
break break
else: else:
raise KeyError raise KeyError
# Find the message in inbox
# for m in json.loads(
# self.api.getInboxMessagesByReceiver(
# 'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK'))['inboxMessages']:
# if m['subject'] == msg_subject:
# inbox_msg = m['message']
# break
except ValueError: except ValueError:
self.fail('sendMessage returned error or ackData is not hex') self.fail('sendMessage returned error or ackData is not hex')
except KeyError: except KeyError:
@ -424,6 +421,13 @@ class TestAPI(TestAPIProto):
finally: finally:
self.assertEqual(self.api.deleteAddress(addr), 'success') self.assertEqual(self.api.deleteAddress(addr), 'success')
# sending from an address without private key
# (Bitmessage new releases/announcements)
result = self.api.sendBroadcast(
'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',
base64.encodestring('test_subject'), msg)
self.assertRegexpMatches(result, r'^API Error 0013:')
def test_chan(self): def test_chan(self):
"""Testing chan creation/joining""" """Testing chan creation/joining"""
# Create chan with known address # Create chan with known address