@@ -51,6 +51,9 @@ describe("DisintermediatedGrants", function () {
51
51
this . parties . forEach ( async ( party ) => {
52
52
await this . token . connect ( party ) . mint ( TEST_DONATION_AMOUNT )
53
53
} )
54
+ this . whitelistDonor = ( donor ) => whitelistDonor ( this . dg , donor )
55
+ this . setDonation = ( donation , id ) => setDonation ( this . dg , donation , id )
56
+ this . setGrant = ( grant , id ) => setGrant ( this . dg , grant , id )
54
57
this . defaultDonation = {
55
58
donor : this . alice . address ,
56
59
token : this . token . address ,
@@ -88,7 +91,7 @@ describe("DisintermediatedGrants", function () {
88
91
) . to . be . revertedWith ( "caller is not whitelisted donor" )
89
92
} )
90
93
it ( "fail if donation amount exceeds donor balance" , async function ( ) {
91
- await whitelistDonor ( this . dg , this . alice . address )
94
+ await this . whitelistDonor ( this . alice . address )
92
95
const donorBalance = await this . token . balanceOf ( this . alice . address )
93
96
const donationAmount = donorBalance . add ( 1 )
94
97
await this . token . connect ( this . alice ) . approve ( this . dg . address , donationAmount )
@@ -97,7 +100,7 @@ describe("DisintermediatedGrants", function () {
97
100
) . to . be . revertedWith ( "donation amount exceeds balance" )
98
101
} )
99
102
it ( "cannot be made with insufficient allowance" , async function ( ) {
100
- await whitelistDonor ( this . dg , this . alice . address )
103
+ await this . whitelistDonor ( this . alice . address )
101
104
const donorBalance = await this . token . balanceOf ( this . alice . address )
102
105
await this . token . connect ( this . alice ) . approve ( this . dg . address , donorBalance . sub ( 1 ) )
103
106
await expect (
@@ -106,7 +109,7 @@ describe("DisintermediatedGrants", function () {
106
109
} )
107
110
it ( "can be made by whitelisted donors" , async function ( ) {
108
111
const initialDonorBalance = await this . token . balanceOf ( this . alice . address )
109
- await whitelistDonor ( this . dg , this . alice . address )
112
+ await this . whitelistDonor ( this . alice . address )
110
113
await this . token . connect ( this . alice ) . approve ( this . dg . address , TEST_DONATION_AMOUNT )
111
114
const donationCount = await this . dg . donationCount ( )
112
115
const tx = await this . dg
@@ -124,14 +127,14 @@ describe("DisintermediatedGrants", function () {
124
127
expect ( await this . token . balanceOf ( this . alice . address ) ) . to . equal ( initialDonorBalance )
125
128
} )
126
129
it ( "fail if donation amount is zero" , async function ( ) {
127
- await whitelistDonor ( this . dg , this . alice . address )
130
+ await this . whitelistDonor ( this . alice . address )
128
131
const donationCount = await this . dg . donationCount ( )
129
132
await expect (
130
133
this . dg . connect ( this . alice ) . donate ( this . token . address , 0 , TEST_GRACE_PERIOD )
131
134
) . to . be . revertedWith ( "donation amount cannot be zero" )
132
135
} )
133
136
it ( "fail if grace period is too long" , async function ( ) {
134
- await whitelistDonor ( this . dg , this . alice . address )
137
+ await this . whitelistDonor ( this . alice . address )
135
138
const donationCount = await this . dg . donationCount ( )
136
139
await expect (
137
140
this . dg
@@ -142,10 +145,10 @@ describe("DisintermediatedGrants", function () {
142
145
} )
143
146
describe ( "donation withdrawal" , function ( ) {
144
147
before ( async function ( ) {
145
- await whitelistDonor ( this . dg , this . alice . address )
148
+ await this . whitelistDonor ( this . alice . address )
146
149
} )
147
150
it ( "fails if already withdrawn" , async function ( ) {
148
- const donationId = await setDonation ( this . dg , {
151
+ const donationId = await this . setDonation ( {
149
152
...this . defaultDonation ,
150
153
withdrawn : true ,
151
154
} )
@@ -154,7 +157,7 @@ describe("DisintermediatedGrants", function () {
154
157
)
155
158
} )
156
159
it ( "fails if caller is not the donor" , async function ( ) {
157
- const donationId = await setDonation ( this . dg , {
160
+ const donationId = await this . setDonation ( {
158
161
...this . defaultDonation ,
159
162
donor : this . alice . address ,
160
163
} )
@@ -163,7 +166,7 @@ describe("DisintermediatedGrants", function () {
163
166
)
164
167
} )
165
168
it ( "fails for fully disbursed donations" , async function ( ) {
166
- const donationId = await setDonation ( this . dg , {
169
+ const donationId = await this . setDonation ( {
167
170
...this . defaultDonation ,
168
171
disbursedAmount : TEST_DONATION_AMOUNT ,
169
172
} )
@@ -175,7 +178,7 @@ describe("DisintermediatedGrants", function () {
175
178
const donorBalance = await this . token . balanceOf ( this . alice . address )
176
179
const withdrawalAmount = this . defaultDonation . amount . div ( 2 )
177
180
await this . token . connect ( this . alice ) . approve ( this . dg . address , this . defaultDonation . amount )
178
- const donationId = await setDonation ( this . dg , {
181
+ const donationId = await this . setDonation ( {
179
182
...this . defaultDonation ,
180
183
donor : this . alice . address ,
181
184
disbursedAmount : this . defaultDonation . amount . sub ( withdrawalAmount ) ,
@@ -189,7 +192,7 @@ describe("DisintermediatedGrants", function () {
189
192
} )
190
193
describe ( "grant proposals" , function ( ) {
191
194
it ( "cannot be created by non-multisig" , async function ( ) {
192
- const donationId = await setDonation ( this . dg , this . defaultDonation )
195
+ const donationId = await this . setDonation ( this . defaultDonation )
193
196
await expect (
194
197
this . dg . connect ( this . eve ) . proposeGrant ( {
195
198
donationId,
@@ -208,7 +211,7 @@ describe("DisintermediatedGrants", function () {
208
211
) . to . be . revertedWith ( "donation does not exist" )
209
212
} )
210
213
it ( "fail if donation cannot cover full grant amount" , async function ( ) {
211
- const donationId = await setDonation ( this . dg , {
214
+ const donationId = await this . setDonation ( {
212
215
...this . defaultDonation ,
213
216
amount : TEST_DONATION_AMOUNT ,
214
217
} )
@@ -221,7 +224,7 @@ describe("DisintermediatedGrants", function () {
221
224
) . to . be . revertedWith ( "donation cannot cover full grant amount" )
222
225
} )
223
226
it ( "can be created by multisig" , async function ( ) {
224
- const donationId = await setDonation ( this . dg , {
227
+ const donationId = await this . setDonation ( {
225
228
...this . defaultDonation ,
226
229
amount : TEST_DONATION_AMOUNT ,
227
230
} )
@@ -243,8 +246,8 @@ describe("DisintermediatedGrants", function () {
243
246
describe ( "multiple grant proposals" , function ( ) {
244
247
beforeEach ( async function ( ) {
245
248
const [ donationAId , donationBId ] = [
246
- await setDonation ( this . dg , this . defaultDonation ) ,
247
- await setDonation ( this . dg , this . defaultDonation ) ,
249
+ await this . setDonation ( this . defaultDonation ) ,
250
+ await this . setDonation ( this . defaultDonation ) ,
248
251
]
249
252
250
253
const [ grantAProposal , grantBProposal ] = [
@@ -281,7 +284,7 @@ describe("DisintermediatedGrants", function () {
281
284
} )
282
285
describe ( "grant disbursal" , function ( ) {
283
286
it ( "fails if grant has already been disbursed" , async function ( ) {
284
- const grantId = await setGrant ( this . dg , {
287
+ const grantId = await this . setGrant ( {
285
288
...this . defaultGrant ,
286
289
disbursed : true ,
287
290
} )
@@ -293,7 +296,7 @@ describe("DisintermediatedGrants", function () {
293
296
await expect ( this . dg . connect ( this . bob ) . disburseGrant ( 404 ) ) . to . be . revertedWith ( "grant does not exist" )
294
297
} )
295
298
it ( "fails if donation does not exist" , async function ( ) {
296
- const grantId = await setGrant ( this . dg , {
299
+ const grantId = await this . setGrant ( {
297
300
...this . defaultGrant ,
298
301
donationId : 404 ,
299
302
proposedAt : 0 ,
@@ -303,11 +306,11 @@ describe("DisintermediatedGrants", function () {
303
306
)
304
307
} )
305
308
it ( "fails if donation has been withdrawn" , async function ( ) {
306
- const donationId = await setDonation ( this . dg , {
309
+ const donationId = await this . setDonation ( {
307
310
...this . defaultDonation ,
308
311
withdrawn : true ,
309
312
} )
310
- const grantId = await setGrant ( this . dg , {
313
+ const grantId = await this . setGrant ( {
311
314
...this . defaultGrant ,
312
315
donationId,
313
316
} )
@@ -316,8 +319,8 @@ describe("DisintermediatedGrants", function () {
316
319
)
317
320
} )
318
321
it ( "fails if donation grace period has not ended" , async function ( ) {
319
- const donationId = await setDonation ( this . dg , this . defaultDonation )
320
- const grantId = await setGrant ( this . dg , {
322
+ const donationId = await this . setDonation ( this . defaultDonation )
323
+ const grantId = await this . setGrant ( {
321
324
...this . defaultGrant ,
322
325
donationId,
323
326
proposedAt : await ethers . provider . getBlockNumber ( ) ,
@@ -327,12 +330,12 @@ describe("DisintermediatedGrants", function () {
327
330
)
328
331
} )
329
332
it ( "fails if grant amount exceeds donation balance" , async function ( ) {
330
- const donationId = await setDonation ( this . dg , {
333
+ const donationId = await this . setDonation ( {
331
334
...this . defaultDonation ,
332
335
amount : TEST_DONATION_AMOUNT ,
333
336
disbursedAmount : TEST_DONATION_AMOUNT . div ( 2 ) ,
334
337
} )
335
- const grantId = await setGrant ( this . dg , {
338
+ const grantId = await this . setGrant ( {
336
339
...this . defaultGrant ,
337
340
donationId,
338
341
amount : TEST_DONATION_AMOUNT ,
@@ -343,12 +346,12 @@ describe("DisintermediatedGrants", function () {
343
346
)
344
347
} )
345
348
it ( "fails if donor has removed allowance" , async function ( ) {
346
- const donationId = await setDonation ( this . dg , {
349
+ const donationId = await this . setDonation ( {
347
350
...this . defaultDonation ,
348
351
amount : TEST_DONATION_AMOUNT ,
349
352
} )
350
353
await this . token . connect ( this . alice ) . approve ( this . dg . address , 0 )
351
- const grantId = await setGrant ( this . dg , {
354
+ const grantId = await this . setGrant ( {
352
355
...this . defaultGrant ,
353
356
donationId,
354
357
amount : TEST_DONATION_AMOUNT ,
@@ -359,12 +362,12 @@ describe("DisintermediatedGrants", function () {
359
362
it ( "fails if donation exceeds donor balance" , async function ( ) {
360
363
const donorBalance = await this . token . balanceOf ( this . alice . address )
361
364
await this . token . connect ( this . alice ) . approve ( this . dg . address , donorBalance )
362
- const donationId = await setDonation ( this . dg , {
365
+ const donationId = await this . setDonation ( {
363
366
...this . defaultDonation ,
364
367
amount : donorBalance ,
365
368
} )
366
369
await this . token . connect ( this . alice ) . transfer ( this . bob . address , donorBalance )
367
- const grantId = await setGrant ( this . dg , {
370
+ const grantId = await this . setGrant ( {
368
371
...this . defaultGrant ,
369
372
donationId,
370
373
amount : donorBalance ,
@@ -377,8 +380,8 @@ describe("DisintermediatedGrants", function () {
377
380
it ( "transfers grant amount to recipient" , async function ( ) {
378
381
await this . token . connect ( this . alice ) . approve ( this . dg . address , TEST_DONATION_AMOUNT )
379
382
const grantRecipientBalance = await this . token . balanceOf ( this . bob . address )
380
- const donationId = await setDonation ( this . dg , this . defaultDonation )
381
- const grantId = await setGrant ( this . dg , {
383
+ const donationId = await this . setDonation ( this . defaultDonation )
384
+ const grantId = await this . setGrant ( {
382
385
...this . defaultGrant ,
383
386
donationId,
384
387
proposedAt : ( await ethers . provider . getBlockNumber ( ) ) - this . defaultDonation . gracePeriod ,
0 commit comments