diff --git a/packages/thirdweb/src/extensions/erc1155/drop1155.test.ts b/packages/thirdweb/src/extensions/erc1155/drop1155.test.ts index 385f4d6d2ab..8320074b65e 100644 --- a/packages/thirdweb/src/extensions/erc1155/drop1155.test.ts +++ b/packages/thirdweb/src/extensions/erc1155/drop1155.test.ts @@ -5,22 +5,28 @@ import { VITALIK_WALLET } from "../../../test/src/addresses.js"; import { ANVIL_CHAIN } from "../../../test/src/chains.js"; import { TEST_CLIENT } from "../../../test/src/test-clients.js"; import { - TEST_ACCOUNT_A, TEST_ACCOUNT_B, + TEST_ACCOUNT_C, TEST_ACCOUNT_D, } from "../../../test/src/test-wallets.js"; +import { NATIVE_TOKEN_ADDRESS } from "../../constants/addresses.js"; import { resolveContractAbi } from "../../contract/actions/resolve-abi.js"; import { type ThirdwebContract, getContract } from "../../contract/contract.js"; import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js"; import { resolvePromisedValue } from "../../utils/promise/resolve-promised-value.js"; import { toEther } from "../../utils/units.js"; +import { generateMerkleTreeInfoERC1155 } from "../airdrop/write/merkleInfoERC1155.js"; +import { deployERC20Contract } from "../prebuilts/deploy-erc20.js"; import { deployERC1155Contract } from "../prebuilts/deploy-erc1155.js"; import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js"; +import { totalSupply } from "./__generated__/IERC1155/read/totalSupply.js"; import { nextTokenIdToMint } from "./__generated__/IERC1155Enumerable/read/nextTokenIdToMint.js"; +import { getActiveClaimCondition } from "./drops/read/getActiveClaimCondition.js"; import { getClaimConditions } from "./drops/read/getClaimConditions.js"; import { claimTo } from "./drops/write/claimTo.js"; import { resetClaimEligibility } from "./drops/write/resetClaimEligibility.js"; import { setClaimConditions } from "./drops/write/setClaimConditions.js"; +import { updateMetadata } from "./drops/write/updateMetadata.js"; import { getNFT } from "./read/getNFT.js"; import { isGetNFTsSupported } from "./read/getNFTs.js"; import { lazyMint } from "./write/lazyMint.js"; @@ -35,7 +41,7 @@ describe.runIf(process.env.TW_SECRET_KEY)( beforeAll(async () => { const contractAddress = await deployERC1155Contract({ - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, chain: ANVIL_CHAIN, client: TEST_CLIENT, params: { @@ -67,7 +73,7 @@ describe.runIf(process.env.TW_SECRET_KEY)( }); await sendAndConfirmTransaction({ transaction: mintTx, - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, }); await expect(nextTokenIdToMint({ contract })).resolves.toBe(6n); @@ -87,9 +93,23 @@ describe.runIf(process.env.TW_SECRET_KEY)( `); }); + it("should update metadata", async () => { + const updateTx = updateMetadata({ + contract, + targetTokenId: 0n, + newMetadata: { name: "Test NFT 1" }, + }); + await sendAndConfirmTransaction({ + transaction: updateTx, + account: TEST_ACCOUNT_C, + }); + const token0 = await getNFT({ contract, tokenId: 0n }); + expect(token0.metadata.name).toBe("Test NFT 1"); + }); + it("should allow to claim tokens", async () => { await expect( - balanceOf({ contract, owner: TEST_ACCOUNT_A.address, tokenId: 0n }), + balanceOf({ contract, owner: TEST_ACCOUNT_C.address, tokenId: 0n }), ).resolves.toBe(0n); await sendAndConfirmTransaction({ transaction: setClaimConditions({ @@ -97,26 +117,26 @@ describe.runIf(process.env.TW_SECRET_KEY)( phases: [{}], tokenId: 0n, }), - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, }); const claimTx = claimTo({ contract, - to: TEST_ACCOUNT_A.address, + to: TEST_ACCOUNT_C.address, tokenId: 0n, quantity: 1n, }); await sendAndConfirmTransaction({ transaction: claimTx, - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, }); await expect( - balanceOf({ contract, owner: TEST_ACCOUNT_A.address, tokenId: 0n }), + balanceOf({ contract, owner: TEST_ACCOUNT_C.address, tokenId: 0n }), ).resolves.toBe(1n); }); it("should allow to claim tokens with price", async () => { await expect( - balanceOf({ contract, owner: TEST_ACCOUNT_A.address, tokenId: 0n }), + balanceOf({ contract, owner: TEST_ACCOUNT_C.address, tokenId: 0n }), ).resolves.toBe(1n); await sendAndConfirmTransaction({ transaction: setClaimConditions({ @@ -128,11 +148,11 @@ describe.runIf(process.env.TW_SECRET_KEY)( ], tokenId: 0n, }), - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, }); const claimTx = claimTo({ contract, - to: TEST_ACCOUNT_A.address, + to: TEST_ACCOUNT_C.address, tokenId: 0n, quantity: 1n, }); @@ -143,10 +163,10 @@ describe.runIf(process.env.TW_SECRET_KEY)( expect(toEther(value)).toBe("0.001"); await sendAndConfirmTransaction({ transaction: claimTx, - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, }); await expect( - balanceOf({ contract, owner: TEST_ACCOUNT_A.address, tokenId: 0n }), + balanceOf({ contract, owner: TEST_ACCOUNT_C.address, tokenId: 0n }), ).resolves.toBe(2n); }); @@ -159,7 +179,7 @@ describe.runIf(process.env.TW_SECRET_KEY)( phases: [ { overrideList: [ - { address: TEST_ACCOUNT_A.address, maxClaimable: "100" }, + { address: TEST_ACCOUNT_C.address, maxClaimable: "100" }, { address: VITALIK_WALLET, maxClaimable: "100" }, ], maxClaimablePerWallet: 0n, @@ -167,7 +187,7 @@ describe.runIf(process.env.TW_SECRET_KEY)( ], tokenId, }), - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, }); await expect( @@ -175,10 +195,10 @@ describe.runIf(process.env.TW_SECRET_KEY)( ).resolves.toBe(0n); await sendAndConfirmTransaction({ - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, transaction: claimTo({ contract, - from: TEST_ACCOUNT_A.address, + from: TEST_ACCOUNT_C.address, to: TEST_ACCOUNT_B.address, tokenId, quantity: 1n, @@ -215,7 +235,7 @@ describe.runIf(process.env.TW_SECRET_KEY)( phases: [ { overrideList: [ - { address: TEST_ACCOUNT_A.address, maxClaimable: "1" }, + { address: TEST_ACCOUNT_C.address, maxClaimable: "1" }, { address: VITALIK_WALLET, maxClaimable: "3" }, ], maxClaimablePerWallet: 0n, @@ -223,19 +243,19 @@ describe.runIf(process.env.TW_SECRET_KEY)( ], tokenId, }), - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, }); await expect( - balanceOf({ contract, owner: TEST_ACCOUNT_A.address, tokenId }), + balanceOf({ contract, owner: TEST_ACCOUNT_C.address, tokenId }), ).resolves.toBe(0n); await expect( sendAndConfirmTransaction({ - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, transaction: claimTo({ contract, - to: TEST_ACCOUNT_A.address, + to: TEST_ACCOUNT_C.address, tokenId, quantity: 2n, }), @@ -248,17 +268,17 @@ describe.runIf(process.env.TW_SECRET_KEY)( `); await sendAndConfirmTransaction({ - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, transaction: claimTo({ contract, - to: TEST_ACCOUNT_A.address, + to: TEST_ACCOUNT_C.address, tokenId, quantity: 1n, }), }); await expect( - balanceOf({ contract, owner: TEST_ACCOUNT_A.address, tokenId }), + balanceOf({ contract, owner: TEST_ACCOUNT_C.address, tokenId }), ).resolves.toBe(1n); }); }); @@ -272,7 +292,7 @@ describe.runIf(process.env.TW_SECRET_KEY)( { overrideList: [ { - address: TEST_ACCOUNT_A.address, + address: TEST_ACCOUNT_C.address, maxClaimable: "10", price: "0", }, @@ -283,25 +303,25 @@ describe.runIf(process.env.TW_SECRET_KEY)( ], tokenId, }), - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, }); await expect( - balanceOf({ contract, owner: TEST_ACCOUNT_A.address, tokenId }), + balanceOf({ contract, owner: TEST_ACCOUNT_C.address, tokenId }), ).resolves.toBe(0n); await sendAndConfirmTransaction({ - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, transaction: claimTo({ contract, - to: TEST_ACCOUNT_A.address, + to: TEST_ACCOUNT_C.address, tokenId, quantity: 1n, }), }); await expect( - balanceOf({ contract, owner: TEST_ACCOUNT_A.address, tokenId }), + balanceOf({ contract, owner: TEST_ACCOUNT_C.address, tokenId }), ).resolves.toBe(1n); }); @@ -321,7 +341,7 @@ describe.runIf(process.env.TW_SECRET_KEY)( }, ], }), - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, }); const phases = await getClaimConditions({ contract, tokenId: 5n }); @@ -342,7 +362,7 @@ describe.runIf(process.env.TW_SECRET_KEY)( }, ], }), - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, }); // claim one token await sendAndConfirmTransaction({ @@ -384,7 +404,7 @@ describe.runIf(process.env.TW_SECRET_KEY)( tokenId: 6n, contract, }), - account: TEST_ACCOUNT_A, + account: TEST_ACCOUNT_C, }); // attempt to claim another token (this should succeed) await sendAndConfirmTransaction({ @@ -409,5 +429,115 @@ describe.runIf(process.env.TW_SECRET_KEY)( .map((f) => toFunctionSelector(f)); expect(isGetNFTsSupported(selectors)).toBe(true); }); + + /** + * This is to document the behavior where one can claim without paying if the claiming address + * is the same as the PrimaryRecipientAddress, because of this Solidity code: + * ```solidity + * // CurrencyTransferLib.sol + * function safeTransferERC20(address _currency, address _from, address _to, uint256 _amount) internal { + * if (_from == _to) { + * return; + * } + * ... + * } + * ``` + */ + it("address that is the same with PrimaryFeeRecipient can claim without paying ERC20", async () => { + const tokenAddress = await deployERC20Contract({ + client: TEST_CLIENT, + chain: ANVIL_CHAIN, + account: TEST_ACCOUNT_C, + type: "TokenERC20", + params: { + name: "token20", + contractURI: TEST_CONTRACT_URI, + }, + }); + const tokenId = 5n; + const setClaimTx = setClaimConditions({ + contract, + tokenId, + phases: [ + { + maxClaimableSupply: 100n, + maxClaimablePerWallet: 100n, + currencyAddress: tokenAddress, + price: 1000, + startTime: new Date(), + }, + ], + }); + await sendAndConfirmTransaction({ + transaction: setClaimTx, + account: TEST_ACCOUNT_C, + }); + + const transaction = claimTo({ + contract, + tokenId, + quantity: 50n, + to: TEST_ACCOUNT_C.address, + }); + await sendAndConfirmTransaction({ + transaction, + account: TEST_ACCOUNT_C, + }); + const supplyCount = await totalSupply({ contract, id: tokenId }); + expect(supplyCount).toBe(50n); + }); + + it("getActiveClaimCondition should work", async () => { + // Create a public allowlist claim phase + const snapshot = [ + { + recipient: TEST_ACCOUNT_B.address, + tokenId: 4, + amount: 5, + }, + { + recipient: TEST_ACCOUNT_D.address, + tokenId: 4, + amount: 5, + }, + ]; + + const { merkleRoot } = await generateMerkleTreeInfoERC1155({ + contract, + tokenAddress: NATIVE_TOKEN_ADDRESS, + snapshot, + }); + + const startTime = new Date(); + const setCC = setClaimConditions({ + contract, + tokenId: 4n, + phases: [ + { + maxClaimableSupply: 100n, + maxClaimablePerWallet: 5n, + currencyAddress: NATIVE_TOKEN_ADDRESS, + price: 0.006, + startTime, + merkleRootHash: merkleRoot, + }, + ], + }); + + await sendAndConfirmTransaction({ + transaction: setCC, + account: TEST_ACCOUNT_C, + }); + + const activeCC = await getActiveClaimCondition({ contract, tokenId: 4n }); + expect(activeCC.currency.toLowerCase()).toBe( + NATIVE_TOKEN_ADDRESS.toLowerCase(), + ); + expect(activeCC.merkleRoot).toBe( + "0x5baa4423af7125448ad7ca6913cdee7dd952a8d10a44f4fad4c50eea65c5c92d", + ); + expect(activeCC.pricePerToken).toBe(6000000000000000n); + expect(activeCC.quantityLimitPerWallet).toBe(5n); + }); }, ); diff --git a/packages/thirdweb/src/extensions/erc1155/drops/read/getActiveClaimCondition.test.ts b/packages/thirdweb/src/extensions/erc1155/drops/read/getActiveClaimCondition.test.ts index 064bbde9b6d..bc8462d8fa6 100644 --- a/packages/thirdweb/src/extensions/erc1155/drops/read/getActiveClaimCondition.test.ts +++ b/packages/thirdweb/src/extensions/erc1155/drops/read/getActiveClaimCondition.test.ts @@ -1,22 +1,8 @@ import { describe, expect, it } from "vitest"; - -import { ANVIL_CHAIN } from "~test/chains.js"; -import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js"; -import { TEST_CLIENT } from "~test/test-clients.js"; import { MAX_UINT256 } from "~test/test-consts.js"; -import { TEST_ACCOUNT_B } from "~test/test-wallets.js"; import { DROP1155_CONTRACT } from "../../../../../test/src/test-contracts.js"; -import { NATIVE_TOKEN_ADDRESS } from "../../../../constants/addresses.js"; -import { getContract } from "../../../../contract/contract.js"; -import { generateMerkleTreeInfoERC1155 } from "../../../../extensions/airdrop/write/merkleInfoERC1155.js"; -import { deployERC1155Contract } from "../../../../extensions/prebuilts/deploy-erc1155.js"; -import { sendAndConfirmTransaction } from "../../../../transaction/actions/send-and-confirm-transaction.js"; -import { lazyMint } from "../../write/lazyMint.js"; -import { setClaimConditions } from "../write/setClaimConditions.js"; import { getActiveClaimCondition } from "./getActiveClaimCondition.js"; -const account = TEST_ACCOUNT_B; - describe.runIf(process.env.TW_SECRET_KEY)("erc1155.getClaimConditions", () => { it("should return the correct claim conditions", async () => { const cc = await getActiveClaimCondition({ @@ -36,80 +22,4 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc1155.getClaimConditions", () => { }); // 1 call for the condition id and 1 call for the condition }); - - it("should return the correct claim condition for the public allowlist claim phase", async () => { - const address = await deployERC1155Contract({ - client: TEST_CLIENT, - chain: ANVIL_CHAIN, - account, - type: "DropERC1155", - params: { - name: "EditionDrop", - contractURI: TEST_CONTRACT_URI, - }, - }); - const contract = getContract({ - address, - chain: ANVIL_CHAIN, - client: TEST_CLIENT, - }); - - // Upload an NFT - const lzMint = lazyMint({ contract, nfts: [{ name: "token #0" }] }); - await sendAndConfirmTransaction({ - transaction: lzMint, - account, - }); - - // Create a public allowlist claim phase - const snapshot = [ - { - recipient: "0x12345674b599ce99958242b3D3741e7b01841DF3", - tokenId: 0, - amount: 5, - }, - { - recipient: "0x89f84D4e4ecaBa42233EEfc46eE49a03Db943bAD", - tokenId: 0, - amount: 5, - }, - ]; - - const { merkleRoot } = await generateMerkleTreeInfoERC1155({ - contract, - tokenAddress: NATIVE_TOKEN_ADDRESS, - snapshot, - }); - - const startTime = new Date(); - const setCC = setClaimConditions({ - contract, - tokenId: 0n, - phases: [ - { - maxClaimableSupply: 100n, - maxClaimablePerWallet: 5n, - currencyAddress: NATIVE_TOKEN_ADDRESS, - price: 0.006, - startTime, - merkleRootHash: merkleRoot, - }, - ], - }); - - await sendAndConfirmTransaction({ - transaction: setCC, - account, - }); - - const activeCC = await getActiveClaimCondition({ contract, tokenId: 0n }); - expect(activeCC.currency.toLowerCase()).toBe( - NATIVE_TOKEN_ADDRESS.toLowerCase(), - ); - expect(activeCC.merkleRoot).toBe( - "0xbfa52e7f255395704d8ea7174ec56f1357e6a1946753fcd64000adb4aeb3ca4a", - ); - expect(activeCC.pricePerToken).toBe(6000000000000000n); - expect(activeCC.quantityLimitPerWallet).toBe(5n); - }); }); diff --git a/packages/thirdweb/src/extensions/erc1155/drops/write/claimTo.test.ts b/packages/thirdweb/src/extensions/erc1155/drops/write/claimTo.test.ts deleted file mode 100644 index 5590c0a6e6c..00000000000 --- a/packages/thirdweb/src/extensions/erc1155/drops/write/claimTo.test.ts +++ /dev/null @@ -1,185 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { ANVIL_CHAIN } from "~test/chains.js"; -import { TEST_CLIENT } from "~test/test-clients.js"; -import { TEST_ACCOUNT_A, TEST_ACCOUNT_B } from "~test/test-wallets.js"; - -import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js"; -import { NATIVE_TOKEN_ADDRESS } from "../../../../constants/addresses.js"; -import { getContract } from "../../../../contract/contract.js"; -import { deployERC20Contract } from "../../../../extensions/prebuilts/deploy-erc20.js"; -import { deployERC1155Contract } from "../../../../extensions/prebuilts/deploy-erc1155.js"; -import { sendAndConfirmTransaction } from "../../../../transaction/actions/send-and-confirm-transaction.js"; -import { totalSupply } from "../../__generated__/IERC1155/read/totalSupply.js"; -import { lazyMint } from "../../write/lazyMint.js"; -import { claimTo } from "./claimTo.js"; -import { setClaimConditions } from "./setClaimConditions.js"; - -const account = TEST_ACCOUNT_A; -const client = TEST_CLIENT; -const chain = ANVIL_CHAIN; - -describe.runIf(process.env.TW_SECRET_KEY)("erc1155 claimTo extension", () => { - it("should claim the nft", async () => { - const address = await deployERC1155Contract({ - client, - chain, - account, - type: "DropERC1155", - params: { - name: "Edition Drop", - contractURI: TEST_CONTRACT_URI, - }, - }); - const contract = getContract({ - address, - client, - chain, - }); - const lazyMintTx = lazyMint({ contract, nfts: [{ name: "token 0" }] }); - await sendAndConfirmTransaction({ transaction: lazyMintTx, account }); - const setClaimTx = setClaimConditions({ - contract, - tokenId: 0n, - phases: [ - { - maxClaimableSupply: 100n, - maxClaimablePerWallet: 100n, - currencyAddress: NATIVE_TOKEN_ADDRESS, - price: 0.1, - startTime: new Date(), - }, - ], - }); - await sendAndConfirmTransaction({ transaction: setClaimTx, account }); - - const transaction = claimTo({ - contract, - tokenId: 0n, - quantity: 1n, - to: account.address, - }); - await sendAndConfirmTransaction({ transaction, account }); - const supplyCount = await totalSupply({ contract, id: 0n }); - expect(supplyCount).toBe(1n); - }); - - it("should claim with allowlist", async () => { - const address = await deployERC1155Contract({ - client, - chain, - account, - type: "DropERC1155", - params: { - name: "Edition Drop", - contractURI: TEST_CONTRACT_URI, - }, - }); - const contract = getContract({ - address, - client, - chain, - }); - const lazyMintTx = lazyMint({ contract, nfts: [{ name: "token 0" }] }); - await sendAndConfirmTransaction({ transaction: lazyMintTx, account }); - const setClaimTx = setClaimConditions({ - contract, - tokenId: 0n, - phases: [ - { - maxClaimableSupply: 100n, - maxClaimablePerWallet: 5n, - currencyAddress: NATIVE_TOKEN_ADDRESS, - price: 0.06, - startTime: new Date(), - overrideList: [ - { - address: TEST_ACCOUNT_B.address, - maxClaimable: "50", - price: "0.3", - currencyAddress: NATIVE_TOKEN_ADDRESS, - }, - ], - }, - ], - }); - await sendAndConfirmTransaction({ transaction: setClaimTx, account }); - - const transaction = claimTo({ - contract, - tokenId: 0n, - quantity: 50n, - to: TEST_ACCOUNT_B.address, - }); - await sendAndConfirmTransaction({ transaction, account: TEST_ACCOUNT_B }); - const supplyCount = await totalSupply({ contract, id: 0n }); - expect(supplyCount).toBe(50n); - }); - - /** - * This is to document the behavior where one can claim without paying if the claiming address - * is the same as the PrimaryRecipientAddress, because of this Solidity code: - * ```solidity - * // CurrencyTransferLib.sol - * function safeTransferERC20(address _currency, address _from, address _to, uint256 _amount) internal { - * if (_from == _to) { - * return; - * } - * ... - * } - * ``` - */ - it("address that is the same with PrimaryFeeRecipient can claim without paying ERC20", async () => { - const tokenAddress = await deployERC20Contract({ - client, - chain, - account, - type: "TokenERC20", - params: { - name: "token20", - contractURI: TEST_CONTRACT_URI, - }, - }); - const address = await deployERC1155Contract({ - client, - chain, - account, - type: "DropERC1155", - params: { - name: "Edition Drop", - contractURI: TEST_CONTRACT_URI, - saleRecipient: account.address, - }, - }); - const contract = getContract({ - address, - client, - chain, - }); - const lazyMintTx = lazyMint({ contract, nfts: [{ name: "token 0" }] }); - await sendAndConfirmTransaction({ transaction: lazyMintTx, account }); - const setClaimTx = setClaimConditions({ - contract, - tokenId: 0n, - phases: [ - { - maxClaimableSupply: 100n, - maxClaimablePerWallet: 100n, - currencyAddress: tokenAddress, - price: 1000, - startTime: new Date(), - }, - ], - }); - await sendAndConfirmTransaction({ transaction: setClaimTx, account }); - - const transaction = claimTo({ - contract, - tokenId: 0n, - quantity: 1n, - to: account.address, - }); - await sendAndConfirmTransaction({ transaction, account }); - const supplyCount = await totalSupply({ contract, id: 0n }); - expect(supplyCount).toBe(1n); - }); -}); diff --git a/packages/thirdweb/src/extensions/erc1155/drops/write/updateMetadata.test.ts b/packages/thirdweb/src/extensions/erc1155/drops/write/updateMetadata.test.ts deleted file mode 100644 index 33d1b02f5a7..00000000000 --- a/packages/thirdweb/src/extensions/erc1155/drops/write/updateMetadata.test.ts +++ /dev/null @@ -1,54 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { ANVIL_CHAIN } from "~test/chains.js"; -import { TEST_CLIENT } from "~test/test-clients.js"; -import { TEST_ACCOUNT_A } from "~test/test-wallets.js"; - -import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js"; -import { getContract } from "../../../../contract/contract.js"; -import { deployERC1155Contract } from "../../../../extensions/prebuilts/deploy-erc1155.js"; -import { sendAndConfirmTransaction } from "../../../../transaction/actions/send-and-confirm-transaction.js"; -import { getNFTs } from "../../read/getNFTs.js"; -import { lazyMint } from "../../write/lazyMint.js"; -import { updateMetadata } from "./updateMetadata.js"; - -const account = TEST_ACCOUNT_A; -const client = TEST_CLIENT; -const chain = ANVIL_CHAIN; -describe.runIf(process.env.TW_SECRET_KEY)("updateMetadata ERC1155", () => { - it("should update metadata", async () => { - const address = await deployERC1155Contract({ - client, - chain, - account, - type: "DropERC1155", - params: { - name: "Edition Drop", - contractURI: TEST_CONTRACT_URI, - }, - }); - const contract = getContract({ - address, - client, - chain, - }); - const lazyMintTx = lazyMint({ - contract, - nfts: [{ name: "token 0" }, { name: "token 1" }, { name: "token 2" }], - }); - await sendAndConfirmTransaction({ transaction: lazyMintTx, account }); - - const updateTx = updateMetadata({ - contract, - targetTokenId: 1n, - newMetadata: { name: "token 1 - updated" }, - }); - await sendAndConfirmTransaction({ transaction: updateTx, account }); - - const nfts = await getNFTs({ contract }); - - expect(nfts.length).toBe(3); - expect(nfts[0]?.metadata.name).toBe("token 0"); - expect(nfts[1]?.metadata.name).toBe("token 1 - updated"); - expect(nfts[2]?.metadata.name).toBe("token 2"); - }); -});