File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change 1
1
import os
2
- from typing import Dict , Tuple
2
+ from typing import Dict , Optional , Tuple
3
3
4
4
from ape .api import UpstreamProvider , Web3Provider
5
5
from ape .exceptions import ContractLogicError , ProviderError , VirtualMachineError
9
9
from web3 .middleware import geth_poa_middleware
10
10
11
11
_ENVIRONMENT_VARIABLE_NAMES = ("WEB3_INFURA_PROJECT_ID" , "WEB3_INFURA_API_KEY" )
12
+ # NOTE: https://docs.infura.io/learn/websockets#supported-networks
13
+ _WEBSOCKET_CAPABLE_ECOSYSTEMS = {
14
+ "ethereum" ,
15
+ "polygon" ,
16
+ "linea" ,
17
+ }
12
18
13
19
14
20
class InfuraProviderError (ProviderError ):
@@ -54,8 +60,11 @@ def http_uri(self) -> str:
54
60
return self .uri
55
61
56
62
@property
57
- def ws_uri (self ) -> str :
63
+ def ws_uri (self ) -> Optional [ str ] :
58
64
# NOTE: Overriding `Web3Provider.ws_uri` implementation
65
+ if self .network .ecosystem .name not in _WEBSOCKET_CAPABLE_ECOSYSTEMS :
66
+ return None
67
+
59
68
# Remove `http` in default URI w/ `ws`, also infura adds `/ws` to URI
60
69
return "ws" + self .uri [4 :].replace ("v3" , "ws/v3" )
61
70
Original file line number Diff line number Diff line change 2
2
import websocket # type: ignore
3
3
from ape .utils import ZERO_ADDRESS
4
4
5
- from ape_infura .provider import Infura
5
+ from ape_infura .provider import _WEBSOCKET_CAPABLE_ECOSYSTEMS , Infura
6
6
7
7
8
8
def test_infura_http (provider ):
@@ -17,6 +17,11 @@ def test_infura_http(provider):
17
17
18
18
19
19
def test_infura_ws (provider ):
20
+ ecosystem = provider .network .ecosystem .name
21
+ if ecosystem not in _WEBSOCKET_CAPABLE_ECOSYSTEMS :
22
+ assert provider .ws_uri is None
23
+ return
24
+
20
25
assert provider .ws_uri .startswith ("wss" )
21
26
22
27
try :
You can’t perform that action at this time.
0 commit comments