forked from ProjectOpenSea/seadrop
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathERC721SeaDropRandomOffset.spec.ts
131 lines (104 loc) · 3.85 KB
/
ERC721SeaDropRandomOffset.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
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 { ERC721SeaDropRandomOffset, ISeaDrop } from "../typechain-types";
import type { Wallet } from "ethers";
describe(`ERC721SeaDropRandomOffset (v${VERSION})`, function () {
const { provider } = ethers;
let seadrop: ISeaDrop;
let token: ERC721SeaDropRandomOffset;
let owner: Wallet;
let creator: 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);
creator = new ethers.Wallet(randomHex(32), provider);
minter = new ethers.Wallet(randomHex(32), provider);
// Add eth to wallets
for (const wallet of [owner, minter, creator]) {
await faucet(wallet.address, provider);
}
// Deploy SeaDrop
const SeaDrop = await ethers.getContractFactory("SeaDrop", owner);
seadrop = await SeaDrop.deploy();
});
beforeEach(async () => {
// Deploy token
const ERC721SeaDropRandomOffset = await ethers.getContractFactory(
"ERC721SeaDropRandomOffset",
owner
);
token = await ERC721SeaDropRandomOffset.deploy("", "", [seadrop.address]);
});
it("Should only let the owner call setRandomOffset once the max supply is reached", async () => {
await token.setMaxSupply(100);
await expect(token.connect(owner).setRandomOffset()).to.be.revertedWith(
"NotFullyMinted()"
);
// Mint to the max supply.
await whileImpersonating(
seadrop.address,
provider,
async (impersonatedSigner) => {
await token
.connect(impersonatedSigner)
.mintSeaDrop(minter.address, 100);
}
);
expect(await token.randomOffset()).to.equal(ethers.constants.Zero);
await token.connect(owner).setRandomOffset();
await expect(token.connect(owner).setRandomOffset()).to.be.revertedWith(
"AlreadyRevealed()"
);
expect(await token.randomOffset()).to.not.equal(ethers.constants.Zero);
});
it("Should return the tokenURI correctly offset by randomOffset", async () => {
await token.setMaxSupply(100);
await expect(token.tokenURI(1)).to.be.revertedWith(
"URIQueryForNonexistentToken()"
);
// Mint to the max supply.
await whileImpersonating(
seadrop.address,
provider,
async (impersonatedSigner) => {
await token
.connect(impersonatedSigner)
.mintSeaDrop(minter.address, 100);
}
);
expect(await token.tokenURI(1)).to.equal("");
await token.setBaseURI("http://example.com/");
expect(await token.tokenURI(1)).to.equal("http://example.com/");
await token.connect(owner).setRandomOffset();
const randomOffset = (await token.randomOffset()).toNumber();
expect(randomOffset).to.be.greaterThan(0);
expect(randomOffset).to.be.lessThanOrEqual(100);
const startTokenId = 1;
expect(await token.tokenURI(1)).to.equal(
`http://example.com/${((1 + randomOffset) % 100) + startTokenId}`
);
expect(await token.tokenURI(100)).to.equal(
`http://example.com/${((100 + randomOffset) % 100) + startTokenId}`
);
const tokenUri2 = 101 - randomOffset;
const tokenUri1 = 100 - randomOffset;
const tokenUri100 = 99 - randomOffset;
const tokenUri99 = 98 - randomOffset;
expect(await token.tokenURI(tokenUri2)).to.equal(`http://example.com/2`);
expect(await token.tokenURI(tokenUri1)).to.equal(`http://example.com/1`);
expect(await token.tokenURI(tokenUri100)).to.equal(
`http://example.com/100`
);
expect(await token.tokenURI(tokenUri99)).to.equal(`http://example.com/99`);
});
});