File tree Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Expand file tree Collapse file tree 2 files changed +68
-0
lines changed Original file line number Diff line number Diff line change
1
+ import importlib
2
+ import sys
3
+
4
+
5
+ def import_fresh (modname : str ):
6
+ """
7
+ Imports or reloads the module from a fresh state.
8
+ """
9
+ to_drop = [m for m in sys .modules if m == modname or m .startswith (modname + "." )]
10
+ for m in to_drop :
11
+ sys .modules .pop (m )
12
+ return importlib .import_module (modname )
13
+
14
+
15
+ def test_env_vars (monkeypatch ):
16
+ monkeypatch .setenv ("SUBSTRATE_CACHE_METHOD_SIZE" , 10 )
17
+ monkeypatch .setenv ("SUBSTRATE_RUNTIME_CACHE_SIZE" , 9 )
18
+ async_substrate = import_fresh ("async_substrate_interface.async_substrate" )
19
+ asi = async_substrate .AsyncSubstrateInterface ("" , _mock = True )
20
+ assert asi .get_runtime_for_version ._max_size == 9
21
+ assert asi .get_block_runtime_info ._max_size == 9
22
+ assert asi .get_parent_block_hash ._max_size == 10
23
+ assert asi .get_block_runtime_version_for ._max_size == 10
24
+ assert asi .get_block_hash ._max_size == 10
25
+
26
+
27
+ def test_defaults ():
28
+ async_substrate = import_fresh ("async_substrate_interface.async_substrate" )
29
+ asi = async_substrate .AsyncSubstrateInterface ("" , _mock = True )
30
+ assert asi .get_runtime_for_version ._max_size == 16
31
+ assert asi .get_block_runtime_info ._max_size == 16
32
+ assert asi .get_parent_block_hash ._max_size == 512
33
+ assert asi .get_block_runtime_version_for ._max_size == 512
34
+ assert asi .get_block_hash ._max_size == 512
Original file line number Diff line number Diff line change
1
+ import importlib
2
+ import sys
3
+
4
+
5
+ def import_fresh (modname : str ):
6
+ """
7
+ Imports or reloads the module from a fresh state.
8
+ """
9
+ to_drop = [m for m in sys .modules if m == modname or m .startswith (modname + "." )]
10
+ for m in to_drop :
11
+ sys .modules .pop (m )
12
+ return importlib .import_module (modname )
13
+
14
+
15
+ def test_env_vars (monkeypatch ):
16
+ monkeypatch .setenv ("SUBSTRATE_CACHE_METHOD_SIZE" , 10 )
17
+ monkeypatch .setenv ("SUBSTRATE_RUNTIME_CACHE_SIZE" , 9 )
18
+ sync_substrate = import_fresh ("async_substrate_interface.sync_substrate" )
19
+ asi = sync_substrate .SubstrateInterface ("" , _mock = True )
20
+ assert asi .get_runtime_for_version .cache_parameters ()["maxsize" ] == 9
21
+ assert asi .get_block_runtime_info .cache_parameters ()["maxsize" ] == 9
22
+ assert asi .get_parent_block_hash .cache_parameters ()["maxsize" ] == 10
23
+ assert asi .get_block_runtime_version_for .cache_parameters ()["maxsize" ] == 10
24
+ assert asi .get_block_hash .cache_parameters ()["maxsize" ] == 10
25
+
26
+
27
+ def test_defaults ():
28
+ sync_substrate = import_fresh ("async_substrate_interface.sync_substrate" )
29
+ asi = sync_substrate .SubstrateInterface ("" , _mock = True )
30
+ assert asi .get_runtime_for_version .cache_parameters ()["maxsize" ] == 16
31
+ assert asi .get_block_runtime_info .cache_parameters ()["maxsize" ] == 16
32
+ assert asi .get_parent_block_hash .cache_parameters ()["maxsize" ] == 512
33
+ assert asi .get_block_runtime_version_for .cache_parameters ()["maxsize" ] == 512
34
+ assert asi .get_block_hash .cache_parameters ()["maxsize" ] == 512
You can’t perform that action at this time.
0 commit comments