Skip to content

Commit

Permalink
test: rate/recovery_manager is not only the dao
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoCentonze committed Oct 14, 2024
1 parent 781c73c commit 7b8ecd8
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 38 deletions.
24 changes: 22 additions & 2 deletions tests/unitary/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import pytest

MOCK_CRV_USD_CIRCULATING_SUPPLY = 69_420_000 * 10**18
CURVE_DAO = boa.env.generate_address()


@pytest.fixture()
Expand All @@ -11,8 +12,27 @@ def yearn_gov():

@pytest.fixture()
def curve_dao():
# TODO add a fixture for rate managers that contains curve dao
return boa.env.generate_address()
return CURVE_DAO


@pytest.fixture(params=[CURVE_DAO, boa.env.generate_address("rate_manager")])
def rate_manager(request, rewards_handler):
_rate_manager = request.param
if _rate_manager != CURVE_DAO:
rewards_handler.grantRole(rewards_handler.RATE_MANAGER(), _rate_manager, sender=CURVE_DAO)

return _rate_manager


@pytest.fixture(params=[CURVE_DAO, boa.env.generate_address("recovery_manager")])
def recovery_manager(request, rewards_handler):
_recovery_manager = request.param
if _recovery_manager != CURVE_DAO:
rewards_handler.grantRole(
rewards_handler.RECOVERY_MANAGER(), _recovery_manager, sender=CURVE_DAO
)

return _recovery_manager


@pytest.fixture()
Expand Down
8 changes: 4 additions & 4 deletions tests/unitary/rewards_handler/test_process_rewards.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import boa


def test_default_behavior(rewards_handler, crvusd, vault, curve_dao):
def test_default_behavior(rewards_handler, crvusd, vault, rate_manager):
distributed_amount = 10**18 * 100
boa.deal(crvusd, rewards_handler, distributed_amount)

rewards_handler.set_distribution_time(86_400 * 7, sender=curve_dao)
rewards_handler.set_distribution_time(86_400 * 7, sender=rate_manager)

assert crvusd.balanceOf(rewards_handler) == distributed_amount

Expand All @@ -22,8 +22,8 @@ def test_over_time(rewards_handler):
rewards_handler.process_rewards()


def test_no_rewards(rewards_handler, curve_dao):
rewards_handler.set_distribution_time(1234, sender=curve_dao)
def test_no_rewards(rewards_handler, rate_manager):
rewards_handler.set_distribution_time(1234, sender=rate_manager)

with boa.reverts("no rewards to distribute"):
rewards_handler.process_rewards()
7 changes: 0 additions & 7 deletions tests/unitary/rewards_handler/test_recover_erc20.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,6 @@ def mock_erc20():
return boa.load("tests/mocks/MockERC20.vy")


@pytest.fixture()
def recovery_manager(rewards_handler, curve_dao):
_recovery_admin = boa.env.generate_address()
rewards_handler.grantRole(rewards_handler.RECOVERY_MANAGER(), _recovery_admin, sender=curve_dao)
return _recovery_admin


def test_default_behavior(rewards_handler, mock_erc20, recovery_manager):
rescue_address = boa.env.generate_address()
boa.deal(mock_erc20, rewards_handler, 10**18)
Expand Down
4 changes: 2 additions & 2 deletions tests/unitary/rewards_handler/test_set_distribution_time.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import boa


def test_default_behavior(rewards_handler, curve_dao):
rewards_handler.set_distribution_time(1234, sender=curve_dao)
def test_default_behavior(rewards_handler, rate_manager):
rewards_handler.set_distribution_time(1234, sender=rate_manager)

assert rewards_handler.distribution_time() == 1234

Expand Down
4 changes: 2 additions & 2 deletions tests/unitary/rewards_handler/test_set_minimum_weight.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import boa


def test_default_behavior(rewards_handler, curve_dao):
rewards_handler.set_minimum_weight(2000, sender=curve_dao)
def test_default_behavior(rewards_handler, rate_manager):
rewards_handler.set_minimum_weight(2000, sender=rate_manager)
events = rewards_handler.get_logs()

# Verify event emission
Expand Down
4 changes: 2 additions & 2 deletions tests/unitary/rewards_handler/test_set_scaling_factor.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import boa


def test_default_behavior(rewards_handler, curve_dao):
rewards_handler.set_scaling_factor(12_000, sender=curve_dao) # 20% boost
def test_default_behavior(rewards_handler, rate_manager):
rewards_handler.set_scaling_factor(12_000, sender=rate_manager) # 20% boost
events = rewards_handler.get_logs()

# Verify event emission
Expand Down
6 changes: 3 additions & 3 deletions tests/unitary/rewards_handler/test_set_twa_frequency.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import boa


def test_default_behavior(rewards_handler, curve_dao):
def test_default_behavior(rewards_handler, rate_manager):
initial_twa_dt = rewards_handler.min_snapshot_dt_seconds()
new_twa_dt = initial_twa_dt + 12
with boa.env.prank(curve_dao):
with boa.env.prank(rate_manager):
rewards_handler.set_twa_snapshot_dt(new_twa_dt)
updated_twa_dt = rewards_handler.min_snapshot_dt_seconds()
assert updated_twa_dt == new_twa_dt


def test_role_access(rewards_handler, curve_dao, dev_address):
def test_role_access(rewards_handler, rate_manager, dev_address):
# validate that deployer can't change twa parameters
with boa.reverts("access_control: account is missing role"):
rewards_handler.set_twa_window(1, sender=dev_address)
Expand Down
6 changes: 3 additions & 3 deletions tests/unitary/rewards_handler/test_set_twa_window.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import boa


def test_default_behavior(rewards_handler, curve_dao):
def test_default_behavior(rewards_handler, rate_manager):
initial_twa_window = rewards_handler.twa_window()
new_twa_window = initial_twa_window + 1000 # Increment by 1000 seconds

with boa.env.prank(curve_dao):
with boa.env.prank(rate_manager):
rewards_handler.set_twa_window(new_twa_window)

# Verify that twa_window has been updated
updated_twa_window = rewards_handler.twa_window()
assert updated_twa_window == new_twa_window


def test_role_access(rewards_handler, curve_dao, dev_address):
def test_role_access(rewards_handler, dev_address):
# validate that deployer can't change twa parameters
with boa.reverts("access_control: account is missing role"):
rewards_handler.set_twa_window(1, sender=dev_address)
Expand Down
4 changes: 2 additions & 2 deletions tests/unitary/rewards_handler/test_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ def requested_weight(request):


def test_default_behavior(
rewards_handler, minimum_weight, scaling_factor, requested_weight, curve_dao
rewards_handler, minimum_weight, scaling_factor, requested_weight, rate_manager
):
rewards_handler.eval(f"twa._take_snapshot({requested_weight})")
boa.env.time_travel(blocks=100)
assert rewards_handler.compute_twa() == requested_weight
rewards_handler.set_minimum_weight(minimum_weight, sender=curve_dao)
rewards_handler.set_minimum_weight(minimum_weight, sender=rate_manager)
assert rewards_handler.weight() == max(
minimum_weight, requested_weight * scaling_factor // 10_000
)
4 changes: 2 additions & 2 deletions tests/unitary/twa/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ def setup_vault(vault, crvusd, vault_god, alice):


@pytest.fixture()
def setup_rewards_handler(rewards_handler, curve_dao, twa_window, snapshot_interval):
with boa.env.prank(curve_dao):
def setup_rewards_handler(rewards_handler, rate_manager, twa_window, snapshot_interval):
with boa.env.prank(rate_manager):
rewards_handler.set_twa_window(twa_window)
rewards_handler.set_twa_snapshot_dt(snapshot_interval)
return rewards_handler
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import boa


def test_default_behavior(rewards_handler, curve_dao):
def test_default_behavior(rewards_handler, rate_manager):
initial_min_snapshot_dt = rewards_handler.min_snapshot_dt_seconds()

# Define a new min_snapshot_dt_seconds value
new_min_snapshot_dt = initial_min_snapshot_dt + 12

with boa.env.prank(curve_dao):
# TODO this is not access internal (should skip role check)
with boa.env.prank(rate_manager):
rewards_handler.set_twa_snapshot_dt(new_min_snapshot_dt)
events = rewards_handler.get_logs()
# Verify event emission
Expand Down
10 changes: 3 additions & 7 deletions tests/unitary/twa/test_internal_set_twa_window.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import boa


def test_default_behavior(rewards_handler, curve_dao):
def test_default_behavior(rewards_handler):
initial_twa_window = rewards_handler.twa_window()
new_twa_window = initial_twa_window + 1000 # Increment by 1000 seconds

with boa.env.prank(curve_dao):
rewards_handler.set_twa_window(new_twa_window)
events = rewards_handler.get_logs()
rewards_handler.eval(f"twa._set_twa_window({new_twa_window})")
events = rewards_handler.get_logs()

# Verify event emission
assert f"TWAWindowUpdated(new_window={new_twa_window}" in repr(events)
Expand Down

0 comments on commit 7b8ecd8

Please sign in to comment.