@@ -19,6 +19,162 @@ describe("TokenGrant", () => {
1919 await token . deployed ( )
2020 } )
2121
22+ describe ( "initialize" , ( ) => {
23+ const revocable = true
24+ const amount = to1e18 ( 120000 ) // 120k tokens
25+ const duration = 15552000 // 180 days
26+ let start
27+ let cliff
28+ const stakingPolicy = ZERO_ADDRESS
29+
30+ let tokenGrant
31+
32+ beforeEach ( async ( ) => {
33+ now = await lastBlockTime ( )
34+ start = now
35+ cliff = now
36+
37+ const TokenGrant = await ethers . getContractFactory ( "TokenGrant" )
38+ tokenGrant = await TokenGrant . deploy ( )
39+ tokenGrant . deployed ( )
40+ } )
41+
42+ context ( "when token is zero address" , ( ) => {
43+ it ( "should revert" , async ( ) => {
44+ await expect (
45+ tokenGrant . initialize (
46+ ZERO_ADDRESS ,
47+ grantee . address ,
48+ revocable ,
49+ amount ,
50+ duration ,
51+ start ,
52+ cliff ,
53+ stakingPolicy
54+ )
55+ ) . to . be . revertedWith ( "Token must not be 0x0" )
56+ } )
57+ } )
58+
59+ context ( "when grantee is zero address" , ( ) => {
60+ it ( "should revert" , async ( ) => {
61+ await expect (
62+ tokenGrant . initialize (
63+ token . address ,
64+ ZERO_ADDRESS ,
65+ revocable ,
66+ amount ,
67+ duration ,
68+ start ,
69+ cliff ,
70+ stakingPolicy
71+ )
72+ ) . to . be . revertedWith ( "Grantee must not be 0x0" )
73+ } )
74+ } )
75+
76+ context ( "when amount is 0" , ( ) => {
77+ it ( "should revert" , async ( ) => {
78+ await expect (
79+ tokenGrant . initialize (
80+ token . address ,
81+ grantee . address ,
82+ revocable ,
83+ 0 ,
84+ duration ,
85+ start ,
86+ cliff ,
87+ stakingPolicy
88+ )
89+ ) . to . be . revertedWith ( "Amount must not be 0" )
90+ } )
91+ } )
92+
93+ context ( "when duration is 0" , ( ) => {
94+ it ( "should revert" , async ( ) => {
95+ await expect (
96+ tokenGrant . initialize (
97+ token . address ,
98+ grantee . address ,
99+ revocable ,
100+ amount ,
101+ 0 ,
102+ start ,
103+ cliff ,
104+ stakingPolicy
105+ )
106+ ) . to . be . revertedWith ( "Duration must not be 0" )
107+ } )
108+ } )
109+
110+ context ( "when start is 0" , ( ) => {
111+ it ( "should revert" , async ( ) => {
112+ await expect (
113+ tokenGrant . initialize (
114+ token . address ,
115+ grantee . address ,
116+ revocable ,
117+ amount ,
118+ duration ,
119+ 0 ,
120+ cliff ,
121+ stakingPolicy
122+ )
123+ ) . to . be . revertedWith ( "Start timestamp must not be 0" )
124+ } )
125+ } )
126+
127+ context ( "when cliff is 0" , ( ) => {
128+ it ( "should revert" , async ( ) => {
129+ await expect (
130+ tokenGrant . initialize (
131+ token . address ,
132+ grantee . address ,
133+ revocable ,
134+ amount ,
135+ duration ,
136+ start ,
137+ 0 ,
138+ stakingPolicy
139+ )
140+ ) . to . be . revertedWith ( "Cliff timestamp must not be 0" )
141+ } )
142+ } )
143+
144+ context ( "when all parameters are valid" , ( ) => {
145+ const amount = to1e18 ( 41211 )
146+
147+ beforeEach ( async ( ) => {
148+ await token . connect ( deployer ) . mint ( deployer . address , amount )
149+ await token . connect ( deployer ) . approve ( tokenGrant . address , amount )
150+
151+ await tokenGrant . initialize (
152+ token . address ,
153+ grantee . address ,
154+ revocable ,
155+ amount ,
156+ duration ,
157+ start ,
158+ cliff ,
159+ ZERO_ADDRESS
160+ )
161+ } )
162+
163+ it ( "should transfer tokens to the grant" , async ( ) => {
164+ expect ( await token . balanceOf ( tokenGrant . address ) ) . to . equal ( amount )
165+ } )
166+
167+ it ( "should initialize all fields" , async ( ) => {
168+ expect ( await tokenGrant . token ( ) ) . to . equal ( token . address )
169+ expect ( await tokenGrant . revocable ( ) ) . to . equal ( revocable )
170+ expect ( await tokenGrant . amount ( ) ) . to . equal ( amount )
171+ expect ( await tokenGrant . duration ( ) ) . to . equal ( duration )
172+ expect ( await tokenGrant . start ( ) ) . to . equal ( start )
173+ expect ( await tokenGrant . cliff ( ) ) . to . equal ( cliff )
174+ } )
175+ } )
176+ } )
177+
22178 describe ( "unlockedAmount" , ( ) => {
23179 const assertionPrecision = to1e18 ( 1 ) // +- 1 token
24180
0 commit comments