|
| 1 | +from sqlalchemy.ext.asyncio import AsyncSession |
| 2 | +from async_asgi_testclient import TestClient |
| 3 | +from tests.client_requests import addresses |
| 4 | +from app.models.output import Output |
| 5 | +from app.utils import to_satoshi |
| 6 | +from tests import helpers |
| 7 | +import secrets |
| 8 | + |
| 9 | + |
| 10 | +async def test_default(client: TestClient, address_utxo: Output, session: AsyncSession): |
| 11 | + extra_amount = 100 |
| 12 | + |
| 13 | + utxo1 = await helpers.create_output( |
| 14 | + session, |
| 15 | + address_utxo.currency, |
| 16 | + address=address_utxo.address, |
| 17 | + spent=False, |
| 18 | + shortcut=secrets.token_hex(16), |
| 19 | + amount=123, |
| 20 | + ) |
| 21 | + |
| 22 | + required_amount = address_utxo.amount + utxo1.amount + extra_amount |
| 23 | + |
| 24 | + response = await addresses.get_address_utxo( |
| 25 | + client, address_utxo.address, float(required_amount), "MBC" |
| 26 | + ) |
| 27 | + print(response.json()) |
| 28 | + assert response.status_code == 200 |
| 29 | + |
| 30 | + assert response.json()["pagination"] == {"total": 2, "pages": 1, "page": 1} |
| 31 | + |
| 32 | + for txo in response.json()["list"]: |
| 33 | + assert txo["timelock"] in (address_utxo.timelock, utxo1.timelock) |
| 34 | + assert txo["amount"] in ( |
| 35 | + to_satoshi(float(address_utxo.amount)), |
| 36 | + to_satoshi(float(utxo1.amount)), |
| 37 | + ) |
| 38 | + assert txo["currency"] in (address_utxo.currency, utxo1.currency) |
| 39 | + assert txo["index"] in (address_utxo.index, utxo1.index) |
| 40 | + assert txo["type"] in (address_utxo.type, utxo1.type) |
| 41 | + assert txo["txid"] in (address_utxo.txid, utxo1.txid) |
| 42 | + assert txo["spent"] is False |
| 43 | + |
| 44 | + |
| 45 | +async def test_none(client, address): |
| 46 | + response = await addresses.get_address_utxo(client, address.address, 1, "MBC") |
| 47 | + print(response.json()) |
| 48 | + assert response.status_code == 200 |
| 49 | + |
| 50 | + assert response.json()["pagination"] == {"total": 0, "pages": 0, "page": 1} |
| 51 | + assert response.json()["list"] == [] |
0 commit comments