-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feat/tests' of github.com:curvefi/twocrypto-ng into fea…
…t/tests
- Loading branch information
Showing
6 changed files
with
125 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from boa.test import strategy | ||
from hypothesis import given, settings | ||
|
||
|
||
@given(val=strategy("uint256[3]", max_value=10**18)) | ||
@settings(max_examples=10000, deadline=None) | ||
def test_pack_unpack_three_integers(swap, twocrypto_factory, val): | ||
|
||
for contract in [swap, twocrypto_factory]: | ||
packed = contract.internal._pack_3(val) | ||
unpacked = swap.internal._unpack_3(packed) # swap unpacks | ||
for i in range(3): | ||
assert unpacked[i] == val[i] | ||
|
||
|
||
@given(val=strategy("uint256[2]", max_value=2**128 - 1)) | ||
@settings(max_examples=10000, deadline=None) | ||
def test_pack_unpack_2_integers(swap, val): | ||
|
||
packed = swap.internal._pack_2(val[0], val[1]) | ||
unpacked = swap.internal._unpack_2(packed) # swap unpacks | ||
for i in range(2): | ||
assert unpacked[i] == val[i] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import boa | ||
|
||
from tests.fixtures.pool import INITIAL_PRICES | ||
from tests.utils.tokens import mint_for_testing | ||
|
||
|
||
def test_admin_fee_after_deposit(swap, coins, fee_receiver, user, user_b): | ||
quantities = [10**42 // p for p in INITIAL_PRICES] | ||
|
||
for coin, q in zip(coins, quantities): | ||
for u in [user, user_b]: | ||
mint_for_testing(coin, u, q) | ||
with boa.env.prank(u): | ||
coin.approve(swap, 2**256 - 1) | ||
|
||
split_quantities = [quantities[0] // 100, quantities[1] // 100] | ||
|
||
with boa.env.prank(user): | ||
swap.add_liquidity(split_quantities, 0) | ||
|
||
with boa.env.prank(user_b): | ||
for _ in range(100): | ||
before = coins[1].balanceOf(user_b) | ||
swap.exchange(0, 1, split_quantities[0] // 100, 0) | ||
after = coins[1].balanceOf(user_b) | ||
to_swap = after - before | ||
swap.exchange(1, 0, to_swap, 0) | ||
|
||
balances = [swap.balances(i) for i in range(2)] | ||
print("Balance of the pool: " + str(balances[0]) + ", " + str(balances[1])) | ||
|
||
ratio = 0.0001 | ||
split_quantities = [int(balances[0] * ratio), int(balances[1] * ratio)] | ||
with boa.env.prank(user): | ||
swap.add_liquidity(split_quantities, 0) | ||
|
||
print("FEES 0: " + str(coins[0].balanceOf(fee_receiver))) | ||
print("FEES 1: " + str(coins[1].balanceOf(fee_receiver))) | ||
|
||
return swap |