Skip to content

Commit 6c4a53c

Browse files
committed
Add more tests
1 parent 6a6e89c commit 6c4a53c

File tree

1 file changed

+55
-2
lines changed

1 file changed

+55
-2
lines changed

tests/integration_tests/test_disk_cache.py

Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
2+
import time
33
from async_substrate_interface.async_substrate import (
44
DiskCachedAsyncSubstrateInterface,
55
AsyncSubstrateInterface,
@@ -41,6 +41,7 @@ async def test_disk_cache():
4141
assert parent_block_hash == parent_block_hash_from_cache
4242
assert block_runtime_info == block_runtime_info_from_cache
4343
assert block_runtime_version_for == block_runtime_version_from_cache
44+
# Verify data integrity with non-disk cached Async Substrate Interface
4445
async with AsyncSubstrateInterface(entrypoint) as non_cache_substrate:
4546
block_hash_non_cache = await non_cache_substrate.get_block_hash(current_block)
4647
parent_block_hash_non_cache = await non_cache_substrate.get_parent_block_hash(
@@ -58,6 +59,7 @@ async def test_disk_cache():
5859
assert parent_block_hash == parent_block_hash_non_cache
5960
assert block_runtime_info == block_runtime_info_non_cache
6061
assert block_runtime_version_for == block_runtime_version_for_non_cache
62+
# Verify data integrity with sync Substrate Interface
6163
with SubstrateInterface(entrypoint) as sync_substrate:
6264
block_hash_sync = sync_substrate.get_block_hash(current_block)
6365
parent_block_hash_sync = sync_substrate.get_parent_block_hash(
@@ -73,4 +75,55 @@ async def test_disk_cache():
7375
assert parent_block_hash == parent_block_hash_sync
7476
assert block_runtime_info == block_runtime_info_sync
7577
assert block_runtime_version_for == block_runtime_version_for_sync
76-
print("test_disk_cache succeeded")
78+
# Verify data is pulling from disk cache
79+
async with DiskCachedAsyncSubstrateInterface(entrypoint) as disk_cached_substrate:
80+
start = time.monotonic()
81+
new_block_hash = await disk_cached_substrate.get_block_hash(current_block)
82+
new_time = time.monotonic()
83+
assert new_time - start < 0.001
84+
85+
start = time.monotonic()
86+
new_parent_block_hash = await disk_cached_substrate.get_parent_block_hash(
87+
block_hash
88+
)
89+
new_time = time.monotonic()
90+
assert new_time - start < 0.001
91+
start = time.monotonic()
92+
new_block_runtime_info = await disk_cached_substrate.get_block_runtime_info(
93+
block_hash
94+
)
95+
new_time = time.monotonic()
96+
assert new_time - start < 0.001
97+
start = time.monotonic()
98+
new_block_runtime_version_for = (
99+
await disk_cached_substrate.get_block_runtime_version_for(block_hash)
100+
)
101+
new_time = time.monotonic()
102+
assert new_time - start < 0.001
103+
start = time.monotonic()
104+
new_block_hash_from_cache = await disk_cached_substrate.get_block_hash(
105+
current_block
106+
)
107+
new_time = time.monotonic()
108+
assert new_time - start < 0.001
109+
start = time.monotonic()
110+
new_parent_block_hash_from_cache = (
111+
await disk_cached_substrate.get_parent_block_hash(block_hash_from_cache)
112+
)
113+
new_time = time.monotonic()
114+
assert new_time - start < 0.001
115+
start = time.monotonic()
116+
new_block_runtime_info_from_cache = (
117+
await disk_cached_substrate.get_block_runtime_info(block_hash_from_cache)
118+
)
119+
new_time = time.monotonic()
120+
assert new_time - start < 0.001
121+
start = time.monotonic()
122+
new_block_runtime_version_from_cache = (
123+
await disk_cached_substrate.get_block_runtime_version_for(
124+
block_hash_from_cache
125+
)
126+
)
127+
new_time = time.monotonic()
128+
assert new_time - start < 0.001
129+
print("Disk Cache tests passed")

0 commit comments

Comments
 (0)