Skip to content

Commit 24bad4d

Browse files
committed
Create this.{whitelistDonor,setDonation,setGrant}
1 parent f04c8ac commit 24bad4d

File tree

1 file changed

+32
-29
lines changed

1 file changed

+32
-29
lines changed

test/DisintermediatedGrants.test.js

+32-29
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ describe("DisintermediatedGrants", function () {
5151
this.parties.forEach(async (party) => {
5252
await this.token.connect(party).mint(TEST_DONATION_AMOUNT)
5353
})
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)
5457
this.defaultDonation = {
5558
donor: this.alice.address,
5659
token: this.token.address,
@@ -88,7 +91,7 @@ describe("DisintermediatedGrants", function () {
8891
).to.be.revertedWith("caller is not whitelisted donor")
8992
})
9093
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)
9295
const donorBalance = await this.token.balanceOf(this.alice.address)
9396
const donationAmount = donorBalance.add(1)
9497
await this.token.connect(this.alice).approve(this.dg.address, donationAmount)
@@ -97,7 +100,7 @@ describe("DisintermediatedGrants", function () {
97100
).to.be.revertedWith("donation amount exceeds balance")
98101
})
99102
it("cannot be made with insufficient allowance", async function () {
100-
await whitelistDonor(this.dg, this.alice.address)
103+
await this.whitelistDonor(this.alice.address)
101104
const donorBalance = await this.token.balanceOf(this.alice.address)
102105
await this.token.connect(this.alice).approve(this.dg.address, donorBalance.sub(1))
103106
await expect(
@@ -106,7 +109,7 @@ describe("DisintermediatedGrants", function () {
106109
})
107110
it("can be made by whitelisted donors", async function () {
108111
const initialDonorBalance = await this.token.balanceOf(this.alice.address)
109-
await whitelistDonor(this.dg, this.alice.address)
112+
await this.whitelistDonor(this.alice.address)
110113
await this.token.connect(this.alice).approve(this.dg.address, TEST_DONATION_AMOUNT)
111114
const donationCount = await this.dg.donationCount()
112115
const tx = await this.dg
@@ -124,14 +127,14 @@ describe("DisintermediatedGrants", function () {
124127
expect(await this.token.balanceOf(this.alice.address)).to.equal(initialDonorBalance)
125128
})
126129
it("fail if donation amount is zero", async function () {
127-
await whitelistDonor(this.dg, this.alice.address)
130+
await this.whitelistDonor(this.alice.address)
128131
const donationCount = await this.dg.donationCount()
129132
await expect(
130133
this.dg.connect(this.alice).donate(this.token.address, 0, TEST_GRACE_PERIOD)
131134
).to.be.revertedWith("donation amount cannot be zero")
132135
})
133136
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)
135138
const donationCount = await this.dg.donationCount()
136139
await expect(
137140
this.dg
@@ -142,10 +145,10 @@ describe("DisintermediatedGrants", function () {
142145
})
143146
describe("donation withdrawal", function () {
144147
before(async function () {
145-
await whitelistDonor(this.dg, this.alice.address)
148+
await this.whitelistDonor(this.alice.address)
146149
})
147150
it("fails if already withdrawn", async function () {
148-
const donationId = await setDonation(this.dg, {
151+
const donationId = await this.setDonation({
149152
...this.defaultDonation,
150153
withdrawn: true,
151154
})
@@ -154,7 +157,7 @@ describe("DisintermediatedGrants", function () {
154157
)
155158
})
156159
it("fails if caller is not the donor", async function () {
157-
const donationId = await setDonation(this.dg, {
160+
const donationId = await this.setDonation({
158161
...this.defaultDonation,
159162
donor: this.alice.address,
160163
})
@@ -163,7 +166,7 @@ describe("DisintermediatedGrants", function () {
163166
)
164167
})
165168
it("fails for fully disbursed donations", async function () {
166-
const donationId = await setDonation(this.dg, {
169+
const donationId = await this.setDonation({
167170
...this.defaultDonation,
168171
disbursedAmount: TEST_DONATION_AMOUNT,
169172
})
@@ -175,7 +178,7 @@ describe("DisintermediatedGrants", function () {
175178
const donorBalance = await this.token.balanceOf(this.alice.address)
176179
const withdrawalAmount = this.defaultDonation.amount.div(2)
177180
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({
179182
...this.defaultDonation,
180183
donor: this.alice.address,
181184
disbursedAmount: this.defaultDonation.amount.sub(withdrawalAmount),
@@ -189,7 +192,7 @@ describe("DisintermediatedGrants", function () {
189192
})
190193
describe("grant proposals", function () {
191194
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)
193196
await expect(
194197
this.dg.connect(this.eve).proposeGrant({
195198
donationId,
@@ -208,7 +211,7 @@ describe("DisintermediatedGrants", function () {
208211
).to.be.revertedWith("donation does not exist")
209212
})
210213
it("fail if donation cannot cover full grant amount", async function () {
211-
const donationId = await setDonation(this.dg, {
214+
const donationId = await this.setDonation({
212215
...this.defaultDonation,
213216
amount: TEST_DONATION_AMOUNT,
214217
})
@@ -221,7 +224,7 @@ describe("DisintermediatedGrants", function () {
221224
).to.be.revertedWith("donation cannot cover full grant amount")
222225
})
223226
it("can be created by multisig", async function () {
224-
const donationId = await setDonation(this.dg, {
227+
const donationId = await this.setDonation({
225228
...this.defaultDonation,
226229
amount: TEST_DONATION_AMOUNT,
227230
})
@@ -243,8 +246,8 @@ describe("DisintermediatedGrants", function () {
243246
describe("multiple grant proposals", function () {
244247
beforeEach(async function () {
245248
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),
248251
]
249252

250253
const [grantAProposal, grantBProposal] = [
@@ -281,7 +284,7 @@ describe("DisintermediatedGrants", function () {
281284
})
282285
describe("grant disbursal", function () {
283286
it("fails if grant has already been disbursed", async function () {
284-
const grantId = await setGrant(this.dg, {
287+
const grantId = await this.setGrant({
285288
...this.defaultGrant,
286289
disbursed: true,
287290
})
@@ -293,7 +296,7 @@ describe("DisintermediatedGrants", function () {
293296
await expect(this.dg.connect(this.bob).disburseGrant(404)).to.be.revertedWith("grant does not exist")
294297
})
295298
it("fails if donation does not exist", async function () {
296-
const grantId = await setGrant(this.dg, {
299+
const grantId = await this.setGrant({
297300
...this.defaultGrant,
298301
donationId: 404,
299302
proposedAt: 0,
@@ -303,11 +306,11 @@ describe("DisintermediatedGrants", function () {
303306
)
304307
})
305308
it("fails if donation has been withdrawn", async function () {
306-
const donationId = await setDonation(this.dg, {
309+
const donationId = await this.setDonation({
307310
...this.defaultDonation,
308311
withdrawn: true,
309312
})
310-
const grantId = await setGrant(this.dg, {
313+
const grantId = await this.setGrant({
311314
...this.defaultGrant,
312315
donationId,
313316
})
@@ -316,8 +319,8 @@ describe("DisintermediatedGrants", function () {
316319
)
317320
})
318321
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({
321324
...this.defaultGrant,
322325
donationId,
323326
proposedAt: await ethers.provider.getBlockNumber(),
@@ -327,12 +330,12 @@ describe("DisintermediatedGrants", function () {
327330
)
328331
})
329332
it("fails if grant amount exceeds donation balance", async function () {
330-
const donationId = await setDonation(this.dg, {
333+
const donationId = await this.setDonation({
331334
...this.defaultDonation,
332335
amount: TEST_DONATION_AMOUNT,
333336
disbursedAmount: TEST_DONATION_AMOUNT.div(2),
334337
})
335-
const grantId = await setGrant(this.dg, {
338+
const grantId = await this.setGrant({
336339
...this.defaultGrant,
337340
donationId,
338341
amount: TEST_DONATION_AMOUNT,
@@ -343,12 +346,12 @@ describe("DisintermediatedGrants", function () {
343346
)
344347
})
345348
it("fails if donor has removed allowance", async function () {
346-
const donationId = await setDonation(this.dg, {
349+
const donationId = await this.setDonation({
347350
...this.defaultDonation,
348351
amount: TEST_DONATION_AMOUNT,
349352
})
350353
await this.token.connect(this.alice).approve(this.dg.address, 0)
351-
const grantId = await setGrant(this.dg, {
354+
const grantId = await this.setGrant({
352355
...this.defaultGrant,
353356
donationId,
354357
amount: TEST_DONATION_AMOUNT,
@@ -359,12 +362,12 @@ describe("DisintermediatedGrants", function () {
359362
it("fails if donation exceeds donor balance", async function () {
360363
const donorBalance = await this.token.balanceOf(this.alice.address)
361364
await this.token.connect(this.alice).approve(this.dg.address, donorBalance)
362-
const donationId = await setDonation(this.dg, {
365+
const donationId = await this.setDonation({
363366
...this.defaultDonation,
364367
amount: donorBalance,
365368
})
366369
await this.token.connect(this.alice).transfer(this.bob.address, donorBalance)
367-
const grantId = await setGrant(this.dg, {
370+
const grantId = await this.setGrant({
368371
...this.defaultGrant,
369372
donationId,
370373
amount: donorBalance,
@@ -377,8 +380,8 @@ describe("DisintermediatedGrants", function () {
377380
it("transfers grant amount to recipient", async function () {
378381
await this.token.connect(this.alice).approve(this.dg.address, TEST_DONATION_AMOUNT)
379382
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({
382385
...this.defaultGrant,
383386
donationId,
384387
proposedAt: (await ethers.provider.getBlockNumber()) - this.defaultDonation.gracePeriod,

0 commit comments

Comments
 (0)