forked from ProjectOpenSea/seadrop
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSeaDrop-mintAllowedTokenHolder.spec.ts
709 lines (624 loc) · 20.7 KB
/
SeaDrop-mintAllowedTokenHolder.spec.ts
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
import { expect } from "chai";
import { ethers, network } from "hardhat";
import { randomHex } from "./utils/encoding";
import { faucet } from "./utils/faucet";
import { VERSION } from "./utils/helpers";
import { whileImpersonating } from "./utils/impersonate";
import type {
ERC721PartnerSeaDrop,
ISeaDrop,
TestERC721,
} from "../typechain-types";
import type { TokenGatedDropStageStruct } from "../typechain-types/src/SeaDrop";
import type { Wallet } from "ethers";
describe(`SeaDrop - Mint Allowed Token Holder (v${VERSION})`, function () {
const { provider } = ethers;
let seadrop: ISeaDrop;
let token: ERC721PartnerSeaDrop;
let allowedNftToken: TestERC721;
let owner: Wallet;
let admin: Wallet;
let creator: Wallet;
let minter: Wallet;
let feeRecipient: Wallet;
let dropStage: TokenGatedDropStageStruct;
after(async () => {
await network.provider.request({
method: "hardhat_reset",
});
});
before(async () => {
// Set the wallets.
owner = new ethers.Wallet(randomHex(32), provider);
admin = new ethers.Wallet(randomHex(32), provider);
creator = new ethers.Wallet(randomHex(32), provider);
minter = new ethers.Wallet(randomHex(32), provider);
feeRecipient = new ethers.Wallet(randomHex(32), provider);
// Add eth to wallets.
for (const wallet of [owner, admin, minter]) {
await faucet(wallet.address, provider);
}
// Deploy Seadrop.
const SeaDrop = await ethers.getContractFactory("SeaDrop");
seadrop = await SeaDrop.deploy();
});
beforeEach(async () => {
// Deploy token.
const SeaDropToken = await ethers.getContractFactory(
"ERC721PartnerSeaDrop",
owner
);
token = await SeaDropToken.deploy("", "", admin.address, [seadrop.address]);
// Deploy the allowed NFT token.
const AllowedNftToken = await ethers.getContractFactory("TestERC721");
allowedNftToken = await AllowedNftToken.deploy();
// Configure token.
await token.setMaxSupply(100);
await token.updateCreatorPayoutAddress(seadrop.address, creator.address);
await token
.connect(admin)
.updateAllowedFeeRecipient(seadrop.address, feeRecipient.address, true);
// Create the drop stage object.
dropStage = {
mintPrice: "10000000000000000", // 0.01 ether
maxTotalMintableByWallet: 10,
startTime: Math.round(Date.now() / 1000) - 100,
endTime: Math.round(Date.now() / 1000) + 500,
dropStageIndex: 1,
maxTokenSupplyForStage: 100,
feeBps: 100,
restrictFeeRecipients: true,
};
// Update the token gated drop for the deployed allowed NFT token.
await token
.connect(admin)
.updateTokenGatedDrop(
seadrop.address,
allowedNftToken.address,
dropStage
);
await token
.connect(owner)
.updateTokenGatedDrop(
seadrop.address,
allowedNftToken.address,
dropStage
);
});
it("Should mint a token to a user with the allowed NFT token", async () => {
// Declare the mint params specifying the allowed NFT token addresses and
// corresponding tokenIds.
const mintParams = {
allowedNftToken: allowedNftToken.address,
allowedNftTokenIds: [0],
};
// Mint an allowedNftToken to the minter.
await allowedNftToken.mint(minter.address, 0);
// Ensure the token id is not already redeemed.
expect(
await seadrop.getAllowedNftTokenIdIsRedeemed(
token.address,
mintParams.allowedNftToken,
mintParams.allowedNftTokenIds[0]
)
).to.be.false;
// Mint the token to the minter and verify the expected event was emitted.
await expect(
seadrop
.connect(minter)
.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
minter.address,
mintParams,
{ value: dropStage.mintPrice }
)
)
.to.emit(seadrop, "SeaDropMint")
.withArgs(
token.address,
minter.address,
feeRecipient.address,
minter.address,
1, // mint quantity
dropStage.mintPrice,
dropStage.feeBps,
dropStage.dropStageIndex
);
// Ensure the token id was redeemed.
expect(
await seadrop.getAllowedNftTokenIdIsRedeemed(
token.address,
mintParams.allowedNftToken,
mintParams.allowedNftTokenIds[0]
)
).to.be.true;
expect(await seadrop.getTokenGatedAllowedTokens(token.address)).to.deep.eq([
allowedNftToken.address,
]);
});
it("Should mint a token to a user with the allowed NFT token when the payer is different from the minter", async () => {
const mintParams = {
allowedNftToken: allowedNftToken.address,
allowedNftTokenIds: [0],
};
// Mint an allowedNftToken to the minter.
await allowedNftToken.mint(minter.address, 0);
// The payer must be allowed first.
await expect(
seadrop
.connect(owner)
.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
minter.address,
mintParams,
{ value: dropStage.mintPrice }
)
).to.be.revertedWith("PayerNotAllowed");
// Allow the payer.
await token
.connect(owner)
.updatePayer(seadrop.address, owner.address, true);
await expect(
seadrop
.connect(owner)
.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
minter.address,
mintParams,
{ value: dropStage.mintPrice }
)
)
.to.emit(seadrop, "SeaDropMint")
.withArgs(
token.address,
minter.address,
feeRecipient.address,
owner.address,
1, // mint quantity
dropStage.mintPrice,
dropStage.feeBps,
dropStage.dropStageIndex
);
const minterBalance = await token.balanceOf(minter.address);
expect(minterBalance).to.eq(1);
});
it("Should mint a token to a user with the allowed NFT token when the mint is free", async () => {
// Create the free mint drop stage object.
const dropStageFreeMint = { ...dropStage, mintPrice: 0 };
// Update the token gated drop for the deployed allowed NFT token.
await token.updateTokenGatedDrop(
seadrop.address,
allowedNftToken.address,
dropStageFreeMint
);
const mintParams = {
allowedNftToken: allowedNftToken.address,
allowedNftTokenIds: [0],
};
// Mint an allowedNftToken to the minter.
await allowedNftToken.mint(minter.address, 0);
await expect(
seadrop
.connect(minter)
.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
minter.address,
mintParams
)
)
.to.emit(seadrop, "SeaDropMint")
.withArgs(
token.address,
minter.address,
feeRecipient.address,
minter.address,
1, // mint quantity
0, // free
dropStage.feeBps,
dropStage.dropStageIndex
);
const minterBalance = await token.balanceOf(minter.address);
expect(minterBalance).to.eq(1);
});
it("Should revert if the allowed NFT token has already been redeemed", async () => {
const mintParams = {
allowedNftToken: allowedNftToken.address,
allowedNftTokenIds: [0],
};
// Mint an allowedNftToken to the minter.
await allowedNftToken.mint(minter.address, 0);
await expect(
seadrop
.connect(minter)
.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
minter.address,
mintParams,
{ value: dropStage.mintPrice }
)
)
.to.emit(seadrop, "SeaDropMint")
.withArgs(
token.address,
minter.address,
feeRecipient.address,
minter.address,
1, // mint quantity
dropStage.mintPrice,
dropStage.feeBps,
dropStage.dropStageIndex
);
await expect(
seadrop
.connect(minter)
.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
minter.address,
mintParams,
{ value: dropStage.mintPrice }
)
).to.be.revertedWith(
`TokenGatedTokenIdAlreadyRedeemed("${token.address}", "${allowedNftToken.address}", 0)`
);
});
it("Should revert if the minter does not own the allowed NFT token passed into the call", async () => {
const mintParams = {
allowedNftToken: allowedNftToken.address,
allowedNftTokenIds: [0],
};
// Mint an allowedNftToken to the owner.
await allowedNftToken.mint(owner.address, 0);
await expect(
seadrop
.connect(minter)
.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
minter.address,
mintParams,
{ value: dropStage.mintPrice }
)
).to.be.revertedWith(
`TokenGatedNotTokenOwner("${token.address}", "${allowedNftToken.address}", 0)`
);
});
it("Should revert if the drop stage is not active", async () => {
// Create the drop stage object.
const dropStageExpired = {
...dropStage,
endTime: Math.round(Date.now() / 1000) - 500,
};
// Update the token gated drop for the deployed allowed NFT token.
await token.updateTokenGatedDrop(
seadrop.address,
allowedNftToken.address,
dropStageExpired
);
const mintParams = {
allowedNftToken: allowedNftToken.address,
allowedNftTokenIds: [0],
};
// Mint an allowedNftToken to the minter.
await allowedNftToken.mint(minter.address, 0);
// Get block.timestamp for custom error.
const mostRecentBlock = await ethers.provider.getBlock(
await ethers.provider.getBlockNumber()
);
const mostRecentBlockTimestamp = mostRecentBlock.timestamp;
await expect(
seadrop.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
ethers.constants.AddressZero,
mintParams
)
).to.be.revertedWith(
`NotActive(${mostRecentBlockTimestamp + 1}, ${dropStage.startTime}, ${
dropStageExpired.endTime
})`
);
});
it("Should not mint an allowed token holder stage with a different fee recipient", async () => {
// Declare the mint params specifying the allowed NFT token addresses and
// corresponding tokenIds.
const mintParams = {
allowedNftToken: allowedNftToken.address,
allowedNftTokenIds: [0],
};
// Mint an allowedNftToken to the minter.
await allowedNftToken.mint(minter.address, 0);
// Expect the transaction to revert since an incorrect fee recipient was given.
await expect(
seadrop
.connect(minter)
.mintAllowedTokenHolder(
token.address,
creator.address,
minter.address,
mintParams,
{ value: dropStage.mintPrice }
)
).to.be.revertedWith("FeeRecipientNotAllowed()");
});
it("Should not mint an allowed token holder stage with a different token contract", async () => {
// Declare the mint params specifying the allowed NFT token addresses and
// corresponding tokenIds.
const mintParams = {
allowedNftToken: allowedNftToken.address,
allowedNftTokenIds: [0],
};
// Mint an allowedNftToken to the minter.
await allowedNftToken.mint(minter.address, 0);
// Deploy a new ERC721PartnerSeaDrop.
const SeaDropToken = await ethers.getContractFactory(
"ERC721PartnerSeaDrop"
);
const differentToken = await SeaDropToken.deploy("", "", owner.address, [
seadrop.address,
]);
// Update the fee recipient and creator payout address for the new token.
await differentToken.setMaxSupply(1000);
await differentToken
.connect(owner)
.updateAllowedFeeRecipient(seadrop.address, feeRecipient.address, true);
await differentToken.updateCreatorPayoutAddress(
seadrop.address,
creator.address
);
// Get block.timestamp for custom error.
const mostRecentBlock = await ethers.provider.getBlock(
await ethers.provider.getBlockNumber()
);
const mostRecentBlockTimestamp = mostRecentBlock.timestamp;
// Expect the transaction to revert since a different token address was given.
// Transaction will revert with NotActive() because startTime and endTime for
// a nonexistent drop stage will be 0.
await expect(
seadrop
.connect(minter)
.mintAllowedTokenHolder(
differentToken.address,
feeRecipient.address,
minter.address,
mintParams,
{ value: dropStage.mintPrice }
)
).to.be.revertedWith(`NotActive(${mostRecentBlockTimestamp + 1}, 0, 0)`);
});
it("Should not mint an allowed token holder stage with different mint params", async () => {
// Deploy a different allowed NFT token.
const AllowedNftToken = await ethers.getContractFactory("TestERC721");
const differentAllowedNftToken = await AllowedNftToken.deploy();
// Declare the mint params specifying the allowed NFT token addresses and
// corresponding tokenIds.
const mintParams = {
allowedNftToken: differentAllowedNftToken.address,
allowedNftTokenIds: [0],
};
// Mint an allowedNftToken to the minter with a tokenId not included in the mintParams.
await allowedNftToken.mint(minter.address, 0);
// Get block.timestamp for custom error.
const mostRecentBlock = await ethers.provider.getBlock(
await ethers.provider.getBlockNumber()
);
const mostRecentBlockTimestamp = mostRecentBlock.timestamp;
// Expect the transaction to revert since a different token address was passed to the mintParams.
await expect(
seadrop
.connect(minter)
.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
minter.address,
mintParams,
{ value: dropStage.mintPrice }
)
).to.be.revertedWith(`NotActive(${mostRecentBlockTimestamp + 1}, 0, 0)`);
});
it("Should not mint an allowed token holder stage after exceeding max mints per wallet", async () => {
// Create an array of tokenIds with length exceeding maxTotalMintableByWallet.
const tokenIds = [...Array(20).keys()];
// Declare the mint params specifying the allowed NFT token addresses and
// corresponding tokenIds.
const mintParams = {
allowedNftToken: allowedNftToken.address,
allowedNftTokenIds: tokenIds,
};
// Mint the tokenIds in the mintParams to the minter.
for (const id of tokenIds) {
await allowedNftToken.mint(minter.address, id);
}
// Calculate the value to send with the mint transaction.
const mintValue = ethers.BigNumber.from(dropStage.mintPrice).mul(
tokenIds.length
);
// Expect the transaction to revert since the mint quantity exceeds the
// max total mintable by a wallet.
await expect(
seadrop
.connect(minter)
.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
minter.address,
mintParams,
{ value: mintValue }
)
).to.be.revertedWith(
`MintQuantityExceedsMaxMintedPerWallet(${tokenIds.length}, ${dropStage.maxTotalMintableByWallet})`
);
});
it("Should not mint an allowed token holder stage after exceeding max token supply for stage", async () => {
// Create a new drop stage object.
const newDropStage = {
...dropStage,
maxTotalMintableByWallet: 20,
maxTokenSupplyForStage: 5,
};
// Update the token gated drop for the deployed allowed NFT token.
await token
.connect(admin)
.updateTokenGatedDrop(
seadrop.address,
allowedNftToken.address,
newDropStage
);
await token
.connect(owner)
.updateTokenGatedDrop(
seadrop.address,
allowedNftToken.address,
newDropStage
);
// Create an array of tokenIds with length exceeding maxTotalMintableByWallet.
const tokenIds = [...Array(20).keys()];
// Declare the mint params specifying the allowed NFT token addresses and
// corresponding tokenIds.
const mintParams = {
allowedNftToken: allowedNftToken.address,
allowedNftTokenIds: tokenIds,
};
// Mint the tokenIds in the mintParams to the minter.
for (const id of tokenIds) {
await allowedNftToken.mint(minter.address, id);
}
// Calculate the value to send with the mint transaction.
const mintValue = ethers.BigNumber.from(dropStage.mintPrice).mul(
tokenIds.length
);
// Expect the transaction to revert since the mint quantity exceeds the
// max total mintable by a wallet.
await expect(
seadrop
.connect(minter)
.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
ethers.constants.AddressZero,
mintParams,
{ value: mintValue }
)
).to.be.revertedWith(
`MintQuantityExceedsMaxTokenSupplyForStage(${tokenIds.length}, 5)`
);
});
it("Should not mint an allowed token holder stage after exceeding max token supply", async () => {
const newDropStage = {
...dropStage,
maxTotalMintableByWallet: 110,
maxTokenSupplyForStage: 110,
};
// Update the token gated drop for the deployed allowed NFT token.
await token.updateTokenGatedDrop(
seadrop.address,
allowedNftToken.address,
newDropStage
);
// Create an array of tokenIds with length exceeding maxTotalMintableByWallet.
const tokenIds = [...Array(110).keys()];
// Declare the mint params specifying the allowed NFT token addresses and
// corresponding tokenIds.
const mintParams = {
allowedNftToken: allowedNftToken.address,
allowedNftTokenIds: tokenIds,
};
// Mint the tokenIds in the mintParams to the minter.
for (const id of tokenIds) {
await allowedNftToken.mint(minter.address, id);
}
// Calculate the value to send with the mint transaction.
const mintValue = ethers.BigNumber.from(dropStage.mintPrice).mul(
tokenIds.length
);
// Expect the transaction to revert since the mint quantity exceeds the
// max supply.
await expect(
seadrop
.connect(minter)
.mintAllowedTokenHolder(
token.address,
feeRecipient.address,
minter.address,
mintParams,
{ value: mintValue }
)
).to.be.revertedWith(
`MintQuantityExceedsMaxSupply(${tokenIds.length}, 100)`
);
});
it("Should not be able to set an allowedNftToken to the drop token itself or zero address", async () => {
await expect(
token
.connect(admin)
.updateTokenGatedDrop(seadrop.address, token.address, dropStage)
).to.be.revertedWith("TokenGatedDropAllowedNftTokenCannotBeDropToken()");
await expect(
token
.connect(admin)
.updateTokenGatedDrop(
seadrop.address,
ethers.constants.AddressZero,
dropStage
)
).to.be.revertedWith("TokenGatedDropAllowedNftTokenCannotBeZeroAddress()");
});
it("Should not be able to set an invalid fee bps", async () => {
await expect(
token
.connect(admin)
.updateTokenGatedDrop(seadrop.address, allowedNftToken.address, {
...dropStage,
feeBps: 15_000,
})
).to.be.revertedWith("InvalidFeeBps");
});
it("Should revert when stage not present or fee not set", async () => {
// Create a non-mintable drop stage object.
const zeroMintDropStage = {
...dropStage,
maxTotalMintableByWallet: 0,
maxTokenSupplyForStage: 5,
};
const token2 = `0x${"2".repeat(40)}`;
await whileImpersonating(
token.address,
provider,
async (impersonatedSigner) => {
// Expect the call to update the drop stage to revert since
// there is no existing drop stage.
await expect(
seadrop
.connect(impersonatedSigner)
.updateTokenGatedDrop(token2, zeroMintDropStage)
).to.be.revertedWith("TokenGatedDropStageNotPresent()");
}
);
// Expect the call to update the drop stage to revert since
// the admin must first initialize with fee.
await expect(
token
.connect(owner)
.updateTokenGatedDrop(seadrop.address, token2, zeroMintDropStage)
).to.be.revertedWith("AdministratorMustInitializeWithFee()");
});
it("Should clear from enumeration when deleted", async () => {
await token
.connect(owner)
.updateTokenGatedDrop(seadrop.address, allowedNftToken.address, {
...dropStage,
maxTotalMintableByWallet: 0,
});
expect(await seadrop.getTokenGatedAllowedTokens(token.address)).to.deep.eq(
[]
);
expect(
await seadrop.getTokenGatedDrop(token.address, allowedNftToken.address)
).to.deep.eq([ethers.BigNumber.from(0), 0, 0, 0, 0, 0, 0, false]);
});
});