Skip to content

Commit 681c450

Browse files
committed
update
1 parent f40d247 commit 681c450

File tree

12 files changed

+158
-334
lines changed

12 files changed

+158
-334
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-co
1616
import { resolvePromisedValue } from "../../utils/promise/resolve-promised-value.js";
1717
import { toEther } from "../../utils/units.js";
1818
import { generateMerkleTreeInfoERC1155 } from "../airdrop/write/merkleInfoERC1155.js";
19+
import { name } from "../common/read/name.js";
1920
import { deployERC20Contract } from "../prebuilts/deploy-erc20.js";
2021
import { deployERC1155Contract } from "../prebuilts/deploy-erc1155.js";
2122
import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
@@ -45,12 +46,21 @@ describe.runIf(process.env.TW_SECRET_KEY)(
4546
chain: ANVIL_CHAIN,
4647
client: TEST_CLIENT,
4748
params: {
48-
name: "Test DropERC1155",
49-
contractURI: TEST_CONTRACT_URI,
49+
name: "EditionDrop",
5050
},
5151
type: "DropERC1155",
5252
});
5353

54+
expect(contractAddress).toBeDefined();
55+
const deployedName = await name({
56+
contract: getContract({
57+
client: TEST_CLIENT,
58+
chain: ANVIL_CHAIN,
59+
address: contractAddress,
60+
}),
61+
});
62+
expect(deployedName).toBe("EditionDrop");
63+
5464
contract = getContract({
5565
address: contractAddress,
5666
chain: ANVIL_CHAIN,

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { resolveContractAbi } from "../../contract/actions/resolve-abi.js";
1212
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
1313
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
14+
import { name } from "../common/read/name.js";
1415
import { deployERC1155Contract } from "../prebuilts/deploy-erc1155.js";
1516
import { balanceOf } from "./__generated__/IERC1155/read/balanceOf.js";
1617
import { totalSupply } from "./__generated__/IERC1155/read/totalSupply.js";
@@ -37,12 +38,21 @@ describe.runIf(process.env.TW_SECRET_KEY)("TokenERC1155", () => {
3738
chain: ANVIL_CHAIN,
3839
client: TEST_CLIENT,
3940
params: {
40-
name: "Test TokenERC1155",
41-
contractURI: TEST_CONTRACT_URI,
41+
name: "Edition",
4242
},
4343
type: "TokenERC1155",
4444
});
4545

46+
expect(contractAddress).toBeDefined();
47+
const deployedName = await name({
48+
contract: getContract({
49+
client: TEST_CLIENT,
50+
chain: ANVIL_CHAIN,
51+
address: contractAddress,
52+
}),
53+
});
54+
expect(deployedName).toBe("Edition");
55+
4656
contract = getContract({
4757
address: contractAddress,
4858
chain: ANVIL_CHAIN,

packages/thirdweb/src/extensions/erc1155/write/mintAdditionalSupplyToBatch.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import {} from "viem";
21
import { describe, expect, it } from "vitest";
32
import { TEST_ACCOUNT_C } from "~test/test-wallets.js";
43
import { optimizeMintBatchContent } from "./mintAdditionalSupplyToBatch.js";

packages/thirdweb/src/extensions/erc20/drop20.test.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { beforeAll, describe, expect, it } from "vitest";
2-
import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js";
32
import { VITALIK_WALLET } from "../../../test/src/addresses.js";
43
import { ANVIL_CHAIN } from "../../../test/src/chains.js";
54
import { TEST_CLIENT } from "../../../test/src/test-clients.js";
@@ -13,6 +12,7 @@ import { type ThirdwebContract, getContract } from "../../contract/contract.js";
1312
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
1413
import { resolvePromisedValue } from "../../utils/promise/resolve-promised-value.js";
1514
import { toEther } from "../../utils/units.js";
15+
import { name } from "../common/read/name.js";
1616
import { deployERC20Contract } from "../prebuilts/deploy-erc20.js";
1717
import { getClaimConditions } from "./drops/read/getClaimConditions.js";
1818
import { claimTo } from "./drops/write/claimTo.js";
@@ -35,11 +35,20 @@ describe.runIf(process.env.TW_SECRET_KEY)(
3535
client: TEST_CLIENT,
3636
params: {
3737
name: "Test DropERC20",
38-
contractURI: TEST_CONTRACT_URI,
3938
},
4039
type: "DropERC20",
4140
});
4241

42+
expect(contractAddress).toBeDefined();
43+
const deployedName = await name({
44+
contract: getContract({
45+
client: TEST_CLIENT,
46+
chain: ANVIL_CHAIN,
47+
address: contractAddress,
48+
}),
49+
});
50+
expect(deployedName).toBe("Test DropERC20");
51+
4352
contract = getContract({
4453
address: contractAddress,
4554
chain: ANVIL_CHAIN,

packages/thirdweb/src/extensions/erc721/drop721.test.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { type ThirdwebContract, getContract } from "../../contract/contract.js";
1313
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
1414
import { resolvePromisedValue } from "../../utils/promise/resolve-promised-value.js";
1515
import { toEther } from "../../utils/units.js";
16+
import { name } from "../common/read/name.js";
1617
import { deployERC20Contract } from "../prebuilts/deploy-erc20.js";
1718
import { deployERC721Contract } from "../prebuilts/deploy-erc721.js";
1819
import { balanceOf } from "./__generated__/IERC721A/read/balanceOf.js";
@@ -40,11 +41,19 @@ describe.runIf(process.env.TW_SECRET_KEY)(
4041
client: TEST_CLIENT,
4142
params: {
4243
name: "Test DropERC721",
43-
contractURI: TEST_CONTRACT_URI,
4444
},
4545
type: "DropERC721",
4646
});
4747

48+
contract = getContract({
49+
address: contractAddress,
50+
chain: ANVIL_CHAIN,
51+
client: TEST_CLIENT,
52+
});
53+
54+
const deployedName = await name({ contract });
55+
expect(deployedName).toBe("Test DropERC721");
56+
4857
const erc20ContractAddress = await deployERC20Contract({
4958
account: TEST_ACCOUNT_A,
5059
chain: ANVIL_CHAIN,
@@ -61,12 +70,6 @@ describe.runIf(process.env.TW_SECRET_KEY)(
6170
chain: ANVIL_CHAIN,
6271
client: TEST_CLIENT,
6372
});
64-
65-
contract = getContract({
66-
address: contractAddress,
67-
chain: ANVIL_CHAIN,
68-
client: TEST_CLIENT,
69-
});
7073
// this deploys a contract, it may take some time
7174
}, 120_000);
7275

packages/thirdweb/src/extensions/erc721/read/getNFT.test.ts

Lines changed: 0 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,5 @@
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 { DOODLES_CONTRACT } from "~test/test-contracts.js";
7-
import { TEST_ACCOUNT_A } from "~test/test-wallets.js";
8-
import { getContract } from "../../../contract/contract.js";
9-
import { deployERC721Contract } from "../../../extensions/prebuilts/deploy-erc721.js";
10-
import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js";
11-
import { parseNFT } from "../../../utils/nft/parseNft.js";
12-
import { setTokenURI } from "../__generated__/INFTMetadata/write/setTokenURI.js";
13-
import { mintTo } from "../write/mintTo.js";
143
import { getNFT } from "./getNFT.js";
154

165
describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFT", () => {
@@ -99,60 +88,4 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFT", () => {
9988
}
10089
`);
10190
});
102-
103-
it("should return a default value if the URI of the token doesn't exist", async () => {
104-
/**
105-
* To create this test scenario, we first deploy an NFTCollection/Edition contract,
106-
* mint a token, then purposefully change that token's URI to an empty string, using setTokenURI
107-
*/
108-
const contract = getContract({
109-
address: await deployERC721Contract({
110-
chain: ANVIL_CHAIN,
111-
client: TEST_CLIENT,
112-
account: TEST_ACCOUNT_A,
113-
type: "TokenERC721",
114-
params: {
115-
name: "",
116-
contractURI: TEST_CONTRACT_URI,
117-
},
118-
}),
119-
chain: ANVIL_CHAIN,
120-
client: TEST_CLIENT,
121-
});
122-
123-
await sendAndConfirmTransaction({
124-
transaction: mintTo({
125-
contract,
126-
nft: { name: "token 0" },
127-
to: TEST_ACCOUNT_A.address,
128-
}),
129-
account: TEST_ACCOUNT_A,
130-
});
131-
132-
await sendAndConfirmTransaction({
133-
transaction: setTokenURI({
134-
contract,
135-
tokenId: 0n,
136-
// Need to have some spaces because NFTMetadata.sol does not allow to update an empty valud
137-
uri: " ",
138-
}),
139-
account: TEST_ACCOUNT_A,
140-
});
141-
142-
expect(await getNFT({ contract, tokenId: 0n })).toStrictEqual(
143-
parseNFT(
144-
{
145-
id: 0n,
146-
type: "ERC721",
147-
uri: "",
148-
},
149-
{
150-
tokenId: 0n,
151-
tokenUri: "",
152-
type: "ERC721",
153-
owner: null,
154-
},
155-
),
156-
);
157-
});
15891
});

packages/thirdweb/src/extensions/erc721/read/getNFTs.test.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,8 @@
1-
import { type Abi, toFunctionSelector } from "viem";
21
import { describe, expect, it } from "vitest";
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 {
73
DOODLES_CONTRACT,
84
UNISWAPV3_FACTORY_CONTRACT,
95
} from "~test/test-contracts.js";
10-
import { TEST_ACCOUNT_B } from "~test/test-wallets.js";
11-
import { resolveContractAbi } from "../../../contract/actions/resolve-abi.js";
12-
import { getContract } from "../../../contract/contract.js";
13-
import { deployERC721Contract } from "../../../extensions/prebuilts/deploy-erc721.js";
14-
import { isGetNFTSupported } from "./getNFT.js";
156
import { getNFTs } from "./getNFTs.js";
167

178
describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
@@ -197,29 +188,6 @@ describe.runIf(process.env.TW_SECRET_KEY)("erc721.getNFTs", () => {
197188
// TODO find a contract that we can use that has "1 indexed" NFTs, then re-enable this test
198189
});
199190

200-
it("isGetNFTsSupported should work", async () => {
201-
const contract = getContract({
202-
address: await deployERC721Contract({
203-
chain: ANVIL_CHAIN,
204-
client: TEST_CLIENT,
205-
type: "TokenERC721",
206-
params: {
207-
name: "",
208-
contractURI: TEST_CONTRACT_URI,
209-
},
210-
account: TEST_ACCOUNT_B,
211-
}),
212-
chain: ANVIL_CHAIN,
213-
client: TEST_CLIENT,
214-
});
215-
216-
const abi = await resolveContractAbi<Abi>(contract);
217-
const selectors = abi
218-
.filter((f) => f.type === "function")
219-
.map((f) => toFunctionSelector(f));
220-
expect(isGetNFTSupported(selectors)).toBe(true);
221-
});
222-
223191
it("should throw error if totalSupply and nextTokenIdToMint are not supported", async () => {
224192
await expect(() =>
225193
getNFTs({ contract: UNISWAPV3_FACTORY_CONTRACT }),
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
import { type Abi, toFunctionSelector } from "viem";
2+
import { describe, expect, it } from "vitest";
3+
import { ANVIL_CHAIN } from "~test/chains.js";
4+
import { TEST_CLIENT } from "~test/test-clients.js";
5+
import { TEST_ACCOUNT_B } from "~test/test-wallets.js";
6+
import { resolveContractAbi } from "../../contract/actions/resolve-abi.js";
7+
import { type ThirdwebContract, getContract } from "../../contract/contract.js";
8+
import { name } from "../../extensions/common/read/name.js";
9+
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
10+
import { parseNFT } from "../../utils/nft/parseNft.js";
11+
import { deployERC721Contract } from "../prebuilts/deploy-erc721.js";
12+
import { tokenURI } from "./__generated__/IERC721A/read/tokenURI.js";
13+
import { setTokenURI } from "./__generated__/INFTMetadata/write/setTokenURI.js";
14+
import { getNFT, isGetNFTSupported } from "./read/getNFT.js";
15+
import { mintTo } from "./write/mintTo.js";
16+
17+
const client = TEST_CLIENT;
18+
const chain = ANVIL_CHAIN;
19+
const account = TEST_ACCOUNT_B;
20+
21+
let token721Contract: ThirdwebContract;
22+
23+
describe.runIf(process.env.TW_SECRET_KEY)("deployERC721", () => {
24+
it("should deploy ERC721 token", async () => {
25+
const address = await deployERC721Contract({
26+
client,
27+
chain,
28+
account,
29+
type: "TokenERC721",
30+
params: {
31+
name: "NFTCollection",
32+
},
33+
});
34+
expect(address).toBeDefined();
35+
token721Contract = getContract({
36+
client: TEST_CLIENT,
37+
chain: ANVIL_CHAIN,
38+
address,
39+
});
40+
const deployedName = await name({ contract: token721Contract });
41+
expect(deployedName).toBe("NFTCollection");
42+
});
43+
44+
it("should mint an nft when passed an object", async () => {
45+
const transaction = mintTo({
46+
contract: token721Contract,
47+
nft: { name: "token 0" },
48+
to: account.address,
49+
});
50+
await sendAndConfirmTransaction({
51+
transaction,
52+
account,
53+
});
54+
55+
const nft = await getNFT({ contract: token721Contract, tokenId: 0n });
56+
expect(nft.metadata.name).toBe("token 0");
57+
});
58+
59+
it("should mint an nft when passed a string", async () => {
60+
const transaction = mintTo({
61+
contract: token721Contract,
62+
nft: "ipfs://fake-token-uri",
63+
to: account.address,
64+
});
65+
await sendAndConfirmTransaction({
66+
transaction,
67+
account,
68+
});
69+
const _uri = await tokenURI({ contract: token721Contract, tokenId: 1n });
70+
expect(_uri).toBe("ipfs://fake-token-uri");
71+
});
72+
73+
it("isGetNFTsSupported should work", async () => {
74+
const abi = await resolveContractAbi<Abi>(token721Contract);
75+
const selectors = abi
76+
.filter((f) => f.type === "function")
77+
.map((f) => toFunctionSelector(f));
78+
expect(isGetNFTSupported(selectors)).toBe(true);
79+
});
80+
81+
it("should return a default value if the URI of the token doesn't exist", async () => {
82+
/**
83+
* mint a token, then purposefully change that token's URI to an empty string, using setTokenURI
84+
*/
85+
await sendAndConfirmTransaction({
86+
transaction: setTokenURI({
87+
contract: token721Contract,
88+
tokenId: 1n,
89+
// Need to have some spaces because NFTMetadata.sol does not allow to update an empty valud
90+
uri: " ",
91+
}),
92+
account,
93+
});
94+
95+
expect(
96+
await getNFT({ contract: token721Contract, tokenId: 1n }),
97+
).toStrictEqual(
98+
parseNFT(
99+
{
100+
id: 0n,
101+
type: "ERC721",
102+
uri: "",
103+
},
104+
{
105+
tokenId: 0n,
106+
tokenUri: "",
107+
type: "ERC721",
108+
owner: null,
109+
},
110+
),
111+
);
112+
});
113+
});

0 commit comments

Comments
 (0)