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

#918 - Remove ganache dependency from predictoor tests #934

Merged
Changes from all 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
40 changes: 34 additions & 6 deletions pdr_backend/predictoor/test/test_predictoor_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from enforce_typing import enforce_types
from numpy.testing import assert_array_equal

from pdr_backend.conftest_ganache import * # pylint: disable=wildcard-import
from pdr_backend.ppss.ppss import PPSS
from pdr_backend.ppss.predictoor_ss import PredictoorSS
from pdr_backend.ppss.web3_pp import Web3PP
Expand Down Expand Up @@ -43,6 +42,14 @@ def test_predictoor_agent_main3(tmpdir, monkeypatch, pred_submitter_mgr):
_test_predictoor_agent_main(3, str(tmpdir), monkeypatch, pred_submitter_mgr)


@pytest.fixture()
def pred_submitter_mgr():
with patch("pdr_backend.predictoor.predictoor_agent.PredSubmitterMgr") as mock:
mock.submit_prediction.return_value = {"transactionHash": b"hello", "status": 1}
mock.contract_address = "0x123"
yield mock


@enforce_types
def _test_predictoor_agent_main(
approach: int, tmpdir: str, monkeypatch, pred_submitter_mgr
Expand All @@ -65,10 +72,21 @@ def _test_predictoor_agent_main(
approach,
tmpdir,
monkeypatch,
pred_submitter_mgr=pred_submitter_mgr.contract_address,
)
assert ppss.predictoor_ss.approach == approach
ppss.predictoor_ss.d["pred_submitter_mgr"] = pred_submitter_mgr.contract_address
feed_contracts = ppss.web3_pp.query_feed_contracts()
web3_config = ppss.web3_pp.web3_config
w3 = ppss.web3_pp.w3
mock_token = Mock()
mock_token.balanceOf.return_value = Eth(1000).to_wei()
ppss.web3_pp = MagicMock(spec=Web3PP)
ppss.web3_pp.OCEAN_Token = mock_token
ppss.web3_pp.NativeToken = mock_token
ppss.web3_pp.get_single_contract.return_value = _mock_pdr_contract
ppss.web3_pp.query_feed_contracts.return_value = feed_contracts
ppss.web3_pp.web3_config = web3_config
ppss.web3_pp.w3 = w3
# now we're done the mocking, time for the real work!!

# real work: main iterations
Expand Down Expand Up @@ -202,6 +220,11 @@ def mock_build(*args, **kwargs): # pylint: disable=unused-argument

# do prediction
mock_model.aimodel_ss = aimodel_ss

feed_contracts = ppss.web3_pp.query_feed_contracts()
ppss.web3_pp = Mock(spec=Web3PP)
ppss.web3_pp.query_feed_contracts.return_value = feed_contracts

agent = PredictoorAgent(ppss)
feed = ppss.predictoor_ss.predict_train_feedsets[0]
agent.calc_stakes2(feed)
Expand Down Expand Up @@ -239,6 +262,9 @@ def mock_build(*args, **kwargs): # pylint: disable=unused-argument
2, str(tmpdir), monkeypatch, pred_submitter_mgr.contract_address
)
assert ppss.predictoor_ss.approach == 2
feed_contracts = ppss.web3_pp.query_feed_contracts()
ppss.web3_pp = Mock(spec=Web3PP)
ppss.web3_pp.query_feed_contracts.return_value = feed_contracts

assert len(feeds) == 2
aimodel_ss = ppss.predictoor_ss.aimodel_ss
Expand Down Expand Up @@ -298,15 +324,17 @@ def test_balance_check(tmpdir, monkeypatch, OCEAN, ROSE, expected, pred_submitte
aimodel_ss = ppss.predictoor_ss.aimodel_ss

mock_model.aimodel_ss = aimodel_ss
agent = PredictoorAgent(ppss)

feed_contracts = ppss.web3_pp.query_feed_contracts()
mock_OCEAN = Mock()
mock_OCEAN.balanceOf.return_value = OCEAN
mock_ROSE = Mock()
mock_ROSE.balanceOf.return_value = ROSE
ppss.web3_pp = Mock(spec=Web3PP)
ppss.web3_pp.OCEAN_Token = mock_OCEAN
ppss.web3_pp.NativeToken = mock_ROSE
ppss.web3_pp.query_feed_contracts.return_value = feed_contracts

agent.ppss.web3_pp = Mock(spec=Web3PP)
agent.ppss.web3_pp.OCEAN_Token = mock_OCEAN
agent.ppss.web3_pp.NativeToken = mock_ROSE
agent = PredictoorAgent(ppss)

assert agent.check_balances(Eth(100)) == expected
Loading