Exemplo n.º 1
0
 def make_external_service(  # pylint: disable=no-self-use
         self,
         data: Dict[str, Any],
         **_kwargs: Any,
 ) -> ExternalServiceApiCredentials:
     """Used when encoding an external resource given in via the API"""
     return ExternalServiceApiCredentials(service=data['name'], api_key=data['api_key'])
Exemplo n.º 2
0
def maybe_include_etherscan_key(db: DBHandler, include_etherscan_key: bool) -> None:
    if not include_etherscan_key:
        return
    # Add the tests only etherscan API key
    db.add_external_service_credentials([ExternalServiceApiCredentials(
        service=ExternalService.ETHERSCAN,
        api_key=ApiKey('8JT7WQBB2VQP5C3416Y8X3S8GBA3CVZKP4'),
    )])
Exemplo n.º 3
0
 def get_external_service_credentials(
         self,
         service_name: ExternalService,
 ) -> Optional[ExternalServiceApiCredentials]:
     """If existing it returns the external service credentials for the given service"""
     short_name = service_name.name.lower()
     api_key = self.config['settings'].get('external_services', {}).get(short_name)
     if not api_key:
         return None
     return ExternalServiceApiCredentials(service=service_name, api_key=api_key)
Exemplo n.º 4
0
def maybe_include_cryptocompare_key(db: DBHandler, include_cryptocompare_key: bool) -> None:
    if not include_cryptocompare_key:
        return
    keys = [
        'a4a36d7fd1835cc1d757186de8e7357b4478b73923933d09d3689140ecc23c03',
        'e929bcf68fa28715fa95f3bfa3baa3b9a6bc8f12112835586c705ab038ee06aa',
        '5159ca00f2579ef634b7f210ad725550572afbfb44e409460dd8a908d1c6416a',
        '6781b638eca6c3ca51a87efcdf0b9032397379a0810c5f8198a25493161c318d',
    ]
    # Add the tests only etherscan API key
    db.add_external_service_credentials([ExternalServiceApiCredentials(
        service=ExternalService.CRYPTOCOMPARE,
        api_key=ApiKey(random.choice(keys)),
    )])
Exemplo n.º 5
0
def test_get_external_service_credentials(database):
    # Test that if the service is not in DB 'None' is returned
    for service in ExternalService:
        assert not database.get_external_service_credentials(service)

    # add entries for all services
    database.add_external_service_credentials(
        [ExternalServiceApiCredentials(s, f'{s.name.lower()}_key') for s in ExternalService],
    )

    # now make sure that they are returned individually
    for service in ExternalService:
        credentials = database.get_external_service_credentials(service)
        assert credentials.service == service
        assert credentials.api_key == f'{service.name.lower()}_key'
Exemplo n.º 6
0
def temp_etherscan(function_scope_messages_aggregator, tmpdir_factory):
    directory = tmpdir_factory.mktemp('data')
    db = DBHandler(
        user_data_dir=directory,
        password='******',
        msg_aggregator=function_scope_messages_aggregator,
    )

    # Test with etherscan API key
    api_key = os.environ.get('ETHERSCAN_API_KEY', None)
    if api_key:
        db.add_external_service_credentials(credentials=[
            ExternalServiceApiCredentials(service=ExternalService.ETHERSCAN, api_key=api_key),
        ])
    etherscan = Etherscan(database=db, msg_aggregator=function_scope_messages_aggregator)
    return etherscan
Exemplo n.º 7
0
def temp_etherscan(database, inquirer, function_scope_messages_aggregator,
                   tmpdir_factory):
    api_key = os.environ.get('ETHERSCAN_API_KEY', None)
    if not api_key:
        pytest.fail('No ETHERSCAN_API_KEY environment variable found.')
    directory = tmpdir_factory.mktemp('data')
    msg_aggregator = MessagesAggregator()
    db = DBHandler(user_data_dir=directory,
                   password='******',
                   msg_aggregator=msg_aggregator)
    db.add_external_service_credentials(credentials=[
        ExternalServiceApiCredentials(service=ExternalService.ETHERSCAN,
                                      api_key=api_key),
    ])
    etherscan = Etherscan(database=db, msg_aggregator=msg_aggregator)
    return etherscan
Exemplo n.º 8
0
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,
) -> DBHandler:
    db = DBHandler(data_dir, password, msg_aggregator)
    settings = {
        # DO not submit usage analytics during tests
        'submit_usage_analytics': False,
        'main_currency': DEFAULT_TESTS_MAIN_CURRENCY,
    }
    # Set the given db_settings. The pre-set values have priority unless overriden here
    if db_settings is not None:
        for key, value in db_settings.items():
            settings[key] = value
    db.set_settings(ModifiableDBSettings(**settings))

    if ignored_assets:
        for asset in ignored_assets:
            db.add_to_ignored_assets(asset)

    # Make sure that the fixture provided accounts are in the blockchain
    db.add_blockchain_accounts(
        SupportedBlockchain.ETHEREUM,
        [BlockchainAccountData(address=x) for x in blockchain_accounts.eth],
    )
    db.add_blockchain_accounts(
        SupportedBlockchain.BITCOIN,
        [BlockchainAccountData(address=x) for x in blockchain_accounts.btc],
    )
    if include_etherscan_key:
        # Add the tests only etherscan API key
        db.add_external_service_credentials([
            ExternalServiceApiCredentials(
                service=ExternalService.ETHERSCAN,
                api_key=ApiKey('8JT7WQBB2VQP5C3416Y8X3S8GBA3CVZKP4'),
            )
        ])

    return db
Exemplo n.º 9
0
 def make_external_service(self, data: Dict, **kwargs) -> ExternalServiceApiCredentials:
     """Used when encoding an external resource given in via the API"""
     return ExternalServiceApiCredentials(service=data['name'], api_key=data['api_key'])