def test_upgrade_sqlcipher_v3_to_v4_with_dbinfo(data_dir): sqlcipher_version = detect_sqlcipher_version() if sqlcipher_version != 4: # nothing to test return username = '******' userdata_dir = os.path.join(data_dir, username) os.mkdir(userdata_dir) # get the v3 database file and copy it into the user's data directory dir_path = os.path.dirname(os.path.realpath(__file__)) copyfile( os.path.join(os.path.dirname(dir_path), 'data', 'sqlcipher_v3_rotkehlchen.db'), os.path.join(userdata_dir, 'rotkehlchen.db'), ) dbinfo = { 'sqlcipher_version': 3, 'md5_hash': '20c910c28ca42370e4a5f24d6d4a73d2' } with open(os.path.join(userdata_dir, DBINFO_FILENAME), 'w') as f: f.write(rlk_jsondumps(dbinfo)) # the constructor should migrate it in-place and we should have a working DB msg_aggregator = MessagesAggregator() db = DBHandler(userdata_dir, '123', msg_aggregator) assert db.get_version() == ROTKEHLCHEN_DB_VERSION
def test_sqlcipher_detect_version(): class QueryMock(): def __init__(self, version): self.version = version def fetchall(self): return [[self.version]] class ConnectionMock(): def __init__(self, version): self.version = version def execute(self, command): # pylint: disable=unused-argument return QueryMock(self.version) def close(self): pass with patch('pysqlcipher3.dbapi2.connect') as sql_mock: sql_mock.return_value = ConnectionMock('4.0.0 community') assert detect_sqlcipher_version() == 4 sql_mock.return_value = ConnectionMock('4.0.1 something') assert detect_sqlcipher_version() == 4 sql_mock.return_value = ConnectionMock('4.9.12 somethingelse') assert detect_sqlcipher_version() == 4 sql_mock.return_value = ConnectionMock('5.10.13 somethingelse') assert detect_sqlcipher_version() == 5 sql_mock.return_value = ConnectionMock('3.1.15 somethingelse') assert detect_sqlcipher_version() == 3 with pytest.raises(ValueError): sql_mock.return_value = ConnectionMock('no version') detect_sqlcipher_version()
def test_upgrade_sqlcipher_v3_to_v4_without_dbinfo(user_data_dir): """Test that we can upgrade from an sqlcipher v3 to v4 rotkehlchen database Issue: https://github.com/rotki/rotki/issues/229 """ sqlcipher_version = detect_sqlcipher_version() if sqlcipher_version != 4: # nothing to test return # get the v3 database file and copy it into the user's data directory dir_path = os.path.dirname(os.path.realpath(__file__)) copyfile( os.path.join(os.path.dirname(dir_path), 'data', 'sqlcipher_v3_rotkehlchen.db'), user_data_dir / 'rotkehlchen.db', ) # the constructor should migrate it in-place and we should have a working DB msg_aggregator = MessagesAggregator() db = DBHandler(user_data_dir, '123', msg_aggregator, None) assert db.get_version() == ROTKEHLCHEN_DB_VERSION
def test_upgrade_sqlcipher_v3_to_v4_without_dbinfo(data_dir): """Test that we can upgrade from an sqlcipher v3 to v4 rotkehlchen database Issue: https://github.com/rotkehlchenio/rotkehlchen/issues/229 """ sqlcipher_version = detect_sqlcipher_version() if sqlcipher_version != 4: # nothing to test return username = '******' userdata_dir = os.path.join(data_dir, username) os.mkdir(userdata_dir) # get the v3 database file and copy it into the user's data directory dir_path = os.path.dirname(os.path.realpath(__file__)) copyfile( os.path.join(dir_path, 'data', 'sqlcipher_v3_rotkehlchen.db'), os.path.join(userdata_dir, 'rotkehlchen.db'), ) # the constructor should migrate it in-place and we should have a working DB db = DBHandler(userdata_dir, '123') assert db.get_version() == ROTKEHLCHEN_DB_VERSION