-
Notifications
You must be signed in to change notification settings - Fork 698
Normalize QuickNode arb/optimism network mapping #940
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
6f24ce6
da05291
ace1fba
afccda5
50ad719
cce8b0f
2732667
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,12 @@ | ||
| import pytest | ||
|
|
||
| import intentkit.utils.chain as chain_utils | ||
| from intentkit.utils.chain import ( | ||
| Chain, | ||
| ChainConfig, | ||
| ChainProvider, | ||
| NetworkId, | ||
| QuicknodeChainProvider, | ||
| QuickNodeNetwork, | ||
| ) | ||
|
|
||
|
|
@@ -26,6 +28,31 @@ def init_chain_configs(self, api_key: str = ""): | |
| self.api_key = api_key | ||
|
|
||
|
|
||
| class DummyResponse: | ||
| def __init__(self, payload: dict[str, list[dict[str, str]]]): | ||
| self._payload = payload | ||
|
|
||
| def raise_for_status(self) -> None: | ||
| return None | ||
|
|
||
| def json(self) -> dict[str, list[dict[str, str]]]: | ||
| return self._payload | ||
|
|
||
|
|
||
| class DummyClient: | ||
| def __init__(self, payload: dict[str, list[dict[str, str]]]): | ||
| self._payload = payload | ||
|
|
||
| def __enter__(self) -> "DummyClient": | ||
| return self | ||
|
|
||
| def __exit__(self, exc_type, exc, traceback) -> None: | ||
| return None | ||
|
|
||
| def get(self, *_, **__) -> DummyResponse: | ||
| return DummyResponse(self._payload) | ||
|
|
||
|
|
||
| def test_chain_config_properties(): | ||
| config = ChainConfig( | ||
| chain=Chain.Ethereum, | ||
|
|
@@ -53,6 +80,34 @@ def test_chain_provider_fetch_by_network_and_id(): | |
| assert config_by_id is config | ||
|
|
||
|
|
||
| def test_quicknode_chain_provider_alias_mapping(monkeypatch: pytest.MonkeyPatch): | ||
| # QuickNode can return chain "arb" with network "optimism"; both should map. | ||
| payload = { | ||
| "data": [ | ||
| { | ||
| "chain": "arb", | ||
| "network": "optimism", | ||
| "http_url": "https://quicknode", | ||
| "ens_url": "https://ens", | ||
| "wss_url": "wss://quicknode", | ||
| } | ||
| ] | ||
| } | ||
|
|
||
| monkeypatch.setattr( | ||
| chain_utils.httpx, | ||
| "Client", | ||
| lambda *_, **__: DummyClient(payload), | ||
| ) | ||
|
|
||
| provider = QuicknodeChainProvider("test-key") | ||
| provider.init_chain_configs() | ||
|
|
||
| config = provider.chain_configs[QuickNodeNetwork.OptimismMainnet] | ||
| assert config.chain is Chain.Arbitrum | ||
| assert config.network is QuickNodeNetwork.OptimismMainnet | ||
|
Comment on lines
+83
to
+108
|
||
|
|
||
|
|
||
| def test_chain_provider_missing_network(): | ||
| provider = DummyChainProvider() | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment states "QuickNode can return chain 'arb' with network 'optimism'" but this is misleading. According to the PR description, QuickNode returns chain='arb' with network='arbitrum-mainnet' for Arbitrum, and chain='optimism' with network='optimism' for Optimism. The comment should accurately describe what the test is validating.