Skip to content

Commit 802525d

Browse files
authored
Merge pull request #793 from valory-xyz/test/rpc-env-vars
Make the public RPCs overridable via environment variables
2 parents cebf363 + 552dcc7 commit 802525d

2 files changed

Lines changed: 50 additions & 10 deletions

File tree

.github/workflows/workflow.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,17 @@ jobs:
527527
tox -e packages-py${{ matrix.python_version }} -- -m 'not integration and not unstable and not profiling'
528528
529529
- name: Plugin unit tests
530+
env:
531+
RPC_ETHEREUM: ${{ secrets.RPC_ETHEREUM || 'https://eth.drpc.org' }}
532+
RPC_ARBITRUM: ${{ secrets.RPC_ARBITRUM || 'https://arbitrum.drpc.org' }}
533+
RPC_ZKSYNC: ${{ secrets.RPC_ZKSYNC || 'https://mainnet.era.zksync.io' }}
534+
RPC_BINANCE: ${{ secrets.RPC_BINANCE || 'https://binance.llamarpc.com' }}
535+
RPC_GNOSIS: ${{ secrets.RPC_GNOSIS || 'https://gnosis.drpc.org' }}
536+
RPC_OPTIMISM: ${{ secrets.RPC_OPTIMISM || 'https://optimism.drpc.org' }}
537+
RPC_BASE: ${{ secrets.RPC_BASE || 'https://base.drpc.org' }}
538+
RPC_MODE: ${{ secrets.RPC_MODE || 'https://mode.drpc.org' }}
539+
RPC_POLYGON: ${{ secrets.RPC_POLYGON || 'https://polygon.drpc.org' }}
540+
RPC_FRAXTAL: ${{ secrets.RPC_FRAXTAL || 'https://fraxtal.drpc.org' }}
530541
run: |
531542
tox -e plugins-py${{ matrix.python_version }} -- -m 'not integration and not unstable and not profiling'
532543

plugins/aea-ledger-ethereum/tests/test_ethereum.py

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,19 @@
1717
# limitations under the License.
1818
#
1919
# ------------------------------------------------------------------------------
20+
2021
"""This module contains the tests of the ethereum module."""
2122

2223
import copy
2324
import hashlib
2425
import logging
2526
import math
27+
import os
2628
import random
2729
import re
2830
import tempfile
2931
import time
32+
from enum import Enum
3033
from pathlib import Path
3134
from typing import Dict, Generator, Optional, Tuple, Union, cast
3235
from unittest import mock
@@ -74,6 +77,32 @@
7477
from tests.conftest import DEFAULT_GANACHE_CHAIN_ID, MAX_FLAKY_RERUNS, ROOT_DIR
7578

7679

80+
RPC_ENV_VAR_PREFIX = "RPC_"
81+
82+
83+
class EIP1559Networks(Enum):
84+
"""The supported networks upgraded with EIP-1559."""
85+
86+
ETHEREUM = "https://eth.drpc.org"
87+
ARBITRUM = "https://arbitrum.drpc.org"
88+
ZKSYNC = "https://mainnet.era.zksync.io"
89+
BINANCE = "https://binance.llamarpc.com"
90+
GNOSIS = "https://gnosis.drpc.org"
91+
OPTIMISM = "https://optimism.drpc.org"
92+
BASE = "https://base.drpc.org"
93+
MODE = "https://mode.drpc.org"
94+
POLYGON = "https://polygon.drpc.org"
95+
FRAXTAL = "https://fraxtal.drpc.org"
96+
97+
98+
def __get_rpc(network: EIP1559Networks) -> str:
99+
"""Get RPC with override from environment variables, or default value."""
100+
return os.getenv(f"{RPC_ENV_VAR_PREFIX}{network.name}", network.value)
101+
102+
103+
RPCS = {network: __get_rpc(network) for network in EIP1559Networks}
104+
105+
77106
def get_default_gas_strategies() -> Dict:
78107
"""Returns default gas price strategy."""
79108
return {
@@ -977,19 +1006,19 @@ def test_try_get_gas_pricing(
9771006
# flake8: noqa: E800 None,
9781007
# flake8: noqa: E800 True,
9791008
# flake8: noqa: E800),
980-
({"address": "https://eth.drpc.org", "chain_id": 1}, None, False),
981-
({"address": "https://arbitrum.drpc.org", "chain_id": 42161}, None, False),
982-
({"address": "https://mainnet.era.zksync.io/", "chain_id": 324}, None, False),
983-
({"address": "https://binance.llamarpc.com", "chain_id": 56}, None, True),
1009+
({"address": RPCS[EIP1559Networks.ETHEREUM], "chain_id": 1}, None, False),
1010+
({"address": RPCS[EIP1559Networks.ARBITRUM], "chain_id": 42161}, None, False),
1011+
({"address": RPCS[EIP1559Networks.ZKSYNC], "chain_id": 324}, None, False),
1012+
({"address": RPCS[EIP1559Networks.BINANCE], "chain_id": 56}, None, True),
9841013
(
985-
{"address": "https://gnosis.drpc.org", "chain_id": 100},
1014+
{"address": RPCS[EIP1559Networks.GNOSIS], "chain_id": 100},
9861015
{"min_allowed_tip": DEFAULT_GNOSIS_MIN_ALLOWED_TIP},
9871016
False,
9881017
),
989-
({"address": "https://optimism.drpc.org", "chain_id": 10}, None, False),
990-
({"address": "https://base.drpc.org", "chain_id": 8453}, None, False),
1018+
({"address": RPCS[EIP1559Networks.OPTIMISM], "chain_id": 10}, None, False),
1019+
({"address": RPCS[EIP1559Networks.BASE], "chain_id": 8453}, None, False),
9911020
(
992-
{"address": "https://mode.drpc.org", "chain_id": 34443},
1021+
{"address": RPCS[EIP1559Networks.MODE], "chain_id": 34443},
9931022
{
9941023
"fee_history_blocks": 20,
9951024
"fallback_estimate": {
@@ -999,8 +1028,8 @@ def test_try_get_gas_pricing(
9991028
},
10001029
False,
10011030
),
1002-
({"address": "https://polygon.drpc.org", "chain_id": 137}, None, True),
1003-
({"address": "https://fraxtal.drpc.org", "chain_id": 252}, None, False),
1031+
({"address": RPCS[EIP1559Networks.POLYGON], "chain_id": 137}, None, True),
1032+
({"address": RPCS[EIP1559Networks.FRAXTAL], "chain_id": 252}, None, False),
10041033
),
10051034
)
10061035
def test_eip1559_on_network(

0 commit comments

Comments
 (0)