Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions packages/thirdweb/src/extensions/erc1155/drop1155.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { type Abi, toFunctionSelector } from "viem";
import { beforeAll, describe, expect, it } from "vitest";
import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js";
import { VITALIK_WALLET } from "../../../test/src/addresses.js";
Expand All @@ -8,6 +9,7 @@ import {
TEST_ACCOUNT_B,
TEST_ACCOUNT_D,
} from "../../../test/src/test-wallets.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";
Expand All @@ -20,6 +22,7 @@ import { claimTo } from "./drops/write/claimTo.js";
import { resetClaimEligibility } from "./drops/write/resetClaimEligibility.js";
import { setClaimConditions } from "./drops/write/setClaimConditions.js";
import { getNFT } from "./read/getNFT.js";
import { isGetNFTsSupported } from "./read/getNFTs.js";
import { lazyMint } from "./write/lazyMint.js";

describe.runIf(process.env.TW_SECRET_KEY)(
Expand Down Expand Up @@ -398,5 +401,13 @@ describe.runIf(process.env.TW_SECRET_KEY)(
balanceOf({ tokenId: 6n, contract, owner: TEST_ACCOUNT_D.address }),
).resolves.toBe(2n);
});

it("isGetNFTsSupported should work with our Edition Drop contracts", async () => {
const abi = await resolveContractAbi<Abi>(contract);
const selectors = abi
.filter((f) => f.type === "function")
.map((f) => toFunctionSelector(f));
expect(isGetNFTsSupported(selectors)).toBe(true);
});
},
);
44 changes: 0 additions & 44 deletions packages/thirdweb/src/extensions/erc1155/read/getNFTs.test.ts

This file was deleted.

This file was deleted.

This file was deleted.

172 changes: 170 additions & 2 deletions packages/thirdweb/src/extensions/erc1155/token1155.test.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
import { type Abi, toFunctionSelector } from "viem";
import { beforeAll, describe, expect, it } from "vitest";
import { TEST_CONTRACT_URI } from "~test/ipfs-uris.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,
} from "../../../test/src/test-wallets.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 { deployERC1155Contract } from "../prebuilts/deploy-erc1155.js";
import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
import { totalSupply } from "./__generated__/IERC1155/read/totalSupply.js";
import { uri } from "./__generated__/IERC1155/read/uri.js";
import { nextTokenIdToMint } from "./__generated__/IERC1155Enumerable/read/nextTokenIdToMint.js";
import { getNFT } from "./read/getNFT.js";
import { getNFTs } from "./read/getNFTs.js";
import { mintAdditionalSupplyTo } from "./write/mintAdditionalSupplyTo.js";
import { getNFTs, isGetNFTsSupported } from "./read/getNFTs.js";
import { getOwnedTokenIds } from "./read/getOwnedTokenIds.js";
import {
isMintAdditionalSupplyToSupported,
mintAdditionalSupplyTo,
} from "./write/mintAdditionalSupplyTo.js";
import { mintAdditionalSupplyToBatch } from "./write/mintAdditionalSupplyToBatch.js";
import { mintTo } from "./write/mintTo.js";
import { mintToBatch } from "./write/mintToBatch.js";
import { updateTokenURI } from "./write/updateTokenURI.js";

describe.runIf(process.env.TW_SECRET_KEY)("TokenERC1155", () => {
let contract: ThirdwebContract;
Expand Down Expand Up @@ -158,4 +169,161 @@ describe.runIf(process.env.TW_SECRET_KEY)("TokenERC1155", () => {
]
`);
});

it("isGetNFTsSupported should work with our Edition contracts", async () => {
const abi = await resolveContractAbi<Abi>(contract);
const selectors = abi
.filter((f) => f.type === "function")
.map((f) => toFunctionSelector(f));
expect(isGetNFTsSupported(selectors)).toBe(true);
});

// tokenId #0 is updated in this test
it("should update tokenURI", async () => {
await sendAndConfirmTransaction({
transaction: updateTokenURI({
contract,
newMetadata: { name: "Test1 Updated" },
tokenId: 0n,
}),
account: TEST_ACCOUNT_A,
});
const nft = await getNFT({ contract, tokenId: 0n });
expect(nft.metadata.name).toBe("Test1 Updated");
});

it("should mint with `nft` being declared as a string", async () => {
await sendAndConfirmTransaction({
transaction: mintTo({
contract,
nft: TEST_CONTRACT_URI,
to: TEST_ACCOUNT_A.address,
supply: 1n,
}),
account: TEST_ACCOUNT_A,
});

const tokenUri = await uri({ contract, tokenId: 2n });
expect(tokenUri).toBe(TEST_CONTRACT_URI);
});

it("`isMintAdditionalSupplyToSupported` should work with our Edition contracts", async () => {
const abi = await resolveContractAbi<Abi>(contract);
const selectors = abi
.filter((f) => f.type === "function")
.map((f) => toFunctionSelector(f));
expect(isMintAdditionalSupplyToSupported(selectors)).toBe(true);
});

it("should mint multiple tokens in one tx", async () => {
await sendAndConfirmTransaction({
account: TEST_ACCOUNT_A,
transaction: mintToBatch({
contract,
to: TEST_ACCOUNT_C.address,
nfts: [
{ metadata: { name: "batch token 0" }, supply: 1n },
{ metadata: { name: "batch token 1" }, supply: 2n },
{ metadata: { name: "batch token 2" }, supply: 3n },
],
}),
});

const nfts = await getNFTs({ contract });
expect(nfts).toStrictEqual([
{
// Updated tokenURI from the test above
metadata: { name: "Test1 Updated" },
owner: null,
id: 0n,
tokenURI: "ipfs://QmTSyt6YgoFtH8yhWgevC22BxjyrkCKuzdk86nqQJCwrV9/0",
type: "ERC1155",
supply: 15n,
},
{
metadata: { name: "Test NFT 2" },
owner: null,
id: 1n,
tokenURI: "ipfs://QmV6gsfzdiMRtpnh8ay3CgutStVbes7qoF4DKpYE64h8hT/0",
type: "ERC1155",
supply: 5n,
},
{
metadata: {
name: "tw-contract-name",
symbol: "tw-contract-symbol",
description: "tw-contract-description",
},
owner: null,
id: 2n,
// Minted using URI from the test above
tokenURI:
"ipfs://bafybeiewg2e3vehsb5pb34xwk25eyyfwlvajzmgz3rtdrvn3upsxnsbhzi/contractUri.json",
type: "ERC1155",
supply: 1n,
},
{
metadata: { name: "batch token 0" },
owner: null,
id: 3n,
tokenURI: "ipfs://QmPSQhC2J6Wig4pH1Lt5th19FM58J5oukhfLfpc9L1i39Q/0",
type: "ERC1155",
supply: 1n,
},
{
metadata: { name: "batch token 1" },
owner: null,
id: 4n,
tokenURI: "ipfs://QmWRQwLBAeq6Wr65Yj7A4aeYqMD1C7Hs1moz15ncS6EhGu/0",
type: "ERC1155",
supply: 2n,
},
{
metadata: { name: "batch token 2" },
owner: null,
id: 5n,
tokenURI: "ipfs://QmTg1wxKGvdZR4NrdkYZGcfB5YYaBz75DH83td5RwprMRP/0",
type: "ERC1155",
supply: 3n,
},
]);
});

it("getOwnedTokenIds should work", async () => {
const ownedTokenIds = await getOwnedTokenIds({
contract,
address: TEST_ACCOUNT_C.address,
});
expect(ownedTokenIds).toStrictEqual([
{ tokenId: 3n, balance: 1n },
{ tokenId: 4n, balance: 2n },
{ tokenId: 5n, balance: 3n },
]);
});

it("should mint multiple ADDITIONAL tokens in one tx", async () => {
await sendAndConfirmTransaction({
account: TEST_ACCOUNT_A,
transaction: mintAdditionalSupplyToBatch({
contract,
nfts: [
{ tokenId: 3n, supply: 99n, to: TEST_ACCOUNT_C.address },
{ tokenId: 4n, supply: 94n, to: TEST_ACCOUNT_C.address },
{ tokenId: 5n, supply: 97n, to: TEST_ACCOUNT_C.address },
{ tokenId: 3n, supply: 4n, to: TEST_ACCOUNT_C.address },
],
}),
});

const ownedTokenIds = await getOwnedTokenIds({
contract,
address: TEST_ACCOUNT_C.address,
});

expect(ownedTokenIds).toStrictEqual([
{ tokenId: 3n, balance: 104n },
{ tokenId: 4n, balance: 96n },
{ tokenId: 5n, balance: 100n },
]);
});
});
Loading
Loading