示例#1
0
def blockchain(
    blockchain_backend,  # pylint: disable=unused-argument
    ethereum_manager,
    blockchain_accounts,
    inquirer,  # pylint: disable=unused-argument
    messages_aggregator,
    greenlet_manager,
    ethereum_modules,
    start_with_valid_premium,
    rotki_premium_credentials,
    database,
):
    premium = None
    if start_with_valid_premium:
        premium = Premium(rotki_premium_credentials)

    with create_zerion_patch():
        chain_manager = ChainManager(
            blockchain_accounts=blockchain_accounts,
            ethereum_manager=ethereum_manager,
            msg_aggregator=messages_aggregator,
            database=database,
            greenlet_manager=greenlet_manager,
            premium=premium,
            eth_modules=ethereum_modules,
        )
        wait_until_zerion_is_initialized(chain_manager)

    return chain_manager
示例#2
0
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,
    eth_rpc_endpoint,
):
    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)
        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,
    )

    wait_until_all_nodes_connected(
        ethereum_manager_connect_at_start=ethereum_manager_connect_at_start,
        ethereum=rotki.chain_manager.ethereum,
    )