From a014fb81fe829b8b93f006ec9dd6383a10ba19d9 Mon Sep 17 00:00:00 2001 From: spuddyminer Date: Mon, 2 Oct 2023 13:40:37 -0400 Subject: [PATCH] fixed tests to use sepolia / goerli --- src/telliot_core/apps/telliot_config.py | 16 +++---- src/telliot_core/model/endpoints.py | 6 +-- tests/conftest.py | 60 +++++++++++++++++++------ tests/test_contract.py | 18 ++++---- tests/test_gas.py | 4 +- tests/test_master_read.py | 4 +- tests/test_oracle_read.py | 28 ++++++------ tests/test_rpc_endpoint.py | 9 ++-- 8 files changed, 88 insertions(+), 57 deletions(-) diff --git a/src/telliot_core/apps/telliot_config.py b/src/telliot_core/apps/telliot_config.py index 6f1b2980..3ac9668f 100644 --- a/src/telliot_core/apps/telliot_config.py +++ b/src/telliot_core/apps/telliot_config.py @@ -105,25 +105,25 @@ def override_test_config(cfg: TelliotConfig, write: bool = False) -> TelliotConf # Override configuration for rinkeby testnet override_main = False - if cfg.main.chain_id != 4: - cfg.main.chain_id = 4 + if cfg.main.chain_id != 11155111: + cfg.main.chain_id = 11155111 override_main = True - rinkeby_endpoint = cfg.get_endpoint() - assert rinkeby_endpoint is not None + sepolia_endpoint = cfg.get_endpoint() + assert sepolia_endpoint is not None override_endpoint = False if os.getenv("NODE_URL", None): - rinkeby_endpoint.url = os.environ["NODE_URL"] + sepolia_endpoint.url = os.environ["NODE_URL"] override_endpoint = True - rinkeby_accounts = find_accounts(chain_id=4) - if not rinkeby_accounts: + sepolia_accounts = find_accounts(chain_id=11155111) + if not sepolia_accounts: # Add private key if detected on git if os.getenv("PRIVATE_KEY", None): # Create an account for use on git - ChainedAccount.add("git-rinkeby-key", chains=[4], key=os.environ["PRIVATE_KEY"], password="") + ChainedAccount.add("git-sepolia-key", chains=[11155111], key=os.environ["PRIVATE_KEY"], password="") if write: if override_endpoint: diff --git a/src/telliot_core/model/endpoints.py b/src/telliot_core/model/endpoints.py index 90c484d7..f415f487 100644 --- a/src/telliot_core/model/endpoints.py +++ b/src/telliot_core/model/endpoints.py @@ -25,7 +25,7 @@ class RPCEndpoint(Base): #: Chain ID chain_id: Optional[int] = None - #: Network Name (e.g. 'mainnet', 'testnet', 'rinkeby') + #: Network Name (e.g. 'mainnet', 'testnet', 'sepolia') network: str = "" #: Provider Name (e.g. 'Infura') @@ -61,8 +61,8 @@ def connect(self) -> bool: else: raise ValueError(f"Invalid endpoint url: {self.url}") - # Inject middleware if connecting to rinkeby (chain_id=4) - if self.chain_id == 4: + # Inject middleware if connecting to sepolia (chain_id=11155111) + if self.chain_id == 11155111: self.web3.middleware_onion.inject(geth_poa_middleware, layer=0) connected = False diff --git a/tests/conftest.py b/tests/conftest.py index c9cfe3dd..9b117fe0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -10,30 +10,59 @@ @pytest.fixture(scope="session", autouse=True) -def rinkeby_cfg(): - """Get rinkeby endpoint from config +def sepolia_cfg(): + """Get sepolia endpoint from config If environment variables are defined, they will override the values in config files """ cfg = TelliotConfig() - # Override configuration for rinkeby testnet - cfg.main.chain_id = 4 + # Override configuration for sepolia testnet + cfg.main.chain_id = 11155111 - rinkeby_endpoint = cfg.get_endpoint() - # assert rinkeby_endpoint.network == "rinkeby" + sepolia_endpoint = cfg.get_endpoint() + # assert sepolia_endpoint.network == "sepolia" if os.getenv("NODE_URL", None): - rinkeby_endpoint.url = os.environ["NODE_URL"] + sepolia_endpoint.url = os.environ["NODE_URL"] - rinkeby_accounts = find_accounts(chain_id=4) - if not rinkeby_accounts: + sepolia_accounts = find_accounts(chain_id=11155111) + if not sepolia_accounts: # Create a test account using PRIVATE_KEY defined on github. key = os.getenv("PRIVATE_KEY", None) if key: - ChainedAccount.add("git-rinkeby-key", chains=4, key=os.environ["PRIVATE_KEY"], password="") + ChainedAccount.add("git-sepolia-key", chains=11155111, key=os.environ["PRIVATE_KEY"], password="") else: - raise Exception("Need a rinkeby account") + raise Exception("Need a sepolia account") + + return cfg + + +@pytest.fixture(scope="session", autouse=True) +def goerli_cfg(): + """Get goerli endpoint from config + + If environment variables are defined, they will override the values in config files + """ + cfg = TelliotConfig() + + # Override configuration for goerli testnet + cfg.main.chain_id = 5 + + goerli_endpoint = cfg.get_endpoint() + # assert goerli_endpoint.network == "goerli" + + if os.getenv("NODE_URL", None): + goerli_endpoint.url = os.environ["NODE_URL"] + + goerli_accounts = find_accounts(chain_id=5) + if not goerli_accounts: + # Create a test account using PRIVATE_KEY defined on github. + key = os.getenv("PRIVATE_KEY", None) + if key: + ChainedAccount.add("git-goerli-key", chains=5, key=os.environ["PRIVATE_KEY"], password="") + else: + raise Exception("Need a goerli account") return cfg @@ -117,5 +146,10 @@ def mumbai_test_cfg(scope="session", autouse=True): @pytest.fixture -def rinkeby_test_cfg(scope="session", autouse=True): - return local_node_cfg(chain_id=4) +def sepolia_test_cfg(scope="session", autouse=True): + return local_node_cfg(chain_id=11155111) + + +@pytest.fixture +def goerli_test_cfg(scope="session", autouse=True): + return local_node_cfg(chain_id=5) diff --git a/tests/test_contract.py b/tests/test_contract.py index e898c369..c1ed4eba 100644 --- a/tests/test_contract.py +++ b/tests/test_contract.py @@ -8,28 +8,28 @@ @pytest.mark.asyncio -async def test_connect_to_tellor(rinkeby_test_cfg): +async def test_connect_to_tellor(sepolia_test_cfg): """Contract object should access Tellor functions""" - async with TelliotCore(config=rinkeby_test_cfg) as core: - tellorx = core.get_tellorx_contracts() - assert len(tellorx.master.contract.all_functions()) > 0 + async with TelliotCore(config=sepolia_test_cfg) as core: + tellor360 = core.get_tellor360_contracts() + assert len(tellor360.token.contract.all_functions()) > 0 assert isinstance( - tellorx.master.contract.all_functions()[0], + tellor360.token.contract.all_functions()[0], web3.contract.ContractFunction, ) @pytest.mark.asyncio -async def test_mixed_gas_inputs(rinkeby_test_cfg): +async def test_mixed_gas_inputs(sepolia_test_cfg): """Contract.write() should refuse a combination of legacy gas args and EIP-1559 gas args""" with pytest.raises(ValueError): - async with TelliotCore(config=rinkeby_test_cfg) as core: - tellorx = core.get_tellorx_contracts() + async with TelliotCore(config=sepolia_test_cfg) as core: + tellor360 = core.get_tellor360_contracts() - tx_receipt, status = await tellorx.oracle.write( + tx_receipt, status = await tellor360.oracle.write( func_name="transfer", _to="0xF90cd1D6C1da49CE2cF5C39f82999D7145aa66aD", _amount=1, diff --git a/tests/test_gas.py b/tests/test_gas.py index 87e9129e..b0df739e 100644 --- a/tests/test_gas.py +++ b/tests/test_gas.py @@ -4,8 +4,8 @@ import pytest from requests.exceptions import SSLError -from telliot_core.gas.legacy_gas import fetch_gas_price -from telliot_core.gas.legacy_gas import legacy_gas_station +from src.telliot_core.gas.legacy_gas import fetch_gas_price +from src.telliot_core.gas.legacy_gas import legacy_gas_station def raise_ssl_error(*args, **kwargs): diff --git a/tests/test_master_read.py b/tests/test_master_read.py index fc66ae95..a9313153 100644 --- a/tests/test_master_read.py +++ b/tests/test_master_read.py @@ -15,10 +15,10 @@ def tellorx_master_mock_contract(): @pytest.mark.asyncio -async def test_get_staker_info(rinkeby_test_cfg, tellorx_master_mock_contract): +async def test_get_staker_info(goerli_test_cfg, tellorx_master_mock_contract): """Test the TellorXMaster contract""" - async with TelliotCore(config=rinkeby_test_cfg) as core: + async with TelliotCore(config=goerli_test_cfg) as core: account = core.get_account() tellorx = TellorxMasterContract(core.endpoint, account) tellorx.address = tellorx_master_mock_contract.address diff --git a/tests/test_oracle_read.py b/tests/test_oracle_read.py index 57cc8951..435f71dd 100644 --- a/tests/test_oracle_read.py +++ b/tests/test_oracle_read.py @@ -14,9 +14,9 @@ def tellorx_oracle_mock_contract(): @pytest.mark.asyncio -async def test_getReportTimestampByIndex(rinkeby_test_cfg, tellorx_oracle_mock_contract): +async def test_getReportTimestampByIndex(goerli_test_cfg, tellorx_oracle_mock_contract): """Test the TellorxOracleContract getReportTimestampByIndex method""" - async with TelliotCore(config=rinkeby_test_cfg) as core: + async with TelliotCore(config=goerli_test_cfg) as core: account = core.get_account() oracle = TellorxOracleContract(core.endpoint, account) oracle.address = tellorx_oracle_mock_contract.address # Override with locally-deployed mock contract address @@ -32,9 +32,9 @@ async def test_getReportTimestampByIndex(rinkeby_test_cfg, tellorx_oracle_mock_c @pytest.mark.asyncio -async def test_getReportingLock(rinkeby_test_cfg, tellorx_oracle_mock_contract): +async def test_getReportingLock(goerli_test_cfg, tellorx_oracle_mock_contract): """Test the TellorxOracleContract.getReportingLock() method""" - async with TelliotCore(config=rinkeby_test_cfg) as core: + async with TelliotCore(config=goerli_test_cfg) as core: account = core.get_account() oracle = TellorxOracleContract(core.endpoint, account) oracle.address = tellorx_oracle_mock_contract.address # Override with locally-deployed mock contract address @@ -47,9 +47,9 @@ async def test_getReportingLock(rinkeby_test_cfg, tellorx_oracle_mock_contract): @pytest.mark.asyncio -async def test_gettimebasedreward(rinkeby_test_cfg, tellorx_oracle_mock_contract): +async def test_gettimebasedreward(goerli_test_cfg, tellorx_oracle_mock_contract): """Test the TellorxOracleContract.getTimeBasedReward() method""" - async with TelliotCore(config=rinkeby_test_cfg) as core: + async with TelliotCore(config=goerli_test_cfg) as core: account = core.get_account() oracle = TellorxOracleContract(core.endpoint, account) oracle.address = tellorx_oracle_mock_contract.address # Override with locally-deployed mock contract address @@ -61,9 +61,9 @@ async def test_gettimebasedreward(rinkeby_test_cfg, tellorx_oracle_mock_contract @pytest.mark.asyncio -async def test_getCurrentReward(rinkeby_test_cfg, tellorx_oracle_mock_contract): +async def test_getCurrentReward(goerli_test_cfg, tellorx_oracle_mock_contract): """Test the TellorX oracle contract""" - async with TelliotCore(config=rinkeby_test_cfg) as core: + async with TelliotCore(config=goerli_test_cfg) as core: account = core.get_account() oracle = TellorxOracleContract(core.endpoint, account) oracle.address = tellorx_oracle_mock_contract.address # Override with locally-deployed mock contract address @@ -78,9 +78,9 @@ async def test_getCurrentReward(rinkeby_test_cfg, tellorx_oracle_mock_contract): @pytest.mark.asyncio -async def test_getTimestampCountById(rinkeby_test_cfg, tellorx_oracle_mock_contract): +async def test_getTimestampCountById(goerli_test_cfg, tellorx_oracle_mock_contract): """Test the TellorX oracle contract""" - async with TelliotCore(config=rinkeby_test_cfg) as core: + async with TelliotCore(config=goerli_test_cfg) as core: account = core.get_account() oracle = TellorxOracleContract(core.endpoint, account) oracle.address = tellorx_oracle_mock_contract.address # Override with locally-deployed mock contract address @@ -94,9 +94,9 @@ async def test_getTimestampCountById(rinkeby_test_cfg, tellorx_oracle_mock_contr @pytest.mark.asyncio -async def test_getTimeOfLastNewValue(rinkeby_test_cfg, tellorx_oracle_mock_contract): +async def test_getTimeOfLastNewValue(goerli_test_cfg, tellorx_oracle_mock_contract): """Test the TellorX oracle contract""" - async with TelliotCore(config=rinkeby_test_cfg) as core: + async with TelliotCore(config=goerli_test_cfg) as core: account = core.get_account() oracle = TellorxOracleContract(core.endpoint, account) oracle.address = tellorx_oracle_mock_contract.address # Override with locally-deployed mock contract address @@ -110,9 +110,9 @@ async def test_getTimeOfLastNewValue(rinkeby_test_cfg, tellorx_oracle_mock_contr @pytest.mark.asyncio -async def test_getTipsById(rinkeby_test_cfg, tellorx_oracle_mock_contract): +async def test_getTipsById(goerli_test_cfg, tellorx_oracle_mock_contract): """Test the TellorX oracle contract""" - async with TelliotCore(config=rinkeby_test_cfg) as core: + async with TelliotCore(config=goerli_test_cfg) as core: account = core.get_account() oracle = TellorxOracleContract(core.endpoint, account) oracle.address = tellorx_oracle_mock_contract.address # Override with locally-deployed mock contract address diff --git a/tests/test_rpc_endpoint.py b/tests/test_rpc_endpoint.py index 8d6fd8be..3f9631fb 100644 --- a/tests/test_rpc_endpoint.py +++ b/tests/test_rpc_endpoint.py @@ -33,7 +33,7 @@ def test_very_bad_rpc_url(): def test_incomplete_rpc_url(): """an incomplete url will raise an exception in RPCEndpoint""" - url = "https://eth-rinkeby.gateway.pokt.network/v1/lb/" + url = "https://eth-rpc.gateway.pokt.network/" endpt = RPCEndpoint(network=network, provider=provider, url=url) try: _ = endpt.connect() @@ -48,8 +48,5 @@ def test_incomplete_rpc_url(): def test_endpoint_list(): sl = EndpointList() # print(json.dumps(sl.get_state(), indent=2)) - ep4 = sl.find(chain_id=4)[0] - assert ep4.network == "rinkeby" - - ep3 = sl.find(chain_id=3)[0] - assert ep3.network == "ropsten" + ep11155111 = sl.find(chain_id=11155111)[0] + assert ep11155111.network == "sepolia"