Skip to content

Commit

Permalink
test: fixtuire scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
heswithme committed Oct 14, 2024
2 parents 547f021 + ad9fd1e commit 6d78641
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 490 deletions.
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 = "[email protected]" }]
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
29 changes: 12 additions & 17 deletions tests/integration/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@
BOA_CACHE = False


@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="session")
@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 @@ -31,22 +31,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 @@ -67,12 +67,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 @@ -95,12 +95,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 @@ -120,12 +120,7 @@ def rewards_handler(vault, minimum_weight):
return rh


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


@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
21 changes: 13 additions & 8 deletions tests/integration/curve_pools/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,27 @@
import pytest


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


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


@pytest.fixture()
def crvusd_init_balance():
return 1_000 * 10**18


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


@pytest.fixture(scope="module")
@pytest.fixture()
def paired_tokens(request):
# This fixture is used to get upstream parametrization and populate the contracts
# Retrieve paired token combination [token1, token2] via request.param
Expand All @@ -30,7 +35,7 @@ def paired_tokens(request):
return tokens_list


@pytest.fixture(scope="module")
@pytest.fixture()
def pool_tokens(paired_tokens, vault):
# in any pool first is scrvusd, then one or two other tokens
return [
Expand All @@ -45,7 +50,7 @@ def pool_tokens(paired_tokens, vault):
]


@pytest.fixture(scope="function")
@pytest.fixture()
def stableswap_pool(stableswap_factory, vault, dev_address, pool_tokens):
# Retrieve token addresses and asset types from request.param
coins = [token["address"] for token in pool_tokens]
Expand Down Expand Up @@ -108,9 +113,9 @@ def stableswap_pool(stableswap_factory, vault, dev_address, pool_tokens):
return pool


@pytest.fixture(scope="function")
@pytest.fixture()
def twocrypto_pool(vault, pair_cryptocoin): ...


@pytest.fixture(scope="function")
@pytest.fixture()
def tricrypto_pool(vault): ...
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
Loading

0 comments on commit 6d78641

Please sign in to comment.