-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhigh_score_test.py
More file actions
56 lines (46 loc) · 1.77 KB
/
high_score_test.py
File metadata and controls
56 lines (46 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""
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_NATIVE_TOKEN
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, orderbook_api: OrderbookAPI, chain_name: str) -> None:
super().__init__()
self.orderbook_api = orderbook_api
self.chain_name = chain_name
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['transactionHashes'][0]}",
f"Winning Solver: {solution['solver']}",
f"Score in ETH: {score}",
]
)
if score > HIGH_SCORE_THRESHOLD_NATIVE_TOKEN[self.chain_name]:
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