-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Co-authored-by: trizin <[email protected]>
- Loading branch information
Showing
4 changed files
with
107 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 41 additions & 3 deletions
44
pdr_backend/predictoor/approach1/test/test_predictoor_approach1_main.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,47 @@ | ||
import pytest | ||
from pdr_backend.predictoor.approach1.main import ( # pylint: disable=unused-import | ||
process_block, | ||
log_loop, | ||
main, | ||
process_topic, | ||
) | ||
import pdr_backend.predictoor.approach1.main as main | ||
from unittest.mock import patch, Mock | ||
from pdr_backend.models.predictoor_contract import PredictoorContract | ||
|
||
|
||
def test_predictoor_approach1_main(): | ||
pass | ||
@pytest.mark.skip(reason="Incomplete, skip") | ||
@patch("pdr_backend.predictoor.approach1.main.get_all_interesting_prediction_contracts") | ||
def test_predictoor_main_process_block(mock_topics): | ||
mock_topics.return_value = {"0x123": "topic"} | ||
|
||
with patch("pdr_backend.predictoor.approach1.main.process_topic") as mock_pt: | ||
process_block({"number": 0, "timestamp": 10}) | ||
assert mock_topics.called | ||
mock_pt.assert_called_with("0x123", 10) | ||
|
||
|
||
@pytest.mark.skip(reason="Incomplete, skip") | ||
def test_predictoor_main_process_topic(monkeypatch): | ||
monkeypatch.setenv("SECONDS_TILL_EPOCH_END", "200") | ||
main.topics["0x123"] = { | ||
"name": "topic", | ||
"address": "0x123", | ||
"last_submited_epoch": 1, | ||
} | ||
|
||
mock_contract = Mock(spec=PredictoorContract) | ||
mock_contract.get_current_epoch.return_value = 2 | ||
mock_contract.get_secondsPerEpoch.return_value = 60 | ||
mock_contract.contract_address = "0x123" | ||
|
||
main.contract_map["0x123"] = mock_contract | ||
|
||
with patch("pdr_backend.predictoor.approach1.main.do_prediction") as mock_dp: | ||
process_topic("0x123", 10) | ||
mock_contract.payout.assert_called_with(60, False) | ||
mock_dp.assert_called_with( | ||
# last submited epoch is 2 now | ||
{"name": "topic", "address": "0x123", "last_submited_epoch": 2}, | ||
2, | ||
mock_contract, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# pytest.ini | ||
[pytest] | ||
env = | ||
D:ADDRESS_FILE=~/.ocean/ocean-contracts/artifacts/address.json | ||
D:RPC_URL=http://127.0.0.1:8545 | ||
D:SUBGRAPH_URL=http://172.15.0.15:8000/subgraphs/name/oceanprotocol/ocean-subgraph | ||
D:PRIVATE_KEY=0xef4b441145c1d0f3b4bc6d61d29f5c6e502359481152f869247c7a4244d45209 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
"pathlib", | ||
"pylint", | ||
"pytest", | ||
"pytest-env", | ||
"requests", | ||
"web3", | ||
"sapphire.py", | ||
|