22from unittest .mock import AsyncMock , MagicMock , ANY
33
44import pytest
5- from scalecodec import ss58_encode
65from websockets .exceptions import InvalidURI
76
87from async_substrate_interface .async_substrate import AsyncSubstrateInterface
98from async_substrate_interface .types import ScaleObj
10- from tests .helpers .settings import ARCHIVE_ENTRYPOINT , LATENT_LITE_ENTRYPOINT
119
1210
1311@pytest .mark .asyncio
@@ -101,7 +99,7 @@ async def test_runtime_call(monkeypatch):
10199@pytest .mark .asyncio
102100async def test_websocket_shutdown_timer ():
103101 # using default ws shutdown timer of 5.0 seconds
104- async with AsyncSubstrateInterface (LATENT_LITE_ENTRYPOINT ) as substrate :
102+ async with AsyncSubstrateInterface ("wss://lite.sub.latent.to:443" ) as substrate :
105103 await substrate .get_chain_head ()
106104 await asyncio .sleep (6 )
107105 assert (
@@ -115,70 +113,3 @@ async def test_websocket_shutdown_timer():
115113 await substrate .get_chain_head ()
116114 await asyncio .sleep (6 ) # same sleep time as before
117115 assert substrate .ws ._initialized is True # connection should still be open
118-
119-
120- @pytest .mark .asyncio
121- async def test_legacy_decoding ():
122- # roughly 4000 blocks before metadata v15 was added
123- pre_metadata_v15_block = 3_010_611
124-
125- async with AsyncSubstrateInterface (ARCHIVE_ENTRYPOINT ) as substrate :
126- block_hash = await substrate .get_block_hash (pre_metadata_v15_block )
127- events = await substrate .get_events (block_hash )
128- assert isinstance (events , list )
129-
130- query_map_result = await substrate .query_map (
131- module = "SubtensorModule" ,
132- storage_function = "NetworksAdded" ,
133- block_hash = block_hash ,
134- )
135- async for key , value in query_map_result :
136- assert isinstance (key , int )
137- assert isinstance (value , ScaleObj )
138-
139- timestamp = await substrate .query (
140- "Timestamp" ,
141- "Now" ,
142- block_hash = block_hash ,
143- )
144- assert timestamp .value == 1716358476004
145-
146-
147- @pytest .mark .asyncio
148- async def test_ss58_conversion ():
149- async with AsyncSubstrateInterface (
150- LATENT_LITE_ENTRYPOINT , ss58_format = 42 , decode_ss58 = False
151- ) as substrate :
152- block_hash = await substrate .get_chain_finalised_head ()
153- qm = await substrate .query_map (
154- "SubtensorModule" ,
155- "OwnedHotkeys" ,
156- block_hash = block_hash ,
157- )
158- # only do the first page, bc otherwise this will be massive
159- for key , value in qm .records :
160- assert isinstance (key , tuple )
161- assert isinstance (value , ScaleObj )
162- assert isinstance (value .value , list )
163- assert len (key ) == 1
164- for key_tuple in value .value :
165- assert len (key_tuple [0 ]) == 32
166- random_key = key_tuple [0 ]
167-
168- ss58_of_key = ss58_encode (bytes (random_key ), substrate .ss58_format )
169- assert isinstance (ss58_of_key , str )
170-
171- substrate .decode_ss58 = True # change to decoding True
172-
173- qm = await substrate .query_map (
174- "SubtensorModule" ,
175- "OwnedHotkeys" ,
176- block_hash = block_hash ,
177- )
178- for key , value in qm .records :
179- assert isinstance (key , str )
180- assert isinstance (value , ScaleObj )
181- assert isinstance (value .value , list )
182- if len (value .value ) > 0 :
183- for decoded_key in value .value :
184- assert isinstance (decoded_key , str )
0 commit comments