1+ from scalecodec import ss58_encode
2+
13from async_substrate_interface .sync_substrate import SubstrateInterface
24from async_substrate_interface .types import ScaleObj
3- from tests .helpers .settings import ARCHIVE_ENTRYPOINT
5+ from tests .helpers .settings import ARCHIVE_ENTRYPOINT , LATENT_LITE_ENTRYPOINT
46
57
68def test_legacy_decoding ():
@@ -27,3 +29,42 @@ def test_legacy_decoding():
2729 block_hash = block_hash ,
2830 )
2931 assert timestamp .value == 1716358476004
32+
33+
34+ def test_ss58_conversion ():
35+ with SubstrateInterface (
36+ LATENT_LITE_ENTRYPOINT , ss58_format = 42 , decode_ss58 = False
37+ ) as substrate :
38+ block_hash = substrate .get_chain_finalised_head ()
39+ qm = substrate .query_map (
40+ "SubtensorModule" ,
41+ "OwnedHotkeys" ,
42+ block_hash = block_hash ,
43+ )
44+ # only do the first page, bc otherwise this will be massive
45+ for key , value in qm .records :
46+ assert isinstance (key , tuple )
47+ assert isinstance (value , ScaleObj )
48+ assert isinstance (value .value , list )
49+ assert len (key ) == 1
50+ for key_tuple in value .value :
51+ assert len (key_tuple [0 ]) == 32
52+ random_key = key_tuple [0 ]
53+
54+ ss58_of_key = ss58_encode (bytes (random_key ), substrate .ss58_format )
55+ assert isinstance (ss58_of_key , str )
56+
57+ substrate .decode_ss58 = True # change to decoding True
58+
59+ qm = substrate .query_map (
60+ "SubtensorModule" ,
61+ "OwnedHotkeys" ,
62+ block_hash = block_hash ,
63+ )
64+ for key , value in qm .records :
65+ assert isinstance (key , str )
66+ assert isinstance (value , ScaleObj )
67+ assert isinstance (value .value , list )
68+ if len (value .value ) > 0 :
69+ for decoded_key in value .value :
70+ assert isinstance (decoded_key , str )
0 commit comments