@reown/appkit-adapter-ethers 1.2.0 → 1.2.1-638deddc0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/esm/src/tests/client.test.js +711 -0
- package/dist/esm/src/tests/client.test.js.map +1 -0
- package/dist/esm/src/tests/mocks/AppKit.js +70 -0
- package/dist/esm/src/tests/mocks/AppKit.js.map +1 -0
- package/dist/esm/src/tests/mocks/AuthConnector.js +29 -0
- package/dist/esm/src/tests/mocks/AuthConnector.js.map +1 -0
- package/dist/esm/src/tests/mocks/EthersConfig.js +29 -0
- package/dist/esm/src/tests/mocks/EthersConfig.js.map +1 -0
- package/dist/esm/src/tests/mocks/Options.js +17 -0
- package/dist/esm/src/tests/mocks/Options.js.map +1 -0
- package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
- package/dist/esm/tsconfig.tsbuildinfo +1 -0
- package/dist/types/src/tests/client.test.d.ts +1 -0
- package/dist/types/src/tests/mocks/AppKit.d.ts +3 -0
- package/dist/types/src/tests/mocks/EthersConfig.d.ts +3 -0
- package/dist/types/src/tests/mocks/Options.d.ts +3 -0
- package/package.json +10 -10
|
@@ -0,0 +1,711 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest';
|
|
2
|
+
import { EthersAdapter } from '../client';
|
|
3
|
+
import { mockOptions } from './mocks/Options';
|
|
4
|
+
import { mockCreateEthersConfig } from './mocks/EthersConfig';
|
|
5
|
+
import mockAppKit from './mocks/AppKit';
|
|
6
|
+
import { mockAuthConnector } from './mocks/AuthConnector';
|
|
7
|
+
import { EthersHelpersUtil } from '@reown/appkit-utils/ethers';
|
|
8
|
+
import { CaipNetworksUtil, ConstantsUtil } from '@reown/appkit-utils';
|
|
9
|
+
import { arbitrum as AppkitArbitrum, mainnet as AppkitMainnet, polygon as AppkitPolygon, optimism as AppkitOptimism, bsc as AppkitBsc, harmonyOne as AppkitHarmonyOne } from '@reown/appkit/networks';
|
|
10
|
+
import { ProviderUtil } from '@reown/appkit/store';
|
|
11
|
+
import { SafeLocalStorage, SafeLocalStorageKeys } from '@reown/appkit-common';
|
|
12
|
+
import {} from '@reown/appkit';
|
|
13
|
+
import { InfuraProvider, JsonRpcProvider } from 'ethers';
|
|
14
|
+
const [mainnet, arbitrum, polygon, optimism, bsc] = CaipNetworksUtil.extendCaipNetworks([AppkitMainnet, AppkitArbitrum, AppkitPolygon, AppkitOptimism, AppkitBsc], {
|
|
15
|
+
customNetworkImageUrls: mockOptions.chainImages,
|
|
16
|
+
projectId: '1234'
|
|
17
|
+
});
|
|
18
|
+
const caipNetworks = [mainnet, arbitrum, polygon];
|
|
19
|
+
vi.mock('@reown/appkit-wallet', () => ({
|
|
20
|
+
W3mFrameProvider: vi.fn().mockImplementation(() => mockAuthConnector),
|
|
21
|
+
W3mFrameHelpers: {
|
|
22
|
+
checkIfRequestExists: vi.fn(),
|
|
23
|
+
checkIfRequestIsSafe: vi.fn()
|
|
24
|
+
},
|
|
25
|
+
W3mFrameRpcConstants: {
|
|
26
|
+
RPC_METHOD_NOT_ALLOWED_UI_MESSAGE: 'RPC method not allowed'
|
|
27
|
+
}
|
|
28
|
+
}));
|
|
29
|
+
vi.mock('@reown/appkit-utils', async (importOriginal) => {
|
|
30
|
+
const actual = await importOriginal();
|
|
31
|
+
const INJECTED_CONNECTOR_ID = 'injected';
|
|
32
|
+
const COINBASE_SDK_CONNECTOR_ID = 'coinbaseWallet';
|
|
33
|
+
const EIP6963_CONNECTOR_ID = 'eip6963';
|
|
34
|
+
const WALLET_CONNECT_CONNECTOR_ID = 'walletConnect';
|
|
35
|
+
const AUTH_CONNECTOR_ID = 'w3mAuth';
|
|
36
|
+
return {
|
|
37
|
+
...actual,
|
|
38
|
+
PresetsUtil: {
|
|
39
|
+
ConnectorTypesMap: {
|
|
40
|
+
[INJECTED_CONNECTOR_ID]: 'INJECTED',
|
|
41
|
+
[COINBASE_SDK_CONNECTOR_ID]: 'EXTERNAL',
|
|
42
|
+
[EIP6963_CONNECTOR_ID]: 'INJECTED'
|
|
43
|
+
},
|
|
44
|
+
ConnectorExplorerIds: {
|
|
45
|
+
[INJECTED_CONNECTOR_ID]: 'injected-explorer',
|
|
46
|
+
[COINBASE_SDK_CONNECTOR_ID]: 'coinbase-explorer',
|
|
47
|
+
[EIP6963_CONNECTOR_ID]: 'eip6963-explorer'
|
|
48
|
+
},
|
|
49
|
+
ConnectorImageIds: {
|
|
50
|
+
[INJECTED_CONNECTOR_ID]: 'injected-image',
|
|
51
|
+
[COINBASE_SDK_CONNECTOR_ID]: 'coinbase-image',
|
|
52
|
+
[EIP6963_CONNECTOR_ID]: 'eip6963-image'
|
|
53
|
+
},
|
|
54
|
+
ConnectorNamesMap: {
|
|
55
|
+
[INJECTED_CONNECTOR_ID]: 'Injected',
|
|
56
|
+
[COINBASE_SDK_CONNECTOR_ID]: 'Coinbase',
|
|
57
|
+
[EIP6963_CONNECTOR_ID]: 'EIP6963'
|
|
58
|
+
},
|
|
59
|
+
WalletConnectRpcChainIds: [1, 137, 10, 42161, 56, 43114, 250, 25, 1313161554, 1284]
|
|
60
|
+
},
|
|
61
|
+
ConstantsUtil: {
|
|
62
|
+
INJECTED_CONNECTOR_ID,
|
|
63
|
+
COINBASE_SDK_CONNECTOR_ID,
|
|
64
|
+
EIP6963_CONNECTOR_ID,
|
|
65
|
+
WALLET_CONNECT_CONNECTOR_ID,
|
|
66
|
+
AUTH_CONNECTOR_ID,
|
|
67
|
+
EIP155: 'eip155'
|
|
68
|
+
},
|
|
69
|
+
HelpersUtil: {
|
|
70
|
+
getCaipTokens: vi.fn().mockReturnValue([])
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
vi.mock('@reown/appkit/store', () => ({
|
|
75
|
+
ProviderUtil: {
|
|
76
|
+
setProvider: vi.fn(),
|
|
77
|
+
setProviderId: vi.fn(),
|
|
78
|
+
state: {
|
|
79
|
+
providerIds: {}
|
|
80
|
+
},
|
|
81
|
+
getProvider: vi.fn()
|
|
82
|
+
}
|
|
83
|
+
}));
|
|
84
|
+
vi.mock('ethers', async () => {
|
|
85
|
+
return {
|
|
86
|
+
InfuraProvider: vi.fn(),
|
|
87
|
+
JsonRpcProvider: vi.fn(),
|
|
88
|
+
formatEther: vi.fn().mockReturnValue('1.0'),
|
|
89
|
+
parseUnits: vi.fn(),
|
|
90
|
+
formatUnits: vi.fn()
|
|
91
|
+
};
|
|
92
|
+
});
|
|
93
|
+
vi.mock('@reown/appkit-common', async (importOriginal) => {
|
|
94
|
+
const actual = await importOriginal();
|
|
95
|
+
return {
|
|
96
|
+
...actual,
|
|
97
|
+
SafeLocalStorage: {
|
|
98
|
+
getItem: vi.fn(key => {
|
|
99
|
+
const values = {
|
|
100
|
+
'@appkit/wallet_id': 'injected'
|
|
101
|
+
};
|
|
102
|
+
return values[key];
|
|
103
|
+
}),
|
|
104
|
+
setItem: vi.fn(),
|
|
105
|
+
removeItem: vi.fn()
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
});
|
|
109
|
+
describe('EthersAdapter', () => {
|
|
110
|
+
let client;
|
|
111
|
+
beforeEach(() => {
|
|
112
|
+
vi.clearAllMocks();
|
|
113
|
+
const ethersConfig = mockCreateEthersConfig();
|
|
114
|
+
client = new EthersAdapter();
|
|
115
|
+
vi.spyOn(client, 'createEthersConfig').mockImplementation(() => ({
|
|
116
|
+
metadata: ethersConfig.metadata,
|
|
117
|
+
injected: ethersConfig.injected
|
|
118
|
+
}));
|
|
119
|
+
const optionsWithEthersConfig = {
|
|
120
|
+
...mockOptions,
|
|
121
|
+
networks: caipNetworks,
|
|
122
|
+
defaultNetwork: undefined,
|
|
123
|
+
ethersConfig
|
|
124
|
+
};
|
|
125
|
+
client.construct(mockAppKit, optionsWithEthersConfig);
|
|
126
|
+
});
|
|
127
|
+
afterEach(() => {
|
|
128
|
+
vi.clearAllMocks();
|
|
129
|
+
});
|
|
130
|
+
describe('EthersClient - Initialization', () => {
|
|
131
|
+
it('should initialize with default values', () => {
|
|
132
|
+
expect(client.chainNamespace).toBe('eip155');
|
|
133
|
+
expect(client.adapterType).toBe('ethers');
|
|
134
|
+
});
|
|
135
|
+
it('should set caipNetworks to provided caipNetworks options', () => {
|
|
136
|
+
expect(client.caipNetworks).toEqual(caipNetworks);
|
|
137
|
+
});
|
|
138
|
+
it('should set chain images', () => {
|
|
139
|
+
Object.entries(mockOptions.chainImages).map(([networkId, imageUrl]) => {
|
|
140
|
+
const caipNetwork = client.caipNetworks.find(caipNetwork => caipNetwork.id === Number(networkId));
|
|
141
|
+
expect(caipNetwork).toBeDefined();
|
|
142
|
+
expect(caipNetwork?.assets?.imageUrl).toEqual(imageUrl);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
it('should set defaultNetwork to first caipNetwork option', () => {
|
|
146
|
+
expect(client.defaultCaipNetwork).toEqual(mainnet);
|
|
147
|
+
});
|
|
148
|
+
it('should create ethers config', () => {
|
|
149
|
+
expect(client['ethersConfig']).toBeDefined();
|
|
150
|
+
});
|
|
151
|
+
});
|
|
152
|
+
describe('EthersClient - Networks', () => {
|
|
153
|
+
const mockProvider = {
|
|
154
|
+
request: vi.fn(),
|
|
155
|
+
on: vi.fn(),
|
|
156
|
+
removeListener: vi.fn()
|
|
157
|
+
};
|
|
158
|
+
beforeEach(() => {
|
|
159
|
+
vi.spyOn(ProviderUtil, 'getProvider').mockReturnValue(mockProvider);
|
|
160
|
+
vi.spyOn(ProviderUtil.state, 'providerIds', 'get').mockReturnValue({
|
|
161
|
+
eip155: 'injected',
|
|
162
|
+
solana: undefined,
|
|
163
|
+
polkadot: undefined
|
|
164
|
+
});
|
|
165
|
+
});
|
|
166
|
+
it('should switch network for injected provider', async () => {
|
|
167
|
+
mockProvider.request.mockResolvedValueOnce(null);
|
|
168
|
+
await client.switchNetwork(polygon);
|
|
169
|
+
expect(mockProvider.request).toHaveBeenCalledWith(expect.objectContaining({
|
|
170
|
+
method: 'wallet_switchEthereumChain',
|
|
171
|
+
params: expect.arrayContaining([
|
|
172
|
+
expect.objectContaining({
|
|
173
|
+
chainId: expect.stringMatching(/^0x/)
|
|
174
|
+
})
|
|
175
|
+
])
|
|
176
|
+
}));
|
|
177
|
+
});
|
|
178
|
+
it('should add network if not recognized by wallet', async () => {
|
|
179
|
+
const switchError = { code: 4902 };
|
|
180
|
+
mockProvider.request.mockRejectedValueOnce(switchError);
|
|
181
|
+
mockProvider.request.mockResolvedValueOnce(null);
|
|
182
|
+
await client.switchNetwork(arbitrum);
|
|
183
|
+
expect(mockProvider.request).toHaveBeenCalledWith(expect.objectContaining({
|
|
184
|
+
method: 'wallet_addEthereumChain',
|
|
185
|
+
params: expect.arrayContaining([
|
|
186
|
+
expect.objectContaining({
|
|
187
|
+
chainId: expect.stringMatching(/^0x/)
|
|
188
|
+
})
|
|
189
|
+
])
|
|
190
|
+
}));
|
|
191
|
+
});
|
|
192
|
+
it('should throw error if switching fails', async () => {
|
|
193
|
+
const switchError = new Error('User rejected the request');
|
|
194
|
+
mockProvider.request.mockRejectedValueOnce(switchError);
|
|
195
|
+
await expect(client.switchNetwork(bsc)).rejects.toThrow('Chain is not supported');
|
|
196
|
+
});
|
|
197
|
+
it('should use universal adapter for WalletConnect', async () => {
|
|
198
|
+
vi.spyOn(ProviderUtil.state, 'providerIds', 'get').mockReturnValue({
|
|
199
|
+
eip155: 'walletConnect',
|
|
200
|
+
solana: undefined,
|
|
201
|
+
polkadot: undefined
|
|
202
|
+
});
|
|
203
|
+
await client.switchNetwork(optimism);
|
|
204
|
+
expect(mockAppKit.universalAdapter?.networkControllerClient.switchCaipNetwork).toHaveBeenCalledWith(optimism);
|
|
205
|
+
});
|
|
206
|
+
it('should set requested CAIP networks for each unique chain namespace', () => {
|
|
207
|
+
const caipNetworks = [mainnet, arbitrum, polygon];
|
|
208
|
+
client['syncRequestedNetworks'](caipNetworks);
|
|
209
|
+
expect(mockAppKit.setRequestedCaipNetworks).toHaveBeenCalledWith([mainnet, arbitrum, polygon], 'eip155');
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
describe('EthersClient - Auth Connector', () => {
|
|
213
|
+
it('should sync auth connector', async () => {
|
|
214
|
+
const projectId = 'test-project-id';
|
|
215
|
+
await client['syncAuthConnector'](projectId, true);
|
|
216
|
+
expect(mockAppKit.addConnector).toHaveBeenCalledWith({
|
|
217
|
+
id: ConstantsUtil.AUTH_CONNECTOR_ID,
|
|
218
|
+
type: 'AUTH',
|
|
219
|
+
name: 'Auth',
|
|
220
|
+
provider: expect.any(Object),
|
|
221
|
+
chain: 'eip155'
|
|
222
|
+
});
|
|
223
|
+
expect(mockAppKit.setLoading).toHaveBeenCalledWith(false);
|
|
224
|
+
});
|
|
225
|
+
describe('Auth Connector Handle Requests', () => {
|
|
226
|
+
beforeEach(() => {
|
|
227
|
+
client['appKit'] = mockAppKit;
|
|
228
|
+
});
|
|
229
|
+
it('should handle RPC request correctly when modal is closed', () => {
|
|
230
|
+
vi.spyOn(mockAppKit, 'isOpen').mockReturnValue(false);
|
|
231
|
+
mockAppKit['handleUnsafeRPCRequest']();
|
|
232
|
+
expect(mockAppKit.open).toHaveBeenCalledWith({ view: 'ApproveTransaction' });
|
|
233
|
+
});
|
|
234
|
+
it('should handle RPC request correctly when modal is open and transaction stack is not empty', () => {
|
|
235
|
+
vi.spyOn(mockAppKit, 'isOpen').mockReturnValue(true);
|
|
236
|
+
vi.spyOn(mockAppKit, 'isTransactionStackEmpty').mockReturnValue(false);
|
|
237
|
+
vi.spyOn(mockAppKit, 'isTransactionShouldReplaceView').mockReturnValue(true);
|
|
238
|
+
mockAppKit['handleUnsafeRPCRequest']();
|
|
239
|
+
expect(mockAppKit.redirect).toHaveBeenCalledWith('ApproveTransaction');
|
|
240
|
+
});
|
|
241
|
+
it('should handle invalid auth request', () => {
|
|
242
|
+
vi.useFakeTimers();
|
|
243
|
+
client['handleInvalidAuthRequest']();
|
|
244
|
+
expect(mockAppKit.open).toHaveBeenCalled();
|
|
245
|
+
vi.advanceTimersByTime(300);
|
|
246
|
+
expect(mockAppKit.showErrorMessage).toHaveBeenCalledWith('RPC method not allowed');
|
|
247
|
+
vi.useRealTimers();
|
|
248
|
+
});
|
|
249
|
+
it('should handle auth RPC error when modal is open and transaction stack is empty', () => {
|
|
250
|
+
vi.spyOn(mockAppKit, 'isOpen').mockReturnValue(true);
|
|
251
|
+
vi.spyOn(mockAppKit, 'isTransactionStackEmpty').mockReturnValue(true);
|
|
252
|
+
client['handleAuthRpcError']();
|
|
253
|
+
expect(mockAppKit.close).toHaveBeenCalled();
|
|
254
|
+
});
|
|
255
|
+
it('should handle auth RPC error when modal is open and transaction stack is not empty', () => {
|
|
256
|
+
vi.spyOn(mockAppKit, 'isOpen').mockReturnValue(true);
|
|
257
|
+
vi.spyOn(mockAppKit, 'isTransactionStackEmpty').mockReturnValue(false);
|
|
258
|
+
client['handleAuthRpcError']();
|
|
259
|
+
expect(mockAppKit.popTransactionStack).toHaveBeenCalledWith(true);
|
|
260
|
+
});
|
|
261
|
+
it('should handle auth RPC success when transaction stack is empty', () => {
|
|
262
|
+
vi.spyOn(mockAppKit, 'isTransactionStackEmpty').mockReturnValue(true);
|
|
263
|
+
client['handleAuthRpcSuccess']({ type: '@w3m-frame/SWITCH_NETWORK_SUCCESS', payload: { chainId: '137' } }, { method: 'eth_accounts' });
|
|
264
|
+
expect(mockAppKit.close).toHaveBeenCalled();
|
|
265
|
+
});
|
|
266
|
+
it('should handle auth RPC success when transaction stack is not empty', () => {
|
|
267
|
+
vi.spyOn(mockAppKit, 'isTransactionStackEmpty').mockReturnValue(false);
|
|
268
|
+
client['handleAuthRpcSuccess']({ type: '@w3m-frame/SWITCH_NETWORK_SUCCESS', payload: { chainId: '137' } }, { method: 'eth_accounts' });
|
|
269
|
+
expect(mockAppKit.popTransactionStack).toHaveBeenCalledWith();
|
|
270
|
+
});
|
|
271
|
+
it('should handle auth not connected', () => {
|
|
272
|
+
client['handleAuthNotConnected']();
|
|
273
|
+
expect(mockAppKit.setCaipAddress).toHaveBeenCalledWith(undefined, 'eip155');
|
|
274
|
+
});
|
|
275
|
+
it('should handle auth is connected', () => {
|
|
276
|
+
vi.spyOn(mockAppKit, 'getActiveChainNamespace').mockReturnValue('eip155');
|
|
277
|
+
const preferredAccountType = 'eoa';
|
|
278
|
+
client['handleAuthIsConnected'](preferredAccountType);
|
|
279
|
+
expect(mockAppKit.setPreferredAccountType).toHaveBeenCalledWith(preferredAccountType, 'eip155');
|
|
280
|
+
});
|
|
281
|
+
it('should handle auth set preferred account', async () => {
|
|
282
|
+
const address = '0x1234567890123456789012345678901234567890';
|
|
283
|
+
const type = 'eoa';
|
|
284
|
+
vi.spyOn(mockAppKit, 'getCaipNetwork').mockReturnValue(mainnet);
|
|
285
|
+
client['caipNetworks'] = [mainnet];
|
|
286
|
+
vi.spyOn(client, 'syncAccount').mockResolvedValue(undefined);
|
|
287
|
+
await client['handleAuthSetPreferredAccount'](address, type);
|
|
288
|
+
expect(mockAppKit.setLoading).toHaveBeenCalledWith(true);
|
|
289
|
+
expect(mockAppKit.setCaipAddress).toHaveBeenCalledWith(`eip155:${1}:${address}`, 'eip155');
|
|
290
|
+
expect(mockAppKit.setStatus).toHaveBeenCalledWith('connected', 'eip155');
|
|
291
|
+
expect(mockAppKit.setPreferredAccountType).toHaveBeenCalledWith(type, 'eip155');
|
|
292
|
+
await new Promise(resolve => setImmediate(resolve));
|
|
293
|
+
expect(mockAppKit.setLoading).toHaveBeenLastCalledWith(false);
|
|
294
|
+
});
|
|
295
|
+
});
|
|
296
|
+
describe('setAuthConnector', () => {
|
|
297
|
+
beforeEach(() => {
|
|
298
|
+
client['appKit'] = mockAppKit;
|
|
299
|
+
client['authProvider'] = mockAuthConnector;
|
|
300
|
+
vi.mocked(ProviderUtil.setProvider).mockClear();
|
|
301
|
+
vi.mocked(ProviderUtil.setProviderId).mockClear();
|
|
302
|
+
});
|
|
303
|
+
it('should set auth provider and update appKit state', async () => {
|
|
304
|
+
const mockAddress = '0x1234567890123456789012345678901234567890';
|
|
305
|
+
const mockChainId = 1;
|
|
306
|
+
const mockSmartAccountDeployed = true;
|
|
307
|
+
const mockPreferredAccountType = 'eoa';
|
|
308
|
+
mockAuthConnector.connect.mockResolvedValueOnce({
|
|
309
|
+
address: mockAddress,
|
|
310
|
+
chainId: mockChainId,
|
|
311
|
+
smartAccountDeployed: mockSmartAccountDeployed,
|
|
312
|
+
preferredAccountType: mockPreferredAccountType,
|
|
313
|
+
accounts: []
|
|
314
|
+
});
|
|
315
|
+
mockAuthConnector.getSmartAccountEnabledNetworks.mockResolvedValueOnce({
|
|
316
|
+
smartAccountEnabledNetworks: [1, 137]
|
|
317
|
+
});
|
|
318
|
+
await client['setAuthProvider']();
|
|
319
|
+
expect(mockAppKit.setSmartAccountEnabledNetworks).toHaveBeenCalledWith([1, 137], 'eip155');
|
|
320
|
+
expect(mockAppKit.setAllAccounts).toHaveBeenCalledWith([{ address: mockAddress, type: mockPreferredAccountType }], 'eip155');
|
|
321
|
+
expect(mockAppKit.setStatus).toHaveBeenCalledWith('connected', 'eip155');
|
|
322
|
+
expect(mockAppKit.setCaipAddress).toHaveBeenCalledWith(`eip155:${mockChainId}:${mockAddress}`, 'eip155');
|
|
323
|
+
expect(mockAppKit.setPreferredAccountType).toHaveBeenCalledWith(mockPreferredAccountType, 'eip155');
|
|
324
|
+
expect(mockAppKit.setSmartAccountDeployed).toHaveBeenCalledWith(mockSmartAccountDeployed, 'eip155');
|
|
325
|
+
expect(ProviderUtil.setProvider).toHaveBeenCalledWith('eip155', expect.any(Object));
|
|
326
|
+
expect(ProviderUtil.setProviderId).toHaveBeenCalledWith('eip155', ConstantsUtil.AUTH_CONNECTOR_ID);
|
|
327
|
+
});
|
|
328
|
+
});
|
|
329
|
+
});
|
|
330
|
+
describe('EthersClient - Sync Connectors', () => {
|
|
331
|
+
it('should handle sync EIP-6963 connector', () => {
|
|
332
|
+
const mockEIP6963Event = {
|
|
333
|
+
detail: {
|
|
334
|
+
info: {
|
|
335
|
+
uuid: 'mock-uuid',
|
|
336
|
+
name: 'MockWallet',
|
|
337
|
+
icon: 'mock-icon-url',
|
|
338
|
+
rdns: 'com.mockwallet'
|
|
339
|
+
},
|
|
340
|
+
provider: {
|
|
341
|
+
request: vi.fn(),
|
|
342
|
+
on: vi.fn(),
|
|
343
|
+
removeListener: vi.fn(),
|
|
344
|
+
emit: function (event) {
|
|
345
|
+
throw new Error(event);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
};
|
|
350
|
+
client['eip6963EventHandler'](mockEIP6963Event);
|
|
351
|
+
expect(mockAppKit.addConnector).toHaveBeenCalledWith(expect.objectContaining({
|
|
352
|
+
id: 'eip6963',
|
|
353
|
+
name: 'MockWallet'
|
|
354
|
+
}));
|
|
355
|
+
});
|
|
356
|
+
it('should sync injected connector when config.injected is true', () => {
|
|
357
|
+
const config = { injected: true, coinbase: false, metadata: {} };
|
|
358
|
+
client['syncConnectors'](config);
|
|
359
|
+
expect(mockAppKit.setConnectors).toHaveBeenCalledWith([
|
|
360
|
+
expect.objectContaining({
|
|
361
|
+
id: 'injected',
|
|
362
|
+
name: 'Injected',
|
|
363
|
+
type: 'INJECTED',
|
|
364
|
+
chain: 'eip155'
|
|
365
|
+
})
|
|
366
|
+
]);
|
|
367
|
+
});
|
|
368
|
+
it('should sync coinbase connector when config.coinbase is true', () => {
|
|
369
|
+
const config = { injected: false, coinbase: true, metadata: {} };
|
|
370
|
+
client['syncConnectors'](config);
|
|
371
|
+
expect(mockAppKit.setConnectors).toHaveBeenCalledWith([
|
|
372
|
+
expect.objectContaining({
|
|
373
|
+
id: 'coinbaseWallet',
|
|
374
|
+
name: 'Coinbase',
|
|
375
|
+
type: 'EXTERNAL',
|
|
376
|
+
chain: 'eip155'
|
|
377
|
+
})
|
|
378
|
+
]);
|
|
379
|
+
});
|
|
380
|
+
it('should sync both connectors when both are true in config', () => {
|
|
381
|
+
const config = { injected: true, coinbase: true, metadata: {} };
|
|
382
|
+
client['syncConnectors'](config);
|
|
383
|
+
expect(mockAppKit.setConnectors).toHaveBeenCalledWith([
|
|
384
|
+
expect.objectContaining({
|
|
385
|
+
id: 'injected',
|
|
386
|
+
name: 'Injected',
|
|
387
|
+
type: 'INJECTED',
|
|
388
|
+
chain: 'eip155'
|
|
389
|
+
}),
|
|
390
|
+
expect.objectContaining({
|
|
391
|
+
id: 'coinbaseWallet',
|
|
392
|
+
name: 'Coinbase',
|
|
393
|
+
type: 'EXTERNAL',
|
|
394
|
+
chain: 'eip155'
|
|
395
|
+
})
|
|
396
|
+
]);
|
|
397
|
+
});
|
|
398
|
+
it('should not sync any connectors when both are false in config', () => {
|
|
399
|
+
const config = { injected: false, coinbase: false, metadata: {} };
|
|
400
|
+
client['syncConnectors'](config);
|
|
401
|
+
expect(mockAppKit.setConnectors).toHaveBeenCalledWith([]);
|
|
402
|
+
});
|
|
403
|
+
});
|
|
404
|
+
describe('EthersClient - State Subscription', () => {
|
|
405
|
+
it('should subscribe to state changes', () => {
|
|
406
|
+
const mockCallback = vi.fn();
|
|
407
|
+
client.subscribeState(mockCallback);
|
|
408
|
+
expect(mockAppKit.subscribeState).toHaveBeenCalled();
|
|
409
|
+
});
|
|
410
|
+
});
|
|
411
|
+
describe('EthersClient - setProvider', () => {
|
|
412
|
+
beforeEach(() => {
|
|
413
|
+
vi.spyOn(SafeLocalStorage, 'setItem');
|
|
414
|
+
vi.spyOn(EthersHelpersUtil, 'getUserInfo').mockResolvedValue({
|
|
415
|
+
addresses: ['0x1234567890123456789012345678901234567890'],
|
|
416
|
+
chainId: 1
|
|
417
|
+
});
|
|
418
|
+
});
|
|
419
|
+
it('should set provider for non-auth providers', async () => {
|
|
420
|
+
const mockProvider = { request: vi.fn() };
|
|
421
|
+
await client['setProvider'](mockProvider, 'injected', 'MetaMask');
|
|
422
|
+
expect(SafeLocalStorage.setItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID, 'injected');
|
|
423
|
+
expect(SafeLocalStorage.setItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_NAME, 'MetaMask');
|
|
424
|
+
expect(mockAppKit.setCaipAddress).toHaveBeenCalled();
|
|
425
|
+
expect(ProviderUtil.setProviderId).toHaveBeenCalledWith('eip155', 'injected');
|
|
426
|
+
expect(ProviderUtil.setProvider).toHaveBeenCalledWith('eip155', mockProvider);
|
|
427
|
+
expect(mockAppKit.setStatus).toHaveBeenCalledWith('connected', 'eip155');
|
|
428
|
+
expect(mockAppKit.setAllAccounts).toHaveBeenCalled();
|
|
429
|
+
});
|
|
430
|
+
});
|
|
431
|
+
describe('EthersClient - setupProviderListeners', () => {
|
|
432
|
+
let mockProvider;
|
|
433
|
+
beforeEach(() => {
|
|
434
|
+
mockProvider = {
|
|
435
|
+
on: vi.fn(),
|
|
436
|
+
removeListener: vi.fn()
|
|
437
|
+
};
|
|
438
|
+
});
|
|
439
|
+
it('should set up listeners for non-auth providers', () => {
|
|
440
|
+
client['setupProviderListeners'](mockProvider, 'injected');
|
|
441
|
+
expect(mockProvider.on).toHaveBeenCalledWith('disconnect', expect.any(Function));
|
|
442
|
+
expect(mockProvider.on).toHaveBeenCalledWith('accountsChanged', expect.any(Function));
|
|
443
|
+
expect(mockProvider.on).toHaveBeenCalledWith('chainChanged', expect.any(Function));
|
|
444
|
+
});
|
|
445
|
+
it('should handle disconnect event', async () => {
|
|
446
|
+
vi.spyOn(SafeLocalStorage, 'removeItem');
|
|
447
|
+
client['setupProviderListeners'](mockProvider, 'injected');
|
|
448
|
+
const disconnectHandler = mockProvider.on.mock.calls.find((call) => call[0] === 'disconnect')[1];
|
|
449
|
+
await disconnectHandler();
|
|
450
|
+
expect(SafeLocalStorage.removeItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID);
|
|
451
|
+
expect(mockProvider.removeListener).toHaveBeenCalledTimes(3);
|
|
452
|
+
});
|
|
453
|
+
it('should handle accountsChanged event', async () => {
|
|
454
|
+
client['setupProviderListeners'](mockProvider, 'injected');
|
|
455
|
+
const accountsChangedHandler = mockProvider.on.mock.calls.find((call) => call[0] === 'accountsChanged')[1];
|
|
456
|
+
await accountsChangedHandler(['0x1234567890123456789012345678901234567890']);
|
|
457
|
+
expect(mockAppKit.setCaipAddress).toHaveBeenCalled();
|
|
458
|
+
});
|
|
459
|
+
it('should handle chainChanged event', async () => {
|
|
460
|
+
client['setupProviderListeners'](mockProvider, 'injected');
|
|
461
|
+
const chainChangedHandler = mockProvider.on.mock.calls.find((call) => call[0] === 'chainChanged')[1];
|
|
462
|
+
await chainChangedHandler('0x10');
|
|
463
|
+
expect(mockAppKit.setCaipNetwork).toHaveBeenCalled();
|
|
464
|
+
});
|
|
465
|
+
});
|
|
466
|
+
describe('EthersClient - checkActiveProviders', () => {
|
|
467
|
+
let mockInjectedProvider;
|
|
468
|
+
beforeEach(() => {
|
|
469
|
+
mockInjectedProvider = {
|
|
470
|
+
request: vi.fn(),
|
|
471
|
+
on: vi.fn(),
|
|
472
|
+
removeListener: vi.fn()
|
|
473
|
+
};
|
|
474
|
+
vi.spyOn(SafeLocalStorage, 'getItem').mockImplementation(key => {
|
|
475
|
+
if (key === SafeLocalStorageKeys.WALLET_ID)
|
|
476
|
+
return ConstantsUtil.INJECTED_CONNECTOR_ID;
|
|
477
|
+
if (key === SafeLocalStorageKeys.WALLET_NAME)
|
|
478
|
+
return 'MetaMask';
|
|
479
|
+
return undefined;
|
|
480
|
+
});
|
|
481
|
+
vi.spyOn(client, 'setProvider').mockImplementation(() => Promise.resolve());
|
|
482
|
+
vi.spyOn(client, 'setupProviderListeners').mockImplementation(() => { });
|
|
483
|
+
});
|
|
484
|
+
it('should check and set active provider for injected wallet', () => {
|
|
485
|
+
const mockConfig = {
|
|
486
|
+
injected: mockInjectedProvider,
|
|
487
|
+
coinbase: undefined,
|
|
488
|
+
metadata: {}
|
|
489
|
+
};
|
|
490
|
+
client['checkActiveProviders'](mockConfig);
|
|
491
|
+
expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID);
|
|
492
|
+
expect(client['setProvider']).toHaveBeenCalledWith(mockInjectedProvider, ConstantsUtil.INJECTED_CONNECTOR_ID);
|
|
493
|
+
expect(client['setupProviderListeners']).toHaveBeenCalledWith(mockInjectedProvider, ConstantsUtil.INJECTED_CONNECTOR_ID);
|
|
494
|
+
});
|
|
495
|
+
it('should not set provider when wallet ID is not found', () => {
|
|
496
|
+
vi.spyOn(SafeLocalStorage, 'getItem').mockReturnValue(undefined);
|
|
497
|
+
const mockConfig = {
|
|
498
|
+
injected: mockInjectedProvider,
|
|
499
|
+
coinbase: undefined,
|
|
500
|
+
metadata: {}
|
|
501
|
+
};
|
|
502
|
+
client['checkActiveProviders'](mockConfig);
|
|
503
|
+
expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID);
|
|
504
|
+
expect(client['setProvider']).not.toHaveBeenCalled();
|
|
505
|
+
expect(client['setupProviderListeners']).not.toHaveBeenCalled();
|
|
506
|
+
});
|
|
507
|
+
it('should not set provider when injected provider is not available', () => {
|
|
508
|
+
const mockConfig = {
|
|
509
|
+
injected: undefined,
|
|
510
|
+
coinbase: undefined,
|
|
511
|
+
metadata: {}
|
|
512
|
+
};
|
|
513
|
+
client['checkActiveProviders'](mockConfig);
|
|
514
|
+
expect(SafeLocalStorage.getItem).toHaveBeenCalledWith(SafeLocalStorageKeys.WALLET_ID);
|
|
515
|
+
expect(client['setProvider']).not.toHaveBeenCalled();
|
|
516
|
+
expect(client['setupProviderListeners']).not.toHaveBeenCalled();
|
|
517
|
+
});
|
|
518
|
+
});
|
|
519
|
+
describe('EthersClient - syncAccount', () => {
|
|
520
|
+
beforeEach(() => {
|
|
521
|
+
vi.spyOn(client, 'syncConnectedWalletInfo').mockImplementation(() => { });
|
|
522
|
+
vi.spyOn(client, 'setupProviderListeners').mockImplementation(() => { });
|
|
523
|
+
vi.spyOn(client, 'setProvider').mockImplementation(() => Promise.resolve());
|
|
524
|
+
vi.spyOn(client, 'syncProfile').mockImplementation(() => Promise.resolve());
|
|
525
|
+
vi.spyOn(client, 'syncBalance').mockImplementation(() => Promise.resolve());
|
|
526
|
+
vi.spyOn(mockAppKit, 'getIsConnectedState').mockReturnValue(true);
|
|
527
|
+
vi.spyOn(mockAppKit, 'getPreferredAccountType').mockReturnValue('eoa');
|
|
528
|
+
});
|
|
529
|
+
it('should sync account when connected and address is provided', async () => {
|
|
530
|
+
const mockAddress = '0x1234567890123456789012345678901234567890';
|
|
531
|
+
const mockCaipNetwork = mainnet;
|
|
532
|
+
vi.spyOn(mockAppKit, 'getCaipNetwork').mockReturnValue(mockCaipNetwork);
|
|
533
|
+
vi.spyOn(EthersHelpersUtil, 'getUserInfo').mockResolvedValue({
|
|
534
|
+
addresses: ['0x1234567890123456789012345678901234567890'],
|
|
535
|
+
chainId: 1
|
|
536
|
+
});
|
|
537
|
+
await client['syncAccount']({ address: mockAddress });
|
|
538
|
+
expect(mockAppKit.setPreferredAccountType).toHaveBeenCalledWith('eoa', 'eip155');
|
|
539
|
+
expect(mockAppKit.setAddressExplorerUrl).toHaveBeenCalledWith(`https://etherscan.io/address/${mockAddress}`, 'eip155');
|
|
540
|
+
expect(client['syncConnectedWalletInfo']).toHaveBeenCalled();
|
|
541
|
+
expect(client['syncProfile']).toHaveBeenCalledWith(mockAddress);
|
|
542
|
+
expect(mockAppKit.setCaipAddress).toHaveBeenCalledTimes(2);
|
|
543
|
+
expect(mockAppKit.setCaipAddress).toHaveBeenCalledWith(`eip155:${mainnet.id}:${mockAddress}`, 'eip155');
|
|
544
|
+
expect(mockAppKit.setCaipNetwork).toHaveBeenCalledOnce();
|
|
545
|
+
expect(mockAppKit.setCaipNetwork).toHaveBeenCalledWith(mainnet);
|
|
546
|
+
expect(mockAppKit.setApprovedCaipNetworksData).toHaveBeenCalledWith('eip155');
|
|
547
|
+
});
|
|
548
|
+
it('it should fallback to first available chain if current chain is unsupported', async () => {
|
|
549
|
+
const mockAddress = '0x1234567890123456789012345678901234567890';
|
|
550
|
+
vi.spyOn(EthersHelpersUtil, 'getUserInfo').mockResolvedValue({
|
|
551
|
+
addresses: [mockAddress],
|
|
552
|
+
chainId: AppkitHarmonyOne.id
|
|
553
|
+
});
|
|
554
|
+
await client['syncAccount']({ address: mockAddress });
|
|
555
|
+
expect(mockAppKit.setCaipAddress).toHaveBeenCalledTimes(2);
|
|
556
|
+
expect(mockAppKit.setCaipAddress).toHaveBeenCalledWith(`eip155:${mainnet.id}:${mockAddress}`, 'eip155');
|
|
557
|
+
expect(mockAppKit.setCaipNetwork).toHaveBeenCalledOnce();
|
|
558
|
+
expect(mockAppKit.setCaipNetwork).toHaveBeenCalledWith(mainnet);
|
|
559
|
+
});
|
|
560
|
+
it('should reset connection when not connected', async () => {
|
|
561
|
+
vi.spyOn(mockAppKit, 'getIsConnectedState').mockReturnValue(false);
|
|
562
|
+
await client['syncAccount']({});
|
|
563
|
+
expect(mockAppKit.resetWcConnection).toHaveBeenCalled();
|
|
564
|
+
expect(mockAppKit.resetNetwork).toHaveBeenCalled();
|
|
565
|
+
expect(mockAppKit.setAllAccounts).toHaveBeenCalledWith([], 'eip155');
|
|
566
|
+
});
|
|
567
|
+
});
|
|
568
|
+
describe('EthersClient - syncProfile', () => {
|
|
569
|
+
const mockAddress = '0x1234567890123456789012345678901234567890';
|
|
570
|
+
beforeEach(() => {
|
|
571
|
+
vi.spyOn(client, 'syncReownName').mockImplementation(() => Promise.resolve());
|
|
572
|
+
});
|
|
573
|
+
it('should set profile from fetchIdentity when successful', async () => {
|
|
574
|
+
const mockIdentity = { name: 'Test Name', avatar: 'https://example.com/avatar.png' };
|
|
575
|
+
vi.spyOn(mockAppKit, 'fetchIdentity').mockResolvedValue(mockIdentity);
|
|
576
|
+
await client['syncProfile'](mockAddress);
|
|
577
|
+
expect(mockAppKit.setProfileName).toHaveBeenCalledWith('Test Name', 'eip155');
|
|
578
|
+
expect(mockAppKit.setProfileImage).toHaveBeenCalledWith('https://example.com/avatar.png', 'eip155');
|
|
579
|
+
});
|
|
580
|
+
it('should use ENS for mainnet when fetchIdentity fails', async () => {
|
|
581
|
+
vi.spyOn(mockAppKit, 'fetchIdentity').mockRejectedValue(new Error('Fetch failed'));
|
|
582
|
+
vi.spyOn(mockAppKit, 'getCaipNetwork').mockReturnValue(mainnet);
|
|
583
|
+
const mockEnsProvider = {
|
|
584
|
+
lookupAddress: vi.fn().mockResolvedValue('test.eth'),
|
|
585
|
+
getAvatar: vi.fn().mockResolvedValue('https://example.com/ens-avatar.png')
|
|
586
|
+
};
|
|
587
|
+
vi.mocked(InfuraProvider).mockImplementation(() => mockEnsProvider);
|
|
588
|
+
await client['syncProfile'](mockAddress);
|
|
589
|
+
expect(mockAppKit.setProfileName).toHaveBeenCalledWith('test.eth', 'eip155');
|
|
590
|
+
expect(mockAppKit.setProfileImage).toHaveBeenCalledWith('https://example.com/ens-avatar.png', 'eip155');
|
|
591
|
+
});
|
|
592
|
+
it('should fallback to syncReownName for non-mainnet chains', async () => {
|
|
593
|
+
vi.spyOn(mockAppKit, 'fetchIdentity').mockRejectedValue(new Error('Fetch failed'));
|
|
594
|
+
vi.spyOn(mockAppKit, 'getCaipNetwork').mockReturnValue(polygon);
|
|
595
|
+
await client['syncProfile'](mockAddress);
|
|
596
|
+
expect(client['syncReownName']).toHaveBeenCalledWith(mockAddress);
|
|
597
|
+
expect(mockAppKit.setProfileImage).toHaveBeenCalledWith(null, 'eip155');
|
|
598
|
+
});
|
|
599
|
+
});
|
|
600
|
+
describe('EthersClient - syncBalance', () => {
|
|
601
|
+
const mockAddress = '0x1234567890123456789012345678901234567890';
|
|
602
|
+
it.skip('should set balance when caipNetwork is available', async () => {
|
|
603
|
+
vi.spyOn(mockAppKit, 'getCaipNetwork').mockReturnValue(mainnet);
|
|
604
|
+
const mockJsonRpcProvider = {
|
|
605
|
+
getBalance: vi.fn().mockResolvedValue(BigInt(1000000000000000000))
|
|
606
|
+
};
|
|
607
|
+
vi.mocked(JsonRpcProvider).mockImplementation(() => mockJsonRpcProvider);
|
|
608
|
+
await client['syncBalance'](mockAddress, mainnet);
|
|
609
|
+
expect(JsonRpcProvider).toHaveBeenCalledWith(mainnet.rpcUrls.default.http[0], {
|
|
610
|
+
chainId: 1,
|
|
611
|
+
name: 'Ethereum'
|
|
612
|
+
});
|
|
613
|
+
expect(mockJsonRpcProvider.getBalance).toHaveBeenCalledWith(mockAddress);
|
|
614
|
+
expect(mockAppKit.setBalance).toHaveBeenCalledWith('1.0', 'ETH', 'eip155');
|
|
615
|
+
});
|
|
616
|
+
it('should not set balance when caipNetwork is unavailable', async () => {
|
|
617
|
+
vi.spyOn(mockAppKit, 'getCaipNetworks').mockReturnValue([]);
|
|
618
|
+
await client['syncBalance'](mockAddress, mainnet);
|
|
619
|
+
expect(JsonRpcProvider).not.toHaveBeenCalled();
|
|
620
|
+
expect(mockAppKit.setBalance).not.toHaveBeenCalled();
|
|
621
|
+
});
|
|
622
|
+
});
|
|
623
|
+
describe('EthersClient - syncReownName', () => {
|
|
624
|
+
const mockAddress = '0x1234567890123456789012345678901234567890';
|
|
625
|
+
it('should set profile name when WalletConnect name is available', async () => {
|
|
626
|
+
const mockWcNames = [
|
|
627
|
+
{ name: 'WC Wallet', registered: 1, updated: 1234567890, addresses: [], attributes: {} }
|
|
628
|
+
];
|
|
629
|
+
vi.spyOn(mockAppKit, 'getReownName').mockResolvedValue(mockWcNames);
|
|
630
|
+
await client['syncReownName'](mockAddress);
|
|
631
|
+
expect(mockAppKit.getReownName).toHaveBeenCalledWith(mockAddress);
|
|
632
|
+
expect(mockAppKit.setProfileName).toHaveBeenCalledWith('WC Wallet', 'eip155');
|
|
633
|
+
});
|
|
634
|
+
it('should set profile name to null when no WalletConnect name is available', async () => {
|
|
635
|
+
vi.spyOn(mockAppKit, 'getReownName').mockResolvedValue([]);
|
|
636
|
+
await client['syncReownName'](mockAddress);
|
|
637
|
+
expect(mockAppKit.getReownName).toHaveBeenCalledWith(mockAddress);
|
|
638
|
+
expect(mockAppKit.setProfileName).toHaveBeenCalledWith(null, 'eip155');
|
|
639
|
+
});
|
|
640
|
+
it('should set profile name to null when getReownName throws an error', async () => {
|
|
641
|
+
vi.spyOn(mockAppKit, 'getReownName').mockRejectedValue(new Error('API Error'));
|
|
642
|
+
await client['syncReownName'](mockAddress);
|
|
643
|
+
expect(mockAppKit.getReownName).toHaveBeenCalledWith(mockAddress);
|
|
644
|
+
expect(mockAppKit.setProfileName).toHaveBeenCalledWith(null, 'eip155');
|
|
645
|
+
});
|
|
646
|
+
});
|
|
647
|
+
describe('EthersClient - syncConnectedWalletInfo', () => {
|
|
648
|
+
beforeEach(() => {
|
|
649
|
+
vi.spyOn(SafeLocalStorage, 'getItem').mockReturnValue('MetaMask');
|
|
650
|
+
vi.spyOn(ProviderUtil.state, 'providerIds', 'get').mockReturnValue({
|
|
651
|
+
eip155: 'injected',
|
|
652
|
+
solana: undefined,
|
|
653
|
+
polkadot: undefined
|
|
654
|
+
});
|
|
655
|
+
});
|
|
656
|
+
it('should set connected wallet info for EIP6963 provider', () => {
|
|
657
|
+
vi.spyOn(ProviderUtil.state, 'providerIds', 'get').mockReturnValue({
|
|
658
|
+
eip155: ConstantsUtil.EIP6963_CONNECTOR_ID,
|
|
659
|
+
solana: undefined
|
|
660
|
+
});
|
|
661
|
+
client['EIP6963Providers'] = [
|
|
662
|
+
{
|
|
663
|
+
info: { name: 'MetaMask', icon: 'icon-url', uuid: 'test-uuid', rdns: 'com.metamask' },
|
|
664
|
+
provider: {}
|
|
665
|
+
}
|
|
666
|
+
];
|
|
667
|
+
client['syncConnectedWalletInfo']();
|
|
668
|
+
expect(mockAppKit.setConnectedWalletInfo).toHaveBeenCalledWith({ name: 'MetaMask', icon: 'icon-url', uuid: 'test-uuid', rdns: 'com.metamask' }, 'eip155');
|
|
669
|
+
});
|
|
670
|
+
it('should set connected wallet info for WalletConnect provider', () => {
|
|
671
|
+
vi.spyOn(ProviderUtil.state, 'providerIds', 'get').mockReturnValue({
|
|
672
|
+
eip155: ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID,
|
|
673
|
+
solana: undefined
|
|
674
|
+
});
|
|
675
|
+
const mockProvider = {
|
|
676
|
+
session: {
|
|
677
|
+
peer: {
|
|
678
|
+
metadata: {
|
|
679
|
+
name: 'WC Wallet',
|
|
680
|
+
icons: ['wc-icon-url']
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
};
|
|
685
|
+
vi.spyOn(ProviderUtil, 'getProvider').mockReturnValue(mockProvider);
|
|
686
|
+
client['syncConnectedWalletInfo']();
|
|
687
|
+
expect(mockAppKit.setConnectedWalletInfo).toHaveBeenCalledWith({
|
|
688
|
+
name: 'WC Wallet',
|
|
689
|
+
icon: 'wc-icon-url',
|
|
690
|
+
icons: ['wc-icon-url']
|
|
691
|
+
}, 'eip155');
|
|
692
|
+
});
|
|
693
|
+
it('should set connected wallet info for Coinbase provider', () => {
|
|
694
|
+
vi.spyOn(ProviderUtil.state, 'providerIds', 'get').mockReturnValue({
|
|
695
|
+
eip155: ConstantsUtil.COINBASE_SDK_CONNECTOR_ID,
|
|
696
|
+
solana: undefined
|
|
697
|
+
});
|
|
698
|
+
vi.spyOn(mockAppKit, 'getConnectors').mockReturnValue([
|
|
699
|
+
{
|
|
700
|
+
id: ConstantsUtil.COINBASE_SDK_CONNECTOR_ID,
|
|
701
|
+
type: 'INJECTED',
|
|
702
|
+
chain: 'eip155'
|
|
703
|
+
}
|
|
704
|
+
]);
|
|
705
|
+
vi.spyOn(mockAppKit, 'getConnectorImage').mockReturnValue('coinbase-icon-url');
|
|
706
|
+
client['syncConnectedWalletInfo']();
|
|
707
|
+
expect(mockAppKit.setConnectedWalletInfo).toHaveBeenCalledWith({ name: 'Coinbase Wallet', icon: 'coinbase-icon-url' }, 'eip155');
|
|
708
|
+
});
|
|
709
|
+
});
|
|
710
|
+
});
|
|
711
|
+
//# sourceMappingURL=client.test.js.map
|