-
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.
[SDK] Improve ERC1155 test coverage (#4985)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on enhancing test coverage for the ERC20 and ERC1155 extensions in the `thirdweb` package. It introduces conditional test execution based on the presence of a secret key and adds new tests to verify specific functionalities. ### Detailed summary - Updated `describe` blocks to conditionally run tests based on `process.env.TW_SECRET_KEY` for multiple test files. - Added tests for `isLazyMintSupported` in `erc1155: lazyMint`. - Added tests for `isMintAdditionalSupplyToSupported` in `erc1155: mintAdditionalSupplyTo`. - Added tests for `mintTo` functionality in `erc1155: mintTo`. - Added tests for `isGetNFTsSupported` in `ERC1155 getNFTs`. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
- Loading branch information
Showing
6 changed files
with
162 additions
and
2 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
packages/thirdweb/src/extensions/erc1155/read/getNFTs.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,44 @@ | ||
import { type Abi, toFunctionSelector } from "viem"; | ||
import { describe, expect, it } from "vitest"; | ||
import { ANVIL_CHAIN } from "~test/chains.js"; | ||
import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js"; | ||
import { TEST_CLIENT } from "~test/test-clients.js"; | ||
import { DROP1155_CONTRACT } from "~test/test-contracts.js"; | ||
import { TEST_ACCOUNT_C } from "~test/test-wallets.js"; | ||
import { resolveContractAbi } from "../../../contract/actions/resolve-abi.js"; | ||
import { getContract } from "../../../contract/contract.js"; | ||
import { deployERC1155Contract } from "../../../extensions/prebuilts/deploy-erc1155.js"; | ||
import { isGetNFTsSupported } from "./getNFTs.js"; | ||
|
||
describe.runIf(process.env.TW_SECRET_KEY)("ERC1155 getNFTs", () => { | ||
it("isGetNFTsSupported should work with our Edition Drop contracts", async () => { | ||
const abi = await resolveContractAbi<Abi>(DROP1155_CONTRACT); | ||
const selectors = abi | ||
.filter((f) => f.type === "function") | ||
.map((f) => toFunctionSelector(f)); | ||
expect(isGetNFTsSupported(selectors)).toBe(true); | ||
}); | ||
|
||
it("isGetNFTsSupported should work with our Edition contracts", async () => { | ||
const contract = getContract({ | ||
address: await deployERC1155Contract({ | ||
chain: ANVIL_CHAIN, | ||
client: TEST_CLIENT, | ||
params: { | ||
name: "", | ||
contractURI: TEST_CONTRACT_URI, | ||
}, | ||
type: "TokenERC1155", | ||
account: TEST_ACCOUNT_C, | ||
}), | ||
chain: ANVIL_CHAIN, | ||
client: TEST_CLIENT, | ||
}); | ||
|
||
const abi = await resolveContractAbi<Abi>(contract); | ||
const selectors = abi | ||
.filter((f) => f.type === "function") | ||
.map((f) => toFunctionSelector(f)); | ||
expect(isGetNFTsSupported(selectors)).toBe(true); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
packages/thirdweb/src/extensions/erc1155/write/lazyMint.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,35 @@ | ||
import { type Abi, toFunctionSelector } from "viem"; | ||
import { describe, expect, it } from "vitest"; | ||
import { ANVIL_CHAIN } from "~test/chains.js"; | ||
import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js"; | ||
import { TEST_CLIENT } from "~test/test-clients.js"; | ||
import { TEST_ACCOUNT_C } from "~test/test-wallets.js"; | ||
import { resolveContractAbi } from "../../../contract/actions/resolve-abi.js"; | ||
import { getContract } from "../../../contract/contract.js"; | ||
import { deployERC1155Contract } from "../../../extensions/prebuilts/deploy-erc1155.js"; | ||
import { isLazyMintSupported } from "./lazyMint.js"; | ||
|
||
describe.runIf(process.env.TW_SECRET_KEY)("erc1155: lazyMint", () => { | ||
it("`isLazyMintSupported` should work with our Edition Drop contracts", async () => { | ||
const contract = getContract({ | ||
address: await deployERC1155Contract({ | ||
chain: ANVIL_CHAIN, | ||
client: TEST_CLIENT, | ||
params: { | ||
name: "", | ||
contractURI: TEST_CONTRACT_URI, | ||
}, | ||
type: "DropERC1155", | ||
account: TEST_ACCOUNT_C, | ||
}), | ||
chain: ANVIL_CHAIN, | ||
client: TEST_CLIENT, | ||
}); | ||
|
||
const abi = await resolveContractAbi<Abi>(contract); | ||
const selectors = abi | ||
.filter((f) => f.type === "function") | ||
.map((f) => toFunctionSelector(f)); | ||
expect(isLazyMintSupported(selectors)).toBe(true); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/thirdweb/src/extensions/erc1155/write/mintAdditionalSupplyTo.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,38 @@ | ||
import { type Abi, toFunctionSelector } from "viem"; | ||
import { describe, expect, it } from "vitest"; | ||
import { ANVIL_CHAIN } from "~test/chains.js"; | ||
import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js"; | ||
import { TEST_CLIENT } from "~test/test-clients.js"; | ||
import { TEST_ACCOUNT_C } from "~test/test-wallets.js"; | ||
import { resolveContractAbi } from "../../../contract/actions/resolve-abi.js"; | ||
import { getContract } from "../../../contract/contract.js"; | ||
import { deployERC1155Contract } from "../../../extensions/prebuilts/deploy-erc1155.js"; | ||
import { isMintAdditionalSupplyToSupported } from "./mintAdditionalSupplyTo.js"; | ||
|
||
describe.runIf(process.env.TW_SECRET_KEY)( | ||
"erc1155: mintAdditionalSupplyTo", | ||
() => { | ||
it("`isMintAdditionalSupplyToSupported` should work with our Edition contracts", async () => { | ||
const contract = getContract({ | ||
address: await deployERC1155Contract({ | ||
chain: ANVIL_CHAIN, | ||
client: TEST_CLIENT, | ||
params: { | ||
name: "", | ||
contractURI: TEST_CONTRACT_URI, | ||
}, | ||
type: "TokenERC1155", | ||
account: TEST_ACCOUNT_C, | ||
}), | ||
chain: ANVIL_CHAIN, | ||
client: TEST_CLIENT, | ||
}); | ||
|
||
const abi = await resolveContractAbi<Abi>(contract); | ||
const selectors = abi | ||
.filter((f) => f.type === "function") | ||
.map((f) => toFunctionSelector(f)); | ||
expect(isMintAdditionalSupplyToSupported(selectors)).toBe(true); | ||
}); | ||
}, | ||
); |
43 changes: 43 additions & 0 deletions
43
packages/thirdweb/src/extensions/erc1155/write/mintTo.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,43 @@ | ||
import {} from "viem"; | ||
import { describe, expect, it } from "vitest"; | ||
import { ANVIL_CHAIN } from "~test/chains.js"; | ||
import { TEST_CONTRACT_URI } from "~test/ipfs-uris.js"; | ||
import { TEST_CLIENT } from "~test/test-clients.js"; | ||
import { TEST_ACCOUNT_C } from "~test/test-wallets.js"; | ||
import { getContract } from "../../../contract/contract.js"; | ||
import { deployERC1155Contract } from "../../../extensions/prebuilts/deploy-erc1155.js"; | ||
import { sendAndConfirmTransaction } from "../../../transaction/actions/send-and-confirm-transaction.js"; | ||
import { uri } from "../__generated__/IERC1155/read/uri.js"; | ||
import { mintTo } from "./mintTo.js"; | ||
|
||
describe.runIf(process.env.TW_SECRET_KEY)("erc1155: mintTo", () => { | ||
it("should mint with `nft` being declared as a string", async () => { | ||
const contract = getContract({ | ||
address: await deployERC1155Contract({ | ||
chain: ANVIL_CHAIN, | ||
client: TEST_CLIENT, | ||
params: { | ||
name: "", | ||
contractURI: TEST_CONTRACT_URI, | ||
}, | ||
type: "TokenERC1155", | ||
account: TEST_ACCOUNT_C, | ||
}), | ||
chain: ANVIL_CHAIN, | ||
client: TEST_CLIENT, | ||
}); | ||
|
||
await sendAndConfirmTransaction({ | ||
transaction: mintTo({ | ||
contract, | ||
nft: TEST_CONTRACT_URI, | ||
to: TEST_ACCOUNT_C.address, | ||
supply: 1n, | ||
}), | ||
account: TEST_ACCOUNT_C, | ||
}); | ||
|
||
const tokenUri = await uri({ contract, tokenId: 0n }); | ||
expect(tokenUri).toBe(TEST_CONTRACT_URI); | ||
}); | ||
}); |
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