Skip to content

Commit

Permalink
testfiles cleanup, remove some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
heswithme committed Sep 27, 2024
1 parent 3b9261b commit df7c91e
Show file tree
Hide file tree
Showing 12 changed files with 80 additions and 161 deletions.
14 changes: 5 additions & 9 deletions contracts/mocks/ERC20Rebasing.vy
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,9 @@ def transfer(_to: address, _value: uint256) -> bool:

@external
def transferFrom(_from: address, _to: address, _value: uint256) -> bool:
self._rebase()
_shares: uint256 = self._get_shares_by_coins(_value)
_shares = min(self.shares[_from], _shares)

if _shares > 0:
# only rebase on nonzero transfers
self._rebase()

# Value can be less than expected even if self.shares[_from] > _shares
_new_value: uint256 = self._get_coins_by_shares(_shares)

Expand All @@ -103,20 +99,20 @@ def approve(_spender: address, _value: uint256) -> bool:
@view
def _share_price() -> uint256:
if self.totalShares == 0:
return 10**self.decimals
return self.totalCoin * 10**self.decimals / self.totalShares
return 10 ** self.decimals
return self.totalCoin * 10 ** self.decimals / self.totalShares


@internal
@view
def _get_coins_by_shares(_shares: uint256) -> uint256:
return _shares * self._share_price() / 10**self.decimals
return _shares * self._share_price() / 10 ** self.decimals


@internal
@view
def _get_shares_by_coins(_coins: uint256) -> uint256:
return _coins * 10**self.decimals / self._share_price()
return _coins * 10 ** self.decimals / self._share_price()


@external
Expand Down
133 changes: 66 additions & 67 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ package-mode = false

[tool.poetry.dependencies]
python = "^3.10"
poetry = "1.8.3"
poetry = "^1.8.0"
vyper = "0.3.10"
pycryptodome = "^3.18.0"
pre-commit = "^3.3.3"
titanoboa-zksync = {git = "https://github.com/DanielSchiavini/titanoboa-zksync.git", tag = "v0.1.2"} # inherits titanoboa 0.1.10

[tool.poetry.group.dev.dependencies]
black = "22.3.0"
flake8 = "4.0.1"
isort = "5.12.0"
mamushi = "^0.0.2a1"
black = "^24.0.0"
flake8 = "^7.0.0"
isort = "^5.0.0"
mamushi = "^0.0.4a3"


[tool.poetry.group.testing.dependencies]
Expand Down
18 changes: 2 additions & 16 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,6 @@


def pytest_generate_tests(metafunc):
# some targeted debug
# if metafunc.function.__name__ == "test_price_ema_remove_imbalance":
# print("Debugging...")
# metafunc.parametrize("pool_type", [0])
# metafunc.parametrize("pool_token_types", [(0, 0)])
# # metafunc.parametrize("sending,receiving", [(0, 1)])
# metafunc.parametrize("metapool_token_type", [None])
# metafunc.parametrize("initial_decimals", [(18, 18)])
# return
# Combined parametrization of pool_type and metapool_token_type (to avoid repeating tests in basic_pools
# for various metapool_token_types)

if ALL_TOKEN_PAIRS and not EXTENSIVE_TOKEN_PAIRS:
metafunc.definition.add_marker(pytest.mark.all_token_pairs)
if EXTENSIVE_TOKEN_PAIRS:
Expand Down Expand Up @@ -92,17 +80,15 @@ def get_pool_token_pairs(metafunc):
items = get_tokens_for_metafunc(metafunc)
# make all combinations possible
all_combinations = list(combinations_with_replacement(items, 2)) # 6 combinations (1,0 == 0,1)
all_all_combinations = list(product(items, items)) # 9 combinations (1,0 != 0,1)
extensive_combinations = list(product(items, items)) # 9 combinations (1,0 != 0,1)
if len(all_combinations) < 2 or metafunc.definition.get_closest_marker("all_token_pairs"):
return all_combinations
if metafunc.definition.get_closest_marker("extensive_token_pairs"):
return all_all_combinations
return extensive_combinations
# make sure we get the same result in each worker
random = Random(len(metafunc.fixturenames))
# take 2 combinations for smaller test set
return sorted(random.sample(all_combinations, k=2))
# Q: why sample only 2 when we have 6? and even 9?
# todo - ideally we test all possible combinations
# dev: added all_ and extensive_token_pairs marker to test all combinations


Expand Down
Loading

0 comments on commit df7c91e

Please sign in to comment.