From 06aa427c5fb1e0f2ad7161fc17ec3ec68259d91e Mon Sep 17 00:00:00 2001 From: Daniel Schiavini Date: Mon, 15 Jan 2024 16:20:41 +0100 Subject: [PATCH] Module for contract loading --- tests/conftest.py | 1 + tests/fixtures/constants.py | 4 +- tests/fixtures/contracts.py | 77 +++++++++++++++++++ tests/fixtures/factory.py | 30 -------- tests/fixtures/mocks.py | 8 +- tests/fixtures/pools.py | 5 -- tests/fixtures/tokens.py | 58 ++++++-------- tests/pools/meta/test_meta_new_ng_base.py | 18 ++--- tests/pools/meta/test_meta_zap.py | 10 +-- tests/pools/test_erc4626_swaps.py | 22 +----- .../test_specific_liquidity_operations.py | 12 +-- 11 files changed, 126 insertions(+), 119 deletions(-) create mode 100644 tests/fixtures/contracts.py diff --git a/tests/conftest.py b/tests/conftest.py index 69301639..0323a59d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -9,6 +9,7 @@ pytest_plugins = [ "tests.fixtures.accounts", "tests.fixtures.constants", + "tests.fixtures.contracts", "tests.fixtures.factory", "tests.fixtures.mocks", "tests.fixtures.pools", diff --git a/tests/fixtures/constants.py b/tests/fixtures/constants.py index 720eb36b..66ff1091 100644 --- a/tests/fixtures/constants.py +++ b/tests/fixtures/constants.py @@ -3,7 +3,7 @@ INITIAL_AMOUNT = 3_000_000 -@pytest.fixture(scope="module") +@pytest.fixture(scope="session") def initial_balance() -> int: return INITIAL_AMOUNT * 10**18 @@ -43,6 +43,6 @@ def deposit_amounts( return amounts -@pytest.fixture(scope="module") +@pytest.fixture(scope="session") def zero_address() -> str: return "0x0000000000000000000000000000000000000000" diff --git a/tests/fixtures/contracts.py b/tests/fixtures/contracts.py new file mode 100644 index 00000000..666c35e8 --- /dev/null +++ b/tests/fixtures/contracts.py @@ -0,0 +1,77 @@ +import boa +import pytest + + +@pytest.fixture(scope="session") +def base_pool_deployer(): + return boa.load_partial("contracts/mocks/CurvePool.vy") + + +@pytest.fixture(scope="session") +def erc20_deployer(): + return boa.load_partial("contracts/mocks/ERC20.vy") + + +@pytest.fixture(scope="session") +def erc20_rebasing_deployer(): + return boa.load_partial("contracts/mocks/ERC20Rebasing.vy") + + +@pytest.fixture(scope="session") +def erc4626_deployer(): + return boa.load_partial("contracts/mocks/ERC4626.vy") + + +@pytest.fixture(scope="session") +def erc20oracle_deployer(): + return boa.load_partial("contracts/mocks/ERC20Oracle.vy") + + +@pytest.fixture(scope="session") +def erc20rebasing_conditional_deployer(): + return boa.load_partial("contracts/mocks/ERC20RebasingConditional.vy") + + +@pytest.fixture(scope="session") +def curve_token_v3_deployer(): + return boa.load_partial("contracts/mocks/CurveTokenV3.vy") + + +@pytest.fixture(scope="session") +def zap_deployer(): + return boa.load_partial("contracts/mocks/Zap.vy") + + +@pytest.fixture(scope="session") +def gauge_deployer(): + return boa.load_partial("contracts/main/LiquidityGauge.vy") + + +@pytest.fixture(scope="session") +def amm_deployer(): + return boa.load_partial("contracts/main/CurveStableSwapNG.vy") + + +@pytest.fixture(scope="session") +def meta_deployer(): + return boa.load_partial("contracts/main/CurveStableSwapMetaNG.vy") + + +@pytest.fixture(scope="session") +def factory_deployer(): + return boa.load_partial("contracts/main/CurveStableSwapFactoryNG.vy") + + +@pytest.fixture(scope="session") +def views_deployer(): + return boa.load_partial("contracts/main/CurveStableSwapNGViews.vy") + + +@pytest.fixture(scope="session") +def math_deployer(): + return boa.load_partial("contracts/main/CurveStableSwapNGMath.vy") + + +@pytest.fixture(scope="session") +def callback_swap_deployer(): + return boa.load_partial("contracts/mocks/CallbackSwap.vy") diff --git a/tests/fixtures/factory.py b/tests/fixtures/factory.py index 62e19423..72d47672 100644 --- a/tests/fixtures/factory.py +++ b/tests/fixtures/factory.py @@ -2,36 +2,6 @@ import pytest -@pytest.fixture(scope="session") -def gauge_deployer(): - return boa.load_partial("contracts/main/LiquidityGauge.vy") - - -@pytest.fixture(scope="session") -def amm_deployer(): - return boa.load_partial("contracts/main/CurveStableSwapNG.vy") - - -@pytest.fixture(scope="session") -def meta_deployer(): - return boa.load_partial("contracts/main/CurveStableSwapMetaNG.vy") - - -@pytest.fixture(scope="session") -def factory_deployer(): - return boa.load_partial("contracts/main/CurveStableSwapFactoryNG.vy") - - -@pytest.fixture(scope="session") -def views_deployer(): - return boa.load_partial("contracts/main/CurveStableSwapNGViews.vy") - - -@pytest.fixture(scope="session") -def math_deployer(): - return boa.load_partial("contracts/main/CurveStableSwapNGMath.vy") - - @pytest.fixture() def gauge_implementation(deployer, gauge_deployer): with boa.env.prank(deployer): diff --git a/tests/fixtures/mocks.py b/tests/fixtures/mocks.py index 325df5b2..723c7765 100644 --- a/tests/fixtures/mocks.py +++ b/tests/fixtures/mocks.py @@ -3,10 +3,10 @@ @pytest.fixture(scope="module") -def callback_contract(bob, swap, pool_tokens, underlying_tokens): +def callback_contract(bob, swap, pool_tokens, underlying_tokens, callback_swap_deployer): with boa.env.prank(bob): - _callback = boa.load("contracts/mocks/CallbackSwap.vy", swap.address, bob) + callback = callback_swap_deployer.deploy(swap.address, bob) for token in pool_tokens + underlying_tokens: - token.approve(_callback.address, 2**256 - 1) + token.approve(callback.address, 2**256 - 1) - return _callback + return callback diff --git a/tests/fixtures/pools.py b/tests/fixtures/pools.py index 6b0ae89f..3dce40c2 100644 --- a/tests/fixtures/pools.py +++ b/tests/fixtures/pools.py @@ -98,11 +98,6 @@ def swap(basic_swap, meta_swap, pool_type): # <--------------------- Metapool configuration ---------------------> -@pytest.fixture(scope="session") -def base_pool_deployer(): - return boa.load_partial("contracts/mocks/CurvePool.vy") - - @pytest.fixture() def base_pool(deployer, owner, alice, base_pool_tokens, base_pool_lp_token, base_pool_deployer): with boa.env.prank(deployer): diff --git a/tests/fixtures/tokens.py b/tests/fixtures/tokens.py index b5754176..d6cc8f1e 100644 --- a/tests/fixtures/tokens.py +++ b/tests/fixtures/tokens.py @@ -3,30 +3,27 @@ @pytest.fixture() -def plain_tokens(deployer, decimals): - tokens = [] +def plain_tokens(erc20_deployer, deployer, decimals): with boa.env.prank(deployer): - for i, d in enumerate(decimals): - tokens.append(boa.load("contracts/mocks/ERC20.vy", f"TKN{i}", f"TKN{i}", decimals[i])) - return tokens + return [erc20_deployer.deploy(f"TKN{i}", f"TKN{i}", decimals[i]) for i, d in enumerate(decimals)] @pytest.fixture() -def oracle_tokens(deployer, decimals): - tokens = [] +def oracle_tokens(erc20oracle_deployer, deployer, decimals): with boa.env.prank(deployer): - tokens.append(boa.load("contracts/mocks/ERC20Oracle.vy", "OTA", "OTA", 18, 1006470359024000000)) - tokens.append(boa.load("contracts/mocks/ERC20Oracle.vy", "OTB", "OTB", 18, 1007580460035000000)) - return tokens + return [ + erc20oracle_deployer.deploy("OTA", "OTA", 18, 1006470359024000000), + erc20oracle_deployer.deploy("OTB", "OTB", 18, 1007580460035000000), + ] @pytest.fixture() -def rebase_tokens(deployer, decimals): - tokens = [] +def rebase_tokens(erc20_rebasing_deployer, deployer, decimals): with boa.env.prank(deployer): - for i, d in enumerate(decimals): - tokens.append(boa.load("contracts/mocks/ERC20Rebasing.vy", f"OR_TKN{i}", f"OR_TKN{i}", decimals[i], True)) - return tokens + return [ + erc20_rebasing_deployer.deploy(f"OR_TKN{i}", f"OR_TKN{i}", decimals[i], True) + for i, d in enumerate(decimals) + ] @pytest.fixture() @@ -47,18 +44,15 @@ def base_pool_decimals(): @pytest.fixture() -def base_pool_tokens(deployer, base_pool_decimals): +def base_pool_tokens(erc20_deployer, deployer, base_pool_decimals): with boa.env.prank(deployer): - return [ - boa.load("contracts/mocks/ERC20.vy", c, c, base_pool_decimals[i]) - for i, c in enumerate(("DAI", "USDC", "USDT")) - ] + return [erc20_deployer.deploy(c, c, base_pool_decimals[i]) for i, c in enumerate(("DAI", "USDC", "USDT"))] @pytest.fixture() -def base_pool_lp_token(deployer): +def base_pool_lp_token(deployer, curve_token_v3_deployer): with boa.env.prank(deployer): - return boa.load("contracts/mocks/CurveTokenV3.vy", "LP", "LP") + return curve_token_v3_deployer.deploy("LP", "LP") @pytest.fixture() @@ -68,28 +62,24 @@ def underlying_tokens(metapool_token, base_pool_tokens, base_pool_lp_token): # <--------------------- Gauge rewards ---------------------> @pytest.fixture() -def coin_reward(owner): +def coin_reward(owner, erc20_deployer): with boa.env.prank(owner): - return boa.load("contracts/mocks/ERC20.vy", "CR", "CR", 18) + return erc20_deployer.deploy("CR", "CR", 18) @pytest.fixture() -def coin_reward_a(owner, mint_owner): +def coin_reward_a(owner, mint_owner, erc20_deployer): with boa.env.prank(owner): - return boa.load("contracts/mocks/ERC20.vy", "CRa", "CRa", 18) + return erc20_deployer.deploy("CRa", "CRa", 18) @pytest.fixture() -def coin_reward_b(owner): +def coin_reward_b(owner, erc20_deployer): with boa.env.prank(owner): - return boa.load("contracts/mocks/ERC20.vy", "CRb", "CRb", 18) + return erc20_deployer.deploy("CRb", "CRb", 18) @pytest.fixture() -def coin_rewards_additional(owner): - coins = [] +def coin_rewards_additional(owner, erc20_deployer): with boa.env.prank(owner): - for i in range(8): - coins.append(boa.load("contracts/mocks/ERC20.vy", f"CR{i}", f"CR{i}", 18)) - - return coins + return [erc20_deployer.deploy(f"CR{i}", f"CR{i}", 18) for i in range(8)] diff --git a/tests/pools/meta/test_meta_new_ng_base.py b/tests/pools/meta/test_meta_new_ng_base.py index c4b254c2..242cbb46 100644 --- a/tests/pools/meta/test_meta_new_ng_base.py +++ b/tests/pools/meta/test_meta_new_ng_base.py @@ -13,21 +13,17 @@ def ng_base_pool_decimals(): return [18] * BASE_N_COINS -@pytest.fixture(scope="module") -def ng_base_pool_tokens(ng_base_pool_decimals): - tokens = [] - for i in range(BASE_N_COINS): - tokens.append(boa.load("contracts/mocks/ERC20.vy", f"tkn{i}", f"tkn{i}", ng_base_pool_decimals[i])) - - return tokens +@pytest.fixture() +def ng_base_pool_tokens(ng_base_pool_decimals, erc20_deployer): + return [erc20_deployer.deploy(f"tkn{i}", f"tkn{i}", ng_base_pool_decimals[i]) for i in range(BASE_N_COINS)] -@pytest.fixture(scope="module") -def meta_token(): - return boa.load("contracts/mocks/ERC20.vy", "OTA", "OTA", 18) +@pytest.fixture() +def meta_token(erc20_deployer): + return erc20_deployer.deploy("OTA", "OTA", 18) -@pytest.fixture(scope="module") +@pytest.fixture() def ng_base_pool(deployer, factory, ng_base_pool_tokens, zero_address, amm_deployer, set_pool_implementations): pool_size = len(ng_base_pool_tokens) offpeg_fee_multiplier = 20000000000 diff --git a/tests/pools/meta/test_meta_zap.py b/tests/pools/meta/test_meta_zap.py index 2cffa6c4..4d72e194 100644 --- a/tests/pools/meta/test_meta_zap.py +++ b/tests/pools/meta/test_meta_zap.py @@ -9,9 +9,9 @@ @pytest.fixture(scope="module") -def meta_token(deployer): +def meta_token(deployer, erc20_deployer): with boa.env.prank(deployer): - return boa.load("contracts/mocks/ERC20.vy", "OTA", "OTA", 18) + return erc20_deployer.deploy("OTA", "OTA", 18) @pytest.fixture(scope="module") @@ -63,10 +63,8 @@ def empty_swap( @pytest.fixture(scope="module") -def zap(base_pool, base_pool_tokens, base_pool_lp_token): - return boa.load( - "contracts/mocks/Zap.vy", base_pool.address, base_pool_lp_token.address, [a.address for a in base_pool_tokens] - ) +def zap(base_pool, base_pool_tokens, base_pool_lp_token, zap_deployer): + return zap_deployer.deploy(base_pool.address, base_pool_lp_token.address, [a.address for a in base_pool_tokens]) @pytest.fixture(scope="module") diff --git a/tests/pools/test_erc4626_swaps.py b/tests/pools/test_erc4626_swaps.py index f686e4b8..08118590 100644 --- a/tests/pools/test_erc4626_swaps.py +++ b/tests/pools/test_erc4626_swaps.py @@ -37,32 +37,12 @@ def mint_tokens(charlie, pool_erc20_tokens, pool_tokens, swap, i): return amount_in -@pytest.fixture(scope="module") -def erc20_deployer(): - return boa.load_partial("contracts/mocks/ERC20.vy") - - @pytest.fixture() def asset(deployer, erc20_deployer): with boa.env.prank(deployer): return erc20_deployer.deploy("Asset", "AST", 8) # 8 decimals -@pytest.fixture(scope="module") -def erc4626_deployer(): - return boa.load_partial("contracts/mocks/ERC4626.vy") - - -@pytest.fixture(scope="module") -def erc20oracle_deployer(): - return boa.load_partial("contracts/mocks/ERC20Oracle.vy") - - -@pytest.fixture(scope="module") -def erc20rebasing_conditional_deployer(): - return boa.load_partial("contracts/mocks/ERC20RebasingConditional.vy") - - @pytest.fixture() def token_a(deployer, asset, erc4626_deployer): with boa.env.prank(deployer): @@ -91,7 +71,7 @@ def pool_erc20_tokens(asset, token_b, token_c): return [asset, token_b, token_c] -@pytest.fixture(scope="module") +@pytest.fixture(scope="session") def asset_types(pool_tokens): _asset_types = [] for token in pool_tokens: diff --git a/tests/pools/test_specific_liquidity_operations.py b/tests/pools/test_specific_liquidity_operations.py index fb127c58..6855d139 100644 --- a/tests/pools/test_specific_liquidity_operations.py +++ b/tests/pools/test_specific_liquidity_operations.py @@ -6,21 +6,21 @@ @pytest.fixture(scope="module") -def token_a(deployer): +def token_a(deployer, erc20oracle_deployer): with boa.env.prank(deployer): - return boa.load("contracts/mocks/ERC20Oracle.vy", "OTA", "OTA", 18, 1006470359024000000) + return erc20oracle_deployer.deploy("OTA", "OTA", 18, 1006470359024000000) @pytest.fixture(scope="module") -def token_b(deployer): +def token_b(deployer, erc20oracle_deployer): with boa.env.prank(deployer): - return boa.load("contracts/mocks/ERC20Oracle.vy", "OTB", "OTB", 18, 1000000000000000000) + return erc20oracle_deployer.deploy("OTB", "OTB", 18, 1000000000000000000) @pytest.fixture(scope="module") -def token_c(deployer): +def token_c(deployer, erc20_deployer): with boa.env.prank(deployer): - return boa.load("contracts/mocks/ERC20.vy", "OTC", "OTC", 18) + return erc20_deployer.deploy("OTC", "OTC", 18) @pytest.fixture(scope="module")