forked from ProjectOpenSea/seadrop
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathSeaDrop.spec.ts
188 lines (166 loc) · 5.99 KB
/
SeaDrop.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
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,
IERC721,
ISeaDrop,
} from "../typechain-types";
import type { Wallet } from "ethers";
describe(`SeaDrop (v${VERSION})`, function () {
const { provider } = ethers;
let seadrop: ISeaDrop;
let token: ERC721PartnerSeaDrop;
let standard721Token: IERC721;
let owner: Wallet;
let admin: Wallet;
let minter: Wallet;
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);
minter = 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", owner);
seadrop = await SeaDrop.deploy();
// Deploy token
const ERC721PartnerSeaDrop = await ethers.getContractFactory(
"ERC721PartnerSeaDrop",
owner
);
token = await ERC721PartnerSeaDrop.deploy("", "", admin.address, [
seadrop.address,
]);
// Deploy a standard (non-IER721SeaDrop) token
const ERC721A = await ethers.getContractFactory("ERC721A", owner);
standard721Token = (await ERC721A.deploy("", "")) as unknown as IERC721;
});
it("Should not let a non-INonFungibleSeaDropToken token contract use the token methods", async () => {
await whileImpersonating(
standard721Token.address,
provider,
async (impersonatedSigner) => {
const publicDrop = {
mintPrice: 1000,
maxTotalMintableByWallet: 1,
startTime: Math.round(Date.now() / 1000) - 100,
endTime: Math.round(Date.now() / 1000) + 100,
feeBps: 1000,
restrictFeeRecipients: false,
};
await expect(
seadrop.connect(impersonatedSigner).updatePublicDrop(publicDrop)
).to.be.revertedWith("OnlyINonFungibleSeaDropToken");
const allowListData = {
merkleRoot: ethers.constants.HashZero,
publicKeyURIs: [],
allowListURI: "",
};
await expect(
seadrop.connect(impersonatedSigner).updateAllowList(allowListData)
).to.be.revertedWith("OnlyINonFungibleSeaDropToken");
const tokenGatedDropStage = {
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,
};
await expect(
seadrop
.connect(impersonatedSigner)
.updateTokenGatedDrop(minter.address, tokenGatedDropStage)
).to.be.revertedWith("OnlyINonFungibleSeaDropToken");
await expect(
seadrop
.connect(impersonatedSigner)
.updateCreatorPayoutAddress(minter.address)
).to.be.revertedWith("OnlyINonFungibleSeaDropToken");
await expect(
seadrop
.connect(impersonatedSigner)
.updateAllowedFeeRecipient(minter.address, true)
).to.be.revertedWith("OnlyINonFungibleSeaDropToken");
const signedMintValidationParams = {
minMintPrice: 1,
maxMaxTotalMintableByWallet: 11,
minStartTime: 50,
maxEndTime: "100000000000",
maxMaxTokenSupplyForStage: 10000,
minFeeBps: 1,
maxFeeBps: 9000,
};
await expect(
seadrop
.connect(impersonatedSigner)
.updateSignedMintValidationParams(
minter.address,
signedMintValidationParams
)
).to.be.revertedWith("OnlyINonFungibleSeaDropToken");
await expect(
seadrop.connect(impersonatedSigner).updateDropURI("http://test.com")
).to.be.revertedWith("OnlyINonFungibleSeaDropToken");
await expect(
seadrop.connect(impersonatedSigner).updatePayer(minter.address, true)
).to.be.revertedWith("OnlyINonFungibleSeaDropToken");
}
);
await expect(
token.connect(owner).updateDropURI(seadrop.address, "http://test.com")
)
.to.emit(seadrop, "DropURIUpdated")
.withArgs(token.address, "http://test.com");
});
it("Should not allow reentrancy during mint", async () => {
// Set a public drop with maxTotalMintableByWallet: 1
// and restrictFeeRecipient: false
await token.setMaxSupply(10);
const oneEther = ethers.utils.parseEther("1");
const publicDrop = {
mintPrice: oneEther,
maxTotalMintableByWallet: 1,
startTime: Math.round(Date.now() / 1000) - 100,
endTime: Math.round(Date.now() / 1000) + 100,
feeBps: 1000,
restrictFeeRecipients: false,
};
await whileImpersonating(
token.address,
provider,
async (impersonatedSigner) => {
await seadrop.connect(impersonatedSigner).updatePublicDrop(publicDrop);
}
);
const MaliciousRecipientFactory = await ethers.getContractFactory(
"MaliciousRecipient",
owner
);
const maliciousRecipient = await MaliciousRecipientFactory.deploy();
// Set the creator address to MaliciousRecipient.
await token
.connect(owner)
.updateCreatorPayoutAddress(seadrop.address, maliciousRecipient.address);
// Should not be able to mint with reentrancy.
await maliciousRecipient.setStartAttack({ value: oneEther.mul(10) });
await expect(
maliciousRecipient.attack(seadrop.address, token.address)
).to.be.revertedWith("ETH_TRANSFER_FAILED");
expect(await token.totalSupply()).to.eq(0);
});
});