|
1 | | -import { beforeAll, describe, expect, it, vi } from "vitest"; |
| 1 | +import { describe, expect, it } from "vitest"; |
| 2 | +import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js"; |
| 3 | +import { TEST_ACCOUNT_D } from "~test/test-wallets.js"; |
2 | 4 | import { ANVIL_CHAIN } from "../../../../../test/src/chains.js"; |
3 | 5 | import { TEST_CLIENT } from "../../../../../test/src/test-clients.js"; |
4 | | -import { |
5 | | - type ThirdwebContract, |
6 | | - getContract, |
7 | | -} from "../../../../contract/contract.js"; |
8 | | -import type { Hex } from "../../../../utils/encoding/hex.js"; |
| 6 | +import { getContract } from "../../../../contract/contract.js"; |
| 7 | +import { deployERC721Contract } from "../../../../extensions/prebuilts/deploy-erc721.js"; |
| 8 | +import { sendAndConfirmTransaction } from "../../../../transaction/actions/send-and-confirm-transaction.js"; |
| 9 | +import { getNFT } from "../../read/getNFT.js"; |
9 | 10 | import { createDelayedRevealBatch } from "./createDelayedRevealBatch.js"; |
| 11 | +import { reveal } from "./reveal.js"; |
10 | 12 |
|
11 | | -const mocks = vi.hoisted(() => ({ |
12 | | - getBaseUriFromBatch: vi.fn(), |
13 | | - getBaseURICount: vi.fn(), |
14 | | - encryptDecrypt: vi.fn(), |
15 | | - lazyMint: vi.fn(), |
16 | | - upload: vi.fn(), |
17 | | -})); |
18 | | - |
19 | | -vi.mock("../../../../utils/ipfs.js", () => ({ |
20 | | - getBaseUriFromBatch: mocks.getBaseUriFromBatch, |
21 | | -})); |
22 | | - |
23 | | -vi.mock( |
24 | | - "../../__generated__/IBatchMintMetadata/read/getBaseURICount.js", |
25 | | - () => ({ |
26 | | - getBaseURICount: mocks.getBaseURICount, |
27 | | - }), |
28 | | -); |
29 | | - |
30 | | -vi.mock("../../__generated__/IDelayedReveal/read/encryptDecrypt.js", () => ({ |
31 | | - encryptDecrypt: mocks.encryptDecrypt, |
32 | | -})); |
33 | | - |
34 | | -vi.mock("../../../../storage/upload.js", () => ({ |
35 | | - upload: mocks.upload, |
36 | | -})); |
37 | | - |
38 | | -const placeholderNFT = { |
| 13 | +const placeholderMetadata = { |
39 | 14 | name: "Hidden NFT", |
40 | 15 | description: "Will be revealed next week!", |
41 | 16 | }; |
| 17 | +const account = TEST_ACCOUNT_D; |
| 18 | +const chain = ANVIL_CHAIN; |
| 19 | +const client = TEST_CLIENT; |
| 20 | +const password = "1234"; |
42 | 21 |
|
43 | | -const realNFTs = [ |
44 | | - { |
45 | | - name: "Common NFT #1", |
46 | | - description: "Common NFT, one of many.", |
47 | | - }, |
48 | | - { |
49 | | - name: "Super Rare NFT #2", |
50 | | - description: "You got a Super Rare NFT!", |
51 | | - }, |
52 | | -]; |
| 22 | +describe.runIf(process.env.TW_SECRET_KEY)("createDelayedRevealedBatch", () => { |
| 23 | + it("should create delayed-reveal batches properly", async () => { |
| 24 | + const contract = getContract({ |
| 25 | + address: await deployERC721Contract({ |
| 26 | + account, |
| 27 | + chain, |
| 28 | + client, |
| 29 | + type: "DropERC721", |
| 30 | + params: { |
| 31 | + name: "nftdrop", |
| 32 | + contractURI: TEST_CONTRACT_URI, |
| 33 | + }, |
| 34 | + }), |
| 35 | + chain, |
| 36 | + client, |
| 37 | + }); |
53 | 38 |
|
54 | | -describe.skip("createDelayedRevealedBatch", () => { |
55 | | - let contract: ThirdwebContract; |
56 | | - beforeAll(() => { |
57 | | - vi.clearAllMocks(); |
58 | | - contract = getContract({ |
59 | | - chain: ANVIL_CHAIN, |
60 | | - address: "0x708781BAE850faA490cB5b5b16b4687Ec0A8D65D", |
61 | | - client: TEST_CLIENT, |
| 39 | + // Create batch #0 |
| 40 | + await sendAndConfirmTransaction({ |
| 41 | + account, |
| 42 | + transaction: createDelayedRevealBatch({ |
| 43 | + contract, |
| 44 | + placeholderMetadata, |
| 45 | + password: "1234", |
| 46 | + metadata: [{ name: "token 0" }, { name: "token 1" }], |
| 47 | + }), |
62 | 48 | }); |
63 | | - }); |
64 | 49 |
|
65 | | - it("should generate the proper calldata", async () => { |
66 | | - mocks.getBaseUriFromBatch |
67 | | - .mockReturnValueOnce( |
68 | | - "ipfs://QmQbqDu4aT7sMJHNUk76s4F6DgGk2hVYXYSqpsTRoRM5G8/", |
69 | | - ) |
70 | | - .mockReturnValueOnce( |
71 | | - "ipfs://QmRhASFGXNRE3NXNTfakz82j4Tmv5A9rBezTKGZ5DL6uip/", |
72 | | - ); |
73 | | - mocks.getBaseURICount.mockResolvedValue(0n); |
74 | | - mocks.encryptDecrypt.mockResolvedValue( |
75 | | - "0x8967ae24bd1c6439791bc1c8ca3b3499537283b71af366693792a707eb99e80bc0058c90c1f92f18ec716e4760fdf9279241d442b5b5", |
76 | | - ); |
| 50 | + // Create batch #1 |
| 51 | + await sendAndConfirmTransaction({ |
| 52 | + account, |
| 53 | + transaction: createDelayedRevealBatch({ |
| 54 | + contract, |
| 55 | + placeholderMetadata, |
| 56 | + password, |
| 57 | + metadata: [{ name: "token 2" }, { name: "token 3" }], |
| 58 | + }), |
| 59 | + }); |
77 | 60 |
|
78 | | - const tx = createDelayedRevealBatch({ |
79 | | - contract, |
80 | | - placeholderMetadata: placeholderNFT, |
81 | | - metadata: realNFTs, |
82 | | - password: "password123", |
| 61 | + // Reveal batch #0 |
| 62 | + await sendAndConfirmTransaction({ |
| 63 | + account, |
| 64 | + transaction: reveal({ contract, batchId: 0n, password }), |
| 65 | + }); |
| 66 | + // Reveal batch #1 |
| 67 | + await sendAndConfirmTransaction({ |
| 68 | + account, |
| 69 | + transaction: reveal({ contract, batchId: 1n, password }), |
83 | 70 | }); |
84 | 71 |
|
85 | | - let data: Hex; |
86 | | - if (typeof tx.data === "string") { |
87 | | - data = tx.data; |
88 | | - } else { |
89 | | - data = (await tx.data?.()) || "0x"; |
90 | | - } |
| 72 | + /** |
| 73 | + * The token URIs of batch 0 should end with "/0" and "/1" |
| 74 | + * while the token URIs of batch 1 should end with "/2" and "/3" |
| 75 | + */ |
| 76 | + const [token0, token1, token2, token3] = await Promise.all([ |
| 77 | + getNFT({ contract, tokenId: 0n }), |
| 78 | + getNFT({ contract, tokenId: 1n }), |
| 79 | + getNFT({ contract, tokenId: 2n }), |
| 80 | + getNFT({ contract, tokenId: 3n }), |
| 81 | + ]); |
91 | 82 |
|
92 | | - expect(data).toEqual( |
93 | | - "0xd37c353b0000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000036697066733a2f2f516d516271447534615437734d4a484e556b3736733446364467476b3268565958595371707354526f524d3547382f0000000000000000000000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000040963325533d81f66ae93aff4f562735814e51020ea8bf2bd48eb983ae88cbc40b00000000000000000000000000000000000000000000000000000000000000368967ae24bd1c6439791bc1c8ca3b3499537283b71af366693792a707eb99e80bc0058c90c1f92f18ec716e4760fdf9279241d442b5b500000000000000000000", |
94 | | - ); |
95 | | - expect(mocks.upload).toHaveBeenCalledTimes(2); |
| 83 | + expect(token0.tokenURI.endsWith("/0")).toBe(true); |
| 84 | + expect(token0.metadata.name).toBe("token 0"); |
| 85 | + expect(token1.tokenURI.endsWith("/1")).toBe(true); |
| 86 | + expect(token1.metadata.name).toBe("token 1"); |
| 87 | + expect(token2.tokenURI.endsWith("/2")).toBe(true); |
| 88 | + expect(token2.metadata.name).toBe("token 2"); |
| 89 | + expect(token3.tokenURI.endsWith("/3")).toBe(true); |
| 90 | + expect(token3.metadata.name).toBe("token 3"); |
96 | 91 | }); |
97 | 92 | }); |
0 commit comments