44from aleph .db .models import AlephBalanceDb
55from aleph .jobs .process_pending_messages import PendingMessageProcessor
66
7- MESSAGES_URI = "/api/v0/addresses/0x9319Ad3B7A8E0eE24f2E639c40D8eD124C5520Ba/balance"
7+ ACCOUNT_BALANCE_URI = (
8+ "/api/v0/addresses/0x9319Ad3B7A8E0eE24f2E639c40D8eD124C5520Ba/balance"
9+ )
10+ BALANCES_URI = "/api/v0/balances"
811
912
1013@pytest .mark .asyncio
@@ -23,7 +26,7 @@ async def test_get_balance(
2326
2427 assert fixture_instance_message .item_content
2528
26- response = await ccn_api_client .get (MESSAGES_URI )
29+ response = await ccn_api_client .get (ACCOUNT_BALANCE_URI )
2730 assert response .status == 200 , await response .text ()
2831 data = await response .json ()
2932 assert data ["balance" ] == user_balance .balance
@@ -51,7 +54,7 @@ async def test_get_balance_with_chain(
5154 expected_locked_amount = 1001.8
5255 chain = Chain .AVAX .value
5356 # Test Avax
54- avax_response = await ccn_api_client .get (f"{ MESSAGES_URI } ?chain={ chain } " )
57+ avax_response = await ccn_api_client .get (f"{ ACCOUNT_BALANCE_URI } ?chain={ chain } " )
5558
5659 assert avax_response .status == 200 , await avax_response .text ()
5760 avax_data = await avax_response .json ()
@@ -61,15 +64,15 @@ async def test_get_balance_with_chain(
6164
6265 # Verify ETH Value
6366 chain = Chain .ETH .value
64- eth_response = await ccn_api_client .get (f"{ MESSAGES_URI } ?chain={ chain } " )
67+ eth_response = await ccn_api_client .get (f"{ ACCOUNT_BALANCE_URI } ?chain={ chain } " )
6568 assert eth_response .status == 200 , await eth_response .text ()
6669 eth_data = await eth_response .json ()
6770 eth_expected_balance = user_balance_eth_avax .balance
6871 assert eth_data ["balance" ] == eth_expected_balance
6972 assert eth_data ["locked_amount" ] == expected_locked_amount
7073
7174 # Verify All Chain
72- total_response = await ccn_api_client .get (f"{ MESSAGES_URI } " )
75+ total_response = await ccn_api_client .get (f"{ ACCOUNT_BALANCE_URI } " )
7376 assert total_response .status == 200 , await total_response .text ()
7477 total_data = await total_response .json ()
7578 total_expected_balance = user_balance_eth_avax .balance * 2
@@ -86,19 +89,41 @@ async def test_get_balance_with_chain(
8689async def test_get_balance_with_no_balance (
8790 ccn_api_client ,
8891):
89- response = await ccn_api_client .get (f"{ MESSAGES_URI } " )
92+ response = await ccn_api_client .get (f"{ ACCOUNT_BALANCE_URI } " )
9093
9194 assert response .status == 200 , await response .text ()
9295 data = await response .json ()
9396 assert data ["balance" ] == 0
9497 assert data ["locked_amount" ] == 0
9598
9699 # Test Eth Case
97- response = await ccn_api_client .get (f"{ MESSAGES_URI } ?chain{ Chain .ETH .value } " )
100+ response = await ccn_api_client .get (f"{ ACCOUNT_BALANCE_URI } ?chain{ Chain .ETH .value } " )
98101
99102 assert response .status == 200 , await response .text ()
100103 data = await response .json ()
101104 assert data ["balance" ] == 0
102105 assert data ["locked_amount" ] == 0
103106 details = data ["details" ]
104107 assert not details
108+
109+
110+ @pytest .mark .asyncio
111+ async def test_get_balances (
112+ ccn_api_client ,
113+ user_balance : AlephBalanceDb ,
114+ ):
115+ response = await ccn_api_client .get (f"{ BALANCES_URI } " )
116+ assert response .status == 200 , await response .text ()
117+ data = await response .json ()
118+ assert len (data ["balances" ]) > 0
119+
120+
121+ @pytest .mark .asyncio
122+ async def test_get_balances_with_chains_param (
123+ ccn_api_client ,
124+ user_balance_eth_avax : AlephBalanceDb ,
125+ ):
126+ response = await ccn_api_client .get (f"{ BALANCES_URI } ?chains=AVAX" )
127+ assert response .status == 200 , await response .text ()
128+ data = await response .json ()
129+ assert len (data ["balances" ]) > 0
0 commit comments