Ejemplo n.º 1
0
def get_payment_command_json(transaction_id: int) -> Optional[Dict]:
    transaction = storage.get_transaction(transaction_id)

    if transaction and transaction.command_json:
        return json.loads(transaction.command_json)

    return None
Ejemplo n.º 2
0
def test_add_funds(patch_blockchain: None):
    buy_amount = 1000
    buy_currency = DiemCurrency.XUS
    inventory_id, account_id, order_id = AddFundsSeeder.run(
        db_session,
        buy_amount=buy_amount,
        buy_currency=buy_currency,
        pay_currency=FiatCurrency.EUR,
        pay_price=900,
    )

    payment_method = "4580 2601 0743 7443"

    order_service.execute_order(order_id, payment_method)

    order = get_order(order_id)
    assert order.order_status == OrderStatus.Executed.value
    assert order.cover_status == CoverStatus.Covered.value

    add_funds_transaction = storage.get_transaction(order.internal_ledger_tx)
    assert add_funds_transaction
    assert add_funds_transaction.currency == buy_currency
    assert add_funds_transaction.amount == buy_amount
    assert add_funds_transaction.source_id == inventory_id
    assert add_funds_transaction.destination_id == account_id
Ejemplo n.º 3
0
def test_withdraw_funds(patch_blockchain: None):
    inventory_id, account_id, order_id = WithdrawFundsSeeder.run(
        db_session,
        account_amount=1000,
        account_currency=DiemCurrency.XUS,
        withdraw_amount=500,
        withdraw_to_currency=FiatCurrency.USD,
        price=550,
    )
    payment_method = "4580 2601 0743 7443"

    order_service.execute_order(order_id, payment_method)

    order = get_order(order_id)
    assert order.order_status == OrderStatus.Executed.value
    assert order.cover_status == CoverStatus.Covered.value

    withdraw_transaction = storage.get_transaction(order.internal_ledger_tx)
    assert withdraw_transaction
    assert withdraw_transaction.currency == DiemCurrency.XUS
    assert withdraw_transaction.amount == 500
    assert withdraw_transaction.source_id == account_id
    assert withdraw_transaction.destination_id == inventory_id