From 6f21be856c22a0f47072f967373a1d307570536f Mon Sep 17 00:00:00 2001 From: Nikita Panin Date: Fri, 24 Jan 2025 16:40:20 +0000 Subject: [PATCH] fix: set_balance + test_permissions.py for ALCHEMY --- tests/regression/test_permissions.py | 11 ++++++++++- utils/balance.py | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/tests/regression/test_permissions.py b/tests/regression/test_permissions.py index dd9f602b..2c0c3246 100644 --- a/tests/regression/test_permissions.py +++ b/tests/regression/test_permissions.py @@ -486,8 +486,17 @@ def collect_permissions_from_events(permission_events): return apps +def get_http_w3_provider_url(): + if os.getenv("WEB3_INFURA_PROJECT_ID") is not None: + return f'https://mainnet.infura.io/v3/{os.getenv("WEB3_INFURA_PROJECT_ID")}' + + if os.getenv("WEB3_ALCHEMY_PROJECT_ID") is not None: + return f'https://eth-mainnet.g.alchemy.com/v2/{os.getenv("WEB3_ALCHEMY_PROJECT_ID")}' + + assert False, 'Web3 HTTP Provider token env var not found' + def active_aragon_roles(protocol_permissions): - w3 = Web3(Web3.HTTPProvider(f'https://mainnet.infura.io/v3/{os.getenv("WEB3_INFURA_PROJECT_ID")}')) + w3 = Web3(Web3.HTTPProvider(get_http_w3_provider_url())) event_signature_hash = w3.keccak(text="SetPermission(address,address,bytes32,bool)").hex() diff --git a/utils/balance.py b/utils/balance.py index 2ed745c2..3df2b5e3 100644 --- a/utils/balance.py +++ b/utils/balance.py @@ -1,4 +1,5 @@ from brownie import accounts, web3 +import time from utils.test.helpers import ETH @@ -16,6 +17,22 @@ def set_balance_in_wei(address, balance): if e.args[0].get("message") != f"Method {provider} is not supported": raise e + if account.balance() != balance: + time.sleep(2) + + if account.balance() != balance: + web3.provider.make_request("evm_mine", [{blocks: 5}]) + + if account.balance() != balance: + time.sleep(2) + + if account.balance() < balance: + eth_whale = accounts.at("0x00000000219ab540356cBB839Cbe05303d7705Fa", force=True) + eth_whale.transfer(account, balance - account.balance()) + + if account.balance() != balance: + time.sleep(2) + assert account.balance() == balance, f"Failed to set balance {balance} for account: {address}" return account