|
2 | 2 | from unittest.mock import AsyncMock, MagicMock, ANY
|
3 | 3 |
|
4 | 4 | import pytest
|
| 5 | +from scalecodec import ss58_encode |
5 | 6 | from websockets.exceptions import InvalidURI
|
6 | 7 |
|
7 | 8 | from async_substrate_interface.async_substrate import AsyncSubstrateInterface
|
8 | 9 | from async_substrate_interface.types import ScaleObj
|
9 |
| -from tests.helpers.settings import ARCHIVE_ENTRYPOINT |
| 10 | +from tests.helpers.settings import ARCHIVE_ENTRYPOINT, LATENT_LITE_ENTRYPOINT |
10 | 11 |
|
11 | 12 |
|
12 | 13 | @pytest.mark.asyncio
|
@@ -100,7 +101,7 @@ async def test_runtime_call(monkeypatch):
|
100 | 101 | @pytest.mark.asyncio
|
101 | 102 | async def test_websocket_shutdown_timer():
|
102 | 103 | # using default ws shutdown timer of 5.0 seconds
|
103 |
| - async with AsyncSubstrateInterface("wss://lite.sub.latent.to:443") as substrate: |
| 104 | + async with AsyncSubstrateInterface(LATENT_LITE_ENTRYPOINT) as substrate: |
104 | 105 | await substrate.get_chain_head()
|
105 | 106 | await asyncio.sleep(6)
|
106 | 107 | assert (
|
@@ -141,3 +142,43 @@ async def test_legacy_decoding():
|
141 | 142 | block_hash=block_hash,
|
142 | 143 | )
|
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