|
6 | 6 | from human_protocol_sdk.escrow import EscrowClientError, EscrowData |
7 | 7 | from human_protocol_sdk.kvstore import KVStoreClientError, KVStoreUtils |
8 | 8 |
|
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 | +) |
10 | 15 | from src.core.config import LocalhostConfig |
11 | 16 |
|
12 | 17 | from tests.utils.constants import ( |
@@ -194,3 +199,25 @@ def set_file_url_and_hash(url: str, key: str): |
194 | 199 | ) |
195 | 200 | == PGP_PUBLIC_KEY_URL_2 |
196 | 201 | ) |
| 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