Skip to content

Commit 451cb5b

Browse files
committed
Moved tests.
1 parent ce2a21c commit 451cb5b

File tree

2 files changed

+84
-2
lines changed

2 files changed

+84
-2
lines changed

tests/integration_tests/test_async_substrate_interface.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import pytest
2+
from scalecodec import ss58_encode
23

34
from async_substrate_interface.async_substrate import AsyncSubstrateInterface
45
from async_substrate_interface.types import ScaleObj
5-
from tests.helpers.settings import ARCHIVE_ENTRYPOINT
6+
from tests.helpers.settings import ARCHIVE_ENTRYPOINT, LATENT_LITE_ENTRYPOINT
67

78

89
@pytest.mark.asyncio
@@ -30,3 +31,43 @@ async def test_legacy_decoding():
3031
block_hash=block_hash,
3132
)
3233
assert timestamp.value == 1716358476004
34+
35+
36+
@pytest.mark.asyncio
37+
async def test_ss58_conversion():
38+
async with AsyncSubstrateInterface(
39+
LATENT_LITE_ENTRYPOINT, ss58_format=42, decode_ss58=False
40+
) as substrate:
41+
block_hash = await substrate.get_chain_finalised_head()
42+
qm = await substrate.query_map(
43+
"SubtensorModule",
44+
"OwnedHotkeys",
45+
block_hash=block_hash,
46+
)
47+
# only do the first page, bc otherwise this will be massive
48+
for key, value in qm.records:
49+
assert isinstance(key, tuple)
50+
assert isinstance(value, ScaleObj)
51+
assert isinstance(value.value, list)
52+
assert len(key) == 1
53+
for key_tuple in value.value:
54+
assert len(key_tuple[0]) == 32
55+
random_key = key_tuple[0]
56+
57+
ss58_of_key = ss58_encode(bytes(random_key), substrate.ss58_format)
58+
assert isinstance(ss58_of_key, str)
59+
60+
substrate.decode_ss58 = True # change to decoding True
61+
62+
qm = await substrate.query_map(
63+
"SubtensorModule",
64+
"OwnedHotkeys",
65+
block_hash=block_hash,
66+
)
67+
for key, value in qm.records:
68+
assert isinstance(key, str)
69+
assert isinstance(value, ScaleObj)
70+
assert isinstance(value.value, list)
71+
if len(value.value) > 0:
72+
for decoded_key in value.value:
73+
assert isinstance(decoded_key, str)

tests/integration_tests/test_substrate_interface.py

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from scalecodec import ss58_encode
2+
13
from async_substrate_interface.sync_substrate import SubstrateInterface
24
from 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

68
def 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

Comments
 (0)