forked from Giveth/coodcad
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hatch_test.py
98 lines (76 loc) · 3.74 KB
/
hatch_test.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from hatch import *
import unittest
import datetime
class HatchTest(unittest.TestCase):
def test_vesting_curve(self):
# At Day 90, the cliff has just ended and the vesting curve has begun at 0
self.assertEqual(vesting_curve(90, 90, 90), 0)
# At Day 180, the cliff has ended and we are in the vesting curve, whose half-life is 90 as well, so at 180 we should get 0.5.
self.assertEqual(vesting_curve(180, 90, 90), 0.5)
# At Day 270, 2 half lives of the vesting curve have passed - 0.75 of tokens should be unlocked.
self.assertEqual(vesting_curve(270, 90, 90), 0.75)
# At Day 270, 2 half lives of the vesting curve have passed - 0.75 of tokens should be unlocked.
self.assertLess(vesting_curve(89, 90, 90), 0)
def test_convert_80p_to_halflife(self):
self.assertEqual(convert_80p_to_cliff_and_halflife(
90), (41.64807836875666, 20.82403918437833))
class TokenBatchTest(unittest.TestCase):
def test_bool(self):
zero = TokenBatch(0)
something = TokenBatch(1)
self.assertTrue(bool(something))
self.assertFalse(bool(zero))
def test_add_(self):
two = TokenBatch(2)
three = TokenBatch(3)
self.assertEqual(two+three, 5)
def test_sub_(self):
five = TokenBatch(5)
four = TokenBatch(4)
self.assertEqual(five-four, 1)
def test_unlocked_fraction(self):
tbh = TokenBatch(10000, vesting_options=VestingOptions(3, 3))
tb = TokenBatch(10000)
self. assertEqual(tbh.unlocked_fraction(), 0)
tbh.current_date = datetime.datetime.today() + datetime.timedelta(days=3)
self.assertEqual(tbh.unlocked_fraction(), 0)
tbh.current_date = datetime.datetime.today() + datetime.timedelta(days=6)
self.assertEqual(tbh.unlocked_fraction(), 0.5)
self.assertEqual(tb.unlocked_fraction(), 1.0)
def test_spend(self):
tbh = TokenBatch(10000, vesting_options=VestingOptions(3, 3))
with self.assertRaises(Exception):
tbh.spend(100)
tb = TokenBatch(10000)
tb.spend(100)
self.assertEqual(tb.value, 9900)
self.assertEqual(tb.spent, 100)
tb.spend(1000)
self.assertEqual(tb.value, 8900)
self.assertEqual(tb.spent, 1100)
with self.assertRaises(Exception):
tb.spend(10000)
class CommonsTest(unittest.TestCase):
def setUp(self):
# 100,000 DAI invested for 1,000,000 tokens.
self.desired_token_price = 0.1
self.hatcher_contributions = [25000, 25000, 50000]
self.token_batches, self.token_supply_initial = contributions_to_token_batches(
self.hatcher_contributions, self.desired_token_price, 90)
# Because of hatch_tribute, the collateral_pool is 0.7e6. This causes the token's post-hatch price to be 0.14.
self.commons = Commons(
sum(self.hatcher_contributions), self.token_supply_initial, hatch_tribute=0.3)
def test_initialization(self):
self.assertEqual(self.commons._collateral_pool, 70000)
self.assertEqual(self.commons._funding_pool, 30000)
self.assertEqual(self.commons._token_supply, self.token_supply_initial)
self.assertEqual(self.commons.token_price(), 0.14)
def test_burn_without_exit_tribute(self):
old_token_supply = self.commons._token_supply
old_collateral_pool = self.commons._collateral_pool
money_returned, realized_price = self.commons.burn(50000)
self.assertEqual(money_returned, 6825.0)
self.assertEqual(realized_price, 0.1365)
self.assertEqual(self.commons._token_supply, old_token_supply-50000)
self.assertEqual(self.commons._collateral_pool,
old_collateral_pool-money_returned)