Skip to content

Commit a343edc

Browse files
committed
Move test
1 parent 747dc32 commit a343edc

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

tests/integration_tests/test_async_substrate_interface.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import time
2+
13
import pytest
24
from scalecodec import ss58_encode
35

@@ -71,3 +73,45 @@ async def test_ss58_conversion():
7173
if len(value.value) > 0:
7274
for decoded_key in value.value:
7375
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

Comments
 (0)