Skip to content

Commit 2bb8111

Browse files
authored
[CVAT][Exchange Oracle] Return correct url from get_reputation_oracle_url (#2562)
* Use correct url for get_reputation_oracle_url * Add tests for `get_reputation_oracle_url` * Minor change to re-run the pipeline Restarting the job doesn't help.
1 parent 1e003e0 commit 2bb8111

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

packages/examples/cvat/exchange-oracle/src/chain/kvstore.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ def get_recording_oracle_url(chain_id: int, escrow_address: str) -> str:
1717

1818

1919
def get_reputation_oracle_url(chain_id: int, escrow_address: str) -> str:
20-
if url := Config.localhost.recording_oracle_url:
20+
if url := Config.localhost.reputation_oracle_url:
2121
return url
2222

2323
escrow = get_escrow(chain_id, escrow_address)
2424

25-
return OperatorUtils.get_leader(ChainId(chain_id), escrow.recording_oracle).webhook_url
25+
return OperatorUtils.get_leader(ChainId(chain_id), escrow.reputation_oracle).webhook_url
2626

2727

2828
def get_job_launcher_url(chain_id: int, escrow_address: str) -> str:

packages/examples/cvat/exchange-oracle/tests/integration/chain/test_kvstore.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
from human_protocol_sdk.escrow import EscrowClientError, EscrowData
77
from human_protocol_sdk.kvstore import KVStoreClientError, KVStoreUtils
88

9-
from src.chain.kvstore import get_job_launcher_url, get_recording_oracle_url, register_in_kvstore
9+
from src.chain.kvstore import (
10+
get_job_launcher_url,
11+
get_recording_oracle_url,
12+
get_reputation_oracle_url,
13+
register_in_kvstore,
14+
)
1015
from src.core.config import LocalhostConfig
1116

1217
from tests.utils.constants import (
@@ -194,3 +199,25 @@ def set_file_url_and_hash(url: str, key: str):
194199
)
195200
== PGP_PUBLIC_KEY_URL_2
196201
)
202+
203+
def test_get_reputation_oracle_url_config_url(self):
204+
with patch(
205+
"src.chain.kvstore.Config.localhost.reputation_oracle_url", DEFAULT_MANIFEST_URL
206+
):
207+
reputation_url = get_reputation_oracle_url(self.w3.eth.chain_id, escrow_address)
208+
assert reputation_url == DEFAULT_MANIFEST_URL
209+
210+
def test_get_reputation_oracle_url_from_escrow(self):
211+
with (
212+
patch("src.chain.kvstore.get_escrow") as mock_escrow,
213+
patch("src.chain.kvstore.OperatorUtils.get_leader") as mock_leader,
214+
patch("src.chain.kvstore.Config.localhost.reputation_oracle_url", None),
215+
):
216+
mock_escrow.return_value = self.escrow_data
217+
mock_leader.return_value = MagicMock(webhook_url=DEFAULT_MANIFEST_URL)
218+
reputation_url = get_reputation_oracle_url(self.w3.eth.chain_id, escrow_address)
219+
assert reputation_url == DEFAULT_MANIFEST_URL
220+
221+
def test_get_reputation_oracle_url_invalid_escrow(self):
222+
with pytest.raises(EscrowClientError, match="Invalid escrow address: invalid address"):
223+
get_reputation_oracle_url(self.w3.eth.chain_id, "invalid address")

0 commit comments

Comments
 (0)