def test_apply_given_new_state_event_updates_correctly(self): # Arrange event1 = AccountState( AccountId("SIM", "001"), [Money("10.00000000", BTC), Money("20.00000000", ETH)], [Money("10.00000000", BTC), Money("20.00000000", ETH)], [Money("0.00000000", BTC), Money("0.00000000", ETH)], info={}, # No default currency set event_id=uuid4(), event_timestamp=UNIX_EPOCH, ) # Act account = Account(event1) # Wire up account to portfolio account.register_portfolio(self.portfolio) self.portfolio.register_account(account) event2 = AccountState( AccountId("SIM", "001"), [Money("9.00000000", BTC), Money("20.00000000", ETH)], [Money("8.50000000", BTC), Money("20.00000000", ETH)], [Money("0.50000000", BTC), Money("0.00000000", ETH)], info={}, # No default currency set event_id=uuid4(), event_timestamp=UNIX_EPOCH, ) # Act account.apply(event2) # Assert self.assertEqual(event2, account.last_event) self.assertEqual([event1, event2], account.events) self.assertEqual(2, account.event_count) self.assertEqual(Money("9.00000000", BTC), account.balance(BTC)) self.assertEqual(Money("8.50000000", BTC), account.balance_free(BTC)) self.assertEqual(Money("0.50000000", BTC), account.balance_locked(BTC)) self.assertEqual(Money("20.00000000", ETH), account.balance(ETH)) self.assertEqual(Money("20.00000000", ETH), account.balance_free(ETH)) self.assertEqual(Money("0.00000000", ETH), account.balance_locked(ETH))
def test_apply_given_new_state_event_updates_correctly(self): # Arrange event1 = AccountState( account_id=AccountId("SIM", "001"), account_type=AccountType.CASH, base_currency=None, # Multi-currency reported=True, balances=[ AccountBalance( BTC, Money(10.00000000, BTC), Money(0.00000000, BTC), Money(10.00000000, BTC), ), AccountBalance( ETH, Money(20.00000000, ETH), Money(0.00000000, ETH), Money(20.00000000, ETH), ), ], info={}, # No default currency set event_id=uuid4(), ts_updated_ns=0, timestamp_ns=0, ) # Act account = Account(event1) # Wire up account to portfolio account.register_portfolio(self.portfolio) self.portfolio.register_account(account) event2 = AccountState( account_id=AccountId("SIM", "001"), account_type=AccountType.CASH, base_currency=None, # Multi-currency reported=True, balances=[ AccountBalance( BTC, Money(9.00000000, BTC), Money(0.50000000, BTC), Money(8.50000000, BTC), ), AccountBalance( ETH, Money(20.00000000, ETH), Money(0.00000000, ETH), Money(20.00000000, ETH), ), ], info={}, # No default currency set event_id=uuid4(), ts_updated_ns=0, timestamp_ns=0, ) # Act account.apply(event=event2) # Assert self.assertEqual(event2, account.last_event) self.assertEqual([event1, event2], account.events) self.assertEqual(2, account.event_count) self.assertEqual(Money(9.00000000, BTC), account.balance_total(BTC)) self.assertEqual(Money(8.50000000, BTC), account.balance_free(BTC)) self.assertEqual(Money(0.50000000, BTC), account.balance_locked(BTC)) self.assertEqual(Money(20.00000000, ETH), account.balance_total(ETH)) self.assertEqual(Money(20.00000000, ETH), account.balance_free(ETH)) self.assertEqual(Money(0.00000000, ETH), account.balance_locked(ETH))