|
| 1 | +import time |
| 2 | + |
1 | 3 | import pytest
|
2 | 4 | from scalecodec import ss58_encode
|
3 | 5 |
|
@@ -71,3 +73,45 @@ async def test_ss58_conversion():
|
71 | 73 | if len(value.value) > 0:
|
72 | 74 | for decoded_key in value.value:
|
73 | 75 | assert isinstance(decoded_key, str)
|
| 76 | + |
| 77 | + |
| 78 | +@pytest.mark.asyncio |
| 79 | +async def test_fully_exhaust_query_map(): |
| 80 | + async with AsyncSubstrateInterface(LATENT_LITE_ENTRYPOINT) as substrate: |
| 81 | + block_hash = await substrate.get_chain_finalised_head() |
| 82 | + non_fully_exhauster_start = time.time() |
| 83 | + non_fully_exhausted_qm = await substrate.query_map( |
| 84 | + "SubtensorModule", |
| 85 | + "CRV3WeightCommits", |
| 86 | + block_hash=block_hash, |
| 87 | + ) |
| 88 | + initial_records_count = len(non_fully_exhausted_qm.records) |
| 89 | + assert initial_records_count <= 100 # default page size |
| 90 | + exhausted_records_count = 0 |
| 91 | + async for _ in non_fully_exhausted_qm: |
| 92 | + exhausted_records_count += 1 |
| 93 | + non_fully_exhausted_time = time.time() - non_fully_exhauster_start |
| 94 | + |
| 95 | + assert len(non_fully_exhausted_qm.records) >= initial_records_count |
| 96 | + fully_exhausted_start = time.time() |
| 97 | + fully_exhausted_qm = await substrate.query_map( |
| 98 | + "SubtensorModule", |
| 99 | + "CRV3WeightCommits", |
| 100 | + block_hash=block_hash, |
| 101 | + fully_exhaust=True, |
| 102 | + ) |
| 103 | + |
| 104 | + fully_exhausted_time = time.time() - fully_exhausted_start |
| 105 | + initial_records_count_fully_exhaust = len(fully_exhausted_qm.records) |
| 106 | + assert fully_exhausted_time <= non_fully_exhausted_time, ( |
| 107 | + f"Fully exhausted took longer than non-fully exhausted with " |
| 108 | + f"{len(non_fully_exhausted_qm.records)} records in non-fully exhausted " |
| 109 | + f"in {non_fully_exhausted_time} seconds, and {initial_records_count_fully_exhaust} in fully exhausted" |
| 110 | + f" in {fully_exhausted_time} seconds. This could be caused by the fact that on this specific block, " |
| 111 | + f"there are fewer records than take up a single page. This difference should still be small." |
| 112 | + ) |
| 113 | + fully_exhausted_records_count = 0 |
| 114 | + async for _ in fully_exhausted_qm: |
| 115 | + fully_exhausted_records_count += 1 |
| 116 | + assert fully_exhausted_records_count == initial_records_count_fully_exhaust |
| 117 | + assert initial_records_count_fully_exhaust == exhausted_records_count |
0 commit comments