Skip to content

Commit 566cd43

Browse files
committed
[SDK] Consolidate ERC1155 Drop tests
1 parent 3c77c6b commit 566cd43

File tree

4 files changed

+130
-329
lines changed

4 files changed

+130
-329
lines changed

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

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@ import {
99
TEST_ACCOUNT_B,
1010
TEST_ACCOUNT_D,
1111
} from "../../../test/src/test-wallets.js";
12+
import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js";
1213
import { resolveContractAbi } from "../../contract/actions/resolve-abi.js";
1314
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
1415
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
1516
import { resolvePromisedValue } from "../../utils/promise/resolve-promised-value.js";
1617
import { toEther } from "../../utils/units.js";
18+
import { generateMerkleTreeInfoERC1155 } from "../airdrop/write/merkleInfoERC1155.js";
19+
import { deployERC20Contract } from "../prebuilts/deploy-erc20.js";
1720
import { deployERC1155Contract } from "../prebuilts/deploy-erc1155.js";
1821
import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
22+
import { totalSupply } from "./__generated__/IERC1155/read/totalSupply.js";
1923
import { nextTokenIdToMint } from "./__generated__/IERC1155Enumerable/read/nextTokenIdToMint.js";
24+
import { getActiveClaimCondition } from "./drops/read/getActiveClaimCondition.js";
2025
import { getClaimConditions } from "./drops/read/getClaimConditions.js";
2126
import { claimTo } from "./drops/write/claimTo.js";
2227
import { resetClaimEligibility } from "./drops/write/resetClaimEligibility.js";
2328
import { setClaimConditions } from "./drops/write/setClaimConditions.js";
29+
import { updateMetadata } from "./drops/write/updateMetadata.js";
2430
import { getNFT } from "./read/getNFT.js";
2531
import { isGetNFTsSupported } from "./read/getNFTs.js";
2632
import { lazyMint } from "./write/lazyMint.js";
@@ -87,6 +93,20 @@ describe.runIf(process.env.TW_SECRET_KEY)(
8793
`);
8894
});
8995

96+
it("should update metadata", async () => {
97+
const updateTx = updateMetadata({
98+
contract,
99+
targetTokenId: 0n,
100+
newMetadata: { name: "Test NFT 1" },
101+
});
102+
await sendAndConfirmTransaction({
103+
transaction: updateTx,
104+
account: TEST_ACCOUNT_A,
105+
});
106+
const token0 = await getNFT({ contract, tokenId: 0n });
107+
expect(token0.metadata.name).toBe("Test NFT 1");
108+
});
109+
90110
it("should allow to claim tokens", async () => {
91111
await expect(
92112
balanceOf({ contract, owner: TEST_ACCOUNT_A.address, tokenId: 0n }),
@@ -409,5 +429,115 @@ describe.runIf(process.env.TW_SECRET_KEY)(
409429
.map((f) => toFunctionSelector(f));
410430
expect(isGetNFTsSupported(selectors)).toBe(true);
411431
});
432+
433+
/**
434+
* This is to document the behavior where one can claim without paying if the claiming address
435+
* is the same as the PrimaryRecipientAddress, because of this Solidity code:
436+
* ```solidity
437+
* // CurrencyTransferLib.sol
438+
* function safeTransferERC20(address _currency, address _from, address _to, uint256 _amount) internal {
439+
* if (_from == _to) {
440+
* return;
441+
* }
442+
* ...
443+
* }
444+
* ```
445+
*/
446+
it("address that is the same with PrimaryFeeRecipient can claim without paying ERC20", async () => {
447+
const tokenAddress = await deployERC20Contract({
448+
client: TEST_CLIENT,
449+
chain: ANVIL_CHAIN,
450+
account: TEST_ACCOUNT_A,
451+
type: "TokenERC20",
452+
params: {
453+
name: "token20",
454+
contractURI: TEST_CONTRACT_URI,
455+
},
456+
});
457+
const tokenId = 5n;
458+
const setClaimTx = setClaimConditions({
459+
contract,
460+
tokenId,
461+
phases: [
462+
{
463+
maxClaimableSupply: 100n,
464+
maxClaimablePerWallet: 100n,
465+
currencyAddress: tokenAddress,
466+
price: 1000,
467+
startTime: new Date(),
468+
},
469+
],
470+
});
471+
await sendAndConfirmTransaction({
472+
transaction: setClaimTx,
473+
account: TEST_ACCOUNT_A,
474+
});
475+
476+
const transaction = claimTo({
477+
contract,
478+
tokenId,
479+
quantity: 50n,
480+
to: TEST_ACCOUNT_A.address,
481+
});
482+
await sendAndConfirmTransaction({
483+
transaction,
484+
account: TEST_ACCOUNT_A,
485+
});
486+
const supplyCount = await totalSupply({ contract, id: tokenId });
487+
expect(supplyCount).toBe(50n);
488+
});
489+
490+
it("getActiveClaimCondition should work", async () => {
491+
// Create a public allowlist claim phase
492+
const snapshot = [
493+
{
494+
recipient: TEST_ACCOUNT_B.address,
495+
tokenId: 4,
496+
amount: 5,
497+
},
498+
{
499+
recipient: TEST_ACCOUNT_D.address,
500+
tokenId: 4,
501+
amount: 5,
502+
},
503+
];
504+
505+
const { merkleRoot } = await generateMerkleTreeInfoERC1155({
506+
contract,
507+
tokenAddress: NATIVE_TOKEN_ADDRESS,
508+
snapshot,
509+
});
510+
511+
const startTime = new Date();
512+
const setCC = setClaimConditions({
513+
contract,
514+
tokenId: 4n,
515+
phases: [
516+
{
517+
maxClaimableSupply: 100n,
518+
maxClaimablePerWallet: 5n,
519+
currencyAddress: NATIVE_TOKEN_ADDRESS,
520+
price: 0.006,
521+
startTime,
522+
merkleRootHash: merkleRoot,
523+
},
524+
],
525+
});
526+
527+
await sendAndConfirmTransaction({
528+
transaction: setCC,
529+
account: TEST_ACCOUNT_A,
530+
});
531+
532+
const activeCC = await getActiveClaimCondition({ contract, tokenId: 4n });
533+
expect(activeCC.currency.toLowerCase()).toBe(
534+
NATIVE_TOKEN_ADDRESS.toLowerCase(),
535+
);
536+
expect(activeCC.merkleRoot).toBe(
537+
"0x5baa4423af7125448ad7ca6913cdee7dd952a8d10a44f4fad4c50eea65c5c92d",
538+
);
539+
expect(activeCC.pricePerToken).toBe(6000000000000000n);
540+
expect(activeCC.quantityLimitPerWallet).toBe(5n);
541+
});
412542
},
413543
);
Lines changed: 0 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,8 @@
11
import { describe, expect, it } from "vitest";
2-
3-
import { ANVIL_CHAIN } from "~test/chains.js";
4-
import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js";
5-
import { TEST_CLIENT } from "~test/test-clients.js";
62
import { MAX_UINT256 } from "~test/test-consts.js";
7-
import { TEST_ACCOUNT_B } from "~test/test-wallets.js";
83
import { DROP1155_CONTRACT } from "../../../../../test/src/test-contracts.js";
9-
import { NATIVE_TOKEN_ADDRESS } from "../../../../constants/addresses.js";
10-
import { getContract } from "../../../../contract/contract.js";
11-
import { generateMerkleTreeInfoERC1155 } from "../../../../extensions/airdrop/write/merkleInfoERC1155.js";
12-
import { deployERC1155Contract } from "../../../../extensions/prebuilts/deploy-erc1155.js";
13-
import { sendAndConfirmTransaction } from "../../../../transaction/actions/send-and-confirm-transaction.js";
14-
import { lazyMint } from "../../write/lazyMint.js";
15-
import { setClaimConditions } from "../write/setClaimConditions.js";
164
import { getActiveClaimCondition } from "./getActiveClaimCondition.js";
175

18-
const account = TEST_ACCOUNT_B;
19-
206
describe.runIf(process.env.TW_SECRET_KEY)("erc1155.getClaimConditions", () => {
217
it("should return the correct claim conditions", async () => {
228
const cc = await getActiveClaimCondition({
@@ -36,80 +22,4 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc1155.getClaimConditions", () => {
3622
});
3723
// 1 call for the condition id and 1 call for the condition
3824
});
39-
40-
it("should return the correct claim condition for the public allowlist claim phase", async () => {
41-
const address = await deployERC1155Contract({
42-
client: TEST_CLIENT,
43-
chain: ANVIL_CHAIN,
44-
account,
45-
type: "DropERC1155",
46-
params: {
47-
name: "EditionDrop",
48-
contractURI: TEST_CONTRACT_URI,
49-
},
50-
});
51-
const contract = getContract({
52-
address,
53-
chain: ANVIL_CHAIN,
54-
client: TEST_CLIENT,
55-
});
56-
57-
// Upload an NFT
58-
const lzMint = lazyMint({ contract, nfts: [{ name: "token #0" }] });
59-
await sendAndConfirmTransaction({
60-
transaction: lzMint,
61-
account,
62-
});
63-
64-
// Create a public allowlist claim phase
65-
const snapshot = [
66-
{
67-
recipient: "0x12345674b599ce99958242b3D3741e7b01841DF3",
68-
tokenId: 0,
69-
amount: 5,
70-
},
71-
{
72-
recipient: "0x89f84D4e4ecaBa42233EEfc46eE49a03Db943bAD",
73-
tokenId: 0,
74-
amount: 5,
75-
},
76-
];
77-
78-
const { merkleRoot } = await generateMerkleTreeInfoERC1155({
79-
contract,
80-
tokenAddress: NATIVE_TOKEN_ADDRESS,
81-
snapshot,
82-
});
83-
84-
const startTime = new Date();
85-
const setCC = setClaimConditions({
86-
contract,
87-
tokenId: 0n,
88-
phases: [
89-
{
90-
maxClaimableSupply: 100n,
91-
maxClaimablePerWallet: 5n,
92-
currencyAddress: NATIVE_TOKEN_ADDRESS,
93-
price: 0.006,
94-
startTime,
95-
merkleRootHash: merkleRoot,
96-
},
97-
],
98-
});
99-
100-
await sendAndConfirmTransaction({
101-
transaction: setCC,
102-
account,
103-
});
104-
105-
const activeCC = await getActiveClaimCondition({ contract, tokenId: 0n });
106-
expect(activeCC.currency.toLowerCase()).toBe(
107-
NATIVE_TOKEN_ADDRESS.toLowerCase(),
108-
);
109-
expect(activeCC.merkleRoot).toBe(
110-
"0xbfa52e7f255395704d8ea7174ec56f1357e6a1946753fcd64000adb4aeb3ca4a",
111-
);
112-
expect(activeCC.pricePerToken).toBe(6000000000000000n);
113-
expect(activeCC.quantityLimitPerWallet).toBe(5n);
114-
});
11525
});

0 commit comments

Comments
 (0)