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

test: restrict scope of fixtures #28

Merged
merged 2 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
description = ""
authors = [{ name = "Curve.fi", email = "info@curve.fi" }]
readme = "README.md"
requires-python = ">=3.10"
requires-python = "==3.12.6"

# Requirements
dependencies = [
Expand All @@ -14,7 +14,7 @@ dependencies = [
]

[tool.uv.sources]
titanoboa = { git = "https://github.com/vyperlang/titanoboa.git", rev = "86df8936654db20686410488738d7abaf165a4c9" }
titanoboa = { git = "https://github.com/vyperlang/titanoboa.git", rev = "a52c79c67ba0e00ceafc70f9daf730c9a57f27c9" }

[tool.uv]
dev-dependencies = [
Expand Down
24 changes: 12 additions & 12 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
boa.set_etherscan(api_key=os.getenv("ETHERSCAN_API_KEY"))


@pytest.fixture(autouse=True, scope="module")
@pytest.fixture(autouse=True)
def better_traces(forked_env):
# contains contracts that are not necessarily called
# but appear in the traces
boa.from_etherscan(ab.vault_original, "vault_original")


@pytest.fixture(scope="module")
@pytest.fixture()
def rpc_url():
return os.getenv("ETH_RPC_URL") or "https://rpc.ankr.com/eth"


@pytest.fixture(scope="module", autouse=True)
@pytest.fixture(autouse=True)
def forked_env(rpc_url):
block_to_fork = 20928372
with boa.swap_env(boa.Env()):
Expand All @@ -30,22 +30,22 @@ def forked_env(rpc_url):
yield


@pytest.fixture(scope="module")
@pytest.fixture()
def controller_factory():
return boa.from_etherscan(ab.crvusd_controller_factory, "controller_factory")


@pytest.fixture(scope="module")
@pytest.fixture()
def lens(controller_factory):
return boa.load("contracts/StablecoinLens.vy", controller_factory)


@pytest.fixture(scope="module")
@pytest.fixture()
def vault_factory():
return boa.from_etherscan(ab.yearn_vault_factory, "vault_factory")


@pytest.fixture(scope="module")
@pytest.fixture()
def fee_splitter(rewards_handler):
_fee_splitter_abi = boa.load_vyi("tests/integration/interfaces/IFeeSplitter.vyi")

Expand All @@ -66,12 +66,12 @@ def fee_splitter(rewards_handler):
return _fee_splitter


@pytest.fixture(scope="module")
@pytest.fixture()
def crvusd():
return boa.from_etherscan(ab.crvusd, "crvusd")


@pytest.fixture(scope="module")
@pytest.fixture()
def vault(vault_factory):
_vault_abi = boa.load_partial("contracts/yearn/VaultV3.vy")

Expand All @@ -94,12 +94,12 @@ def vault(vault_factory):
return _vault


@pytest.fixture(scope="module")
@pytest.fixture()
def minimum_weight():
return 500


@pytest.fixture(scope="module")
@pytest.fixture()
def rewards_handler(vault, minimum_weight):
rh = boa.load(
"contracts/RewardsHandler.vy",
Expand All @@ -119,7 +119,7 @@ def rewards_handler(vault, minimum_weight):
return rh


@pytest.fixture(scope="module")
@pytest.fixture()
def active_controllers(fee_splitter):
# useful to call dispatch_fees
# we skip the first one as the market is deprecated
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/test_dynamic_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import address_book as ab


@pytest.fixture(scope="module")
@pytest.fixture()
def new_depositor(crvusd, vault):
def _new_depositor(amount):
depositor = boa.env.generate_address()
Expand All @@ -19,7 +19,7 @@ def _new_depositor(amount):
return _new_depositor


@pytest.fixture(autouse=True, scope="module")
@pytest.fixture(autouse=True)
def inject_raw_weight(rewards_handler):
raw_weight_source = textwrap.dedent("""
@view
Expand Down
38 changes: 19 additions & 19 deletions tests/unitary/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,46 @@
MOCK_CRV_USD_CIRCULATING_SUPPLY = 69_420_000 * 10**18


@pytest.fixture(scope="module")
@pytest.fixture()
def yearn_gov():
return boa.env.generate_address()


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


@pytest.fixture(scope="module")
@pytest.fixture()
def dev_address():
return boa.env.generate_address()


@pytest.fixture(scope="module")
@pytest.fixture()
def security_agent():
return boa.env.generate_address()


@pytest.fixture(scope="module")
@pytest.fixture()
def vault_init_deposit_cap():
return 5_000_000 * 10**18


@pytest.fixture(scope="module")
@pytest.fixture()
def deposit_limit_module(dev_address, crvusd, vault, vault_init_deposit_cap):
contract_deployer = boa.load_partial("contracts/DepositLimitModule.vy")
with boa.env.prank(dev_address):
contract = contract_deployer(vault, vault_init_deposit_cap)
return contract


@pytest.fixture(scope="module")
@pytest.fixture()
def vault_original():
return boa.load("contracts/yearn/VaultV3.vy")


@pytest.fixture(scope="module")
@pytest.fixture()
def vault_factory(vault_original, yearn_gov):
return boa.load(
"contracts/yearn/VaultFactory.vy",
Expand All @@ -53,17 +53,17 @@ def vault_factory(vault_original, yearn_gov):
)


@pytest.fixture(scope="module")
@pytest.fixture()
def crvusd():
return boa.load("tests/mocks/MockERC20.vy")


@pytest.fixture(scope="module")
@pytest.fixture()
def role_manager():
return boa.env.generate_address()


@pytest.fixture(scope="module")
@pytest.fixture()
def vault(vault_factory, crvusd, role_manager, dev_address):
vault_deployer = boa.load_partial("contracts/yearn/VaultV3.vy")

Expand All @@ -75,7 +75,7 @@ def vault(vault_factory, crvusd, role_manager, dev_address):
return vault_deployer.at(address)


@pytest.fixture(scope="module")
@pytest.fixture()
def vault_god(vault, role_manager):
_god = boa.env.generate_address()

Expand All @@ -84,17 +84,17 @@ def vault_god(vault, role_manager):
return _god


@pytest.fixture(scope="module")
@pytest.fixture()
def minimum_weight(request):
return 1000 # 10%


@pytest.fixture(scope="module")
@pytest.fixture()
def scaling_factor(request):
return 10000 # 100%


@pytest.fixture(scope="module")
@pytest.fixture()
def mock_controller_factory(mock_controller):
mock_controller_factory = boa.load("tests/mocks/MockControllerFactory.vy")
for i in range(4): # because we use 3rd controller (weth) in contract code
Expand All @@ -104,27 +104,27 @@ def mock_controller_factory(mock_controller):
return mock_controller_factory


@pytest.fixture(scope="module")
@pytest.fixture()
def mock_controller(mock_monetary_policy):
mock_controller = boa.load("tests/mocks/MockController.vy")
mock_controller.eval(f"self._monetary_policy={mock_monetary_policy.address}")
return mock_controller


@pytest.fixture(scope="module")
@pytest.fixture()
def mock_monetary_policy(mock_peg_keeper):
mock_monetary_policy = boa.load("tests/mocks/MockMonetaryPolicy.vy")
mock_monetary_policy.eval(f"self.peg_keeper_array[0] = IPegKeeper({mock_peg_keeper.address})")
return mock_monetary_policy


@pytest.fixture(scope="module")
@pytest.fixture()
def mock_peg_keeper():
mock_peg_keeper = boa.load("tests/mocks/MockPegKeeper.vy", MOCK_CRV_USD_CIRCULATING_SUPPLY)
return mock_peg_keeper


@pytest.fixture(scope="module")
@pytest.fixture()
def rewards_handler(
vault,
crvusd,
Expand Down
4 changes: 2 additions & 2 deletions tests/unitary/rewards_handler/test_recover_erc20.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import pytest


@pytest.fixture(scope="module")
@pytest.fixture()
def mock_erc20():
return boa.load("tests/mocks/MockERC20.vy")


@pytest.fixture(scope="module")
@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)
Expand Down
2 changes: 1 addition & 1 deletion tests/unitary/rewards_handler/test_rh_constructor.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import pytest


@pytest.fixture(scope="module")
@pytest.fixture()
def rewards_handler_deployer():
return boa.load_partial("contracts/RewardsHandler.vy")

Expand Down
6 changes: 3 additions & 3 deletions tests/unitary/rewards_handler/test_weight.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@
possible_req_weight = [i * 4000 for i in range(0, 3)]


@pytest.fixture(params=possible_min_weight, scope="module")
@pytest.fixture(params=possible_min_weight)
def minimum_weight(request):
return request.param


@pytest.fixture(params=possible_scaling_factor, scope="module")
@pytest.fixture(params=possible_scaling_factor)
def scaling_factor(request):
return request.param


@pytest.fixture(params=possible_req_weight, scope="module")
@pytest.fixture(params=possible_req_weight)
def requested_weight(request):
return request.param

Expand Down
14 changes: 7 additions & 7 deletions tests/unitary/twa/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,43 +9,43 @@
TWA_WINDOW = 1000


@pytest.fixture(scope="module")
@pytest.fixture()
def alice(crvusd):
alice = boa.env.generate_address()
boa.deal(crvusd, alice, INITIAL_BALANCE)
return alice


@pytest.fixture(scope="module")
@pytest.fixture()
def setup_vault(vault, crvusd, vault_god, alice):
crvusd.approve(vault.address, 2**256 - 1, sender=alice)
vault.set_deposit_limit(crvusd.balanceOf(alice), sender=vault_god)
return vault


@pytest.fixture
@pytest.fixture()
def setup_rewards_handler(rewards_handler, curve_dao, twa_window, snapshot_interval):
with boa.env.prank(curve_dao):
rewards_handler.set_twa_window(twa_window)
rewards_handler.set_twa_snapshot_dt(snapshot_interval)
return rewards_handler


@pytest.fixture
@pytest.fixture()
def amt_deposit():
return AMT_DEPOSIT


@pytest.fixture
@pytest.fixture()
def snapshot_amount():
return SNAPSHOT_AMOUNT


@pytest.fixture
@pytest.fixture()
def snapshot_interval():
return MIN_SNAPSHOT_DT


@pytest.fixture
@pytest.fixture()
def twa_window():
return TWA_WINDOW
Loading
Loading