def test_instantiate_single_asset_cash_account(self): # Arrange event = AccountState( account_id=AccountId("SIM", "000"), account_type=AccountType.BETTING, base_currency=GBP, reported=True, balances=[ AccountBalance( GBP, Money(1_000_000, GBP), Money(0, GBP), Money(1_000_000, GBP), ), ], info={}, event_id=UUID4(), ts_event=0, ts_init=0, ) # Act account = BettingAccount(event) # Assert assert account.base_currency == GBP assert account.last_event == event assert account.events == [event] assert account.event_count == 1 assert account.balance_total() == Money(1_000_000, GBP) assert account.balance_free() == Money(1_000_000, GBP) assert account.balance_locked() == Money(0, GBP) assert account.balances_total() == {GBP: Money(1_000_000, GBP)} assert account.balances_free() == {GBP: Money(1_000_000, GBP)} assert account.balances_locked() == {GBP: Money(0, GBP)}
def test_apply_given_new_state_event_updates_correctly(self): # Arrange event1 = AccountState( account_id=AccountId("SIM", "001"), account_type=AccountType.BETTING, base_currency=None, # Multi-currency reported=True, balances=[ AccountBalance( GBP, Money(10.00000000, GBP), Money(0.00000000, GBP), Money(10.00000000, GBP), ), ], info={}, # No default currency set event_id=UUID4(), ts_event=0, ts_init=0, ) # Act account = BettingAccount(event1) event2 = AccountState( account_id=AccountId("SIM", "001"), account_type=AccountType.BETTING, base_currency=None, # Multi-currency reported=True, balances=[ AccountBalance( GBP, Money(9.00000000, GBP), Money(0.50000000, GBP), Money(8.50000000, GBP), ), ], info={}, # No default currency set event_id=UUID4(), ts_event=0, ts_init=0, ) # Act account.apply(event=event2) # Assert assert account.last_event == event2 assert account.events == [event1, event2] assert account.event_count == 2 assert account.balance_total(GBP) == Money(9.00000000, GBP) assert account.balance_free(GBP) == Money(8.50000000, GBP) assert account.balance_locked(GBP) == Money(0.50000000, GBP)