Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit d6acbc3

Browse files
committedFeb 23, 2022
refactor sqlthread and add create test cases
1 parent 3b5c239 commit d6acbc3

28 files changed

+913
-548
lines changed
 

‎setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def run(self):
5151
if __name__ == "__main__":
5252
here = os.path.abspath(os.path.dirname(__file__))
5353
with open(os.path.join(here, 'README.md')) as f:
54-
README = f.read()
54+
README. = f.read()
5555

5656
with open(os.path.join(here, 'requirements.txt'), 'r') as f:
5757
requirements = list(f.readlines())

‎src/class_sqlThread.py

Lines changed: 341 additions & 519 deletions
Large diffs are not rendered by default.

‎src/sql/config_setting_ver_2.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE pubkeys ADD usedpersonally text DEFAULT 'no';

‎src/sql/config_setting_ver_3.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
ALTER TABLE inbox ADD encodingtype int DEFAULT '2';
2+
3+
ALTER TABLE inbox ADD read bool DEFAULT '1';
4+
5+
ALTER TABLE sent ADD encodingtype int DEFAULT '2';

‎src/sql/init_version_10.sql

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
-- --
2+
-- -- Update the address colunm to unique in addressbook table
3+
-- --
4+
5+
ALTER TABLE addressbook RENAME TO old_addressbook;
6+
7+
CREATE TABLE `addressbook` (
8+
`label` text ,
9+
`address` text ,
10+
UNIQUE(address) ON CONFLICT IGNORE
11+
) ;
12+
13+
INSERT INTO addressbook SELECT label, address FROM old_addressbook;
14+
15+
DROP TABLE old_addressbook;

‎src/sql/init_version_2.sql

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--
2+
-- Let's get rid of the first20bytesofencryptedmessage field in the inventory table.
3+
--
4+
5+
CREATE TEMP TABLE `inventory_backup` (
6+
`hash` blob ,
7+
`objecttype` text ,
8+
`streamnumber` int ,
9+
`payload` blob ,
10+
`receivedtime` int ,
11+
UNIQUE(hash) ON CONFLICT REPLACE
12+
) ;
13+
14+
INSERT INTO `inventory_backup` SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory;
15+
16+
DROP TABLE inventory;
17+
18+
CREATE TABLE `inventory` (
19+
`hash` blob ,
20+
`objecttype` text ,
21+
`streamnumber` int ,
22+
`payload` blob ,
23+
`receivedtime` int ,
24+
UNIQUE(hash) ON CONFLICT REPLACE
25+
) ;
26+
27+
INSERT INTO inventory SELECT hash, objecttype, streamnumber, payload, receivedtime FROM inventory_backup;
28+
29+
DROP TABLE inventory_backup;

‎src/sql/init_version_3.sql

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
--
2+
-- Add a new column to the inventory table to store tags.
3+
--
4+
5+
ALTER TABLE inventory ADD tag blob DEFAULT '';

‎src/sql/init_version_4.sql

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--
2+
-- Add a new column to the pubkeys table to store the address version.
3+
-- We're going to trash all of our pubkeys and let them be redownloaded.
4+
--
5+
6+
DROP TABLE pubkeys;
7+
8+
CREATE TABLE `pubkeys` (
9+
`hash` blob ,
10+
`addressversion` int ,
11+
`transmitdata` blob ,
12+
`time` int ,
13+
`usedpersonally` text ,
14+
UNIQUE(hash, addressversion) ON CONFLICT REPLACE
15+
) ;
16+
17+
DELETE FROM inventory WHERE objecttype = 'pubkey';

‎src/sql/init_version_5.sql

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--
2+
-- Add a new table: objectprocessorqueue with which to hold objects
3+
-- that have yet to be processed if the user shuts down Bitmessage.
4+
--
5+
6+
DROP TABLE knownnodes;
7+
8+
CREATE TABLE `objectprocessorqueue` (
9+
`objecttype` text,
10+
`data` blob,
11+
UNIQUE(objecttype, data) ON CONFLICT REPLACE
12+
) ;

‎src/sql/init_version_6.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
--
2+
-- changes related to protocol v3
3+
-- In table inventory and objectprocessorqueue, objecttype is now
4+
-- an integer (it was a human-friendly string previously)
5+
--
6+
7+
DROP TABLE inventory;
8+
9+
CREATE TABLE `inventory` (
10+
`hash` blob,
11+
`objecttype` int,
12+
`streamnumber` int,
13+
`payload` blob,
14+
`expirestime` integer,
15+
`tag` blob,
16+
UNIQUE(hash) ON CONFLICT REPLACE
17+
) ;
18+
19+
DROP TABLE objectprocessorqueue;
20+
21+
CREATE TABLE `objectprocessorqueue` (
22+
`objecttype` int,
23+
`data` blob,
24+
UNIQUE(objecttype, data) ON CONFLICT REPLACE
25+
) ;

‎src/sql/init_version_7.sql

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--
2+
-- The format of data stored in the pubkeys table has changed. Let's
3+
-- clear it, and the pubkeys from inventory, so that they'll
4+
-- be re-downloaded.
5+
--
6+
7+
DELETE FROM inventory WHERE objecttype = 1;
8+
9+
DELETE FROM pubkeys;
10+
11+
UPDATE sent SET status='msgqueued' WHERE status='doingmsgpow' or status='badkey';

‎src/sql/init_version_8.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
--
2+
-- Add a new column to the inbox table to store the hash of
3+
-- the message signature. We'll use this as temporary message UUID
4+
-- in order to detect duplicates.
5+
--
6+
7+
ALTER TABLE inbox ADD sighash blob DEFAULT '';

‎src/sql/init_version_9.sql

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
CREATE TEMPORARY TABLE `sent_backup` (
2+
`msgid` blob,
3+
`toaddress` text,
4+
`toripe` blob,
5+
`fromaddress` text,
6+
`subject` text,
7+
`message` text,
8+
`ackdata` blob,
9+
`lastactiontime` integer,
10+
`status` text,
11+
`retrynumber` integer,
12+
`folder` text,
13+
`encodingtype` int
14+
) ;
15+
16+
INSERT INTO sent_backup SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, status, 0, folder, encodingtype FROM sent;
17+
18+
DROP TABLE sent;
19+
20+
CREATE TABLE `sent` (
21+
`msgid` blob,
22+
`toaddress` text,
23+
`toripe` blob,
24+
`fromaddress` text,
25+
`subject` text,
26+
`message` text,
27+
`ackdata` blob,
28+
`senttime` integer,
29+
`lastactiontime` integer,
30+
`sleeptill` int,
31+
`status` text,
32+
`retrynumber` integer,
33+
`folder` text,
34+
`encodingtype` int,
35+
`ttl` int
36+
) ;
37+
38+
INSERT INTO sent SELECT msgid, toaddress, toripe, fromaddress, subject, message, ackdata, lastactiontime, lastactiontime, 0, status, 0, folder, encodingtype, 216000 FROM sent_backup;
39+
40+
DROP TABLE sent_backup;
41+
42+
ALTER TABLE pubkeys ADD address text DEFAULT '' ;
43+
44+
--
45+
-- replica for loop to update hashed address
46+
--
47+
48+
UPDATE pubkeys SET address=(enaddr(pubkeys.addressversion, 1, hash));
49+
50+
CREATE TEMPORARY TABLE `pubkeys_backup` (
51+
`address` text,
52+
`addressversion` int,
53+
`transmitdata` blob,
54+
`time` int,
55+
`usedpersonally` text,
56+
UNIQUE(address) ON CONFLICT REPLACE
57+
) ;
58+
59+
INSERT INTO pubkeys_backup SELECT address, addressversion, transmitdata, `time`, usedpersonally FROM pubkeys;
60+
61+
DROP TABLE pubkeys;
62+
63+
CREATE TABLE `pubkeys` (
64+
`address` text,
65+
`addressversion` int,
66+
`transmitdata` blob,
67+
`time` int,
68+
`usedpersonally` text,
69+
UNIQUE(address) ON CONFLICT REPLACE
70+
) ;
71+
72+
INSERT INTO pubkeys SELECT address, addressversion, transmitdata, `time`, usedpersonally FROM pubkeys_backup;
73+
74+
DROP TABLE pubkeys_backup;

‎src/sql/initialize_schema.sql

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
CREATE TABLE `inbox` (
2+
`msgid` blob,
3+
`toaddress` text,
4+
`fromaddress` text,
5+
`subject` text,
6+
`received` text,
7+
`message` text,
8+
`folder` text,
9+
`encodingtype` int,
10+
`read` bool,
11+
`sighash` blob,
12+
UNIQUE(msgid) ON CONFLICT REPLACE
13+
) ;
14+
15+
CREATE TABLE `sent` (
16+
`msgid` blob,
17+
`toaddress` text,
18+
`toripe` blob,
19+
`fromaddress` text,
20+
`subject` text,
21+
`message` text,
22+
`ackdata` blob,
23+
`senttime` integer,
24+
`lastactiontime` integer,
25+
`sleeptill` integer,
26+
`status` text,
27+
`retrynumber` integer,
28+
`folder` text,
29+
`encodingtype` int,
30+
`ttl` int
31+
) ;
32+
33+
34+
CREATE TABLE `subscriptions` (
35+
`label` text,
36+
`address` text,
37+
`enabled` bool
38+
) ;
39+
40+
41+
CREATE TABLE `addressbook` (
42+
`label` text,
43+
`address` text,
44+
UNIQUE(address) ON CONFLICT IGNORE
45+
) ;
46+
47+
48+
CREATE TABLE `blacklist` (
49+
`label` text,
50+
`address` text,
51+
`enabled` bool
52+
) ;
53+
54+
55+
CREATE TABLE `whitelist` (
56+
`label` text,
57+
`address` text,
58+
`enabled` bool
59+
) ;
60+
61+
62+
CREATE TABLE `pubkeys` (
63+
`address` text,
64+
`addressversion` int,
65+
`transmitdata` blob,
66+
`time` int,
67+
`usedpersonally` text,
68+
UNIQUE(address) ON CONFLICT REPLACE
69+
) ;
70+
71+
72+
CREATE TABLE `inventory` (
73+
`hash` blob,
74+
`objecttype` int,
75+
`streamnumber` int,
76+
`payload` blob,
77+
`expirestime` integer,
78+
`tag` blob,
79+
UNIQUE(hash) ON CONFLICT REPLACE
80+
) ;
81+
82+
83+
INSERT INTO subscriptions VALUES ('Bitmessage new releases/announcements', 'BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw', 1);
84+
85+
86+
CREATE TABLE `settings` (
87+
`key` blob,
88+
`value` blob,
89+
UNIQUE(key) ON CONFLICT REPLACE
90+
) ;
91+
92+
INSERT INTO settings VALUES('version','11');
93+
94+
INSERT INTO settings VALUES('lastvacuumtime', CAST(strftime('%s', 'now') AS STR) );
95+
96+
CREATE TABLE `objectprocessorqueue` (
97+
`objecttype` int,
98+
`data` blob,
99+
UNIQUE(objecttype, data) ON CONFLICT REPLACE
100+
) ;
101+
102+
103+

‎src/sql/upg_sc_if_old_ver_1.sql

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
CREATE TEMPORARY TABLE `pubkeys_backup` (
2+
`hash` blob,
3+
`transmitdata` blob,
4+
`time` int,
5+
`usedpersonally` text,
6+
UNIQUE(hash) ON CONFLICT REPLACE
7+
) ;
8+
9+
INSERT INTO `pubkeys_backup` SELECT hash, transmitdata, `time`, usedpersonally FROM `pubkeys`;
10+
11+
DROP TABLE `pubkeys`
12+
13+
CREATE TABLE `pubkeys` (
14+
`hash` blob,
15+
`transmitdata` blob,
16+
`time` int,
17+
`usedpersonally` text,
18+
UNIQUE(hash) ON CONFLICT REPLACE
19+
) ;
20+
21+
22+
INSERT INTO `pubkeys` SELECT hash, transmitdata, `time`, usedpersonally FROM `pubkeys_backup`;
23+
24+
DROP TABLE `pubkeys_backup`;
25+
26+
DELETE FROM inventory WHERE objecttype = 'pubkey';
27+
28+
DELETE FROM subscriptions WHERE address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx'
29+
30+
INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)

‎src/sql/upg_sc_if_old_ver_2.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
UPDATE `sent` SET status='doingmsgpow' WHERE status='doingpow';
2+
3+
UPDATE `sent` SET status='msgsent' WHERE status='sentmessage';
4+
5+
UPDATE `sent` SET status='doingpubkeypow' WHERE status='findingpubkey';
6+
7+
UPDATE `sent` SET status='broadcastqueued' WHERE status='broadcastpending';

‎src/tests/core.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

2424
from bmconfigparser import config
2525
from helper_msgcoding import MsgEncode, MsgDecode
26-
from helper_sql import sqlQuery
26+
from helper_sql import sqlQuery, sqlExecute
2727
from network import asyncore_pollchoose as asyncore, knownnodes
2828
from network.bmproto import BMProto
2929
from network.connectionpool import BMConnectionPool
@@ -409,6 +409,22 @@ def test_adding_two_same_case_sensitive_addresses(self):
409409
self.delete_address_from_addressbook(address1)
410410
self.delete_address_from_addressbook(address2)
411411

412+
def test_sqlscripts(self):
413+
""" Test sql statements"""
414+
415+
sqlExecute('create table if not exists testtbl (id integer)')
416+
tables = list(sqlQuery("select name from sqlite_master where type is 'table'"))
417+
res = [item for item in tables if 'testtbl' in item]
418+
self.assertEqual(res[0][0], 'testtbl')
419+
420+
queryreturn = sqlExecute("INSERT INTO testtbl VALUES(101);")
421+
self.assertEqual(queryreturn, 1)
422+
423+
queryreturn = sqlQuery('''SELECT * FROM testtbl''')
424+
self.assertEqual(queryreturn[0][0], 101)
425+
426+
sqlQuery("DROP TABLE testtbl")
427+
412428

413429
def run():
414430
"""Starts all tests defined in this module"""

‎src/tests/sql/__init__.py

Whitespace-only changes.

‎src/tests/sql/init_version_10.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INSERT INTO `addressbook` VALUES ('test', "BM-2cWzMnxjJ7yRP3nLEWUV5LisTZyREWSxYz"), ('testone', "BM-2cWzMnxjJ7yRP3nLEWUV5LisTZyREWSxYz");

‎src/tests/sql/init_version_2.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INSERT INTO `inventory` VALUES ('hash', 1, 1,1, 1,'test');

‎src/tests/sql/init_version_3.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INSERT INTO `settings` VALUES ('version','3');

‎src/tests/sql/init_version_4.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INSERT INTO `pubkeys` VALUES ('hash', 1, 1, 1,'test');
2+

‎src/tests/sql/init_version_5.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INSERT INTO `objectprocessorqueue` VALUES ('hash', 1);
2+

‎src/tests/sql/init_version_6.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INSERT INTO `inventory` VALUES ('hash', 1, 1, 1,'test','test');
2+

‎src/tests/sql/init_version_7.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
INSERT INTO `sent` VALUES
2+
(1,'BM-2cWzMnxjJ7yRP3nLEWUV5LisTZyREWSxYz',1,'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK','Test1 subject','message test 1','ackdata',1638176409,1638176409,1638176423,'msgqueued',1,'testfolder',1,2),
3+
(2,'BM-2cWzMnxjJ7yRP3nLEWUV5LisTZyREWSxYz',1,'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK','Test2 subject','message test 2','ackdata',1638176423,1638176423,1638176423,'msgqueued',1,'testfolder',1,2);

‎src/tests/sql/init_version_8.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
INSERT INTO `inbox` VALUES (1, "poland", "malasia", "test", "yes", "test message", "folder", 1, 1, 1);

‎src/tests/sql/init_version_9.sql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
INSERT INTO `sent` VALUES
2+
(1,'BM-2cWzMnxjJ7yRP3nLEWUV5LisTZyREWSxYz',1,'BM-2cWzSnwjJ7yRP3nLEWUV5LisTZyREWSzUK','Test1 subject','message test 1','ackdata',1638176409,1638176409,1638176423,'msgqueued',1,'testfolder',1,2);

‎src/tests/test_sqlthread.py

Lines changed: 198 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,214 @@
22
# flake8: noqa:E402
33
import os
44
import tempfile
5-
import threading
65
import unittest
76

8-
from .common import skip_python3
9-
10-
skip_python3()
11-
127
os.environ['BITMESSAGE_HOME'] = tempfile.gettempdir()
138

14-
from pybitmessage.helper_sql import (
15-
sqlQuery, sql_ready, sqlStoredProcedure) # noqa:E402
16-
from pybitmessage.class_sqlThread import sqlThread # noqa:E402
9+
from pybitmessage.class_sqlThread import TestDB # noqa:E402
1710
from pybitmessage.addresses import encodeAddress # noqa:E402
1811

1912

20-
class TestSqlThread(unittest.TestCase):
21-
"""Test case for SQL thread"""
13+
def filter_table_column(schema, column):
14+
"""
15+
Filter column from schema
16+
"""
17+
for x in schema:
18+
for y in x:
19+
if y == column:
20+
yield y
21+
22+
23+
class TestSqlBase(object): # pylint: disable=E1101, too-few-public-methods, E1004, W0232
24+
""" Base for test case """
25+
26+
__name__ = None
27+
root_path = os.path.dirname(os.path.dirname(__file__))
28+
test_db = None
29+
30+
def _setup_db(self): # pylint: disable=W0622, redefined-builtin
31+
"""
32+
Drop all tables before each test case start
33+
"""
34+
self.test_db = TestDB()
35+
self.test_db.create_sql_function()
36+
self.test_db.initialize_schema()
37+
38+
def initialise_database(self, test_db_cur, file): # pylint: disable=W0622, redefined-builtin
39+
"""
40+
Initialise DB
41+
"""
42+
43+
with open(os.path.join(self.root_path, "tests/sql/{}.sql".format(file)), 'r') as sql_as_string:
44+
sql_as_string = sql_as_string.read()
45+
46+
test_db_cur.cur.executescript(sql_as_string)
47+
2248

23-
@classmethod
24-
def setUpClass(cls):
25-
# Start SQL thread
26-
sqlLookup = sqlThread()
27-
sqlLookup.daemon = True
28-
sqlLookup.start()
29-
sql_ready.wait()
49+
class TestFnBitmessageDB(TestSqlBase, unittest.TestCase): # pylint: disable=protected-access
50+
""" Test case for Sql function"""
3051

31-
@classmethod
32-
def tearDownClass(cls):
33-
sqlStoredProcedure('exit')
34-
for thread in threading.enumerate():
35-
if thread.name == "SQL":
36-
thread.join()
52+
def setUp(self):
53+
"""
54+
setup for test case
55+
"""
56+
self._setup_db()
3757

3858
def test_create_function(self):
3959
"""Check the result of enaddr function"""
40-
encoded_str = encodeAddress(4, 1, "21122112211221122112")
60+
st = "21122112211221122112".encode()
61+
encoded_str = encodeAddress(4, 1, st)
62+
63+
item = '''SELECT enaddr(4, 1, ?);'''
64+
parameters = (st, )
65+
self.test_db.cur.execute(item, parameters)
66+
query = self.test_db.cur.fetchall()
67+
self.assertEqual(query[0][-1], encoded_str, "test case fail for create_function")
68+
69+
70+
class TestUpgradeBitmessageDB(TestSqlBase, unittest.TestCase): # pylint: disable=protected-access
71+
"""Test case for SQL versions"""
72+
73+
def setUp(self):
74+
"""
75+
Setup DB schema before start.
76+
And applying default schema for version test.
77+
"""
78+
self._setup_db()
79+
self.test_db.cur.execute('''INSERT INTO settings VALUES('version','2')''')
80+
81+
def version(self):
82+
"""
83+
Run SQL Scripts, Initialize DB with respect to versioning
84+
and Upgrade DB schema for all versions
85+
"""
86+
def wrapper(*args):
87+
"""
88+
Run SQL and mocking DB for versions
89+
"""
90+
self = args[0]
91+
func_name = func.__name__
92+
version = func_name.rsplit('_', 1)[-1]
93+
94+
self.test_db._upgrade_one_level_sql_statement(int(version)) # pylint: disable= W0212, protected-access
95+
96+
# Update versions DB mocking
97+
self.initialise_database(self.test_db, "init_version_{}".format(version))
98+
99+
return func(*args) # <-- use (self, ...)
100+
func = self
101+
return wrapper
102+
103+
@version
104+
def test_bm_db_version_2(self):
105+
"""
106+
Test with version 2
107+
"""
108+
109+
res = self.test_db.cur.execute(''' SELECT count(name) FROM sqlite_master
110+
WHERE type='table' AND name='inventory_backup' ''')
111+
self.assertNotEqual(res, 1, "Table inventory_backup not deleted in versioning 2")
112+
113+
@version
114+
def test_bm_db_version_3(self):
115+
"""
116+
Test with version 1
117+
Version 1 and 3 are same so will skip 3
118+
"""
119+
120+
res = self.test_db.cur.execute('''PRAGMA table_info('inventory');''')
121+
result = list(filter_table_column(res, "tag"))
122+
self.assertEqual(result, ['tag'], "Data not migrated for version 3")
123+
124+
@version
125+
def test_bm_db_version_4(self):
126+
"""
127+
Test with version 4
128+
"""
129+
130+
self.test_db.cur.execute("select * from pubkeys where addressversion = '1';")
131+
res = self.test_db.cur.fetchall()
132+
self.assertEqual(len(res), 1, "Table inventory not deleted in versioning 4")
133+
134+
@version
135+
def test_bm_db_version_5(self):
136+
"""
137+
Test with version 5
138+
"""
139+
140+
self.test_db.cur.execute(''' SELECT count(name) FROM sqlite_master WHERE type='table' AND name='knownnodes' ''') # noqa
141+
res = self.test_db.cur.fetchall()
142+
self.assertNotEqual(res[0][0], 1, "Table knownnodes not deleted in versioning 5")
143+
self.test_db.cur.execute(''' SELECT count(name) FROM sqlite_master
144+
WHERE type='table' AND name='objectprocessorqueue'; ''')
145+
res = self.test_db.cur.fetchall()
146+
self.assertNotEqual(len(res), 0, "Table objectprocessorqueue not created in versioning 5")
147+
self.test_db.cur.execute(''' SELECT * FROM objectprocessorqueue where objecttype='hash' ; ''')
148+
res = self.test_db.cur.fetchall()
149+
self.assertNotEqual(len(res), 0, "Table objectprocessorqueue not created in versioning 5")
150+
151+
@version
152+
def test_bm_db_version_6(self):
153+
"""
154+
Test with version 6
155+
"""
156+
157+
self.test_db.cur.execute('''PRAGMA table_info('inventory');''')
158+
inventory = self.test_db.cur.fetchall()
159+
inventory = list(filter_table_column(inventory, "expirestime"))
160+
self.assertEqual(inventory, ['expirestime'], "Data not migrated for version 6")
161+
162+
self.test_db.cur.execute('''PRAGMA table_info('objectprocessorqueue');''')
163+
objectprocessorqueue = self.test_db.cur.fetchall()
164+
objectprocessorqueue = list(filter_table_column(objectprocessorqueue, "objecttype"))
165+
self.assertEqual(objectprocessorqueue, ['objecttype'], "Data not migrated for version 6")
166+
167+
@version
168+
def test_bm_db_version_7(self):
169+
"""
170+
Test with version 7
171+
"""
172+
173+
self.test_db.cur.execute('''SELECT * FROM pubkeys ''')
174+
pubkeys = self.test_db.cur.fetchall()
175+
self.assertEqual(pubkeys, [], "Data not migrated for version 7")
176+
177+
self.test_db.cur.execute('''SELECT * FROM inventory ''')
178+
inventory = self.test_db.cur.fetchall()
179+
self.assertEqual(inventory, [], "Data not migrated for version 7")
180+
181+
self.test_db.cur.execute('''SELECT status FROM sent ''')
182+
sent = self.test_db.cur.fetchall()
183+
self.assertEqual(sent, [('msgqueued',), ('msgqueued',)], "Data not migrated for version 7")
184+
185+
@version
186+
def test_bm_db_version_8(self):
187+
"""
188+
Test with version 8
189+
"""
190+
191+
self.test_db.cur.execute('''PRAGMA table_info('inbox');''')
192+
res = self.test_db.cur.fetchall()
193+
result = list(filter_table_column(res, "sighash"))
194+
self.assertEqual(result, ['sighash'], "Data not migrated for version 8")
195+
196+
@version
197+
def test_bm_db_version_9(self):
198+
"""
199+
Test with version 9
200+
"""
201+
202+
self.test_db.cur.execute("SELECT count(name) FROM sqlite_master WHERE type='table' AND name='pubkeys_backup'") # noqa
203+
res = self.test_db.cur.fetchall()
204+
self.assertNotEqual(res[0][0], 1, "Table pubkeys_backup not deleted")
205+
206+
@version
207+
def test_bm_db_version_10(self):
208+
"""
209+
Test with version 10
210+
"""
41211

42-
query = sqlQuery('SELECT enaddr(4, 1, "21122112211221122112")')
43-
self.assertEqual(
44-
query[0][-1], encoded_str, "test case fail for create_function")
212+
label = "test"
213+
self.test_db.cur.execute("SELECT * FROM addressbook WHERE label='test' ") # noqa
214+
res = self.test_db.cur.fetchall()
215+
self.assertEqual(res[0][0], label, "Data not migrated for version 10")

0 commit comments

Comments
 (0)
Please sign in to comment.