diff --git a/packages/thirdweb/src/extensions/prebuilts/deploy-split.test.ts b/packages/thirdweb/src/extensions/prebuilts/deploy-split.test.ts deleted file mode 100644 index 075c202e8fd..00000000000 --- a/packages/thirdweb/src/extensions/prebuilts/deploy-split.test.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { describe, expect, it } from "vitest"; -import { ANVIL_CHAIN } from "~test/chains.js"; -import { TEST_CLIENT } from "~test/test-clients.js"; -import { TEST_ACCOUNT_D } from "~test/test-wallets.js"; -import { isAddress } from "../../utils/address.js"; -import { deploySplitContract } from "./deploy-split.js"; - -describe.runIf(process.env.TW_SECRET_KEY)("deploy-split contract", () => { - it("should deploy Split contract", async () => { - const address = await deploySplitContract({ - account: TEST_ACCOUNT_D, - client: TEST_CLIENT, - chain: ANVIL_CHAIN, - params: { - name: "split-contract", - payees: [ - "0x12345674b599ce99958242b3D3741e7b01841DF3", - "0xA6f11e47dE28B3dB934e945daeb6F538E9019694", - ], - shares: [ - 5100n, // 51% - 4900n, // 49% - ], - }, - }); - expect(address).toBeDefined(); - expect(isAddress(address)).toBe(true); - // Further tests to verify the functionality of this contract - // are done in other Split tests - }); -}); diff --git a/packages/thirdweb/src/extensions/split/read/getAllRecipientsAddresses.test.ts b/packages/thirdweb/src/extensions/split/read/getAllRecipientsAddresses.test.ts deleted file mode 100644 index 967d890f9b0..00000000000 --- a/packages/thirdweb/src/extensions/split/read/getAllRecipientsAddresses.test.ts +++ /dev/null @@ -1,41 +0,0 @@ -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 { deploySplitContract } from "../../../extensions/prebuilts/deploy-split.js"; -import { getAllRecipientsAddresses } from "./getAllRecipientsAddresses.js"; - -const chain = ANVIL_CHAIN; -const client = TEST_CLIENT; - -describe.runIf(process.env.TW_SECRET_KEY)("getAllRecipientsAddresses", () => { - it("should work", async () => { - const payees = [ - "0x12345674b599ce99958242b3D3741e7b01841DF3", - "0xA6f11e47dE28B3dB934e945daeb6F538E9019694", - ]; - const address = await deploySplitContract({ - account: TEST_ACCOUNT_C, - client: TEST_CLIENT, - chain: ANVIL_CHAIN, - params: { - name: "split-contract", - contractURI: TEST_CONTRACT_URI, // just to speed up the test - payees, - shares: [ - 5100n, // 51% - 4900n, // 49% - ], - }, - }); - const contract = getContract({ - address, - chain, - client, - }); - const result = await getAllRecipientsAddresses({ contract }); - expect(result).toStrictEqual(payees); - }); -}); diff --git a/packages/thirdweb/src/extensions/split/read/getAllRecipientsPercentages.test.ts b/packages/thirdweb/src/extensions/split/read/getAllRecipientsPercentages.test.ts deleted file mode 100644 index fe3e92cc837..00000000000 --- a/packages/thirdweb/src/extensions/split/read/getAllRecipientsPercentages.test.ts +++ /dev/null @@ -1,50 +0,0 @@ -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 { deploySplitContract } from "../../../extensions/prebuilts/deploy-split.js"; -import { getAllRecipientsPercentages } from "./getAllRecipientsPercentages.js"; - -const chain = ANVIL_CHAIN; -const client = TEST_CLIENT; - -describe.runIf(process.env.TW_SECRET_KEY)("getAllRecipientsPercentages", () => { - it("should work", async () => { - const payees = [ - "0x12345674b599ce99958242b3D3741e7b01841DF3", - "0xA6f11e47dE28B3dB934e945daeb6F538E9019694", - ]; - const address = await deploySplitContract({ - account: TEST_ACCOUNT_C, - client: TEST_CLIENT, - chain: ANVIL_CHAIN, - params: { - name: "split-contract", - contractURI: TEST_CONTRACT_URI, // just to speed up the test - payees, - shares: [ - 5100n, // 51% - 4900n, // 49% - ], - }, - }); - const contract = getContract({ - address, - chain, - client, - }); - const result = await getAllRecipientsPercentages({ contract }); - expect(result).toStrictEqual([ - { - address: "0x12345674b599ce99958242b3D3741e7b01841DF3", - splitPercentage: 51, - }, - { - address: "0xA6f11e47dE28B3dB934e945daeb6F538E9019694", - splitPercentage: 49, - }, - ]); - }); -}); diff --git a/packages/thirdweb/src/extensions/split/read/getRecipientSplitPercentage.test.ts b/packages/thirdweb/src/extensions/split/read/getRecipientSplitPercentage.test.ts deleted file mode 100644 index eb6fcbb9502..00000000000 --- a/packages/thirdweb/src/extensions/split/read/getRecipientSplitPercentage.test.ts +++ /dev/null @@ -1,49 +0,0 @@ -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 { deploySplitContract } from "../../../extensions/prebuilts/deploy-split.js"; -import { getRecipientSplitPercentage } from "./getRecipientSplitPercentage.js"; - -const chain = ANVIL_CHAIN; -const client = TEST_CLIENT; -const account = TEST_ACCOUNT_C; - -describe.runIf(process.env.TW_SECRET_KEY)("getRecipientSplitPercentage", () => { - it("should work", async () => { - const payees = [ - "0x12345674b599ce99958242b3D3741e7b01841DF3", - "0xA6f11e47dE28B3dB934e945daeb6F538E9019694", - ]; - const address = await deploySplitContract({ - account, - client: TEST_CLIENT, - chain: ANVIL_CHAIN, - params: { - name: "split-contract", - contractURI: TEST_CONTRACT_URI, // just to speed up the test - payees, - shares: [ - 5100n, // 51% - 4900n, // 49% - ], - }, - }); - const contract = getContract({ - address, - chain, - client, - }); - const result = await getRecipientSplitPercentage({ - contract, - recipientAddress: "0x12345674b599ce99958242b3D3741e7b01841DF3", - }); - - expect(result).toStrictEqual({ - address: "0x12345674b599ce99958242b3D3741e7b01841DF3", - splitPercentage: 51, - }); - }); -}); diff --git a/packages/thirdweb/src/extensions/split/split.test.ts b/packages/thirdweb/src/extensions/split/split.test.ts new file mode 100644 index 00000000000..ba9a28d056f --- /dev/null +++ b/packages/thirdweb/src/extensions/split/split.test.ts @@ -0,0 +1,76 @@ +import { beforeAll, describe, expect, it } from "vitest"; +import { ANVIL_CHAIN } from "~test/chains.js"; +import { TEST_CLIENT } from "~test/test-clients.js"; +import { TEST_ACCOUNT_D } from "~test/test-wallets.js"; +import { type ThirdwebContract, getContract } from "../../contract/contract.js"; +import { isAddress } from "../../utils/address.js"; +import { deploySplitContract } from "../prebuilts/deploy-split.js"; +import { getAllRecipientsAddresses } from "./read/getAllRecipientsAddresses.js"; +import { getAllRecipientsPercentages } from "./read/getAllRecipientsPercentages.js"; +import { getRecipientSplitPercentage } from "./read/getRecipientSplitPercentage.js"; + +let contract: ThirdwebContract; +const chain = ANVIL_CHAIN; +const client = TEST_CLIENT; + +describe.runIf(process.env.TW_SECRET_KEY)("Split contract tests", () => { + beforeAll(async () => { + const address = await deploySplitContract({ + account: TEST_ACCOUNT_D, + client, + chain, + params: { + name: "split-contract", + payees: [ + "0x12345674b599ce99958242b3D3741e7b01841DF3", + "0xA6f11e47dE28B3dB934e945daeb6F538E9019694", + ], + shares: [ + 5100n, // 51% + 4900n, // 49% + ], + }, + }); + expect(address).toBeDefined(); + expect(isAddress(address)).toBe(true); + contract = getContract({ + address, + client, + chain, + }); + }, 60_000); + + it("should return all recipient addresses", async () => { + const result = await getAllRecipientsAddresses({ contract }); + expect(result).toStrictEqual([ + "0x12345674b599ce99958242b3D3741e7b01841DF3", + "0xA6f11e47dE28B3dB934e945daeb6F538E9019694", + ]); + }); + + it("should return all recipients and their share percentages", async () => { + const result = await getAllRecipientsPercentages({ contract }); + expect(result).toStrictEqual([ + { + address: "0x12345674b599ce99958242b3D3741e7b01841DF3", + splitPercentage: 51, + }, + { + address: "0xA6f11e47dE28B3dB934e945daeb6F538E9019694", + splitPercentage: 49, + }, + ]); + }); + + it("should return split percentage for individual recipient", async () => { + const result = await getRecipientSplitPercentage({ + contract, + recipientAddress: "0x12345674b599ce99958242b3D3741e7b01841DF3", + }); + + expect(result).toStrictEqual({ + address: "0x12345674b599ce99958242b3D3741e7b01841DF3", + splitPercentage: 51, + }); + }); +});