diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 9b230151..4365843a 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -29,34 +29,16 @@ jobs: - name: Install Foundry uses: foundry-rs/foundry-toolchain@v1 - - name: Integration tests with pytest, holesky fork - run: | - poetry run pytest tests -m integration_holesky - env: - WEB3_RPC_ENDPOINTS: ${{ secrets.HOLESKY_WEB3_RPC_ENDPOINT }} - DEPOSIT_CONTRACT: "0x4242424242424242424242424242424242424242" - LIDO_LOCATOR: "0x28FAB2059C713A7F9D8c86Db49f9bb0e96Af1ef8" - MELLOW_CONTRACT_ADDRESS: "0x182Cb3A76B0EFaCb25255F9594B5807460882fa4" - ANVIL_PATH: "" - - - name: Integration tests with pytest, chiado testnet - run: | - poetry run pytest tests -m integration_chiado - env: - WEB3_RPC_ENDPOINTS: "https://gnosis-chiado-rpc.publicnode.com" - ONCHAIN_TRANSPORT_RPC_ENDPOINTS: "https://gnosis-chiado-rpc.publicnode.com" - ONCHAIN_TRANSPORT_ADDRESS: "0x42E1DEfC18388E3AA1fCADa851499A11405cf37f" - DEPOSIT_CONTRACT: "0x4242424242424242424242424242424242424242" - LIDO_LOCATOR: "0x28FAB2059C713A7F9D8c86Db49f9bb0e96Af1ef8" - MELLOW_CONTRACT_ADDRESS: "0x182Cb3A76B0EFaCb25255F9594B5807460882fa4" - ANVIL_PATH: "" - - - name: Integration tests with pytest, mainnet fork + - name: Integration tests with pytest if: success() || failure() run: | poetry run pytest tests -m integration env: WEB3_RPC_ENDPOINTS: ${{ secrets.WEB3_RPC_ENDPOINT }} + TESTNET_WEB3_RPC_ENDPOINTS: 'https://ethereum-holesky-rpc.publicnode.com' DEPOSIT_CONTRACT: "0x00000000219ab540356cBB839Cbe05303d7705Fa" LIDO_LOCATOR: "0xC1d0b3DE6792Bf6b4b37EccdcC24e45978Cfd2Eb" + ONCHAIN_TRANSPORT_RPC_ENDPOINTS: "https://gnosis-chiado-rpc.publicnode.com" + ONCHAIN_TRANSPORT_ADDRESS: "0x42E1DEfC18388E3AA1fCADa851499A11405cf37f" + MELLOW_CONTRACT_ADDRESS: "0x182Cb3A76B0EFaCb25255F9594B5807460882fa4" ANVIL_PATH: "" diff --git a/README.md b/README.md index c4528c20..d3c765ee 100644 --- a/README.md +++ b/README.md @@ -34,13 +34,13 @@ Unvetting is the proces of decreasing approved depositable signing keys. ## Running Daemon -1. Create `.env` file +1. Create `.env` file 2. Setup variables - - Set WEB3_RPC_ENDPOINTS - - Set WALLET_PRIVATE_KEY - - Set CREATE_TRANSACTIONS to true - - Set MESSAGE_TRANSPORTS to rabbit - - Set RABBIT_MQ_URL, RABBIT_MQ_USERNAME and RABBIT_MQ_PASSWORD + - Set WEB3_RPC_ENDPOINTS + - Set WALLET_PRIVATE_KEY + - Set CREATE_TRANSACTIONS to true + - Set MESSAGE_TRANSPORTS to rabbit + - Set RABBIT_MQ_URL, RABBIT_MQ_USERNAME and RABBIT_MQ_PASSWORD 3. ```docker-compose up``` 4. Send metrics and logs to grafana 5. Setup alerts @@ -83,6 +83,7 @@ Unvetting is the proces of decreasing approved depositable signing keys. | MAX_CYCLE_LIFETIME_IN_SECONDS | 1200 | Max lifetime of usual cycle. If cycle will not end in this time, bot will crush | | MELLOW_CONTRACT_ADDRESS | None | If variable is set then deposit can go to predifined module | | VAULT_DIRECT_DEPOSIT_THRESHOLD | 1 ether | If mellow vault has VAULT_DIRECT_DEPOSIT_THRESHOLD ethers then direct deposit will be sent | +| ONCHAIN_TRANSPORT_RPC_ENDPOINTS | - | RPC endpoint for the databus RPC, Gnosis at the moment | ## Metrics and logs @@ -119,6 +120,8 @@ poetry run pytest tests -m unit #### Run integration tests. +TESTNET_WEB3_RPC_ENDPOINTS - set this variable for the Ethereum EL testnet RPC, Holesky only. + Install Anvil ```bash diff --git a/pyproject.toml b/pyproject.toml index e783ae85..e90c410b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,8 +34,6 @@ pythonpath = [ markers = [ "unit", # offline "integration", # hardhat fork - "integration_holesky", # holesky fork - "integration_chiado", # chiado(gnosis testnet) run only ] [tool.ruff] diff --git a/src/variables.py b/src/variables.py index 9426abb0..da8d7fb0 100644 --- a/src/variables.py +++ b/src/variables.py @@ -12,6 +12,8 @@ # EL node WEB3_RPC_ENDPOINTS = os.getenv('WEB3_RPC_ENDPOINTS', '').split(',') +TESTNET_WEB3_RPC_ENDPOINTS = os.getenv('TESTNET_WEB3_RPC_ENDPOINTS', '').split(',') + # Account private key WALLET_PRIVATE_KEY = os.getenv('WALLET_PRIVATE_KEY', None) diff --git a/tests/blockchain/contracts/test_erc20.py b/tests/blockchain/contracts/test_erc20.py index 0778588e..8c93ef84 100644 --- a/tests/blockchain/contracts/test_erc20.py +++ b/tests/blockchain/contracts/test_erc20.py @@ -1,10 +1,16 @@ import pytest +import variables from tests.utils.contract_utils import check_contract from tests.utils.regrex import check_value_type -@pytest.mark.integration_holesky +@pytest.mark.integration +@pytest.mark.parametrize( + 'web3_provider_integration', + [{'endpoint': variables.TESTNET_WEB3_RPC_ENDPOINTS[0]}], + indirect=['web3_provider_integration'], +) def test_erc20(weth, simple_dvt_staking_strategy, caplog): check_contract( weth, diff --git a/tests/blockchain/contracts/test_simple_dvt_staking_strategy.py b/tests/blockchain/contracts/test_simple_dvt_staking_strategy.py index 1ab70758..b67aadff 100644 --- a/tests/blockchain/contracts/test_simple_dvt_staking_strategy.py +++ b/tests/blockchain/contracts/test_simple_dvt_staking_strategy.py @@ -1,10 +1,16 @@ import pytest +import variables from tests.utils.contract_utils import check_contract from tests.utils.regrex import ADDRESS_REGREX, check_value_re -@pytest.mark.integration_holesky +@pytest.mark.integration +@pytest.mark.parametrize( + 'web3_provider_integration', + [{'endpoint': variables.TESTNET_WEB3_RPC_ENDPOINTS[0]}], + indirect=['web3_provider_integration'], +) def test_simple_dvt_staking_strategy_contract_call(simple_dvt_staking_strategy, caplog): check_contract( simple_dvt_staking_strategy, diff --git a/tests/blockchain/contracts/test_staking_module.py b/tests/blockchain/contracts/test_staking_module.py index 38b8eee0..0090df38 100644 --- a/tests/blockchain/contracts/test_staking_module.py +++ b/tests/blockchain/contracts/test_staking_module.py @@ -1,10 +1,16 @@ import pytest +import variables from tests.utils.contract_utils import check_contract from tests.utils.regrex import ADDRESS_REGREX, check_value_re, check_value_type -@pytest.mark.integration_holesky +@pytest.mark.integration +@pytest.mark.parametrize( + 'web3_provider_integration', + [{'endpoint': variables.TESTNET_WEB3_RPC_ENDPOINTS[0]}], + indirect=['web3_provider_integration'], +) def test_staking_module_contract_call(staking_module, caplog): check_contract( staking_module, diff --git a/tests/bots/test_depositor.py b/tests/bots/test_depositor.py index 63ec9774..67c760a8 100644 --- a/tests/bots/test_depositor.py +++ b/tests/bots/test_depositor.py @@ -246,7 +246,7 @@ def test_get_quorum(depositor_bot, setup_deposit_message): @pytest.mark.integration @pytest.mark.parametrize( 'web3_provider_integration,module_id', - [[19628126, 1], [19628126, 2]], + [[{'block': 19628126}, 1], [{'block': 19628126}, 2]], indirect=['web3_provider_integration'], ) def test_depositor_bot_non_mellow_deposits( diff --git a/tests/bots/test_mellow.py b/tests/bots/test_mellow.py index 9c3968c4..7b2cf6f6 100644 --- a/tests/bots/test_mellow.py +++ b/tests/bots/test_mellow.py @@ -18,11 +18,10 @@ def setup_mellow_env(): @pytest.mark.integration @pytest.mark.parametrize( 'web3_provider_integration,module_id', - [[20529904, 2], [20529995, 2]], + [[{'block': 20529904}, 2], [{'block': 20529995}, 2]], indirect=['web3_provider_integration'], ) def test_depositor_bot_mellow_deposits( - web3_provider_integration, web3_lido_integration, deposit_transaction_sender_integration, mellow_deposit_strategy_integration, diff --git a/tests/bots/test_pauser.py b/tests/bots/test_pauser.py index d5ae9b24..9c08c94c 100644 --- a/tests/bots/test_pauser.py +++ b/tests/bots/test_pauser.py @@ -158,7 +158,7 @@ def test_pause_message_filtered_by_module_id(pause_bot, block_data, pause_messag @pytest.mark.integration @pytest.mark.parametrize( 'web3_provider_integration,module_id', - [[19628126, 1], [19628126, 2]], + [[{'block': 19628126}, 1], [{'block': 19628126}, 2]], indirect=['web3_provider_integration'], ) def test_pauser_bot(web3_lido_integration, web3_provider_integration, add_account_to_guardian, module_id, caplog): diff --git a/tests/bots/test_unvetter.py b/tests/bots/test_unvetter.py index 734c89fb..a11a4326 100644 --- a/tests/bots/test_unvetter.py +++ b/tests/bots/test_unvetter.py @@ -61,7 +61,11 @@ def get_unvet_message(web3) -> UnvetMessage: @pytest.mark.integration @pytest.mark.parametrize( 'web3_provider_integration', - [19628126], + [ + { + 'block': 19628126, + } + ], indirect=['web3_provider_integration'], ) def test_unvetter(web3_provider_integration, web3_lido_integration, caplog): diff --git a/tests/fixtures/provider.py b/tests/fixtures/provider.py index bb453c79..ed5d8f09 100644 --- a/tests/fixtures/provider.py +++ b/tests/fixtures/provider.py @@ -27,23 +27,21 @@ def web3_lido_unit() -> Web3: # -- Integration fixtures -- @pytest.fixture def web3_provider_integration(request) -> Web3: - block_num = getattr(request, 'param', None) + params = getattr(request, 'param', {}) + rpc_endpoint = params.get('endpoint', variables.WEB3_RPC_ENDPOINTS[0]) + block_num = params.get('block', None) + anvil_path = os.getenv('ANVIL_PATH', '') - with anvil_fork( - os.getenv('ANVIL_PATH', ''), - variables.WEB3_RPC_ENDPOINTS[0], - block_num, - ): + with anvil_fork(anvil_path, rpc_endpoint, block_num): web3 = Web3(HTTPProvider('http://127.0.0.1:8545', request_kwargs={'timeout': 3600})) - assert web3.is_connected() + assert web3.is_connected(), 'Failed to connect to the Web3 provider.' yield web3 @pytest.fixture -def web3_lido_integration(web3_provider_integration: Web3) -> Web3: +def web3_transaction_integration(web3_provider_integration: Web3) -> Web3: web3_provider_integration.attach_modules( { - 'lido': LidoContracts, 'transaction': TransactionUtils, } ) @@ -51,10 +49,10 @@ def web3_lido_integration(web3_provider_integration: Web3) -> Web3: @pytest.fixture -def web3_transaction_integration(web3_provider_integration: Web3) -> Web3: - web3_provider_integration.attach_modules( +def web3_lido_integration(web3_transaction_integration: Web3) -> Web3: + web3_transaction_integration.attach_modules( { - 'transaction': TransactionUtils, + 'lido': LidoContracts, } ) - yield web3_provider_integration + yield web3_transaction_integration diff --git a/tests/transport/test_base_provider.py b/tests/transport/test_base_provider.py index dc215e48..f9270b67 100644 --- a/tests/transport/test_base_provider.py +++ b/tests/transport/test_base_provider.py @@ -1,25 +1,10 @@ -from unittest.mock import Mock - import pytest -from prometheus_client import Gauge from schema import Or, Schema from transport.msg_providers.common import BaseMessageProvider from transport.msg_types.deposit import DepositMessageSchema class FakeMessageProvider(BaseMessageProvider): - @property - def fetched_messages_metric(self) -> Gauge: - return Mock() - - @property - def processed_messages_metric(self) -> Gauge: - return Mock() - - @property - def valid_messages_metric(self) -> Gauge: - return Mock() - MAX_MESSAGES_RECEIVE = 1 def _fetch_messages(self) -> list: diff --git a/tests/transport/test_data_bus.py b/tests/transport/test_data_bus.py index 5f504a95..06b7ecfb 100644 --- a/tests/transport/test_data_bus.py +++ b/tests/transport/test_data_bus.py @@ -32,7 +32,12 @@ # NODE_HOST: 'http://127.0.0.1:8888', # DATA_BUS_ADDRESS: '0x5FbDB2315678afecb367f032d93F642f64180aa3' # } -@pytest.mark.integration_chiado +@pytest.mark.integration +@pytest.mark.parametrize( + 'web3_provider_integration', + [{'endpoint': variables.ONCHAIN_TRANSPORT_RPC_ENDPOINTS[0]}], + indirect=['web3_provider_integration'], +) def test_data_bus_provider( web3_transaction_integration, ): @@ -61,7 +66,12 @@ def test_data_bus_provider( assert messages -@pytest.mark.integration_chiado +@pytest.mark.integration +@pytest.mark.parametrize( + 'web3_provider_integration', + [{'endpoint': variables.ONCHAIN_TRANSPORT_RPC_ENDPOINTS[0]}], + indirect=['web3_provider_integration'], +) def test_data_bus_provider_unvet( web3_transaction_integration, ): @@ -111,7 +121,12 @@ def test_data_bus_provider_unvet( assert len(messages) == 1 -@pytest.mark.integration_chiado +@pytest.mark.integration +@pytest.mark.parametrize( + 'web3_provider_integration', + [{'endpoint': variables.ONCHAIN_TRANSPORT_RPC_ENDPOINTS[0]}], + indirect=['web3_provider_integration'], +) def test_data_bus_provider_pause_v2( web3_transaction_integration, ): @@ -157,7 +172,12 @@ def test_data_bus_provider_pause_v2( assert len(messages) == 1 -@pytest.mark.integration_chiado +@pytest.mark.integration +@pytest.mark.parametrize( + 'web3_provider_integration', + [{'endpoint': variables.ONCHAIN_TRANSPORT_RPC_ENDPOINTS[0]}], + indirect=['web3_provider_integration'], +) def test_data_bus_provider_pause_v3( web3_transaction_integration, ):