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

Towards #13: tests & refactoring predictoor/ #101

Merged
merged 43 commits into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0737408
Towards #13: tests & refactoring predictoor/
trentmc Aug 28, 2023
c9e4e16
WIP big refactor
trentmc Aug 29, 2023
5a47107
wip
trentmc Aug 29, 2023
51189ac
wip
trentmc Aug 29, 2023
15f6c31
wip
trentmc Aug 29, 2023
a01b3c8
wip
trentmc Aug 29, 2023
81808d9
wip
trentmc Aug 30, 2023
35e6f06
back out approach2 refactor. Will focus on approach1. Set up appropri…
trentmc Aug 30, 2023
8c6d504
test_predictoor_config.py is passing
trentmc Aug 30, 2023
24eb754
flesh out predictoor_config tests.
trentmc Aug 30, 2023
aab4fb7
more thorough predictoor_config tests yet. They all pass. Done these …
trentmc Aug 30, 2023
c17014b
Merge branch 'main' into issue13-tests
trentmc Aug 31, 2023
d08bcbe
Merge branch 'main' into issue13-tests
trentmc Aug 31, 2023
258573a
Now PredictoorConfig inherits from BaseConfig
trentmc Aug 31, 2023
a31b61a
wip
trentmc Aug 31, 2023
c7d49c1
git merge main
trentmc Aug 31, 2023
6df8a5a
Merge branch 'main' into issue13-tests
trentmc Aug 31, 2023
42019da
Merge branch 'main' into issue13-tests
trentmc Aug 31, 2023
64982d0
wip
trentmc Aug 31, 2023
b31bfb4
wip
trentmc Aug 31, 2023
4066bbd
wip. test_predictoor_agent1.py is passing on a basic test
trentmc Aug 31, 2023
6bcfda3
wip
trentmc Aug 31, 2023
75871e4
wip
trentmc Aug 31, 2023
5d101ef
wip
trentmc Aug 31, 2023
c16c21e
wip
trentmc Aug 31, 2023
ba869a7
Add StrMixin, better logging
trentmc Aug 31, 2023
15f04ed
wip logging
trentmc Aug 31, 2023
182dd9a
Better logging, add payout() mock
trentmc Aug 31, 2023
9c34a01
wip
trentmc Aug 31, 2023
b161d92
Better core to track time/epoch in the test. Much better logging.
trentmc Sep 1, 2023
2cae408
wip
trentmc Sep 1, 2023
a976bff
Track contract calls to make predictions and do payouts. Raise errors…
trentmc Sep 1, 2023
a1bb625
wip
trentmc Sep 1, 2023
89b8eb2
wip
trentmc Sep 1, 2023
5ef8698
wip
trentmc Sep 1, 2023
103cf75
wip
trentmc Sep 1, 2023
5b842e2
Merge branch 'main' into issue13-tests
trentmc Sep 1, 2023
d481023
black
trentmc Sep 1, 2023
11471e6
bug fixes
trentmc Sep 1, 2023
08d5d22
fix mypy complaint in predictoor_batcher
trentmc Sep 1, 2023
7aa226e
linting wip
trentmc Sep 1, 2023
40c98ab
all linters happy
trentmc Sep 1, 2023
e371d37
touch
trentmc Sep 1, 2023
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
Prev Previous commit
Next Next commit
wip. test_predictoor_agent1.py is passing on a basic test
  • Loading branch information
trentmc committed Aug 31, 2023
commit 4066bbd0058922fa38ca785b8d04ba6b819b8a6e
17 changes: 11 additions & 6 deletions pdr_backend/predictoor/approach1/predictoor_agent1.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import time
from typing import Dict
from typing import Dict, Tuple

from enforce_typing import enforce_types

from pdr_backend.predictoor.predictoor_config import PredictoorConfig
from pdr_backend.models.feed import Feed
from pdr_backend.predictoor.approach1.predictoor_config1 import \
PredictoorConfig1


@enforce_types
Expand All @@ -15,10 +17,13 @@ class PredictoorAgent1:
- When a value can be predicted, call predict.py::predict_function()
"""

def __init__(self, config: PredictoorConfig):
self.config = config
self.feeds = self.config.get_feeds() # [addr] : feed
self.contracts = self.config.get_contracts() # [addr] : contract
def __init__(self, config: PredictoorConfig1):
self.config = config

self.feeds: Dict[str,Feed] = self.config.get_feeds() # [addr] : Feed

feed_addrs = list(self.feeds.keys())
self.contracts = self.config.get_contracts(feed_addrs) # [addr] : contract

self.prev_block_time: int = 0
self.prev_block_number: int = 0
Expand Down
70 changes: 67 additions & 3 deletions pdr_backend/predictoor/approach1/test/test_predictoor_agent1.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,70 @@
#from pdr_backend.approach1.predictoor_agent1 import PredictoorAgent1
from unittest.mock import patch, Mock

def test1():
pass
from enforce_typing import enforce_types

from pdr_backend.predictoor.approach1.predictoor_config1 import \
PredictoorConfig1
from pdr_backend.predictoor.approach1.predictoor_agent1 import \
PredictoorAgent1

PRIV_KEY = "0xef4b441145c1d0f3b4bc6d61d29f5c6e502359481152f869247c7a4244d45209"

ADDR = "0xe8933f2950aec1080efad1ca160a6bb641ad245d" # predictoor contract addr

FEED_DICT = { # info inside a predictoor contract
"name": "Contract Name",
"address": ADDR,
"symbol": "test",
"seconds_per_epoch": 300,
"seconds_per_subscription": 60,
"trueval_submit_timeout": 15,
"owner": "0xowner",
"pair": "BTC-ETH",
"timeframe": "1h",
"source": "binance",
}


def test_predictoor_agent1(monkeypatch):
_setenvs(monkeypatch)

# mock query_feed_contracts()
def _mock_query_feed_contracts(*args, **kwargs): # pylint: disable=unused-argument
feed_dicts = {ADDR: FEED_DICT}
return feed_dicts
monkeypatch.setattr(
"pdr_backend.models.base_config.query_feed_contracts",
_mock_query_feed_contracts,
)

# mock PredictoorContract
def _mock_contract(*args, **kwarg): # pylint: disable=unused-argument
m = Mock()
m.contract_address = ADDR
return m
monkeypatch.setattr(
"pdr_backend.models.base_config.PredictoorContract",
_mock_contract
)

# now do work
c = PredictoorConfig1()
agent = PredictoorAgent1(c)


def _setenvs(monkeypatch):
#envvars handled by PredictoorConfig1
monkeypatch.setenv("SECONDS_TILL_EPOCH_END", "60")
monkeypatch.setenv("STAKE_AMOUNT", "30000")

#envvars handled by BaseConfig
monkeypatch.setenv("RPC_URL", "http://foo")
monkeypatch.setenv("SUBGRAPH_URL", "http://bar")
monkeypatch.setenv("PRIVATE_KEY", PRIV_KEY)

monkeypatch.setenv("PAIR_FILTER", "BTC/USDT,ETH/USDT")
monkeypatch.setenv("TIMEFRAME_FILTER", "5m,15m")
monkeypatch.setenv("SOURCE_FILTER", "binance,kraken")
monkeypatch.setenv("OWNER_ADDRS", "0x123,0x124")