Skip to content

Commit

Permalink
Beacon: add get_attestations_rewards endpoint
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Rusak <[email protected]>
  • Loading branch information
lrusak committed Oct 8, 2024
1 parent 2ddf4d8 commit 787e613
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/beacon/test_beacon.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,24 @@ def test_cl_validator_get_sync_committee_duties(beacon):

response = beacon.get_sync_committee_duties(epoch, [random_validator_index])
_assert_valid_response(response)


# Rewards endpoint tests:


def test_cl_validator_get_attestations_rewards(beacon):
finality_checkpoint_response = beacon.get_finality_checkpoint()
_assert_valid_response(finality_checkpoint_response)

finality_checkpoint = finality_checkpoint_response["data"]
epoch = finality_checkpoint["finalized"]["epoch"]

validators_response = beacon.get_validators()
_assert_valid_response(validators_response)

validators = validators_response["data"]
random_validator = validators[randint(0, len(validators))]
random_validator_index = random_validator["index"]

response = beacon.get_attestations_rewards(epoch, [random_validator_index])
_assert_valid_response(response)
10 changes: 10 additions & 0 deletions web3/beacon/beacon.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
)
from web3.beacon.api_endpoints import (
GET_ATTESTATIONS,
GET_ATTESTATIONS_REWARDS,
GET_ATTESTER_DUTIES,
GET_ATTESTER_SLASHINGS,
GET_BEACON_HEADS,
Expand Down Expand Up @@ -257,3 +258,12 @@ def get_sync_committee_duties(
return self._make_post_request(
GET_SYNC_COMMITTEE_DUTIES.format(epoch), validator_indices
)

# [ REWARDS endpoints ]

def get_attestations_rewards(
self, epoch: str, validator_indices: List[str]
) -> Dict[str, Any]:
return self._make_post_request(
GET_ATTESTATIONS_REWARDS.format(epoch), validator_indices
)

0 comments on commit 787e613

Please sign in to comment.