forked from R1372/curve-stablecoin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconftest.py
72 lines (52 loc) · 1.81 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
from datetime import timedelta
from math import log
from typing import Any, Callable, List
import boa
import pytest
from boa.environment import AddressT
from hypothesis import settings
boa.interpret.set_cache_dir()
boa.reset_env()
PRICE = 3000
settings.register_profile("default", deadline=timedelta(seconds=1000))
settings.load_profile(os.getenv(u"HYPOTHESIS_PROFILE", "default"))
def approx(x1: int, x2: int, precision: int, abs_precision=None):
if precision >= 1:
return True
result = False
if abs_precision is not None:
result = abs(x2 - x1) <= abs_precision
else:
abs_precision = 0
if x2 == 0:
return abs(x1) <= abs_precision
elif x1 == 0:
return abs(x2) <= abs_precision
return result or (abs(log(x1 / x2)) <= precision)
@pytest.fixture(scope="session")
def accounts() -> List[AddressT]:
return [boa.env.generate_address() for _ in range(10)]
@pytest.fixture(scope="session")
def admin() -> AddressT:
return boa.env.generate_address()
@pytest.fixture(scope="session")
def get_collateral_token(admin) -> Callable[[int], Any]:
def f(digits):
with boa.env.prank(admin):
return boa.load('contracts/testing/ERC20Mock.vy', "Colalteral", "ETH", digits)
return f
@pytest.fixture(scope="session")
def get_borrowed_token(admin) -> Callable[[int], Any]:
def f(digits):
with boa.env.prank(admin):
return boa.load('contracts/testing/ERC20Mock.vy', "Rugworks USD", "rUSD", digits)
return f
@pytest.fixture(scope="module")
def collateral_token(get_collateral_token):
return get_collateral_token(18)
@pytest.fixture(scope="module")
def price_oracle(admin):
with boa.env.prank(admin):
oracle = boa.load('contracts/testing/DummyPriceOracle.vy', admin, PRICE * 10**18)
return oracle