|
| 1 | +import { type Abi, toFunctionSelector } from "viem"; |
1 | 2 | import { beforeAll, describe, expect, it } from "vitest";
|
2 | 3 | import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js";
|
3 | 4 | import { ANVIL_CHAIN } from "../../../test/src/chains.js";
|
4 | 5 | import { TEST_CLIENT } from "../../../test/src/test-clients.js";
|
5 | 6 | import {
|
6 | 7 | TEST_ACCOUNT_A,
|
7 | 8 | TEST_ACCOUNT_B,
|
| 9 | + TEST_ACCOUNT_C, |
8 | 10 | } from "../../../test/src/test-wallets.js";
|
| 11 | +import { resolveContractAbi } from "../../contract/actions/resolve-abi.js"; |
9 | 12 | import { type ThirdwebContract, getContract } from "../../contract/contract.js";
|
10 | 13 | import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
|
11 | 14 | import { deployERC1155Contract } from "../prebuilts/deploy-erc1155.js";
|
12 | 15 | import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
|
13 | 16 | import { totalSupply } from "./__generated__/IERC1155/read/totalSupply.js";
|
| 17 | +import { uri } from "./__generated__/IERC1155/read/uri.js"; |
14 | 18 | import { nextTokenIdToMint } from "./__generated__/IERC1155Enumerable/read/nextTokenIdToMint.js";
|
15 | 19 | import { getNFT } from "./read/getNFT.js";
|
16 |
| -import { getNFTs } from "./read/getNFTs.js"; |
17 |
| -import { mintAdditionalSupplyTo } from "./write/mintAdditionalSupplyTo.js"; |
| 20 | +import { getNFTs, isGetNFTsSupported } from "./read/getNFTs.js"; |
| 21 | +import { getOwnedTokenIds } from "./read/getOwnedTokenIds.js"; |
| 22 | +import { |
| 23 | + isMintAdditionalSupplyToSupported, |
| 24 | + mintAdditionalSupplyTo, |
| 25 | +} from "./write/mintAdditionalSupplyTo.js"; |
| 26 | +import { mintAdditionalSupplyToBatch } from "./write/mintAdditionalSupplyToBatch.js"; |
18 | 27 | import { mintTo } from "./write/mintTo.js";
|
| 28 | +import { mintToBatch } from "./write/mintToBatch.js"; |
| 29 | +import { updateTokenURI } from "./write/updateTokenURI.js"; |
19 | 30 |
|
20 | 31 | describe.runIf(process.env.TW_SECRET_KEY)("TokenERC1155", () => {
|
21 | 32 | let contract: ThirdwebContract;
|
@@ -158,4 +169,161 @@ describe.runIf(process.env.TW_SECRET_KEY)("TokenERC1155", () => {
|
158 | 169 | ]
|
159 | 170 | `);
|
160 | 171 | });
|
| 172 | + |
| 173 | + it("isGetNFTsSupported should work with our Edition contracts", async () => { |
| 174 | + const abi = await resolveContractAbi<Abi>(contract); |
| 175 | + const selectors = abi |
| 176 | + .filter((f) => f.type === "function") |
| 177 | + .map((f) => toFunctionSelector(f)); |
| 178 | + expect(isGetNFTsSupported(selectors)).toBe(true); |
| 179 | + }); |
| 180 | + |
| 181 | + // tokenId #0 is updated in this test |
| 182 | + it("should update tokenURI", async () => { |
| 183 | + await sendAndConfirmTransaction({ |
| 184 | + transaction: updateTokenURI({ |
| 185 | + contract, |
| 186 | + newMetadata: { name: "Test1 Updated" }, |
| 187 | + tokenId: 0n, |
| 188 | + }), |
| 189 | + account: TEST_ACCOUNT_A, |
| 190 | + }); |
| 191 | + const nft = await getNFT({ contract, tokenId: 0n }); |
| 192 | + expect(nft.metadata.name).toBe("Test1 Updated"); |
| 193 | + }); |
| 194 | + |
| 195 | + it("should mint with `nft` being declared as a string", async () => { |
| 196 | + await sendAndConfirmTransaction({ |
| 197 | + transaction: mintTo({ |
| 198 | + contract, |
| 199 | + nft: TEST_CONTRACT_URI, |
| 200 | + to: TEST_ACCOUNT_A.address, |
| 201 | + supply: 1n, |
| 202 | + }), |
| 203 | + account: TEST_ACCOUNT_A, |
| 204 | + }); |
| 205 | + |
| 206 | + const tokenUri = await uri({ contract, tokenId: 2n }); |
| 207 | + expect(tokenUri).toBe(TEST_CONTRACT_URI); |
| 208 | + }); |
| 209 | + |
| 210 | + it("`isMintAdditionalSupplyToSupported` should work with our Edition contracts", async () => { |
| 211 | + const abi = await resolveContractAbi<Abi>(contract); |
| 212 | + const selectors = abi |
| 213 | + .filter((f) => f.type === "function") |
| 214 | + .map((f) => toFunctionSelector(f)); |
| 215 | + expect(isMintAdditionalSupplyToSupported(selectors)).toBe(true); |
| 216 | + }); |
| 217 | + |
| 218 | + it("should mint multiple tokens in one tx", async () => { |
| 219 | + await sendAndConfirmTransaction({ |
| 220 | + account: TEST_ACCOUNT_A, |
| 221 | + transaction: mintToBatch({ |
| 222 | + contract, |
| 223 | + to: TEST_ACCOUNT_C.address, |
| 224 | + nfts: [ |
| 225 | + { metadata: { name: "batch token 0" }, supply: 1n }, |
| 226 | + { metadata: { name: "batch token 1" }, supply: 2n }, |
| 227 | + { metadata: { name: "batch token 2" }, supply: 3n }, |
| 228 | + ], |
| 229 | + }), |
| 230 | + }); |
| 231 | + |
| 232 | + const nfts = await getNFTs({ contract }); |
| 233 | + expect(nfts).toStrictEqual([ |
| 234 | + { |
| 235 | + // Updated tokenURI from the test above |
| 236 | + metadata: { name: "Test1 Updated" }, |
| 237 | + owner: null, |
| 238 | + id: 0n, |
| 239 | + tokenURI: "ipfs://QmTSyt6YgoFtH8yhWgevC22BxjyrkCKuzdk86nqQJCwrV9/0", |
| 240 | + type: "ERC1155", |
| 241 | + supply: 15n, |
| 242 | + }, |
| 243 | + { |
| 244 | + metadata: { name: "Test NFT 2" }, |
| 245 | + owner: null, |
| 246 | + id: 1n, |
| 247 | + tokenURI: "ipfs://QmV6gsfzdiMRtpnh8ay3CgutStVbes7qoF4DKpYE64h8hT/0", |
| 248 | + type: "ERC1155", |
| 249 | + supply: 5n, |
| 250 | + }, |
| 251 | + { |
| 252 | + metadata: { |
| 253 | + name: "tw-contract-name", |
| 254 | + symbol: "tw-contract-symbol", |
| 255 | + description: "tw-contract-description", |
| 256 | + }, |
| 257 | + owner: null, |
| 258 | + id: 2n, |
| 259 | + // Minted using URI from the test above |
| 260 | + tokenURI: |
| 261 | + "ipfs://bafybeiewg2e3vehsb5pb34xwk25eyyfwlvajzmgz3rtdrvn3upsxnsbhzi/contractUri.json", |
| 262 | + type: "ERC1155", |
| 263 | + supply: 1n, |
| 264 | + }, |
| 265 | + { |
| 266 | + metadata: { name: "batch token 0" }, |
| 267 | + owner: null, |
| 268 | + id: 3n, |
| 269 | + tokenURI: "ipfs://QmPSQhC2J6Wig4pH1Lt5th19FM58J5oukhfLfpc9L1i39Q/0", |
| 270 | + type: "ERC1155", |
| 271 | + supply: 1n, |
| 272 | + }, |
| 273 | + { |
| 274 | + metadata: { name: "batch token 1" }, |
| 275 | + owner: null, |
| 276 | + id: 4n, |
| 277 | + tokenURI: "ipfs://QmWRQwLBAeq6Wr65Yj7A4aeYqMD1C7Hs1moz15ncS6EhGu/0", |
| 278 | + type: "ERC1155", |
| 279 | + supply: 2n, |
| 280 | + }, |
| 281 | + { |
| 282 | + metadata: { name: "batch token 2" }, |
| 283 | + owner: null, |
| 284 | + id: 5n, |
| 285 | + tokenURI: "ipfs://QmTg1wxKGvdZR4NrdkYZGcfB5YYaBz75DH83td5RwprMRP/0", |
| 286 | + type: "ERC1155", |
| 287 | + supply: 3n, |
| 288 | + }, |
| 289 | + ]); |
| 290 | + }); |
| 291 | + |
| 292 | + it("getOwnedTokenIds should work", async () => { |
| 293 | + const ownedTokenIds = await getOwnedTokenIds({ |
| 294 | + contract, |
| 295 | + address: TEST_ACCOUNT_C.address, |
| 296 | + }); |
| 297 | + expect(ownedTokenIds).toStrictEqual([ |
| 298 | + { tokenId: 3n, balance: 1n }, |
| 299 | + { tokenId: 4n, balance: 2n }, |
| 300 | + { tokenId: 5n, balance: 3n }, |
| 301 | + ]); |
| 302 | + }); |
| 303 | + |
| 304 | + it("should mint multiple ADDITIONAL tokens in one tx", async () => { |
| 305 | + await sendAndConfirmTransaction({ |
| 306 | + account: TEST_ACCOUNT_A, |
| 307 | + transaction: mintAdditionalSupplyToBatch({ |
| 308 | + contract, |
| 309 | + nfts: [ |
| 310 | + { tokenId: 3n, supply: 99n, to: TEST_ACCOUNT_C.address }, |
| 311 | + { tokenId: 4n, supply: 94n, to: TEST_ACCOUNT_C.address }, |
| 312 | + { tokenId: 5n, supply: 97n, to: TEST_ACCOUNT_C.address }, |
| 313 | + { tokenId: 3n, supply: 4n, to: TEST_ACCOUNT_C.address }, |
| 314 | + ], |
| 315 | + }), |
| 316 | + }); |
| 317 | + |
| 318 | + const ownedTokenIds = await getOwnedTokenIds({ |
| 319 | + contract, |
| 320 | + address: TEST_ACCOUNT_C.address, |
| 321 | + }); |
| 322 | + |
| 323 | + expect(ownedTokenIds).toStrictEqual([ |
| 324 | + { tokenId: 3n, balance: 104n }, |
| 325 | + { tokenId: 4n, balance: 96n }, |
| 326 | + { tokenId: 5n, balance: 100n }, |
| 327 | + ]); |
| 328 | + }); |
161 | 329 | });
|
0 commit comments