-
Notifications
You must be signed in to change notification settings - Fork 359
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
158 additions
and
334 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
packages/thirdweb/src/extensions/erc1155/write/mintAdditionalSupplyToBatch.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
packages/thirdweb/src/extensions/erc721/token721.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
import { type Abi, toFunctionSelector } from "viem"; | ||
import { describe, expect, it } from "vitest"; | ||
import { ANVIL_CHAIN } from "~test/chains.js"; | ||
import { TEST_CLIENT } from "~test/test-clients.js"; | ||
import { TEST_ACCOUNT_B } from "~test/test-wallets.js"; | ||
import { resolveContractAbi } from "../../contract/actions/resolve-abi.js"; | ||
import { type ThirdwebContract, getContract } from "../../contract/contract.js"; | ||
import { name } from "../../extensions/common/read/name.js"; | ||
import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js"; | ||
import { parseNFT } from "../../utils/nft/parseNft.js"; | ||
import { deployERC721Contract } from "../prebuilts/deploy-erc721.js"; | ||
import { tokenURI } from "./__generated__/IERC721A/read/tokenURI.js"; | ||
import { setTokenURI } from "./__generated__/INFTMetadata/write/setTokenURI.js"; | ||
import { getNFT, isGetNFTSupported } from "./read/getNFT.js"; | ||
import { mintTo } from "./write/mintTo.js"; | ||
|
||
const client = TEST_CLIENT; | ||
const chain = ANVIL_CHAIN; | ||
const account = TEST_ACCOUNT_B; | ||
|
||
let token721Contract: ThirdwebContract; | ||
|
||
describe.runIf(process.env.TW_SECRET_KEY)("deployERC721", () => { | ||
it("should deploy ERC721 token", async () => { | ||
const address = await deployERC721Contract({ | ||
client, | ||
chain, | ||
account, | ||
type: "TokenERC721", | ||
params: { | ||
name: "NFTCollection", | ||
}, | ||
}); | ||
expect(address).toBeDefined(); | ||
token721Contract = getContract({ | ||
client: TEST_CLIENT, | ||
chain: ANVIL_CHAIN, | ||
address, | ||
}); | ||
const deployedName = await name({ contract: token721Contract }); | ||
expect(deployedName).toBe("NFTCollection"); | ||
}); | ||
|
||
it("should mint an nft when passed an object", async () => { | ||
const transaction = mintTo({ | ||
contract: token721Contract, | ||
nft: { name: "token 0" }, | ||
to: account.address, | ||
}); | ||
await sendAndConfirmTransaction({ | ||
transaction, | ||
account, | ||
}); | ||
|
||
const nft = await getNFT({ contract: token721Contract, tokenId: 0n }); | ||
expect(nft.metadata.name).toBe("token 0"); | ||
}); | ||
|
||
it("should mint an nft when passed a string", async () => { | ||
const transaction = mintTo({ | ||
contract: token721Contract, | ||
nft: "ipfs://fake-token-uri", | ||
to: account.address, | ||
}); | ||
await sendAndConfirmTransaction({ | ||
transaction, | ||
account, | ||
}); | ||
const _uri = await tokenURI({ contract: token721Contract, tokenId: 1n }); | ||
expect(_uri).toBe("ipfs://fake-token-uri"); | ||
}); | ||
|
||
it("isGetNFTsSupported should work", async () => { | ||
const abi = await resolveContractAbi<Abi>(token721Contract); | ||
const selectors = abi | ||
.filter((f) => f.type === "function") | ||
.map((f) => toFunctionSelector(f)); | ||
expect(isGetNFTSupported(selectors)).toBe(true); | ||
}); | ||
|
||
it("should return a default value if the URI of the token doesn't exist", async () => { | ||
/** | ||
* mint a token, then purposefully change that token's URI to an empty string, using setTokenURI | ||
*/ | ||
await sendAndConfirmTransaction({ | ||
transaction: setTokenURI({ | ||
contract: token721Contract, | ||
tokenId: 1n, | ||
// Need to have some spaces because NFTMetadata.sol does not allow to update an empty valud | ||
uri: " ", | ||
}), | ||
account, | ||
}); | ||
|
||
expect( | ||
await getNFT({ contract: token721Contract, tokenId: 1n }), | ||
).toStrictEqual( | ||
parseNFT( | ||
{ | ||
id: 0n, | ||
type: "ERC721", | ||
uri: "", | ||
}, | ||
{ | ||
tokenId: 0n, | ||
tokenUri: "", | ||
type: "ERC721", | ||
owner: null, | ||
}, | ||
), | ||
); | ||
}); | ||
}); |
Oops, something went wrong.