Repository: rotki/rotki

Issue:
Allow per protocol reset of DB data in Defi deposits
## Problem Definition

![2020-09-21-104840_234x220_scrot](https://user-images.githubusercontent.com/1658405/93748782-19699600-fbf9-11ea-8ce2-9df786905f94.png)

Right now only AAve data are resettable in the "Deposits" DeFi section. All protocols for which `reset_db` option exists in the API should be possible here and additionally the user should be able to select a single, or a selection of protocols to reset. Shouldn't force reset all as this may take ages.

## Task

Do it


Discussion:
### Note
- Make the protocols to reset selectable in the confirmation popup.
- Make the loading action work with selected protocols for reset.

Resolving patch:
diff --git a/rotkehlchen/assets/resolver.py b/rotkehlchen/assets/resolver.py
--- a/rotkehlchen/assets/resolver.py
+++ b/rotkehlchen/assets/resolver.py
@@ -174,7 +174,9 @@ def is_identifier_canonical(asset_identifier: str) -> bool:
     def get_asset_data(asset_identifier: str) -> AssetData:
         """Get all asset data from the known assets file for valid asset symbol"""
         data = AssetResolver().assets[asset_identifier]
-        asset_type = asset_type_mapping[data['type']]
+        # If an unknown asset is found (can happen if list is updated but code is not)
+        # then default to the "own chain" type"
+        asset_type = asset_type_mapping.get(data['type'], AssetType.OWN_CHAIN)
         result = AssetData(
             identifier=asset_identifier,
             symbol=data['symbol'],
@@ -200,7 +202,9 @@ def get_all_eth_token_info() -> List[EthTokenInfo]:
         all_tokens = []
 
         for identifier, asset_data in AssetResolver().assets.items():
-            asset_type = asset_type_mapping[asset_data['type']]
+            # If an unknown asset is found (can happen if list is updated but code is not)
+            # then default to the "own chain" type"
+            asset_type = asset_type_mapping.get(asset_data['type'], AssetType.OWN_CHAIN)
             if asset_type not in (AssetType.ETH_TOKEN_AND_MORE, AssetType.ETH_TOKEN):
                 continue
 
diff --git a/rotkehlchen/externalapis/cryptocompare.py b/rotkehlchen/externalapis/cryptocompare.py
--- a/rotkehlchen/externalapis/cryptocompare.py
+++ b/rotkehlchen/externalapis/cryptocompare.py
@@ -108,6 +108,7 @@
     Asset('KRT'): Asset('KRW'),
     Asset('RVC'): Asset('USDT'),
     Asset('SDT'): Asset('USDT'),
+    Asset('CHI'): Asset('USDT'),
 }
 CRYPTOCOMPARE_SPECIAL_CASES = CRYPTOCOMPARE_SPECIAL_CASES_MAPPING.keys()
 
@@ -335,8 +336,11 @@ def _special_case_handling(
         elif method_name == 'query_endpoint_price':
             result = {
                 to_asset.identifier: _multiply_str_nums(
-                    result1[intermediate_asset.identifier],
-                    result2[to_asset.identifier]),
+                    # up until 23/09/2020 cryptocompare may return {} due to bug. Handle
+                    # that case by assuming 0 if that happens
+                    result1.get(intermediate_asset.identifier, '0'),
+                    result2.get(to_asset.identifier, '0'),
+                ),
             }
         elif method_name == 'query_endpoint_pricehistorical':
             result = result1 * result2


Test patch:
diff --git a/rotkehlchen/tests/unit/test_assets.py b/rotkehlchen/tests/unit/test_assets.py
--- a/rotkehlchen/tests/unit/test_assets.py
+++ b/rotkehlchen/tests/unit/test_assets.py
@@ -143,7 +143,7 @@ def test_coingecko_identifiers_are_reachable():
 def test_assets_json_meta():
     """Test that all_assets.json md5 matches and that if md5 changes since last
     time then version is also bumped"""
-    last_meta = {'md5': '5e46f13a42763826d67dfab43fe50203', 'version': 14}
+    last_meta = {'md5': 'ac11839fc91d6c79d65dc1d7e0fc223d', 'version': 16}
     data_dir = Path(__file__).resolve().parent.parent.parent / 'data'
     data_md5 = file_md5(data_dir / 'all_assets.json')
 
@@ -179,3 +179,25 @@ def test_assets_pulling_from_github_works(asset_resolver):  # pylint: disable=un
     # After the test runs we must reset the asset resolver so that it goes back to
     # the normal list of assets
     AssetResolver._AssetResolver__instance = None
+
+
+@pytest.mark.parametrize('mock_asset_meta_github_response', ['{"md5": "", "version": 99999999}'])
+@pytest.mark.parametrize('use_clean_caching_directory', [True])
+@pytest.mark.parametrize('mock_asset_github_response', ["""{
+"COMPRLASSET": {
+    "coingecko": "",
+    "name": "Completely real asset, totally not for testing only",
+    "symbol": "COMPRLASSET",
+    "type": "not existing type"
+}
+}"""])
+@pytest.mark.parametrize('force_reinitialize_asset_resolver', [True])
+def test_asset_with_unknown_type_does_not_crash(asset_resolver):  # pylint: disable=unused-argument
+    """Test that finding an asset with an unknown type does not crash Rotki"""
+    new_asset = Asset("COMPRLASSET")
+    assert new_asset.name == 'Completely real asset, totally not for testing only'
+    token_list = AssetResolver().get_all_eth_token_info()
+    assert len(token_list) == 0
+    # After the test runs we must reset the asset resolver so that it goes back to
+    # the normal list of assets
+    AssetResolver._AssetResolver__instance = None