imported helper_addressGenerator module

This commit is contained in:
navjot 2021-01-06 12:27:35 +05:30 committed by Muzahid
parent 7825229444
commit 07a1ce9914
Signed by untrusted user: cis-muzahid
GPG Key ID: 1DC85E7D3AB613EA
2 changed files with 13 additions and 23 deletions

View File

@ -47,7 +47,7 @@ class sqlThread(threading.Thread):
self.cur.execute(
'''CREATE TABLE subscriptions (label text, address text, enabled bool)''')
self.cur.execute(
'''CREATE TABLE addressbook (label text, address text, UNIQUE(address) ON CONFLICT REPLACE)''')
'''CREATE TABLE addressbook (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''')
self.cur.execute(
'''CREATE TABLE blacklist (label text, address text, enabled bool)''')
self.cur.execute(
@ -388,9 +388,7 @@ class sqlThread(threading.Thread):
logger.debug(
'In messages.dat database, done adding address field to the pubkeys table'
' and removing the hash field.')
item = '''update settings set value=? WHERE key='version';'''
parameters = (10,)
self.cur.execute(item, parameters)
self.cur.execute('''update settings set value=10 WHERE key='version';''')
# Update the address colunm to unique in addressbook table
item = '''SELECT value FROM settings WHERE key='version';'''
@ -405,9 +403,10 @@ class sqlThread(threading.Thread):
'''ALTER TABLE addressbook RENAME TO old_addressbook''')
self.cur.execute(
'''CREATE TABLE addressbook'''
''' (label text, address text, UNIQUE(address) ON CONFLICT REPLACE)''')
''' (label text, address text, UNIQUE(address) ON CONFLICT IGNORE)''')
self.cur.execute(
'''INSERT INTO addressbook SELECT label, address FROM old_addressbook;''')
self.cur.execute('''DROP TABLE old_addressbook''')
self.cur.execute('''update settings set value=11 WHERE key='version';''')
# Are you hoping to add a new option to the keys.dat file of existing

View File

@ -277,15 +277,7 @@ class TestCore(unittest.TestCase):
cleanup(files=('knownnodes.dat',))
@staticmethod
def generate_random_address():
"""Generating random address"""
import queues
streamNumberForAddress = 1
queues.addressGeneratorQueue.put((
'createRandomAddress', 4, streamNumberForAddress,
"test1", 1, "", False))
def delete_address_from_database(self, address):
def delete_address_from_addressbook(address):
"""Clean up addressbook"""
sqlQuery('''delete from addressbook where address=?''', address)
@ -293,22 +285,21 @@ class TestCore(unittest.TestCase):
"""checking same address is added twice in addressbook"""
self.assertTrue(helper_addressbook.insert(label='test1', address=self.addr))
self.assertFalse(helper_addressbook.insert(label='test1', address=self.addr))
self.delete_address_from_database(self.addr)
self.delete_address_from_addressbook(self.addr)
def test_is_address_present_in_addressbook(self):
"""checking is address added in addressbook or not"""
helper_addressbook.insert(label='test1', address=self.addr)
queryreturn = sqlQuery('''select count(*) from addressbook where address=?''', self.addr)
self.assertTrue(bool(queryreturn[0][0]))
self.delete_address_from_database(self.addr)
self.assertEqual(queryreturn[0][0], 1)
self.delete_address_from_addressbook(self.addr)
def test_is_own_address_add_to_addressbook(self):
"""Checking own address adding in addressbook"""
self.generate_random_address()
time.sleep(.5)
from helper_addressGenerator import createAddressIfNeeded
try:
all_addresses = BMConfigParser().addresses()
self.assertFalse(helper_addressbook.insert(label='test', address=all_addresses[0]))
address = createAddressIfNeeded('test1')
self.assertFalse(helper_addressbook.insert(label='test', address=address))
except IndexError:
self.fail("Can't generate addresses")
@ -318,8 +309,8 @@ class TestCore(unittest.TestCase):
address2 = 'BM-2CvwTDuZpWf7ungdRzFTwUhwIj6XXbPIsp'
self.assertTrue(helper_addressbook.insert(label='test1', address=address1))
self.assertTrue(helper_addressbook.insert(label='test2', address=address2))
self.delete_address_from_database(address1)
self.delete_address_from_database(address2)
self.delete_address_from_addressbook(address1)
self.delete_address_from_addressbook(address2)
def run():