From 7b8ecd8d35ecf217e847bf6a7cb5d19e787721a3 Mon Sep 17 00:00:00 2001 From: Alberto Date: Mon, 14 Oct 2024 18:27:29 +0200 Subject: [PATCH] test: rate/recovery_manager is not only the dao --- tests/unitary/conftest.py | 24 +++++++++++++++++-- .../rewards_handler/test_process_rewards.py | 8 +++---- .../rewards_handler/test_recover_erc20.py | 7 ------ .../test_set_distribution_time.py | 4 ++-- .../test_set_minimum_weight.py | 4 ++-- .../test_set_scaling_factor.py | 4 ++-- .../rewards_handler/test_set_twa_frequency.py | 6 ++--- .../rewards_handler/test_set_twa_window.py | 6 ++--- tests/unitary/rewards_handler/test_weight.py | 4 ++-- tests/unitary/twa/conftest.py | 4 ++-- ...st_internal_set_min_snapshot_dt_seconds.py | 5 ++-- .../twa/test_internal_set_twa_window.py | 10 +++----- 12 files changed, 48 insertions(+), 38 deletions(-) diff --git a/tests/unitary/conftest.py b/tests/unitary/conftest.py index 92e8a32..19f6e4b 100644 --- a/tests/unitary/conftest.py +++ b/tests/unitary/conftest.py @@ -2,6 +2,7 @@ import pytest MOCK_CRV_USD_CIRCULATING_SUPPLY = 69_420_000 * 10**18 +CURVE_DAO = boa.env.generate_address() @pytest.fixture() @@ -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() diff --git a/tests/unitary/rewards_handler/test_process_rewards.py b/tests/unitary/rewards_handler/test_process_rewards.py index f1619b0..4dedca5 100644 --- a/tests/unitary/rewards_handler/test_process_rewards.py +++ b/tests/unitary/rewards_handler/test_process_rewards.py @@ -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 @@ -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() diff --git a/tests/unitary/rewards_handler/test_recover_erc20.py b/tests/unitary/rewards_handler/test_recover_erc20.py index a23a5f2..10ce9fa 100644 --- a/tests/unitary/rewards_handler/test_recover_erc20.py +++ b/tests/unitary/rewards_handler/test_recover_erc20.py @@ -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) diff --git a/tests/unitary/rewards_handler/test_set_distribution_time.py b/tests/unitary/rewards_handler/test_set_distribution_time.py index daa0704..3ebe968 100644 --- a/tests/unitary/rewards_handler/test_set_distribution_time.py +++ b/tests/unitary/rewards_handler/test_set_distribution_time.py @@ -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 diff --git a/tests/unitary/rewards_handler/test_set_minimum_weight.py b/tests/unitary/rewards_handler/test_set_minimum_weight.py index 475c6a9..9e7bdbc 100644 --- a/tests/unitary/rewards_handler/test_set_minimum_weight.py +++ b/tests/unitary/rewards_handler/test_set_minimum_weight.py @@ -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 diff --git a/tests/unitary/rewards_handler/test_set_scaling_factor.py b/tests/unitary/rewards_handler/test_set_scaling_factor.py index 537f18f..98120da 100644 --- a/tests/unitary/rewards_handler/test_set_scaling_factor.py +++ b/tests/unitary/rewards_handler/test_set_scaling_factor.py @@ -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 diff --git a/tests/unitary/rewards_handler/test_set_twa_frequency.py b/tests/unitary/rewards_handler/test_set_twa_frequency.py index 6b67b16..0e63598 100644 --- a/tests/unitary/rewards_handler/test_set_twa_frequency.py +++ b/tests/unitary/rewards_handler/test_set_twa_frequency.py @@ -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) diff --git a/tests/unitary/rewards_handler/test_set_twa_window.py b/tests/unitary/rewards_handler/test_set_twa_window.py index 2eaeca6..5b8fead 100644 --- a/tests/unitary/rewards_handler/test_set_twa_window.py +++ b/tests/unitary/rewards_handler/test_set_twa_window.py @@ -1,11 +1,11 @@ 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 @@ -13,7 +13,7 @@ def test_default_behavior(rewards_handler, curve_dao): 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) diff --git a/tests/unitary/rewards_handler/test_weight.py b/tests/unitary/rewards_handler/test_weight.py index 1ae8bc7..4fba09c 100644 --- a/tests/unitary/rewards_handler/test_weight.py +++ b/tests/unitary/rewards_handler/test_weight.py @@ -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 ) diff --git a/tests/unitary/twa/conftest.py b/tests/unitary/twa/conftest.py index a8affda..ac1d53b 100644 --- a/tests/unitary/twa/conftest.py +++ b/tests/unitary/twa/conftest.py @@ -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 diff --git a/tests/unitary/twa/test_internal_set_min_snapshot_dt_seconds.py b/tests/unitary/twa/test_internal_set_min_snapshot_dt_seconds.py index 0deae17..991c6f9 100644 --- a/tests/unitary/twa/test_internal_set_min_snapshot_dt_seconds.py +++ b/tests/unitary/twa/test_internal_set_min_snapshot_dt_seconds.py @@ -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 diff --git a/tests/unitary/twa/test_internal_set_twa_window.py b/tests/unitary/twa/test_internal_set_twa_window.py index 88ae96f..36b6e82 100644 --- a/tests/unitary/twa/test_internal_set_twa_window.py +++ b/tests/unitary/twa/test_internal_set_twa_window.py @@ -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)