Skip to content

Commit 195e36f

Browse files
committed
test(sdk)
1 parent 39a122c commit 195e36f

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

packages/thirdweb/src/wallets/manager/connection-manager.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,61 @@ describe.runIf(process.env.TW_SECRET_KEY)("Connection Manager", () => {
120120
"Cannot set a wallet without an account as active",
121121
);
122122
});
123+
124+
it("should set active wallet and update storage", async () => {
125+
const manager = createConnectionManager(storage);
126+
127+
await manager.setActiveWallet(wallet);
128+
129+
expect(manager.activeWalletStore.getValue()).toBe(wallet);
130+
expect(storage.setItem).toHaveBeenCalledWith(
131+
"thirdweb:active-wallet-id",
132+
wallet.id,
133+
);
134+
});
135+
136+
it("should switch active wallet chain", async () => {
137+
const manager = createConnectionManager(storage);
138+
139+
await manager.handleConnection(wallet, { client });
140+
141+
const newChain = {
142+
id: 2,
143+
name: "New Chain",
144+
rpc: "https://rpc.example.com",
145+
};
146+
147+
// Mock the switchChain method to update the activeWalletChainStore
148+
wallet.switchChain = vi.fn().mockImplementation((chain) => {
149+
manager.activeWalletChainStore.setValue(chain);
150+
});
151+
152+
await manager.switchActiveWalletChain(newChain);
153+
154+
expect(wallet.switchChain).toHaveBeenCalledWith(newChain);
155+
});
156+
157+
it("should define chains", async () => {
158+
const manager = createConnectionManager(storage);
159+
await manager.handleConnection(wallet, { client });
160+
161+
const chains = [
162+
{ id: 1, name: "Chain 1", rpc: "https://rpc1.example.com" },
163+
{ id: 2, name: "Chain 2", rpc: "https://rpc2.example.com" },
164+
];
165+
manager.defineChains(chains);
166+
167+
const activeWalletChain = manager.activeWalletChainStore.getValue();
168+
expect(activeWalletChain).toBeDefined();
169+
});
170+
171+
it("should remove connected wallet", () => {
172+
const manager = createConnectionManager(storage);
173+
174+
manager.addConnectedWallet(wallet);
175+
expect(manager.connectedWallets.getValue()).toContain(wallet);
176+
177+
manager.removeConnectedWallet(wallet);
178+
expect(manager.connectedWallets.getValue()).not.toContain(wallet);
179+
});
123180
});

0 commit comments

Comments
 (0)