Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slight improvement in visibility and fetching events with batches #323

Merged
merged 1 commit into from
Nov 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions tests/regression/test_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest
import os

from tqdm import tqdm
TheDZhon marked this conversation as resolved.
Show resolved Hide resolved
from web3 import Web3
from brownie import interface, convert, web3
from brownie.network.event import _decode_logs
Expand Down Expand Up @@ -489,19 +490,30 @@ def active_aragon_roles(protocol_permissions):
w3 = Web3(Web3.HTTPProvider(f'https://mainnet.infura.io/v3/{os.getenv("WEB3_INFURA_PROJECT_ID")}'))

event_signature_hash = w3.keccak(text="SetPermission(address,address,bytes32,bool)").hex()
events_before_voting = w3.eth.filter(
{"address": contracts.acl.address, "fromBlock": ACL_DEPLOY_BLOCK_NUMBER, "topics": [event_signature_hash]}
).get_all_entries()

def fetch_events_in_batches(start_block, end_block, step=100000):
"""Fetch events in batches of `step` blocks with a progress bar."""
events = []
total_batches = (end_block - start_block) // step + 1
with tqdm(total=total_batches, desc="Fetching Events") as pbar:
for batch_start in range(start_block, end_block, step):
batch_end = min(batch_start + step - 1, end_block)
batch_events = w3.eth.filter(
{"address": contracts.acl.address, "fromBlock": batch_start, "toBlock": batch_end, "topics": [event_signature_hash]}
).get_all_entries()
events.extend(batch_events)
pbar.update(1)
return events

events_before_voting = fetch_events_in_batches(ACL_DEPLOY_BLOCK_NUMBER, w3.eth.block_number)

permission_events = _decode_logs(events_before_voting)["SetPermission"]._ordered

history = TxHistory()
if len(history) > 0:
vote_block = history[0].block_number

events_after_voting = web3.eth.filter(
{"address": contracts.acl.address, "fromBlock": vote_block, "topics": [event_signature_hash]}
).get_all_entries()
events_after_voting = fetch_events_in_batches(vote_block, w3.eth.block_number)

try:
permission_events_after_voting = _decode_logs(events_after_voting)["SetPermission"]._ordered
Expand Down
Loading