-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: upgrade balance endpoint (#471)
Problem: Currently, the Balance API Endpoint only returns the total balance for an address. The user (also frontend) has no easy way to get the amount of locked tokens. On : `/api/v0/addresses/{address}/balance` Solution: Enhance the Balance API Endpoint to include the "locked_amount" field in the response, indicating the amount of tokens in use for a specific address. Example: ```json { "address": "0x9319Ad3B7A8E0eE24f2E639c40D8eD124C5520Ba", "balance": 22192, "locked_amount": 2726 } ```
- Loading branch information
Showing
5 changed files
with
280 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import json | ||
|
||
import pytest | ||
from aleph.db.models import ( | ||
AlephBalanceDb, | ||
) | ||
from aleph.jobs.process_pending_messages import PendingMessageProcessor | ||
|
||
MESSAGES_URI = "/api/v0/addresses/0x9319Ad3B7A8E0eE24f2E639c40D8eD124C5520Ba/balance" | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_get_balance( | ||
ccn_api_client, | ||
message_processor: PendingMessageProcessor, | ||
instance_message_with_volumes_in_db, | ||
fixture_instance_message, | ||
user_balance: AlephBalanceDb, | ||
): | ||
pipeline = message_processor.make_pipeline() | ||
# Exhaust the iterator | ||
_ = [message async for message in pipeline] | ||
|
||
assert fixture_instance_message.item_content | ||
|
||
response = await ccn_api_client.get(MESSAGES_URI) | ||
assert response.status == 200, await response.text() | ||
data = await response.json() | ||
assert data["balance"] == user_balance.balance | ||
assert data["locked_amount"] == 2726 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters