Skip to content

Commit 6736490

Browse files
committed
test
1 parent 78924f2 commit 6736490

File tree

1 file changed

+86
-0
lines changed

1 file changed

+86
-0
lines changed

packages/thirdweb/src/extensions/erc1155/customDrop1155.test.ts

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,16 @@ import { TEST_CLIENT } from "../../../test/src/test-clients.js";
77
import {
88
TEST_ACCOUNT_B,
99
TEST_ACCOUNT_C,
10+
TEST_ACCOUNT_D,
1011
} from "../../../test/src/test-wallets.js";
1112
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
1213
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
1314
import { deployContractfromDeployMetadata } from "../prebuilts/deploy-published.js";
1415
import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
1516
import { nextTokenIdToMint } from "./__generated__/IERC1155Enumerable/read/nextTokenIdToMint.js";
17+
import { getClaimConditions } from "./drops/read/getClaimConditions.js";
1618
import { claimTo } from "./drops/write/claimTo.js";
19+
import { resetClaimEligibility } from "./drops/write/resetClaimEligibility.js";
1720
import { setClaimConditions } from "./drops/write/setClaimConditions.js";
1821
import { getNFT } from "./read/getNFT.js";
1922
import { lazyMint } from "./write/lazyMint.js";
@@ -92,6 +95,14 @@ describe.runIf(process.env.TW_SECRET_KEY)(
9295
}),
9396
account: TEST_ACCOUNT_C,
9497
});
98+
99+
const condition = await getClaimConditions({
100+
contract,
101+
tokenId: 0n,
102+
});
103+
expect(condition.length).to.eq(1);
104+
expect(condition[0]?.maxClaimableSupply).to.eq(10n);
105+
95106
const claimTx = claimTo({
96107
contract,
97108
to: TEST_ACCOUNT_C.address,
@@ -166,5 +177,80 @@ describe.runIf(process.env.TW_SECRET_KEY)(
166177
chainId: ${contract.chain.id}]
167178
`);
168179
});
180+
181+
it("should reset claim eligibility", async () => {
182+
await sendAndConfirmTransaction({
183+
transaction: setClaimConditions({
184+
contract,
185+
phases: [
186+
{
187+
startTime: new Date(0),
188+
maxClaimableSupply: 10n,
189+
maxClaimablePerWallet: 1n,
190+
},
191+
],
192+
tokenId: 0n,
193+
singlePhaseDrop: true,
194+
}),
195+
account: TEST_ACCOUNT_C,
196+
});
197+
// claim one token
198+
const claimTx = claimTo({
199+
contract,
200+
to: TEST_ACCOUNT_D.address,
201+
tokenId: 0n,
202+
quantity: 1n,
203+
singlePhaseDrop: true,
204+
});
205+
await sendAndConfirmTransaction({
206+
transaction: claimTx,
207+
account: TEST_ACCOUNT_D,
208+
});
209+
await expect(
210+
balanceOf({ contract, owner: TEST_ACCOUNT_D.address, tokenId: 0n }),
211+
).resolves.toBe(1n);
212+
213+
// attempt to claim another token (this should fail)
214+
await expect(
215+
sendAndConfirmTransaction({
216+
transaction: claimTo({
217+
tokenId: 0n,
218+
contract,
219+
to: TEST_ACCOUNT_D.address,
220+
quantity: 1n,
221+
}),
222+
account: TEST_ACCOUNT_D,
223+
}),
224+
).rejects.toThrowErrorMatchingInlineSnapshot(`
225+
[TransactionError: Error - !Qty
226+
227+
contract: ${contract.address}
228+
chainId: ${contract.chain.id}]
229+
`);
230+
231+
// reset claim eligibility
232+
await sendAndConfirmTransaction({
233+
transaction: resetClaimEligibility({
234+
tokenId: 0n,
235+
contract,
236+
singlePhaseDrop: true,
237+
}),
238+
account: TEST_ACCOUNT_C,
239+
});
240+
// attempt to claim another token (this should succeed)
241+
await sendAndConfirmTransaction({
242+
transaction: claimTo({
243+
tokenId: 0n,
244+
contract,
245+
to: TEST_ACCOUNT_D.address,
246+
quantity: 1n,
247+
}),
248+
account: TEST_ACCOUNT_D,
249+
});
250+
// check that the account has claimed two tokens
251+
await expect(
252+
balanceOf({ tokenId: 0n, contract, owner: TEST_ACCOUNT_D.address }),
253+
).resolves.toBe(2n);
254+
});
169255
},
170256
);

0 commit comments

Comments
 (0)