|
| 1 | +import { beforeAll, describe, expect, it } from "vitest"; |
| 2 | +import { ANVIL_CHAIN } from "~test/chains.js"; |
| 3 | +import { TEST_CLIENT } from "~test/test-clients.js"; |
| 4 | +import { TEST_ACCOUNT_D } from "~test/test-wallets.js"; |
| 5 | +import { type ThirdwebContract, getContract } from "../../contract/contract.js"; |
| 6 | +import { isAddress } from "../../utils/address.js"; |
| 7 | +import { deploySplitContract } from "../prebuilts/deploy-split.js"; |
| 8 | +import { getAllRecipientsAddresses } from "./read/getAllRecipientsAddresses.js"; |
| 9 | +import { getAllRecipientsPercentages } from "./read/getAllRecipientsPercentages.js"; |
| 10 | +import { getRecipientSplitPercentage } from "./read/getRecipientSplitPercentage.js"; |
| 11 | + |
| 12 | +let contract: ThirdwebContract; |
| 13 | +const chain = ANVIL_CHAIN; |
| 14 | +const client = TEST_CLIENT; |
| 15 | + |
| 16 | +describe.runIf(process.env.TW_SECRET_KEY)("Split contract tests", () => { |
| 17 | + beforeAll(async () => { |
| 18 | + const address = await deploySplitContract({ |
| 19 | + account: TEST_ACCOUNT_D, |
| 20 | + client, |
| 21 | + chain, |
| 22 | + params: { |
| 23 | + name: "split-contract", |
| 24 | + payees: [ |
| 25 | + "0x12345674b599ce99958242b3D3741e7b01841DF3", |
| 26 | + "0xA6f11e47dE28B3dB934e945daeb6F538E9019694", |
| 27 | + ], |
| 28 | + shares: [ |
| 29 | + 5100n, // 51% |
| 30 | + 4900n, // 49% |
| 31 | + ], |
| 32 | + }, |
| 33 | + }); |
| 34 | + expect(address).toBeDefined(); |
| 35 | + expect(isAddress(address)).toBe(true); |
| 36 | + contract = getContract({ |
| 37 | + address, |
| 38 | + client, |
| 39 | + chain, |
| 40 | + }); |
| 41 | + }, 60_000); |
| 42 | + |
| 43 | + it("should return all recipient addresses", async () => { |
| 44 | + const result = await getAllRecipientsAddresses({ contract }); |
| 45 | + expect(result).toStrictEqual([ |
| 46 | + "0x12345674b599ce99958242b3D3741e7b01841DF3", |
| 47 | + "0xA6f11e47dE28B3dB934e945daeb6F538E9019694", |
| 48 | + ]); |
| 49 | + }); |
| 50 | + |
| 51 | + it("should return all recipients and their share percentages", async () => { |
| 52 | + const result = await getAllRecipientsPercentages({ contract }); |
| 53 | + expect(result).toStrictEqual([ |
| 54 | + { |
| 55 | + address: "0x12345674b599ce99958242b3D3741e7b01841DF3", |
| 56 | + splitPercentage: 51, |
| 57 | + }, |
| 58 | + { |
| 59 | + address: "0xA6f11e47dE28B3dB934e945daeb6F538E9019694", |
| 60 | + splitPercentage: 49, |
| 61 | + }, |
| 62 | + ]); |
| 63 | + }); |
| 64 | + |
| 65 | + it("should return split percentage for individual recipient", async () => { |
| 66 | + const result = await getRecipientSplitPercentage({ |
| 67 | + contract, |
| 68 | + recipientAddress: "0x12345674b599ce99958242b3D3741e7b01841DF3", |
| 69 | + }); |
| 70 | + |
| 71 | + expect(result).toStrictEqual({ |
| 72 | + address: "0x12345674b599ce99958242b3D3741e7b01841DF3", |
| 73 | + splitPercentage: 51, |
| 74 | + }); |
| 75 | + }); |
| 76 | +}); |
0 commit comments