Skip to content

Commit

Permalink
fix: set_balance + test_permissions.py for ALCHEMY
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikita Panin committed Jan 24, 2025
1 parent 94b7e3f commit 6f21be8
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
11 changes: 10 additions & 1 deletion tests/regression/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
17 changes: 17 additions & 0 deletions utils/balance.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from brownie import accounts, web3
import time
from utils.test.helpers import ETH


Expand All @@ -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

Expand Down

0 comments on commit 6f21be8

Please sign in to comment.