Skip to content

Commit

Permalink
Merge branch 'main' into issue658-use-ocean-in-challenge-df-reward-ca…
Browse files Browse the repository at this point in the history
…lculations
  • Loading branch information
trizin authored Jul 2, 2023
2 parents 5d5c046 + 5fc69ca commit b3eac54
Show file tree
Hide file tree
Showing 44 changed files with 710 additions and 679 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/checkpoint_feedist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,20 @@ jobs:
matrix:
python-version: [3.8]
steps:
- uses: actions/checkout@v2
- id: df-py
uses: pozetroninc/github-action-get-latest-release@master
with:
owner: oceanprotocol
repo: df-py
excludes: prerelease, draft

- name: Set branch to checkout
id: set_branch
run: echo "BRANCH=${{ github.event_name == 'schedule' && steps.df-py.outputs.release || github.ref }}" >> $GITHUB_ENV

- uses: actions/checkout@v3
with:
ref: ${{ env.BRANCH }}

- name: Set up Python {{ matrix.python-version }}
uses: actions/setup-python@v2
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/dispense_passive.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,20 @@ jobs:
matrix:
python-version: [3.8]
steps:
- uses: actions/checkout@v2
- id: df-py
uses: pozetroninc/github-action-get-latest-release@master
with:
owner: oceanprotocol
repo: df-py
excludes: prerelease, draft

- name: Set branch to checkout
id: set_branch
run: echo "BRANCH=${{ github.event_name == 'schedule' && steps.df-py.outputs.release || github.ref }}" >> $GITHUB_ENV

- uses: actions/checkout@v3
with:
ref: ${{ env.BRANCH }}

- name: Set up Python {{ matrix.python-version }}
uses: actions/setup-python@v2
Expand Down
15 changes: 14 additions & 1 deletion .github/workflows/flow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,20 @@ jobs:
python-version: [3.8]
#needs: run-tests
steps:
- id: df-py
uses: pozetroninc/github-action-get-latest-release@master
with:
owner: oceanprotocol
repo: df-py
excludes: prerelease, draft

- name: Set branch to checkout
id: set_branch
run: echo "BRANCH=${{ github.event_name == 'schedule' && steps.df-py.outputs.release || github.ref }}" >> $GITHUB_ENV

- uses: actions/checkout@v3
with:
ref: ${{ env.BRANCH }}

- name: Set up Python {{ matrix.python-version }}
uses: actions/setup-python@v2
Expand Down Expand Up @@ -138,7 +151,7 @@ jobs:
credentials_json: "${{ secrets.GC_SECRET }}"
#workload_identity_provider: ${{ secrets.GCLOUD_IDENTITY_PROVIDER }}
#service_account: ${{ secrets.SERVICE_ACCOUNT }}

- name: Set upload destination
run: |
if [[ "${{ github.event_name }}" == "schedule" ]]; then
Expand Down
2 changes: 1 addition & 1 deletion df_py/challenge/csvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def load_challenge_data_csv(csv_dir: str) -> Tuple[List[str], List[str], list]:

@enforce_types
def challenge_data_csv_filename(csv_dir: str) -> str:
f = "challenge.csv"
f = "challenge_data.csv"
return os.path.join(csv_dir, f)


Expand Down
4 changes: 2 additions & 2 deletions df_py/challenge/judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ def _from_addr(tx):

@enforce_types
def _nft_addr_to_pred_vals(nft_addr: str, judge_acct) -> List[float]:
nft = oceanutil.getDataNFT(nft_addr)
pred_vals_str_enc = oceanutil.getDataField(nft, "predictions")
nft = oceanutil.get_data_nft(nft_addr)
pred_vals_str_enc = oceanutil.get_data_field(nft, "predictions")
try:
pred_vals_str = crypto.asym_decrypt(pred_vals_str_enc, judge_acct.private_key)
pred_vals = [float(s) for s in pred_vals_str[1:-1].split(",")]
Expand Down
2 changes: 1 addition & 1 deletion df_py/challenge/test/test_challenge_csvs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_challenge_data(tmp_path):
csv_dir = str(tmp_path)

# filename
assert "challenge.csv" in csvs.challenge_data_csv_filename(csv_dir)
assert "challenge_data.csv" in csvs.challenge_data_csv_filename(csv_dir)

# save
from_addrs = ["0xfrom1", "0xfrom2"]
Expand Down
10 changes: 5 additions & 5 deletions df_py/challenge/test/test_dftool_challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@


@enforce_types
def test1(tmp_path):
def test_empty_deadline(tmp_path):
_test(tmp_path, DEADLINE=None)


@enforce_types
def test2(tmp_path):
def test_deadline_none_string(tmp_path):
_test(tmp_path, DEADLINE="None")


@enforce_types
def test3(tmp_path):
def test_explicit_deadlin(tmp_path):
_test(tmp_path, DEADLINE="2023-05-03_23:59")


Expand All @@ -53,7 +53,7 @@ def _test(tmp_path, DEADLINE: Optional[str]):
)

# Mock the connection, use test data
with patch("df_py.util.dftool_module.recordDeployedContracts"):
with patch("df_py.util.dftool_module.record_deployed_contracts"):
with patch.object(dftool_module.judge, "get_challenge_data") as mock:
mock.return_value = (target_from_addrs, target_nft_addrs, target_nmses)
with sysargs_context(sysargs):
Expand Down Expand Up @@ -83,7 +83,7 @@ def setup_function():

networkutil.connect(CHAINID)
accounts = brownie.network.accounts
oceanutil.recordDevDeployedContracts()
oceanutil.record_dev_deployed_contracts()
oceantestutil.fill_accounts_with_OCEAN()

DFTOOL_ACCT = accounts.add()
Expand Down
6 changes: 3 additions & 3 deletions df_py/challenge/test/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@


@enforce_types
def test_dt_to_ut__timezone():
def test_dt_to_ut_timezone():
# setup
unaware_dt = datetime.datetime(2011, 8, 15, 8, 15, 12, 0)
aware_dt = datetime.datetime(2011, 8, 15, 8, 15, 12, 0, tzinfo=timezone.utc)
Expand All @@ -31,7 +31,7 @@ def test_dt_to_ut__timezone():


@enforce_types
def test_dt_to_ut__main():
def test_dt_to_ut_main():
# time = when unix time starts
dt = datetime.datetime(1970, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc)
ut = helpers.dt_to_ut(dt)
Expand All @@ -44,7 +44,7 @@ def test_dt_to_ut__main():


@enforce_types
def test_ut_to_dt__main():
def test_ut_to_dt_main():
# time = when unix time starts
ut = 0
target_dt = datetime.datetime(1970, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc)
Expand Down
12 changes: 6 additions & 6 deletions df_py/challenge/test/test_judge.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ def test_get_txs():

# sort txs by nft address, to ease subsequent testing
nft_addrs = [tx["nft"]["id"] for tx in txs]
I = np.argsort(nft_addrs)
txs = [txs[i] for i in I]
sorted_txs = np.argsort(nft_addrs)
txs = [txs[i] for i in sorted_txs]

# now test
nft_addrs = [tx["nft"]["id"] for tx in txs]
Expand Down Expand Up @@ -66,7 +66,7 @@ def test_nft_addr_to_pred_vals():


@enforce_types
def test_get_cex_vals1():
def test_get_cex_vals_1():
today = datetime.today().replace(tzinfo=timezone.utc)
deadline_dt = today - timedelta(days=2)
deadline_dt = deadline_dt.replace(hour=12, minute=59, second=0, microsecond=0)
Expand All @@ -75,21 +75,21 @@ def test_get_cex_vals1():


@enforce_types
def test_get_cex_vals2():
def test_get_cex_vals_2():
deadline_dt = datetime(2023, 5, 3, 23, 59, tzinfo=timezone.utc)
cex_vals = judge._get_cex_vals(deadline_dt)
assert len(cex_vals) == 12


@enforce_types
def test_parse_deadline_str1():
def test_parse_deadline_str_1():
dt = judge.parse_deadline_str("2023-05-03_23:59")
dt_target = datetime(2023, 5, 3, 23, 59, tzinfo=timezone.utc)
assert dt == dt_target


@enforce_types
def test_parse_deadline_str2():
def test_parse_deadline_str_2():
dt = judge.parse_deadline_str()

assert (datetime.now(timezone.utc) - dt) < timedelta(days=7) # within 1 wk
Expand Down
6 changes: 3 additions & 3 deletions df_py/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from enforce_typing import enforce_types

from df_py.util import networkutil
from df_py.util.oceanutil import OCEANtoken, recordDevDeployedContracts
from df_py.util.oceanutil import OCEAN_token, record_dev_deployed_contracts


@enforce_types
Expand All @@ -21,6 +21,6 @@ def network_setup_and_teardown():

def pytest_sessionstart():
networkutil.connect_dev()
recordDevDeployedContracts()
record_dev_deployed_contracts()
accs = brownie.network.accounts
OCEANtoken().mint(accs[0], 1e24, {"from": accs[0]})
OCEAN_token().mint(accs[0], 1e24, {"from": accs[0]})
12 changes: 6 additions & 6 deletions df_py/predictoor/test/test_predictoor_calc_rewards.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from df_py.util.constants import MIN_PREDICTIONS


def test_filterPredictoors():
def test_filter_predictoors():
p1 = Predictoor("0x1")
p1._prediction_count = MIN_PREDICTIONS - 1
p2 = Predictoor("0x2")
Expand All @@ -23,15 +23,15 @@ def test_filterPredictoors():
assert "0x3" in filtered


def test_calcPredictoorRewards_no_predictions():
def test_calc_predictoor_rewards_no_predictions():
predictoors: Dict[str, Union[PredictoorBase, Predictoor]] = {}

rewards = calc_predictoor_rewards(predictoors, 100)

assert len(rewards) == 0


def test_calcPredictoorRewards_one_prediction_not_eligible():
def test_calc_predictoor_rewards_one_prediction_not_eligible():
p1 = Predictoor("0x1")
p1._prediction_count = MIN_PREDICTIONS - 1
p1._correct_prediction_count = 5
Expand All @@ -43,7 +43,7 @@ def test_calcPredictoorRewards_one_prediction_not_eligible():
assert rewards.get(p1.address, 0) == 0


def test_calcPredictoorRewards_one_prediction_eligible():
def test_calc_predictoor_rewards_one_prediction_eligible():
p1 = Predictoor("0x1")
p1._prediction_count = MIN_PREDICTIONS + 1
p1._correct_prediction_count = 5
Expand All @@ -55,7 +55,7 @@ def test_calcPredictoorRewards_one_prediction_eligible():
assert rewards.get(p1.address, 0) == 100


def test_calcPredictoorRewards_with_predictions():
def test_calc_predictoor_rewards_with_predictions():
p1 = Predictoor("0x1")
p1._prediction_count = MIN_PREDICTIONS + 100
p1._correct_prediction_count = 5
Expand All @@ -74,7 +74,7 @@ def test_calcPredictoorRewards_with_predictions():
assert rewards["0x2"] == 50.0


def test_calcPredictoorRewards_fuzz():
def test_calc_predictoor_rewards_fuzz():
predictoors = {}
total_accuracy = 0
for i in range(100): # generate 100 predictoors
Expand Down
4 changes: 2 additions & 2 deletions df_py/tests/stress.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):

def main():
networkutil.connect(CHAINID) # Connect to ganache
oceanutil.recordDevDeployedContracts() # Record deployed contract addresses on ganache
oceanutil.record_dev_deployed_contracts() # Record deployed contract addresses on ganache

CSV_DIR = str("/tmp/df_stress_test")

Expand All @@ -64,7 +64,7 @@ def main():
accounts = brownie.network.accounts
assert len(test_accounts) == NUMBER_OF_ACCOUNTS

OCEAN = oceanutil.OCEANtoken()
OCEAN = oceanutil.OCEAN_token()

## Deploy pool
print("Deploying pool")
Expand Down
Loading

0 comments on commit b3eac54

Please sign in to comment.