Skip to content

Commit 4b18351

Browse files
committed
[SDK] Improve Split contract tests (#5155)
## Problem solved Short description of the bug fixed or feature added <!-- start pr-codex --> --- ## PR-Codex overview This PR focuses on adding tests for the `split` functionality of a smart contract in the `thirdweb` package, ensuring that the contract behaves as expected when deployed and queried for recipient addresses and their share percentages. ### Detailed summary - Deleted several test files related to `deploy-split` and recipient functions. - Introduced a new test suite for the `split` contract in `split.test.ts`. - Added tests for: - Deployment of the split contract. - Retrieving all recipient addresses. - Retrieving all recipients and their share percentages. - Retrieving the split percentage for an individual recipient. > ✨ Ask PR-Codex anything about this PR by commenting with `/codex {your question}` <!-- end pr-codex -->
1 parent e8f952a commit 4b18351

File tree

5 files changed

+76
-171
lines changed

5 files changed

+76
-171
lines changed

packages/thirdweb/src/extensions/prebuilts/deploy-split.test.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

packages/thirdweb/src/extensions/split/read/getAllRecipientsAddresses.test.ts

Lines changed: 0 additions & 41 deletions
This file was deleted.

packages/thirdweb/src/extensions/split/read/getAllRecipientsPercentages.test.ts

Lines changed: 0 additions & 50 deletions
This file was deleted.

packages/thirdweb/src/extensions/split/read/getRecipientSplitPercentage.test.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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

Comments
 (0)