Skip to content

Commit

Permalink
Module for contract loading
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Jan 15, 2024
1 parent 33e4ba9 commit 06aa427
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 119 deletions.
1 change: 1 addition & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
pytest_plugins = [
"tests.fixtures.accounts",
"tests.fixtures.constants",
"tests.fixtures.contracts",
"tests.fixtures.factory",
"tests.fixtures.mocks",
"tests.fixtures.pools",
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -43,6 +43,6 @@ def deposit_amounts(
return amounts


@pytest.fixture(scope="module")
@pytest.fixture(scope="session")
def zero_address() -> str:
return "0x0000000000000000000000000000000000000000"
77 changes: 77 additions & 0 deletions tests/fixtures/contracts.py
Original file line number Diff line number Diff line change
@@ -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")
30 changes: 0 additions & 30 deletions tests/fixtures/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions tests/fixtures/mocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 0 additions & 5 deletions tests/fixtures/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
58 changes: 24 additions & 34 deletions tests/fixtures/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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)]
18 changes: 7 additions & 11 deletions tests/pools/meta/test_meta_new_ng_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 4 additions & 6 deletions tests/pools/meta/test_meta_zap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
22 changes: 1 addition & 21 deletions tests/pools/test_erc4626_swaps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
12 changes: 6 additions & 6 deletions tests/pools/test_specific_liquidity_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 06aa427

Please sign in to comment.