def _init_database( data_dir: Path, password: str, msg_aggregator: MessagesAggregator, db_settings: Optional[Dict[str, Any]], ignored_assets: Optional[List[Asset]], blockchain_accounts: BlockchainAccounts, include_etherscan_key: bool, include_cryptocompare_key: bool, tags: List[Dict[str, Any]], manually_tracked_balances: List[ManuallyTrackedBalance], data_migration_version: int, use_custom_database: Optional[str], ) -> DBHandler: if use_custom_database is not None: _use_prepared_db(data_dir, use_custom_database) db = DBHandler( user_data_dir=data_dir, password=password, msg_aggregator=msg_aggregator, initial_settings=None, ) # Make sure that the fixture provided data are included in the DB add_settings_to_test_db(db, db_settings, ignored_assets, data_migration_version) add_blockchain_accounts_to_db(db, blockchain_accounts) maybe_include_etherscan_key(db, include_etherscan_key) maybe_include_cryptocompare_key(db, include_cryptocompare_key) add_tags_to_test_db(db, tags) add_manually_tracked_balances_to_test_db(db, manually_tracked_balances) return db
def initialize_mock_rotkehlchen_instance( rotki, start_with_logged_in_user, start_with_valid_premium, db_password, rotki_premium_credentials, username, blockchain_accounts, owned_eth_tokens, include_etherscan_key, include_cryptocompare_key, should_mock_price_queries, mocked_price_queries, ethereum_modules, db_settings, ignored_assets, tags, manually_tracked_balances, default_mock_price_value, ): if start_with_logged_in_user: rotki.unlock_user( user=username, password=db_password, create_new=True, sync_approval='no', premium_credentials=None, given_ethereum_modules=ethereum_modules, ) if start_with_valid_premium: rotki.premium = Premium(rotki_premium_credentials) rotki.premium_sync_manager.premium = rotki.premium # After unlocking when all objects are created we need to also include # customized fixtures that may have been set by the tests rotki.chain_manager.owned_eth_tokens = owned_eth_tokens rotki.chain_manager.accounts = blockchain_accounts add_settings_to_test_db(rotki.data.db, db_settings, ignored_assets) maybe_include_etherscan_key(rotki.data.db, include_etherscan_key) maybe_include_cryptocompare_key(rotki.data.db, include_cryptocompare_key) add_blockchain_accounts_to_db(rotki.data.db, blockchain_accounts) add_tags_to_test_db(rotki.data.db, tags) add_manually_tracked_balances_to_test_db(rotki.data.db, manually_tracked_balances) maybe_mock_historical_price_queries( historian=PriceHistorian(), should_mock_price_queries=should_mock_price_queries, mocked_price_queries=mocked_price_queries, default_mock_value=default_mock_price_value, )
def _init_database( data_dir: FilePath, password: str, msg_aggregator: MessagesAggregator, db_settings: Optional[Dict[str, Any]], ignored_assets: Optional[List[Asset]], blockchain_accounts: BlockchainAccounts, include_etherscan_key: bool, include_cryptocompare_key: bool, tags: List[Dict[str, Any]], manually_tracked_balances: List[ManuallyTrackedBalance], ) -> DBHandler: db = DBHandler(data_dir, password, msg_aggregator) # Make sure that the fixture provided data are included in the DB add_settings_to_test_db(db, db_settings, ignored_assets) add_blockchain_accounts_to_db(db, blockchain_accounts) maybe_include_etherscan_key(db, include_etherscan_key) maybe_include_cryptocompare_key(db, include_cryptocompare_key) add_tags_to_test_db(db, tags) add_manually_tracked_balances_to_test_db(db, manually_tracked_balances) return db
def initialize_mock_rotkehlchen_instance( rotki, start_with_logged_in_user, start_with_valid_premium, db_password, rotki_premium_credentials, username, blockchain_accounts, include_etherscan_key, include_cryptocompare_key, should_mock_price_queries, mocked_price_queries, ethereum_modules, db_settings, ignored_assets, tags, manually_tracked_balances, default_mock_price_value, ethereum_manager_connect_at_start, kusama_manager_connect_at_start, eth_rpc_endpoint, ksm_rpc_endpoint, aave_use_graph, max_tasks_num, ): if not start_with_logged_in_user: return # Mock the initial get settings to include the specified ethereum modules def mock_get_settings() -> DBSettings: settings = DBSettings( active_modules=ethereum_modules, eth_rpc_endpoint=eth_rpc_endpoint, ksm_rpc_endpoint=ksm_rpc_endpoint, ) return settings settings_patch = patch.object(rotki, 'get_settings', side_effect=mock_get_settings) # Do not connect to the usual nodes at start by default. Do not want to spam # them during our tests. It's configurable per test, with the default being nothing eth_rpcconnect_patch = patch( 'rotkehlchen.rotkehlchen.ETHEREUM_NODES_TO_CONNECT_AT_START', new=ethereum_manager_connect_at_start, ) ksm_rpcconnect_patch = patch( 'rotkehlchen.rotkehlchen.KUSAMA_NODES_TO_CONNECT_AT_START', new=kusama_manager_connect_at_start, ) ksm_connect_on_startup_patch = patch.object( rotki, '_connect_ksm_manager_on_startup', return_value=bool(blockchain_accounts.ksm), ) with settings_patch, eth_rpcconnect_patch, ksm_rpcconnect_patch, ksm_connect_on_startup_patch: rotki.unlock_user( user=username, password=db_password, create_new=True, sync_approval='no', premium_credentials=None, ) # configure when task manager should run for tests rotki.task_manager.max_tasks_num = max_tasks_num if start_with_valid_premium: rotki.premium = Premium(rotki_premium_credentials) rotki.premium_sync_manager.premium = rotki.premium # After unlocking when all objects are created we need to also include # customized fixtures that may have been set by the tests rotki.chain_manager.accounts = blockchain_accounts add_settings_to_test_db(rotki.data.db, db_settings, ignored_assets) maybe_include_etherscan_key(rotki.data.db, include_etherscan_key) maybe_include_cryptocompare_key(rotki.data.db, include_cryptocompare_key) add_blockchain_accounts_to_db(rotki.data.db, blockchain_accounts) add_tags_to_test_db(rotki.data.db, tags) add_manually_tracked_balances_to_test_db(rotki.data.db, manually_tracked_balances) maybe_mock_historical_price_queries( historian=PriceHistorian(), should_mock_price_queries=should_mock_price_queries, mocked_price_queries=mocked_price_queries, default_mock_value=default_mock_price_value, ) wait_until_all_nodes_connected( ethereum_manager_connect_at_start=ethereum_manager_connect_at_start, ethereum=rotki.chain_manager.ethereum, ) wait_until_all_substrate_nodes_connected( substrate_manager_connect_at_start=kusama_manager_connect_at_start, substrate_manager=rotki.chain_manager.kusama, ) aave = rotki.chain_manager.get_module('aave') if aave: aave.use_graph = aave_use_graph
def initialize_mock_rotkehlchen_instance( rotki, start_with_logged_in_user, start_with_valid_premium, db_password, rotki_premium_credentials, username, blockchain_accounts, include_etherscan_key, include_cryptocompare_key, should_mock_price_queries, mocked_price_queries, ethereum_modules, db_settings, ignored_assets, tags, manually_tracked_balances, default_mock_price_value, ethereum_manager_connect_at_start, kusama_manager_connect_at_start, eth_rpc_endpoint, ksm_rpc_endpoint, aave_use_graph, max_tasks_num, legacy_messages_via_websockets, data_migration_version, use_custom_database, user_data_dir, perform_migrations_at_unlock, perform_upgrades_at_unlock, ): if not start_with_logged_in_user: return # Mock the initial get settings to include the specified ethereum modules def mock_get_settings() -> DBSettings: settings = DBSettings( active_modules=ethereum_modules, eth_rpc_endpoint=eth_rpc_endpoint, ksm_rpc_endpoint=ksm_rpc_endpoint, ) return settings settings_patch = patch.object(rotki, 'get_settings', side_effect=mock_get_settings) # Do not connect to the usual nodes at start by default. Do not want to spam # them during our tests. It's configurable per test, with the default being nothing eth_rpcconnect_patch = patch( 'rotkehlchen.rotkehlchen.ETHEREUM_NODES_TO_CONNECT_AT_START', new=ethereum_manager_connect_at_start, ) ksm_rpcconnect_patch = patch( 'rotkehlchen.rotkehlchen.KUSAMA_NODES_TO_CONNECT_AT_START', new=kusama_manager_connect_at_start, ) ksm_connect_on_startup_patch = patch.object( rotki, '_connect_ksm_manager_on_startup', return_value=bool(blockchain_accounts.ksm), ) # patch the constants to make sure that the periodic query for icons # does not run during tests size_patch = patch('rotkehlchen.rotkehlchen.ICONS_BATCH_SIZE', new=0) sleep_patch = patch('rotkehlchen.rotkehlchen.ICONS_QUERY_SLEEP', new=999999) create_new = True if use_custom_database is not None: _use_prepared_db(user_data_dir, use_custom_database) create_new = False with ExitStack() as stack: stack.enter_context(settings_patch) stack.enter_context(eth_rpcconnect_patch) stack.enter_context(ksm_rpcconnect_patch) stack.enter_context(ksm_connect_on_startup_patch) stack.enter_context(size_patch) stack.enter_context(sleep_patch) if perform_migrations_at_unlock is False: migrations_patch = patch.object( DataMigrationManager, 'maybe_migrate_data', side_effect=lambda *args: None, ) stack.enter_context(migrations_patch) if perform_upgrades_at_unlock is False: upgrades_patch = patch.object( DBUpgradeManager, 'run_upgrades', side_effect=lambda *args: None, ) stack.enter_context(upgrades_patch) rotki.unlock_user( user=username, password=db_password, create_new=create_new, sync_approval='no', premium_credentials=None, ) # configure when task manager should run for tests rotki.task_manager.max_tasks_num = max_tasks_num if start_with_valid_premium: rotki.premium = Premium(rotki_premium_credentials) rotki.premium_sync_manager.premium = rotki.premium rotki.chain_manager.premium = rotki.premium # Add premium to all the modules for module_name in AVAILABLE_MODULES_MAP: module = rotki.chain_manager.get_module(module_name) if module is not None: module.premium = rotki.premium if legacy_messages_via_websockets is False: rotki.msg_aggregator.rotki_notifier = None # After unlocking when all objects are created we need to also include # customized fixtures that may have been set by the tests rotki.chain_manager.accounts = blockchain_accounts add_settings_to_test_db(rotki.data.db, db_settings, ignored_assets, data_migration_version) maybe_include_etherscan_key(rotki.data.db, include_etherscan_key) maybe_include_cryptocompare_key(rotki.data.db, include_cryptocompare_key) add_blockchain_accounts_to_db(rotki.data.db, blockchain_accounts) add_tags_to_test_db(rotki.data.db, tags) add_manually_tracked_balances_to_test_db(rotki.data.db, manually_tracked_balances) maybe_mock_historical_price_queries( historian=PriceHistorian(), should_mock_price_queries=should_mock_price_queries, mocked_price_queries=mocked_price_queries, default_mock_value=default_mock_price_value, ) wait_until_all_nodes_connected( ethereum_manager_connect_at_start=ethereum_manager_connect_at_start, ethereum=rotki.chain_manager.ethereum, ) wait_until_all_substrate_nodes_connected( substrate_manager_connect_at_start=kusama_manager_connect_at_start, substrate_manager=rotki.chain_manager.kusama, ) aave = rotki.chain_manager.get_module('aave') if aave: aave.use_graph = aave_use_graph
def initialize_mock_rotkehlchen_instance( rotki, start_with_logged_in_user, start_with_valid_premium, db_password, rotki_premium_credentials, username, blockchain_accounts, include_etherscan_key, include_cryptocompare_key, should_mock_price_queries, mocked_price_queries, ethereum_modules, db_settings, ignored_assets, tags, manually_tracked_balances, default_mock_price_value, ethereum_manager_connect_at_start, ): if not start_with_logged_in_user: return # Mock the initial get settings to include the specified ethereum modules def mock_get_settings() -> DBSettings: settings = DBSettings(active_modules=ethereum_modules) return settings settings_patch = patch.object(rotki, 'get_settings', side_effect=mock_get_settings) # Do not connect to the usual nodes at start by default. Do not want to spam # them during our tests. It's configurable per test, with the default being nothing rpcconnect_patch = patch( 'rotkehlchen.rotkehlchen.ETHEREUM_NODES_TO_CONNECT_AT_START', new=ethereum_manager_connect_at_start, ) zerion_patch = create_zerion_patch() with settings_patch, zerion_patch, rpcconnect_patch: rotki.unlock_user( user=username, password=db_password, create_new=True, sync_approval='no', premium_credentials=None, ) wait_until_zerion_is_initialized(rotki.chain_manager) if start_with_valid_premium: rotki.premium = Premium(rotki_premium_credentials) rotki.premium_sync_manager.premium = rotki.premium # After unlocking when all objects are created we need to also include # customized fixtures that may have been set by the tests rotki.chain_manager.accounts = blockchain_accounts add_settings_to_test_db(rotki.data.db, db_settings, ignored_assets) maybe_include_etherscan_key(rotki.data.db, include_etherscan_key) maybe_include_cryptocompare_key(rotki.data.db, include_cryptocompare_key) add_blockchain_accounts_to_db(rotki.data.db, blockchain_accounts) add_tags_to_test_db(rotki.data.db, tags) add_manually_tracked_balances_to_test_db(rotki.data.db, manually_tracked_balances) maybe_mock_historical_price_queries( historian=PriceHistorian(), should_mock_price_queries=should_mock_price_queries, mocked_price_queries=mocked_price_queries, default_mock_value=default_mock_price_value, )