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

Add high score alert #122

Merged
merged 4 commits into from
Oct 15, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions src/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
# threshold to generate an alert for violating UDP
UDP_SENSITIVITY_THRESHOLD = 0.005

# threshold to generate an alert for high score
HIGH_SCORE_THRESHOLD_ETH = 10

# relevant addresses
SETTLEMENT_CONTRACT_ADDRESS = "0x9008D19f58AAbD9eD0D60971565AA8510560ab41"
MEV_BLOCKER_KICKBACKS_ADDRESSES = [
Expand Down
55 changes: 55 additions & 0 deletions src/monitoring_tests/high_score_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""
Checking winner's score and generating an alert if score is very large
"""

# pylint: disable=logging-fstring-interpolation

from typing import Any
from src.monitoring_tests.base_test import BaseTest
from src.apis.orderbookapi import OrderbookAPI
from src.constants import HIGH_SCORE_THRESHOLD_ETH


class HighScoreTest(BaseTest):
"""
This test checks how large is the winning score and raises an alert if score
is above certain threshold
"""

def __init__(self) -> None:
super().__init__()
self.orderbook_api = OrderbookAPI()

def compute_winning_score(self, competition_data: dict[str, Any]) -> bool:
"""
This function simply returns the winning score.
"""
solution = competition_data["solutions"][-1]
score = int(solution["score"]) / 10**18
log_output = "\t".join(
[
"Large score test:",
f"Tx Hash: {competition_data['transactionHash']}",
f"Winning Solver: {solution['solver']}",
f"Score in ETH: {score}",
]
)
if score > HIGH_SCORE_THRESHOLD_ETH:
self.alert(log_output)
return True

def run(self, tx_hash: str) -> bool:
"""
Wrapper function for the whole test. Checks if solver competition data is retrievable
and then checks how large the winning score is.
"""

solver_competition_data = self.orderbook_api.get_solver_competition_data(
tx_hash
)
if solver_competition_data is None:
return False

success = self.compute_winning_score(solver_competition_data)

return success
24 changes: 24 additions & 0 deletions tests/e2e/high_score_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
"""
Tests for large score test.
"""

import unittest
from src.monitoring_tests.high_score_test import (
HighScoreTest,
)


class TestHighScore(unittest.TestCase):
def test_high_score(self) -> None:
high_score_test = HighScoreTest()
# large score tx
tx_hash = "0x5eef22d04a2f30e62df76614decf43e1cc92ab957285a687f182a0191d85d15a"
self.assertTrue(high_score_test.run(tx_hash))

# small score tx
tx_hash = "0x37e7dbc2f3df5f31f017634d07855933c6d82f4fda033daebd4377987d2b5ae9"
self.assertTrue(high_score_test.run(tx_hash))


if __name__ == "__main__":
unittest.main()
Loading