예제 #1
0
def rotkehlchen_instance(
    cli_args,
    username,
    blockchain,
    accountant,
    start_with_logged_in_user,
    start_with_valid_premium,
    function_scope_messages_aggregator,
    db_password,
    rotkehlchen_api_key,
    rotkehlchen_api_secret,
):
    """A partially mocked rotkehlchen instance"""
    rotkehlchen = Rotkehlchen(cli_args)

    initialize_mock_rotkehlchen_instance(
        rotki=rotkehlchen,
        start_with_logged_in_user=start_with_logged_in_user,
        start_with_valid_premium=start_with_valid_premium,
        msg_aggregator=function_scope_messages_aggregator,
        username=username,
        accountant=accountant,
        blockchain=blockchain,
        db_password=db_password,
        rotkehlchen_api_key=rotkehlchen_api_key,
        rotkehlchen_api_secret=rotkehlchen_api_secret,
    )
    return rotkehlchen
예제 #2
0
    def __init__(self, args):
        args.logfile = 'data_faker.log'
        self.rotki = Rotkehlchen(args)

        random_seed = datetime.datetime.now()
        logger.info(f'Random seed used: {random_seed}')
        random.seed(random_seed)
        self.faker = Faker()

        self.create_new_user(args.user_name, args.user_password)
        # register the exchanges with the rotkehlchen DB of the new user
        self.rotki.data.db.add_exchange(
            name='kraken',
            api_key=make_random_b64bytes(128),
            api_secret=make_random_b64bytes(128),
        )

        self.fake_kraken = FakeKraken()
        self.writer = ActionWriter(
            trades_number=args.trades_number,
            rotkehlchen=self.rotki,
            fake_kraken=self.fake_kraken,
        )

        self.writer.generate_history()
예제 #3
0
 def __init__(self) -> None:
     """Initializes the backend server
     May raise:
     - SystemPermissionError due to the given args containing a datadir
     that does not have the correct permissions
     """
     arg_parser = app_args(
         prog='rotki',
         description=
         ('Rotki, the portfolio tracker and accounting tool that respects your privacy'
          ),
     )
     self.args = arg_parser.parse_args()
     self.rotkehlchen = Rotkehlchen(self.args)
     self.stop_event = gevent.event.Event()
     domain_list = []
     if self.args.api_cors:
         if "," in self.args.api_cors:
             for domain in self.args.api_cors.split(","):
                 domain_list.append(str(domain))
         else:
             domain_list.append(str(self.args.api_cors))
     self.api_server = APIServer(
         rest_api=RestAPI(rotkehlchen=self.rotkehlchen),
         cors_domain_list=domain_list,
     )
예제 #4
0
파일: rotkehlchen.py 프로젝트: davbre/rotki
def uninitialized_rotkehlchen(cli_args, inquirer):  # pylint: disable=unused-argument
    """A rotkehlchen instance that has only had __init__ run but is not unlocked

    Adding the inquirer fixture as a requirement to make sure that any mocking that
    happens at the inquirer level is reflected in the tests.

    For this to happen inquirer fixture must be initialized before Rotkehlchen so
    that the inquirer initialization in Rotkehlchen's __init__ uses the fixture's instance
    """
    return Rotkehlchen(cli_args)
예제 #5
0
 def __init__(self):
     self.args = app_args()
     self.rotkehlchen = Rotkehlchen(self.args)
     self.stop_event = Event()
     mainloop_greenlet = self.rotkehlchen.start()
     mainloop_greenlet.link_exception(self.handle_killed_greenlets)
     self.greenlets = [mainloop_greenlet]
     self.task_lock = Semaphore()
     self.task_id = 0
     self.task_results = {}
예제 #6
0
def rotkehlchen_instance(cli_args, username, blockchain, accountant):
    """A partially mocked rotkehlchen instance"""
    r = Rotkehlchen(cli_args)
    r.data.unlock(username, '123', create_new=True)
    # Remember accountant fixture has a mocked accounting data dir
    # different to the usual user one
    r.accountant = accountant
    r.blockchain = blockchain
    r.trades_historian = object()
    r.user_is_logged_in = True
    return r
예제 #7
0
 def __init__(self):
     self.args = app_args()
     self.rotkehlchen = Rotkehlchen(self.args)
     self.stop_event = Event()
     mainloop_greenlet = self.rotkehlchen.start()
     mainloop_greenlet.link_exception(self.handle_killed_greenlets)
     # Greenlets that will be waited for when we shutdown
     self.waited_greenlets = [mainloop_greenlet]
     # Greenlets that can be killed instead of waited for when we shutdown
     self.killable_greenlets = []
     self.task_lock = Semaphore()
     self.task_id = 0
     self.task_results = {}
예제 #8
0
def fixture_uninitialized_rotkehlchen(cli_args, inquirer, asset_resolver, globaldb):  # pylint: disable=unused-argument  # noqa: E501
    """A rotkehlchen instance that has only had __init__ run but is not unlocked

    Adding the inquirer fixture as a requirement to make sure that any mocking that
    happens at the inquirer level is reflected in the tests.

    For this to happen inquirer fixture must be initialized before Rotkehlchen so
    that the inquirer initialization in Rotkehlchen's __init__ uses the fixture's instance

    Adding the AssetResolver as a requirement so that the first initialization happens here
    """
    rotki = Rotkehlchen(cli_args)
    return rotki
예제 #9
0
def test_initializing_rotki_with_datadir_with_wrong_permissions(
        cli_args, data_dir):
    os.chmod(data_dir, 0o200)
    success = True
    try:
        with pytest.raises(SystemPermissionError):
            Rotkehlchen(args=cli_args)
    except Exception:  # pylint: disable=broad-except
        success = False
    finally:
        os.chmod(data_dir, 0o777)

    assert success is True
예제 #10
0
 def __init__(self):
     arg_parser = app_args(
         prog='rotkehlchen',
         description='Rotkehlchen Crypto Portfolio Management',
     )
     self.args = arg_parser.parse_args()
     self.rotkehlchen = Rotkehlchen(self.args)
     self.stop_event = Event()
     mainloop_greenlet = self.rotkehlchen.start()
     mainloop_greenlet.link_exception(self.handle_killed_greenlets)
     # Greenlets that will be waited for when we shutdown
     self.waited_greenlets = [mainloop_greenlet]
     # Greenlets that can be killed instead of waited for when we shutdown
     self.killable_greenlets = []
     self.task_lock = Semaphore()
     self.task_id = 0
     self.task_results = {}
예제 #11
0
    def __init__(self, args: argparse.Namespace) -> None:
        args.logfile = 'data_faker.log'
        self.rotki = Rotkehlchen(args)

        random_seed = datetime.datetime.now()
        logger.info(f'Random seed used: {random_seed}')
        random.seed(random_seed)

        self.create_new_user(args.user_name, args.user_password)

        # Start the fake exchanges API for the duration of the fake
        # history creation. We need it up so that we can emulate responses
        # from the exchanges
        self.fake_kraken = FakeKraken()
        self.fake_binance = FakeBinance()
        mock_api = RestAPI(fake_kraken=self.fake_kraken,
                           fake_binance=self.fake_binance)
        self.mock_server = APIServer(rest_api=mock_api)
        self.mock_server.start()

        self.rotki.setup_exchange(
            name='kraken',
            location=Location.KRAKEN,
            api_key=ApiKey(str(make_random_b64bytes(128))),
            api_secret=ApiSecret(make_random_b64bytes(128)),
        )
        self.rotki.setup_exchange(
            name='binance',
            location=Location.BINANCE,
            api_key=ApiKey(str(make_random_b64bytes(128))),
            api_secret=ApiSecret(make_random_b64bytes(128)),
        )

        self.writer = ActionWriter(
            trades_number=args.trades_number,
            seconds_between_trades=args.seconds_between_trades,
            seconds_between_balance_save=args.seconds_between_balance_save,
            rotkehlchen=self.rotki,
            fake_kraken=self.fake_kraken,
            fake_binance=self.fake_binance,
        )

        self.writer.generate_history()
        # stop the fake exchange API. Will be started again once we are finished,
        # ready to serve the Rotkehlchen client
        self.mock_server.stop()
예제 #12
0
def uninitialized_rotkehlchen(cli_args, inquirer, asset_resolver):  # pylint: disable=unused-argument  # noqa: E501
    """A rotkehlchen instance that has only had __init__ run but is not unlocked

    Adding the inquirer fixture as a requirement to make sure that any mocking that
    happens at the inquirer level is reflected in the tests.

    For this to happen inquirer fixture must be initialized before Rotkehlchen so
    that the inquirer initialization in Rotkehlchen's __init__ uses the fixture's instance

    Adding the AssetResolver as a requirement so that the first initialization happens here
    """
    # 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)
    with size_patch, sleep_patch:
        rotki = Rotkehlchen(cli_args)
    return rotki
예제 #13
0
 def __init__(self) -> None:
     arg_parser = app_args(
         prog='rotki',
         description=
         ('Rotki, the portfolio tracker and accounting tool that respects your privacy'
          ),
     )
     self.args = arg_parser.parse_args()
     self.rotkehlchen = Rotkehlchen(self.args)
     self.stop_event = gevent.event.Event()
     domain_list = []
     if self.args.api_cors:
         if "," in self.args.api_cors:
             for domain in self.args.api_cors.split(","):
                 domain_list.append(str(domain))
         else:
             domain_list.append(str(self.args.api_cors))
     self.api_server = APIServer(
         rest_api=RestAPI(rotkehlchen=self.rotkehlchen),
         cors_domain_list=domain_list,
     )
예제 #14
0
def rotkehlchen_instance(cli_args, username, blockchain):
    r = Rotkehlchen(cli_args)
    r.data.unlock(username, '123', create_new=True)
    r.blockchain = blockchain
    return r
예제 #15
0
파일: test_app.py 프로젝트: step21/rotki
def test_initializing_rotki_with_datadir_with_wrong_permissions(
        cli_args, data_dir):
    os.chmod(data_dir, 0o200)
    with pytest.raises(SystemPermissionError):
        Rotkehlchen(args=cli_args)
    os.chmod(data_dir, 0o777)
예제 #16
0
def test_periodic_data_before_login_completion(cli_args):
    """Test that periodic query returns empty list if user is not yet logged in"""
    rotkehlchen = Rotkehlchen(cli_args)
    result = rotkehlchen.query_periodic_data()
    assert len(result) == 0
예제 #17
0
def uninitialized_rotkehlchen(cli_args):
    """A rotkehlchen instance that has only had __init__ run but is not unlocked"""
    return Rotkehlchen(cli_args)