|
| 1 | +import pytest |
| 2 | +from loguru import logger |
| 3 | +from utils.address import stake_public_key_to_address |
| 4 | +from utils.snapshot import snapshot |
| 5 | +from utils.auth_token import rbac_auth_token_factory |
| 6 | +from api.v1 import cardano |
| 7 | + |
| 8 | + |
| 9 | +@pytest.mark.skip("To be refactored when the api is ready") |
| 10 | +def test_persistent_ada_amount_endpoint(snapshot, rbac_auth_token_factory): |
| 11 | + # health.is_live() |
| 12 | + # health.is_ready() |
| 13 | + logger.info(f"{snapshot.network}, {snapshot.slot_no}") |
| 14 | + token = rbac_auth_token_factory() |
| 15 | + |
| 16 | + total_len = len(snapshot.data) |
| 17 | + for i, entry in enumerate(snapshot.data): |
| 18 | + logger.info(f"Checking .... {round(i / total_len * 100, 1)}%") |
| 19 | + expected_amount = entry["voting_power"] |
| 20 | + stake_address = stake_public_key_to_address( |
| 21 | + key=entry["stake_public_key"][2:], |
| 22 | + is_stake=True, |
| 23 | + network_type=snapshot.network, |
| 24 | + ) |
| 25 | + resp = cardano.assets(stake_address, snapshot.slot_no, token) |
| 26 | + if expected_amount == 0 and resp.status_code == 404: |
| 27 | + # it is possible that snapshot tool collected data for the stake key which does not have any unspent utxo |
| 28 | + # at this case cat-gateway return 404, that is why we are checking this case additionally |
| 29 | + continue |
| 30 | + |
| 31 | + assert ( |
| 32 | + resp.status_code == 200 |
| 33 | + ), f"Cannot find assets for stake_address: {stake_address}" |
| 34 | + assets = resp.json() |
| 35 | + if assets["persistent"]["ada_amount"] != expected_amount: |
| 36 | + logger.error( |
| 37 | + f"Not expected ada amount for stake_address: {stake_address}, {entry["stake_public_key"]}" |
| 38 | + ) |
| 39 | + # assert ( |
| 40 | + # assets["persistent"]["ada_amount"] == expected_amount |
| 41 | + # ), f"Not expected ada amount for stake_address: {stake_address}, {entry["stake_public_key"]}" |
0 commit comments