Пример #1
0
def test_balance_calculation_out_canceled() -> None:
    account_id = 1
    counter_id = 0
    income = Transaction(
        source_id=counter_id,
        destination_id=account_id,
        amount=100,
        currency=DiemCurrency.XUS,
        status=TransactionStatus.COMPLETED,
    )
    outgoing = Transaction(
        source_id=account_id,
        destination_id=counter_id,
        amount=50,
        currency=DiemCurrency.XUS,
        status=TransactionStatus.CANCELED,
    )
    balance = calc_account_balance(account_id=account_id,
                                   transactions=[income, outgoing])

    assert balance.total == {
        DiemCurrency.XUS: 100,
    }
    assert balance.frozen == {
        DiemCurrency.XUS: 0,
    }
def test_balance_calculation_in_pending() -> None:
    account_id = 1
    counter_id = 0
    income = Transaction(
        source_id=counter_id,
        destination_id=account_id,
        amount=100,
        currency=DiemCurrency.Coin1,
        status=TransactionStatus.PENDING,
    )
    balance = calc_account_balance(account_id=account_id, transactions=[income])

    assert balance.total == {
        DiemCurrency.Coin1: 0,
    }
Пример #3
0
def test_balance_calculation_simple_income() -> None:
    account_id = 1
    counter_id = 0
    tx = Transaction(
        source_id=counter_id,
        destination_id=account_id,
        amount=100,
        currency=DiemCurrency.XUS,
        status=TransactionStatus.COMPLETED,
    )
    balance = calc_account_balance(account_id=account_id, transactions=[tx])

    assert balance.total == {
        DiemCurrency.XUS: 100,
    }
def test_balance_calculation_in_and_out() -> None:
    account_id = 1
    counter_id = 0
    income = Transaction(
        source_id=counter_id,
        destination_id=account_id,
        amount=100,
        currency=DiemCurrency.Coin1,
        status=TransactionStatus.COMPLETED,
    )
    outgoing = Transaction(
        source_id=account_id,
        destination_id=counter_id,
        amount=50,
        currency=DiemCurrency.Coin1,
        status=TransactionStatus.COMPLETED,
    )
    balance = calc_account_balance(
        account_id=account_id, transactions=[income, outgoing]
    )

    assert balance.total == {
        DiemCurrency.Coin1: 50,
    }