Skip to content

Commit ca25e6c

Browse files
committed
update
1 parent f40d247 commit ca25e6c

File tree

12 files changed

+160
-332
lines changed

12 files changed

+160
-332
lines changed

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

Lines changed: 12 additions & 1 deletion
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,22 @@ describe.runIf(process.env.TW_SECRET_KEY)(
4546
chain: ANVIL_CHAIN,
4647
client: TEST_CLIENT,
4748
params: {
48-
name: "Test DropERC1155",
49+
name: "EditionDrop",
4950
contractURI: TEST_CONTRACT_URI,
5051
},
5152
type: "DropERC1155",
5253
});
5354

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

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

Lines changed: 12 additions & 1 deletion
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,22 @@ describe.runIf(process.env.TW_SECRET_KEY)("TokenERC1155", () => {
3738
chain: ANVIL_CHAIN,
3839
client: TEST_CLIENT,
3940
params: {
40-
name: "Test TokenERC1155",
41+
name: "Edition",
4142
contractURI: TEST_CONTRACT_URI,
4243
},
4344
type: "TokenERC1155",
4445
});
4546

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

0 commit comments

Comments
 (0)