Skip to content

Commit

Permalink
Remove command line arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSchiavini committed Jan 11, 2024
1 parent 5b62ba3 commit c91d58f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 128 deletions.
10 changes: 1 addition & 9 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ For a full list of deployments, please check: [The deployment script](scripts/de
The metapool factory has several core components:

- [`Factory`](contracts/main/CurveStableSwapFactoryNG.vy) is the main contract used to deploy new metapools. It also acts a registry for finding the deployed pools and querying information about them.
- New pools are deployed via blueprints. The [implementation contract](contracts/main/CurveStableSwapNG.vy) targetted by the proxy is determined according to the base pool.
- New pools are deployed via blueprints. The [implementation contract](contracts/main/CurveStableSwapNG.vy) targeted by the proxy is determined according to the base pool.

See the [documentation](https://docs.curve.fi) for more detailed information.

Expand All @@ -28,14 +28,6 @@ pip install poetry==1.5.1
poetry install
```

### Paramaters

- `--pool-size` - size of pool (N_COINS), available parameters: `[2]`
- `--pool-type` - type of pool, available parameters: `[basic,meta]`
- `--token-types` - token types to test against(divided by comma), available parameters: `[plain,eth,oracle,rebasing]`
- `--decimals` - token decimals (divided by comma), default `18,18`
- `--return-types` - types of .transfer() returns to test against (divided by comma), default `revert,False,None`

### Type of tests

Testing gauge
Expand Down
121 changes: 29 additions & 92 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,148 +18,85 @@
pool_types = {"basic": 0, "meta": 1}
token_types = {"plain": 0, "oracle": 1, "rebasing": 2}
return_types = {"revert": 0, "False": 1, "None": 2}


def pytest_addoption(parser):
parser.addoption(
"--pool-size",
action="store",
default="2",
help="pool size to test against",
)
parser.addoption(
"--pool-types",
action="store",
default="basic,meta",
help="pool type to test against",
)
parser.addoption(
"--token-types",
action="store",
default="plain,oracle,rebasing",
help="comma-separated list of ERC20 token types to test against",
)
parser.addoption(
"--decimals",
action="store",
default="18,18",
help="comma-separated list of ERC20 token precisions to test against",
)
parser.addoption(
"--return-type",
action="store",
default="revert,False,None",
help="comma-separated list of ERC20 token return types to test against",
)
decimal_types = [(18, 18), (10, 12)]


def pytest_generate_tests(metafunc):
pool_size = int(metafunc.config.getoption("pool_size"))

if "pool_size" in metafunc.fixturenames:
metafunc.parametrize(
"pool_size",
[pool_size],
indirect=True,
ids=[f"(PoolSize={pool_size})"],
)

if "pool_type" in metafunc.fixturenames:
cli_options = metafunc.config.getoption("pool_types").split(",")
pool_type_items = sorted(pool_types.items())
metafunc.parametrize(
"pool_type",
[pool_types[pool_type] for pool_type in cli_options],
indirect=True,
ids=[f"(PoolType={pool_type})" for pool_type in cli_options],
[v for k, v in pool_type_items],
ids=[f"(PoolType={k})" for k, v in pool_type_items],
indirect=True, # to declare the fixture scope
)

if "pool_token_types" in metafunc.fixturenames:
cli_options = metafunc.config.getoption("token_types").split(",")
if "eth" in cli_options:
cli_options.remove("eth")
cli_options = ["eth"] + cli_options

combinations = list(itertools.combinations_with_replacement(cli_options, pool_size))

combinations = sorted(itertools.combinations_with_replacement(token_types.items(), 2))
metafunc.parametrize(
"pool_token_types",
[[token_types[idx] for idx in c] for c in combinations],
indirect=True,
ids=[f"(PoolTokenTypes={c})" for c in combinations],
[(v1, v2) for (k1, v1), (k2, v2) in combinations],
ids=[f"(PoolTokenTypes={k1}+{k2})" for (k1, v1), (k2, v2) in combinations],
indirect=True, # to declare the fixture scope
)

if "metapool_token_type" in metafunc.fixturenames:
cli_options = metafunc.config.getoption("token_types").split(",")

# for meta pool only 1st coin is selected
token_type_items = sorted(token_types.items())
metafunc.parametrize(
"metapool_token_type",
[token_types[c] for c in cli_options],
indirect=True,
ids=[f"(MetaTokenType={c})" for c in cli_options],
[v for k, v in token_type_items],
ids=[f"(MetaTokenType={k})" for k, v in token_type_items],
indirect=True, # to declare the fixture scope
)

if "initial_decimals" in metafunc.fixturenames:
cli_options = metafunc.config.getoption("decimals")
metafunc.parametrize(
"initial_decimals",
[[int(i) for i in cli_options.split(",")]],
indirect=True,
ids=[f"(Decimals={cli_options})"],
)

if "return_type" in metafunc.fixturenames:
cli_options = metafunc.config.getoption("return_type").split(",")
return_type_ids = [return_types[v] for v in cli_options]

metafunc.parametrize(
"return_type",
return_type_ids,
indirect=True,
ids=[f"(ReturnType={i})" for i in cli_options],
decimal_types,
ids=[f"(Decimals={i},{j})" for i, j in decimal_types],
indirect=True, # to declare the fixture scope
)


@pytest.fixture(scope="session")
def pool_size(request):
return request.param
def pool_size():
return 2


@pytest.fixture(scope="session")
def pool_type(request):
def pool_type(request): # to declare the fixture scope
return request.param


@pytest.fixture(scope="session")
def pool_token_types(request):
def pool_token_types(request): # to declare the fixture scope
return request.param


@pytest.fixture(scope="session")
def metapool_token_type(request):
def metapool_token_type(request): # to declare the fixture scope
return request.param


@pytest.fixture(scope="session")
def return_type(request):
return request.param


@pytest.fixture(scope="session")
def initial_decimals(request):
def initial_decimals(request): # to declare the fixture scope
return request.param


@pytest.fixture(scope="session")
def decimals(initial_decimals, pool_token_types):
# oracle tokens are always 18 decimals
return [d if t != 1 else 18 for d, t in zip(initial_decimals, pool_token_types)]
return [
# oracle tokens are always 18 decimals
18 if token_type == 1 else decimals
for decimals, token_type in zip(initial_decimals, pool_token_types)
]


@pytest.fixture(scope="session")
def meta_decimals(initial_decimals, metapool_token_type, decimals):
def meta_decimals(metapool_token_type, decimals):
# oracle tokens are always 18 decimals
return decimals[0] if metapool_token_type != 1 else 18
return 18 if metapool_token_type == 1 else decimals[0]


# Usage
Expand Down
2 changes: 0 additions & 2 deletions tests/fixtures/pools.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ def swap(
factory,
pool_size,
pool_type,
pool_token_types,
metapool_token_type,
pool_tokens,
zero_address,
amm_interface,
Expand Down
32 changes: 7 additions & 25 deletions tests/fixtures/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,31 +47,14 @@ def rebase_tokens(deployer, decimals):

@pytest.fixture(scope="module")
def pool_tokens(pool_token_types, plain_tokens, oracle_tokens, rebase_tokens):
pool_tokens = []
for i, t in enumerate(pool_token_types):
if t == 0:
pool_tokens.append(plain_tokens[i])
elif t == 1:
pool_tokens.append(oracle_tokens[i])
elif t == 2:
pool_tokens.append(rebase_tokens[i])
else:
raise ValueError("Wrong pool token type")

return pool_tokens
tokens = {0: plain_tokens, 1: oracle_tokens, 2: rebase_tokens}
return [tokens[t][i] for i, t in enumerate(pool_token_types)]


# <--------------------- Metapool configuration --------------------->
@pytest.fixture(scope="module")
def metapool_token(metapool_token_type, plain_tokens, oracle_tokens, rebase_tokens):
if metapool_token_type == 0:
return plain_tokens[0]
elif metapool_token_type == 1:
return oracle_tokens[0]
elif metapool_token_type == 2:
return rebase_tokens[0]
else:
raise ValueError("Wrong pool token type")
return {0: plain_tokens, 1: oracle_tokens, 2: rebase_tokens}[metapool_token_type][0]


@pytest.fixture(scope="module")
Expand All @@ -81,12 +64,11 @@ def base_pool_decimals():

@pytest.fixture(scope="module")
def base_pool_tokens(deployer, base_pool_decimals):
tokens = []
with boa.env.prank(deployer):
tokens.append(boa.load("contracts/mocks/ERC20.vy", "DAI", "DAI", base_pool_decimals[0]))
tokens.append(boa.load("contracts/mocks/ERC20.vy", "USDC", "USDC", base_pool_decimals[1]))
tokens.append(boa.load("contracts/mocks/ERC20.vy", "USDT", "USDT", base_pool_decimals[2]))
return tokens
return [
boa.load("contracts/mocks/ERC20.vy", c, c, base_pool_decimals[i])
for i, c in enumerate(("DAI", "USDC", "USDT"))
]


@pytest.fixture(scope="module")
Expand Down

0 comments on commit c91d58f

Please sign in to comment.