Skip to content

Commit 78761b5

Browse files
committed
Adding tests
1 parent ee7032d commit 78761b5

File tree

7 files changed

+528
-16
lines changed

7 files changed

+528
-16
lines changed

async_substrate_interface/async_substrate.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,7 @@ def __init__(
648648
auto_discover: bool = True,
649649
ss58_format: Optional[int] = None,
650650
type_registry: Optional[dict] = None,
651+
type_registry_preset: Optional[str] = None,
651652
chain_name: str = "",
652653
max_retries: int = 5,
653654
retry_timeout: float = 60.0,
@@ -664,6 +665,7 @@ def __init__(
664665
auto_discover: whether to automatically pull the presets based on the chain name and type registry
665666
ss58_format: the specific SS58 format to use
666667
type_registry: a dict of custom types
668+
type_registry_preset: preset
667669
chain_name: the name of the chain (the result of the rpc request for "system_chain")
668670
max_retries: number of times to retry RPC requests before giving up
669671
retry_timeout: how to long wait since the last ping to retry the RPC request
@@ -693,6 +695,7 @@ def __init__(
693695
self._forgettable_task = None
694696
self.ss58_format = ss58_format
695697
self.type_registry = type_registry
698+
self.type_registry_preset = type_registry_preset
696699
self.runtime_cache = RuntimeCache()
697700
self.runtime_config = RuntimeConfigurationObject(
698701
ss58_format=self.ss58_format, implements_scale_info=True

async_substrate_interface/sync_substrate.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,7 @@ def __init__(
456456
auto_discover: bool = True,
457457
ss58_format: Optional[int] = None,
458458
type_registry: Optional[dict] = None,
459+
type_registry_preset: Optional[str] = None,
459460
chain_name: str = "",
460461
max_retries: int = 5,
461462
retry_timeout: float = 60.0,
@@ -471,6 +472,7 @@ def __init__(
471472
auto_discover: whether to automatically pull the presets based on the chain name and type registry
472473
ss58_format: the specific SS58 format to use
473474
type_registry: a dict of custom types
475+
type_registry_preset: preset
474476
chain_name: the name of the chain (the result of the rpc request for "system_chain")
475477
max_retries: number of times to retry RPC requests before giving up
476478
retry_timeout: how to long wait since the last ping to retry the RPC request
@@ -492,13 +494,15 @@ def __init__(
492494
self._forgettable_task = None
493495
self.ss58_format = ss58_format
494496
self.type_registry = type_registry
497+
self.type_registry_preset = type_registry_preset
495498
self.runtime_cache = RuntimeCache()
496499
self.runtime_config = RuntimeConfigurationObject(
497500
ss58_format=self.ss58_format, implements_scale_info=True
498501
)
499502
self._metadata_cache = {}
500503
self.metadata_version_hex = "0x0f000000" # v15
501504
self.reload_type_registry()
505+
self.initialize()
502506

503507
def __enter__(self):
504508
self.initialize()
@@ -552,16 +556,6 @@ def name(self):
552556
self._name = self.rpc_request("system_name", []).get("result")
553557
return self._name
554558

555-
@property
556-
def ws(self) -> ClientConnection:
557-
return connect(
558-
self.chain_endpoint,
559-
options={
560-
"max_size": 2**32,
561-
"write_limit": 2**16,
562-
},
563-
)
564-
565559
def get_storage_item(self, module: str, storage_function: str):
566560
if not self._metadata:
567561
self.init_runtime()
@@ -1634,11 +1628,11 @@ def _make_rpc_request(
16341628
_received = {}
16351629
subscription_added = False
16361630

1637-
with self.ws as ws:
1631+
with connect(self.chain_endpoint, max_size=2**32) as ws:
16381632
item_id = 0
16391633
for payload in payloads:
16401634
item_id += 1
1641-
ws.send(ujson.dumps(payload["payload"]))
1635+
ws.send(ujson.dumps({**payload["payload"], **{"id": item_id}}))
16421636
request_manager.add_request(item_id, payload["id"])
16431637

16441638
while True:

tests/helpers/fixtures.py

Lines changed: 23 additions & 0 deletions
Large diffs are not rendered by default.

tests/helpers/settings.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# Python Substrate Interface Library
2+
#
3+
# Copyright 2018-2020 Stichting Polkascan (Polkascan Foundation).
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
from os import environ
17+
18+
KUSAMA_NODE_URL = (
19+
environ.get("SUBSTRATE_NODE_URL_KUSAMA") or "wss://kusama-rpc.polkadot.io/"
20+
)
21+
POLKADOT_NODE_URL = (
22+
environ.get("SUBSTRATE_NODE_URL_POLKADOT") or "wss://rpc.polkadot.io/"
23+
)
24+
ROCOCO_NODE_URL = (
25+
environ.get("SUBSTRATE_NODE_URL_ROCOCO") or "wss://rococo-rpc.polkadot.io"
26+
)
27+
MOONBEAM_NODE_URL = (
28+
environ.get("SUBSTRATE_NODE_URL_ROCOCO") or "wss://wss.api.moonbeam.network"
29+
)
30+
31+
BABE_NODE_URL = environ.get("SUBSTRATE_BABE_NODE_URL") or POLKADOT_NODE_URL
32+
AURA_NODE_URL = (
33+
environ.get("SUBSTRATE_AURA_NODE_URL") or "wss://acala-rpc-1.aca-api.network"
34+
)

tests/unit_tests/asyncio/test_substrate_interface.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import pytest
22
from websockets.exceptions import InvalidURI
33

4-
from async_substrate_interface.async_substrate import (
5-
AsyncSubstrateInterface
6-
)
4+
from async_substrate_interface.async_substrate import AsyncSubstrateInterface
75

86

97
@pytest.mark.asyncio

0 commit comments

Comments
 (0)