Skip to content

Commit 0747ec7

Browse files
committed
test: Add comprehensive tests for hasSponsoredTransactionsEnabled function
1 parent 4e60c0a commit 0747ec7

File tree

2 files changed

+82
-0
lines changed

2 files changed

+82
-0
lines changed

.changeset/lazy-games-cheat.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Fix ecosystem wallet AA detection in Pay modal
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { describe, expect, it } from "vitest";
2+
import type { Wallet } from "../../../wallets/interfaces/wallet";
3+
import { hasSponsoredTransactionsEnabled } from "./wallet";
4+
5+
describe("hasSponsoredTransactionsEnabled", () => {
6+
it("should return false for undefined wallet", () => {
7+
expect(hasSponsoredTransactionsEnabled(undefined)).toBe(false);
8+
});
9+
10+
it("should handle smart wallet with sponsorGas config", () => {
11+
const mockSmartWallet = {
12+
id: "smart",
13+
getConfig: () => ({ sponsorGas: true }),
14+
} as Wallet;
15+
expect(hasSponsoredTransactionsEnabled(mockSmartWallet)).toBe(true);
16+
17+
const mockSmartWalletDisabled = {
18+
id: "smart",
19+
getConfig: () => ({ sponsorGas: false }),
20+
} as Wallet;
21+
expect(hasSponsoredTransactionsEnabled(mockSmartWalletDisabled)).toBe(
22+
false,
23+
);
24+
});
25+
26+
it("should handle smart wallet with gasless config", () => {
27+
const mockSmartWallet = {
28+
id: "smart",
29+
getConfig: () => ({ gasless: true }),
30+
} as Wallet;
31+
expect(hasSponsoredTransactionsEnabled(mockSmartWallet)).toBe(true);
32+
});
33+
34+
it("should handle inApp wallet with smartAccount config", () => {
35+
const mockInAppWallet = {
36+
id: "inApp",
37+
getConfig: () => ({
38+
smartAccount: {
39+
sponsorGas: true,
40+
},
41+
}),
42+
} as Wallet;
43+
expect(hasSponsoredTransactionsEnabled(mockInAppWallet)).toBe(true);
44+
45+
const mockInAppWalletDisabled = {
46+
id: "inApp",
47+
getConfig: () => ({
48+
smartAccount: {
49+
sponsorGas: false,
50+
},
51+
}),
52+
} as Wallet;
53+
expect(hasSponsoredTransactionsEnabled(mockInAppWalletDisabled)).toBe(
54+
false,
55+
);
56+
});
57+
58+
it("should handle inApp wallet with gasless config", () => {
59+
const mockInAppWallet = {
60+
id: "inApp",
61+
getConfig: () => ({
62+
smartAccount: {
63+
gasless: true,
64+
},
65+
}),
66+
} as Wallet;
67+
expect(hasSponsoredTransactionsEnabled(mockInAppWallet)).toBe(true);
68+
});
69+
70+
it("should return false for regular wallet without smart account config", () => {
71+
const mockRegularWallet = {
72+
id: "inApp",
73+
getConfig: () => ({}),
74+
} as Wallet;
75+
expect(hasSponsoredTransactionsEnabled(mockRegularWallet)).toBe(false);
76+
});
77+
});

0 commit comments

Comments
 (0)