Repository: rotki/rotki

Issue:
Fix treating of WETH in cost basis calculations for DEXes
## Problem Definition

Most DEXes treat ETH and WETH identically. They wrap ETH to WETH and unwrap it back to ETH under the hood. While at the same time the trades are trades of the WETH token and not ETH.

This creates a problem calculating the cost basis. Since rotki knows where you got the ETH but is lost with the WETH.

## Task

To fix this we should treat ETH and WETH as having the exact same cost basis and provenance. Since wrapping and unwrapping should not really be a taxable event. And even if someone wanted to consider it as such ... detecting it is not always trivial.


Discussion:

Resolving patch:
diff --git a/rotkehlchen/accounting/cost_basis.py b/rotkehlchen/accounting/cost_basis.py
--- a/rotkehlchen/accounting/cost_basis.py
+++ b/rotkehlchen/accounting/cost_basis.py
@@ -4,6 +4,7 @@
 from typing import Any, Callable, DefaultDict, Dict, List, NamedTuple, Optional, Tuple
 
 from rotkehlchen.assets.asset import Asset
+from rotkehlchen.constants.assets import A_ETH, A_WETH
 from rotkehlchen.constants.misc import ZERO
 from rotkehlchen.csv_exporter import CSVExporter
 from rotkehlchen.fval import FVal
@@ -156,7 +157,7 @@ def __init__(
 
     def reset(self, profit_currency: Asset) -> None:
         self.profit_currency = profit_currency
-        self.events: DefaultDict[Asset, CostBasisEvents] = defaultdict(CostBasisEvents)
+        self._events: DefaultDict[Asset, CostBasisEvents] = defaultdict(CostBasisEvents)
 
     @property
     def taxfree_after_period(self) -> Optional[int]:
@@ -168,6 +169,13 @@ def taxfree_after_period(self, value: Optional[int]) -> None:
         assert is_valid, 'set taxfree_after_period should only get int or None'
         self._taxfree_after_period = value
 
+    def get_events(self, asset: Asset) -> CostBasisEvents:
+        """Custom getter for events so that we have common cost basis for some assets"""
+        if asset == A_WETH:
+            asset = A_ETH
+
+        return self._events[asset]
+
     def inform_user_missing_acquisition(
             self,
             asset: Asset,
@@ -200,12 +208,13 @@ def reduce_asset_amount(self, asset: Asset, amount: FVal) -> bool:
         if amount == ZERO:
             return True
 
-        if asset not in self.events or len(self.events[asset].acquisitions) == 0:
+        asset_events = self.get_events(asset)
+        if len(asset_events.acquisitions) == 0:
             return False
 
         remaining_amount_from_last_buy = FVal('-1')
         remaining_amount = amount
-        for idx, acquisition_event in enumerate(self.events[asset].acquisitions):
+        for idx, acquisition_event in enumerate(asset_events.acquisitions):
             if remaining_amount < acquisition_event.remaining_amount:
                 stop_index = idx
                 remaining_amount_from_last_buy = acquisition_event.remaining_amount - remaining_amount  # noqa: E501
@@ -214,14 +223,14 @@ def reduce_asset_amount(self, asset: Asset, amount: FVal) -> bool:
 
             # else
             remaining_amount -= acquisition_event.remaining_amount
-            if idx == len(self.events[asset].acquisitions) - 1:
+            if idx == len(asset_events.acquisitions) - 1:
                 stop_index = idx + 1
 
         # Otherwise, delete all the used up acquisitions from the list
-        del self.events[asset].acquisitions[:stop_index]
+        del asset_events.acquisitions[:stop_index]
         # and modify the amount of the buy where we stopped if there is one
         if remaining_amount_from_last_buy != FVal('-1'):
-            self.events[asset].acquisitions[0].remaining_amount = remaining_amount_from_last_buy
+            asset_events.acquisitions[0].remaining_amount = remaining_amount_from_last_buy
         elif remaining_amount != ZERO:
             return False
 
@@ -251,7 +260,8 @@ def obtain_asset(
             rate=rate,
             fee_rate=fee_in_profit_currency / amount,
         )
-        self.events[asset].acquisitions.append(event)
+        asset_events = self.get_events(asset)
+        asset_events.acquisitions.append(event)
         logger.debug(event)
 
     def spend_asset(
@@ -272,7 +282,8 @@ def spend_asset(
             fee_rate=fee_in_profit_currency / amount,
             gain=gain_in_profit_currency,
         )
-        self.events[asset].spends.append(event)
+        asset_events = self.get_events(asset)
+        asset_events.spends.append(event)
         logger.debug(event)
 
     def calculate_spend_cost_basis(
@@ -298,7 +309,8 @@ def calculate_spend_cost_basis(
         taxfree_amount = ZERO
         remaining_amount_from_last_buy = FVal('-1')
         matched_acquisitions = []
-        for idx, acquisition_event in enumerate(self.events[spending_asset].acquisitions):
+        asset_events = self.get_events(spending_asset)
+        for idx, acquisition_event in enumerate(asset_events.acquisitions):
             if self.taxfree_after_period is None:
                 at_taxfree_period = False
             else:
@@ -365,10 +377,10 @@ def calculate_spend_cost_basis(
             acquisition_event.remaining_amount = ZERO
 
             # If the sell used up the last historical acquisition
-            if idx == len(self.events[spending_asset].acquisitions) - 1:
+            if idx == len(asset_events.acquisitions) - 1:
                 stop_index = idx + 1
 
-        if len(self.events[spending_asset].acquisitions) == 0:
+        if len(asset_events.acquisitions) == 0:
             self.inform_user_missing_acquisition(spending_asset, timestamp)
             # That means we had no documented acquisition for that asset. This is not good
             # because we can't prove a corresponding acquisition and as such we are burdened
@@ -383,13 +395,13 @@ def calculate_spend_cost_basis(
 
         is_complete = True
         # Otherwise, delete all the used up acquisitions from the list
-        self.events[spending_asset].used_acquisitions.extend(
-            self.events[spending_asset].acquisitions[:stop_index],
+        asset_events.used_acquisitions.extend(
+            asset_events.acquisitions[:stop_index],
         )
-        del self.events[spending_asset].acquisitions[:stop_index]
+        del asset_events.acquisitions[:stop_index]
         # and modify the amount of the buy where we stopped if there is one
         if remaining_amount_from_last_buy != FVal('-1'):
-            self.events[spending_asset].acquisitions[0].remaining_amount = remaining_amount_from_last_buy  # noqa: E501
+            asset_events.acquisitions[0].remaining_amount = remaining_amount_from_last_buy  # noqa: E501
         elif remaining_sold_amount != ZERO:
             # if we still have sold amount but no acquisitions to satisfy it then we only
             # found acquisitions to partially satisfy the sell
@@ -419,7 +431,7 @@ def calculate_asset_details(
         and is hence tax-free and also the average buy price for each asset"""
         self.details: Dict[Asset, Tuple[FVal, FVal]] = {}
         now = ts_now()
-        for asset, events in self.events.items():
+        for asset, events in self._events.items():
             tax_free_amount_left = ZERO
             amount_sum = ZERO
             average = ZERO
@@ -441,10 +453,11 @@ def get_calculated_asset_amount(self, asset: Asset) -> Optional[FVal]:
         """Get the amount of asset accounting has calculated we should have after
         the history has been processed
         """
-        if asset not in self.events:
+        asset_events = self.get_events(asset)
+        if len(asset_events.acquisitions) == 0:
             return None
 
         amount = FVal(0)
-        for acquisition_event in self.events[asset].acquisitions:
+        for acquisition_event in asset_events.acquisitions:
             amount += acquisition_event.remaining_amount
         return amount


Test patch:
diff --git a/rotkehlchen/tests/unit/test_accounting.py b/rotkehlchen/tests/unit/test_accounting.py
--- a/rotkehlchen/tests/unit/test_accounting.py
+++ b/rotkehlchen/tests/unit/test_accounting.py
@@ -1,18 +1,12 @@
 import pytest
 
-from rotkehlchen.constants.assets import A_BTC, A_ETH
+from rotkehlchen.constants.assets import A_BCH, A_BSV, A_BTC, A_ETH
 from rotkehlchen.exchanges.data_structures import AssetMovement, MarginPosition
 from rotkehlchen.fval import FVal
 from rotkehlchen.tests.utils.accounting import accounting_history_process
 from rotkehlchen.tests.utils.constants import A_DASH
 from rotkehlchen.tests.utils.history import prices
-from rotkehlchen.typing import (
-    AssetMovementCategory,
-    EthereumTransaction,
-    Fee,
-    Location,
-    Timestamp,
-)
+from rotkehlchen.typing import AssetMovementCategory, EthereumTransaction, Fee, Location, Timestamp
 
 DUMMY_ADDRESS = '0x0'
 DUMMY_HASH = b''
@@ -104,7 +98,7 @@ def test_selling_crypto_bought_with_crypto(accountant):
     }]
     accounting_history_process(accountant, 1436979735, 1495751688, history)
     # Make sure buying XMR with BTC also creates a BTC sell
-    sells = accountant.events.cost_basis.events['BTC'].spends
+    sells = accountant.events.cost_basis.get_events(A_BTC).spends
     assert len(sells) == 1
     assert sells[0].amount == FVal('0.3853125')
     assert sells[0].timestamp == 1449809536
@@ -216,14 +210,14 @@ def test_buying_selling_btc_before_bchfork(accountant):
 
     amount_bch = FVal(3.9)
     amount_btc = FVal(4.8)
-    buys = accountant.events.cost_basis.events['BCH'].acquisitions
+    buys = accountant.events.cost_basis.get_events(A_BCH).acquisitions
     assert len(buys) == 1
     assert buys[0].remaining_amount == amount_bch
     assert buys[0].timestamp == 1491593374
     assert buys[0].rate == FVal('1128.905')
     assert buys[0].fee_rate.is_close(FVal('0.0846153846154'))
-    assert accountant.events.cost_basis.get_calculated_asset_amount('BCH') == amount_bch
-    assert accountant.events.cost_basis.get_calculated_asset_amount('BTC') == amount_btc
+    assert accountant.events.cost_basis.get_calculated_asset_amount(A_BCH) == amount_bch
+    assert accountant.events.cost_basis.get_calculated_asset_amount(A_BTC) == amount_btc
 
     assert accountant.general_trade_pl.is_close('13876.6464615')
     assert accountant.taxable_trade_pl.is_close('13876.6464615')
@@ -314,19 +308,19 @@ def test_buying_selling_bch_before_bsvfork(accountant):
     amount_btc = FVal(4.8)
     amount_bch = FVal(4.1)
     amount_bsv = FVal(4.6)
-    bch_buys = accountant.events.cost_basis.events['BCH'].acquisitions
+    bch_buys = accountant.events.cost_basis.get_events(A_BCH).acquisitions
     assert len(bch_buys) == 2
     assert sum(x.remaining_amount for x in bch_buys) == amount_bch
     assert bch_buys[0].timestamp == 1491593374
     assert bch_buys[1].timestamp == 1524937600
-    bsv_buys = accountant.events.cost_basis.events['BSV'].acquisitions
+    bsv_buys = accountant.events.cost_basis.get_events(A_BSV).acquisitions
     assert len(bsv_buys) == 2
     assert sum(x.remaining_amount for x in bsv_buys) == amount_bsv
     assert bsv_buys[0].timestamp == 1491593374
     assert bsv_buys[1].timestamp == 1524937600
-    assert accountant.events.cost_basis.get_calculated_asset_amount('BCH') == amount_bch
-    assert accountant.events.cost_basis.get_calculated_asset_amount('BTC') == amount_btc
-    assert accountant.events.cost_basis.get_calculated_asset_amount('BSV') == amount_bsv
+    assert accountant.events.cost_basis.get_calculated_asset_amount(A_BCH) == amount_bch
+    assert accountant.events.cost_basis.get_calculated_asset_amount(A_BTC) == amount_btc
+    assert accountant.events.cost_basis.get_calculated_asset_amount(A_BSV) == amount_bsv
 
     assert accountant.general_trade_pl.is_close('13411.164769')
     assert accountant.taxable_trade_pl.is_close('13876.646461')
@@ -403,7 +397,7 @@ def test_buy_event_creation(accountant):
         'location': 'kraken',
     }]
     accounting_history_process(accountant, 1436979735, 1519693374, history)
-    buys = accountant.events.cost_basis.events['BTC'].acquisitions
+    buys = accountant.events.cost_basis.get_events(A_BTC).acquisitions
     assert len(buys) == 2
     assert buys[0].amount == FVal(5)
     assert buys[0].timestamp == 1476979735
diff --git a/rotkehlchen/tests/unit/test_cost_basis.py b/rotkehlchen/tests/unit/test_cost_basis.py
--- a/rotkehlchen/tests/unit/test_cost_basis.py
+++ b/rotkehlchen/tests/unit/test_cost_basis.py
@@ -1,16 +1,17 @@
 import pytest
 
 from rotkehlchen.accounting.cost_basis import AssetAcquisitionEvent
+from rotkehlchen.constants.assets import A_BTC, A_ETH, A_WETH
+from rotkehlchen.constants.misc import ZERO
 from rotkehlchen.fval import FVal
 from rotkehlchen.typing import Location
-from rotkehlchen.constants.misc import ZERO
 
 
 @pytest.mark.parametrize('accounting_initialize_parameters', [True])
 def test_calculate_spend_cost_basis_after_year(accountant):
-    asset = 'BTC'
-    events = accountant.events.cost_basis.events
-    events[asset].acquisitions.append(
+    asset = A_BTC
+    asset_events = accountant.events.cost_basis.get_events(asset)
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -20,7 +21,7 @@ def test_calculate_spend_cost_basis_after_year(accountant):
             fee_rate=FVal(0.0001),
         ),
     )
-    events[asset].acquisitions.append(
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -30,7 +31,7 @@ def test_calculate_spend_cost_basis_after_year(accountant):
             fee_rate=FVal(0.0019),
         ),
     )
-    events[asset].acquisitions.append(
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -61,9 +62,9 @@ def test_calculate_spend_cost_basis_after_year(accountant):
     assert cinfo.matched_acquisitions[1].event.amount == FVal(15)
     assert cinfo.matched_acquisitions[1].event.remaining_amount == FVal(12)
 
-    acquisitions_num = len(accountant.events.cost_basis.events[asset].acquisitions)
+    acquisitions_num = len(asset_events.acquisitions)
     assert acquisitions_num == 2, 'first buy should have been used'
-    remaining_amount = accountant.events.cost_basis.events[asset].acquisitions[0].remaining_amount
+    remaining_amount = asset_events.acquisitions[0].remaining_amount
     assert remaining_amount == FVal(12), '3 of 15 should have been consumed'
 
 
@@ -72,9 +73,9 @@ def test_calculate_spend_cost_basis_1_buy_consumed_by_1_sell(accountant):
 
     Regression test for part of https://github.com/rotki/rotki/issues/223
     """
-    asset = 'BTC'
-    events = accountant.events.cost_basis.events
-    events[asset].acquisitions.append(
+    asset = A_BTC
+    asset_events = accountant.events.cost_basis.get_events(asset)
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -101,7 +102,7 @@ def test_calculate_spend_cost_basis_1_buy_consumed_by_1_sell(accountant):
     assert cinfo.matched_acquisitions[0].event.amount == FVal(5)
     assert cinfo.matched_acquisitions[0].event.remaining_amount == ZERO
 
-    acquisitions_num = len(accountant.events.cost_basis.events[asset].acquisitions)
+    acquisitions_num = len(asset_events.acquisitions)
     assert acquisitions_num == 0, 'only buy should have been used'
 
 
@@ -111,9 +112,9 @@ def test_calculate_spend_cost_basis1_buy_used_by_2_sells_taxable(accountant):
     Regression test for taxable part of:
     https://github.com/rotki/rotki/issues/223
     """
-    asset = 'BTC'
-    events = accountant.events.cost_basis.events
-    events[asset].acquisitions.append(
+    asset = A_BTC
+    asset_events = accountant.events.cost_basis.get_events(asset)
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -140,9 +141,9 @@ def test_calculate_spend_cost_basis1_buy_used_by_2_sells_taxable(accountant):
     assert cinfo.matched_acquisitions[0].event.amount == FVal(5)
     assert cinfo.matched_acquisitions[0].event.remaining_amount == FVal(2)
 
-    acquisitions_num = len(accountant.events.cost_basis.events[asset].acquisitions)
+    acquisitions_num = len(asset_events.acquisitions)
     assert acquisitions_num == 1, 'whole buy was not used'
-    remaining_amount = accountant.events.cost_basis.events[asset].acquisitions[0].remaining_amount
+    remaining_amount = asset_events.acquisitions[0].remaining_amount
     assert remaining_amount == FVal(2), '3 of 5 should have been consumed'
 
     # now eat up all the rest
@@ -162,7 +163,7 @@ def test_calculate_spend_cost_basis1_buy_used_by_2_sells_taxable(accountant):
     assert cinfo.matched_acquisitions[0].event.amount == FVal(5)
     assert cinfo.matched_acquisitions[0].event.remaining_amount == ZERO
 
-    acquisitions_num = len(accountant.events.cost_basis.events[asset].acquisitions)
+    acquisitions_num = len(asset_events.acquisitions)
     assert acquisitions_num == 0, 'the buy should have been used'
 
 
@@ -173,9 +174,9 @@ def test_calculate_spend_cost_basis_1_buy_used_by_2_sells_taxfree(accountant):
     Regression test for taxfree part of:
     https://github.com/rotki/rotki/issues/223
     """
-    asset = 'BTC'
-    events = accountant.events.cost_basis.events
-    events[asset].acquisitions.append(
+    asset = A_BTC
+    asset_events = accountant.events.cost_basis.get_events(asset)
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -202,9 +203,9 @@ def test_calculate_spend_cost_basis_1_buy_used_by_2_sells_taxfree(accountant):
     assert cinfo.matched_acquisitions[0].event.amount == FVal(5)
     assert cinfo.matched_acquisitions[0].event.remaining_amount == FVal(2)
 
-    acquisitions_num = len(accountant.events.cost_basis.events[asset].acquisitions)
+    acquisitions_num = len(asset_events.acquisitions)
     assert acquisitions_num == 1, 'whole buy was not used'
-    remaining_amount = accountant.events.cost_basis.events[asset].acquisitions[0].remaining_amount
+    remaining_amount = asset_events.acquisitions[0].remaining_amount
     assert remaining_amount == FVal(2), '3 of 5 should have been consumed'
 
     spending_amount = FVal(2)
@@ -223,15 +224,15 @@ def test_calculate_spend_cost_basis_1_buy_used_by_2_sells_taxfree(accountant):
     assert cinfo.matched_acquisitions[0].event.amount == FVal(5)
     assert cinfo.matched_acquisitions[0].event.remaining_amount == ZERO
 
-    acquisitions_num = len(accountant.events.cost_basis.events[asset].acquisitions)
+    acquisitions_num = len(asset_events.acquisitions)
     assert acquisitions_num == 0, 'the buy should have been used'
 
 
 @pytest.mark.parametrize('accounting_initialize_parameters', [True])
 def test_calculate_spend_cost_basis_sell_more_than_bought_within_year(accountant):
-    asset = 'BTC'
-    events = accountant.events.cost_basis.events
-    events[asset].acquisitions.append(
+    asset = A_BTC
+    asset_events = accountant.events.cost_basis.get_events(asset)
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -241,7 +242,7 @@ def test_calculate_spend_cost_basis_sell_more_than_bought_within_year(accountant
             fee_rate=FVal(0.0001),
         ),
     )
-    events[asset].acquisitions.append(
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -272,15 +273,15 @@ def test_calculate_spend_cost_basis_sell_more_than_bought_within_year(accountant
     assert cinfo.matched_acquisitions[1].event.amount == FVal(1)
     assert cinfo.matched_acquisitions[1].event.remaining_amount == ZERO
 
-    acquisitions_num = len(accountant.events.cost_basis.events[asset].acquisitions)
+    acquisitions_num = len(asset_events.acquisitions)
     assert acquisitions_num == 0, 'only buy should have been used'
 
 
 @pytest.mark.parametrize('accounting_initialize_parameters', [True])
 def test_calculate_spend_cost_basis_sell_more_than_bought_after_year(accountant):
-    asset = 'BTC'
-    events = accountant.events.cost_basis.events
-    events[asset].acquisitions.append(
+    asset = A_BTC
+    asset_events = accountant.events.cost_basis.get_events(asset)
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -290,7 +291,7 @@ def test_calculate_spend_cost_basis_sell_more_than_bought_after_year(accountant)
             fee_rate=FVal(0.0001),
         ),
     )
-    events[asset].acquisitions.append(
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -321,14 +322,14 @@ def test_calculate_spend_cost_basis_sell_more_than_bought_after_year(accountant)
     assert cinfo.matched_acquisitions[1].event.amount == FVal(1)
     assert cinfo.matched_acquisitions[1].event.remaining_amount == ZERO
 
-    acquisitions_num = len(accountant.events.cost_basis.events[asset].acquisitions)
+    acquisitions_num = len(asset_events.acquisitions)
     assert acquisitions_num == 0, 'only buy should have been used'
 
 
 def test_reduce_asset_amount(accountant):
-    asset = 'BTC'
-    events = accountant.events.cost_basis.events
-    events[asset].acquisitions.append(
+    asset = A_ETH
+    asset_events = accountant.events.cost_basis.get_events(asset)
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -338,7 +339,7 @@ def test_reduce_asset_amount(accountant):
             fee_rate=FVal(0.0001),
         ),
     )
-    events[asset].acquisitions.append(
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -348,7 +349,7 @@ def test_reduce_asset_amount(accountant):
             fee_rate=FVal(0.0019),
         ),
     )
-    events[asset].acquisitions.append(
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -360,16 +361,20 @@ def test_reduce_asset_amount(accountant):
     )
 
     assert accountant.events.cost_basis.reduce_asset_amount(asset, FVal(1.5))
-    acquisitions_num = len(accountant.events.cost_basis.events[asset].acquisitions)
+    acquisitions_num = len(asset_events.acquisitions)
     assert acquisitions_num == 2, '1 buy should be used'
-    remaining_amount = accountant.events.cost_basis.events[asset].acquisitions[0].remaining_amount
+    remaining_amount = asset_events.acquisitions[0].remaining_amount
     assert remaining_amount == FVal(0.5), '0.5 of 2nd buy should remain'
 
+    # make sure same thing works for WETH
+    equivalent_events = accountant.events.cost_basis.get_events(A_WETH)
+    assert equivalent_events.acquisitions[0].remaining_amount == FVal(0.5)
+
 
 def test_reduce_asset_amount_exact(accountant):
-    asset = 'BTC'
-    events = accountant.events.cost_basis.events
-    events[asset].acquisitions.append(
+    asset = A_BTC
+    asset_events = accountant.events.cost_basis.get_events(asset)
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -379,7 +384,7 @@ def test_reduce_asset_amount_exact(accountant):
             fee_rate=FVal(0.0001),
         ),
     )
-    events[asset].acquisitions.append(
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -391,7 +396,7 @@ def test_reduce_asset_amount_exact(accountant):
     )
 
     assert accountant.events.cost_basis.reduce_asset_amount(asset, FVal(2))
-    acquisitions_num = len(accountant.events.cost_basis.events[asset].acquisitions)
+    acquisitions_num = len(asset_events.acquisitions)
     assert acquisitions_num == 0, 'all buys should be used'
 
 
@@ -401,9 +406,9 @@ def test_reduce_asset_amount_not_bought(accountant):
 
 
 def test_reduce_asset_amount_more_that_bought(accountant):
-    asset = 'BTC'
-    events = accountant.events.cost_basis.events
-    events[asset].acquisitions.append(
+    asset = A_ETH
+    asset_events = accountant.events.cost_basis.get_events(asset)
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -413,7 +418,7 @@ def test_reduce_asset_amount_more_that_bought(accountant):
             fee_rate=FVal(0.0001),
         ),
     )
-    events[asset].acquisitions.append(
+    asset_events.acquisitions.append(
         AssetAcquisitionEvent(
             location=Location.EXTERNAL,
             description='trade',
@@ -424,6 +429,7 @@ def test_reduce_asset_amount_more_that_bought(accountant):
         ),
     )
 
-    assert not accountant.events.cost_basis.reduce_asset_amount(asset, FVal(3))
-    acquisitions_num = len(accountant.events.cost_basis.events[asset].acquisitions)
+    # Also reduce WETH, to make sure it's counted same as ETH
+    assert not accountant.events.cost_basis.reduce_asset_amount(A_WETH, FVal(3))
+    acquisitions_num = len(asset_events.acquisitions)
     assert acquisitions_num == 0, 'all buys should be used'