@spacesops/wdk-react-native-core 1.0.0-beta.40
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/README.md +551 -0
- package/dist/__mocks__/react.d.ts +40 -0
- package/dist/__mocks__/react.js +33 -0
- package/dist/__mocks__/react.js.map +1 -0
- package/dist/__mocks__/secureStorage.d.ts +26 -0
- package/dist/__mocks__/secureStorage.js +80 -0
- package/dist/__mocks__/secureStorage.js.map +1 -0
- package/dist/__tests__/hooks/useBalance.test.d.ts +6 -0
- package/dist/__tests__/hooks/useBalance.test.js +217 -0
- package/dist/__tests__/hooks/useBalance.test.js.map +1 -0
- package/dist/__tests__/hooks/useWallet.test.d.ts +6 -0
- package/dist/__tests__/hooks/useWallet.test.js +105 -0
- package/dist/__tests__/hooks/useWallet.test.js.map +1 -0
- package/dist/__tests__/hooks/useWalletManager.test.d.ts +6 -0
- package/dist/__tests__/hooks/useWalletManager.test.js +193 -0
- package/dist/__tests__/hooks/useWalletManager.test.js.map +1 -0
- package/dist/__tests__/hooks/useWdkApp.test.d.ts +6 -0
- package/dist/__tests__/hooks/useWdkApp.test.js +55 -0
- package/dist/__tests__/hooks/useWdkApp.test.js.map +1 -0
- package/dist/__tests__/hooks/useWorklet.test.d.ts +6 -0
- package/dist/__tests__/hooks/useWorklet.test.js +168 -0
- package/dist/__tests__/hooks/useWorklet.test.js.map +1 -0
- package/dist/__tests__/provider/WdkAppProvider.test.d.ts +6 -0
- package/dist/__tests__/provider/WdkAppProvider.test.js +57 -0
- package/dist/__tests__/provider/WdkAppProvider.test.js.map +1 -0
- package/dist/__tests__/services/accountService.test.d.ts +6 -0
- package/dist/__tests__/services/accountService.test.js +216 -0
- package/dist/__tests__/services/accountService.test.js.map +1 -0
- package/dist/__tests__/services/addressService.test.d.ts +6 -0
- package/dist/__tests__/services/addressService.test.js +246 -0
- package/dist/__tests__/services/addressService.test.js.map +1 -0
- package/dist/__tests__/services/balanceService.test.d.ts +6 -0
- package/dist/__tests__/services/balanceService.test.js +333 -0
- package/dist/__tests__/services/balanceService.test.js.map +1 -0
- package/dist/__tests__/services/walletSetupService.test.d.ts +6 -0
- package/dist/__tests__/services/walletSetupService.test.js +304 -0
- package/dist/__tests__/services/walletSetupService.test.js.map +1 -0
- package/dist/__tests__/services/walletSwitchingService.test.d.ts +6 -0
- package/dist/__tests__/services/walletSwitchingService.test.js +209 -0
- package/dist/__tests__/services/walletSwitchingService.test.js.map +1 -0
- package/dist/__tests__/services/workletLifecycleService.test.d.ts +6 -0
- package/dist/__tests__/services/workletLifecycleService.test.js +451 -0
- package/dist/__tests__/services/workletLifecycleService.test.js.map +1 -0
- package/dist/__tests__/setup.d.ts +7 -0
- package/dist/__tests__/setup.js +49 -0
- package/dist/__tests__/setup.js.map +1 -0
- package/dist/__tests__/storage/mmkvStorage.test.d.ts +6 -0
- package/dist/__tests__/storage/mmkvStorage.test.js +213 -0
- package/dist/__tests__/storage/mmkvStorage.test.js.map +1 -0
- package/dist/__tests__/store/walletStore.test.d.ts +4 -0
- package/dist/__tests__/store/walletStore.test.js +86 -0
- package/dist/__tests__/store/walletStore.test.js.map +1 -0
- package/dist/__tests__/store/workletStore.test.d.ts +4 -0
- package/dist/__tests__/store/workletStore.test.js +255 -0
- package/dist/__tests__/store/workletStore.test.js.map +1 -0
- package/dist/__tests__/types/hrpc.test.d.ts +4 -0
- package/dist/__tests__/types/hrpc.test.js +99 -0
- package/dist/__tests__/types/hrpc.test.js.map +1 -0
- package/dist/__tests__/utils/balanceUtils.test.d.ts +4 -0
- package/dist/__tests__/utils/balanceUtils.test.js +133 -0
- package/dist/__tests__/utils/balanceUtils.test.js.map +1 -0
- package/dist/__tests__/utils/errorHandling.test.d.ts +6 -0
- package/dist/__tests__/utils/errorHandling.test.js +119 -0
- package/dist/__tests__/utils/errorHandling.test.js.map +1 -0
- package/dist/__tests__/utils/errorUtils.test.d.ts +4 -0
- package/dist/__tests__/utils/errorUtils.test.js +133 -0
- package/dist/__tests__/utils/errorUtils.test.js.map +1 -0
- package/dist/__tests__/utils/initializationState.test.d.ts +6 -0
- package/dist/__tests__/utils/initializationState.test.js +243 -0
- package/dist/__tests__/utils/initializationState.test.js.map +1 -0
- package/dist/__tests__/utils/jsonUtils.test.d.ts +4 -0
- package/dist/__tests__/utils/jsonUtils.test.js +118 -0
- package/dist/__tests__/utils/jsonUtils.test.js.map +1 -0
- package/dist/__tests__/utils/mmkvKeyManager.test.d.ts +6 -0
- package/dist/__tests__/utils/mmkvKeyManager.test.js +158 -0
- package/dist/__tests__/utils/mmkvKeyManager.test.js.map +1 -0
- package/dist/__tests__/utils/mnemonicUtils.test.d.ts +4 -0
- package/dist/__tests__/utils/mnemonicUtils.test.js +40 -0
- package/dist/__tests__/utils/mnemonicUtils.test.js.map +1 -0
- package/dist/__tests__/utils/raceConditions.test.d.ts +6 -0
- package/dist/__tests__/utils/raceConditions.test.js +239 -0
- package/dist/__tests__/utils/raceConditions.test.js.map +1 -0
- package/dist/__tests__/utils/result.test.d.ts +4 -0
- package/dist/__tests__/utils/result.test.js +66 -0
- package/dist/__tests__/utils/result.test.js.map +1 -0
- package/dist/__tests__/utils/schemas.test.d.ts +4 -0
- package/dist/__tests__/utils/schemas.test.js +66 -0
- package/dist/__tests__/utils/schemas.test.js.map +1 -0
- package/dist/__tests__/utils/storeHelpers.test.d.ts +4 -0
- package/dist/__tests__/utils/storeHelpers.test.js +227 -0
- package/dist/__tests__/utils/storeHelpers.test.js.map +1 -0
- package/dist/__tests__/utils/typeGuards.test.d.ts +4 -0
- package/dist/__tests__/utils/typeGuards.test.js +175 -0
- package/dist/__tests__/utils/typeGuards.test.js.map +1 -0
- package/dist/__tests__/utils/validation.test.d.ts +4 -0
- package/dist/__tests__/utils/validation.test.js +126 -0
- package/dist/__tests__/utils/validation.test.js.map +1 -0
- package/dist/__tests__/utils/walletUtils.test.d.ts +4 -0
- package/dist/__tests__/utils/walletUtils.test.js +156 -0
- package/dist/__tests__/utils/walletUtils.test.js.map +1 -0
- package/dist/hooks/useBalance.d.ts +170 -0
- package/dist/hooks/useBalance.js +442 -0
- package/dist/hooks/useBalance.js.map +1 -0
- package/dist/hooks/useWallet.d.ts +43 -0
- package/dist/hooks/useWallet.js +193 -0
- package/dist/hooks/useWallet.js.map +1 -0
- package/dist/hooks/useWalletManager.d.ts +100 -0
- package/dist/hooks/useWalletManager.js +526 -0
- package/dist/hooks/useWalletManager.js.map +1 -0
- package/dist/hooks/useWdkApp.d.ts +66 -0
- package/dist/hooks/useWdkApp.js +74 -0
- package/dist/hooks/useWdkApp.js.map +1 -0
- package/dist/hooks/useWorklet.d.ts +66 -0
- package/dist/hooks/useWorklet.js +42 -0
- package/dist/hooks/useWorklet.js.map +1 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.js +36 -0
- package/dist/index.js.map +1 -0
- package/dist/provider/WdkAppProvider.d.ts +112 -0
- package/dist/provider/WdkAppProvider.js +558 -0
- package/dist/provider/WdkAppProvider.js.map +1 -0
- package/dist/services/accountService.d.ts +52 -0
- package/dist/services/accountService.js +119 -0
- package/dist/services/accountService.js.map +1 -0
- package/dist/services/addressService.d.ts +22 -0
- package/dist/services/addressService.js +110 -0
- package/dist/services/addressService.js.map +1 -0
- package/dist/services/balanceService.d.ts +114 -0
- package/dist/services/balanceService.js +208 -0
- package/dist/services/balanceService.js.map +1 -0
- package/dist/services/walletSetupService.d.ts +217 -0
- package/dist/services/walletSetupService.js +535 -0
- package/dist/services/walletSetupService.js.map +1 -0
- package/dist/services/walletSwitchingService.d.ts +48 -0
- package/dist/services/walletSwitchingService.js +143 -0
- package/dist/services/walletSwitchingService.js.map +1 -0
- package/dist/services/workletLifecycleService.d.ts +117 -0
- package/dist/services/workletLifecycleService.js +433 -0
- package/dist/services/workletLifecycleService.js.map +1 -0
- package/dist/storage/mmkvStorage.d.ts +44 -0
- package/dist/storage/mmkvStorage.js +348 -0
- package/dist/storage/mmkvStorage.js.map +1 -0
- package/dist/store/walletStore.d.ts +130 -0
- package/dist/store/walletStore.js +204 -0
- package/dist/store/walletStore.js.map +1 -0
- package/dist/store/workletStore.d.ts +121 -0
- package/dist/store/workletStore.js +256 -0
- package/dist/store/workletStore.js.map +1 -0
- package/dist/types/hrpc.d.ts +60 -0
- package/dist/types/hrpc.js +26 -0
- package/dist/types/hrpc.js.map +1 -0
- package/dist/types.d.ts +168 -0
- package/dist/types.js +7 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/balanceUtils.d.ts +30 -0
- package/dist/utils/balanceUtils.js +86 -0
- package/dist/utils/balanceUtils.js.map +1 -0
- package/dist/utils/constants.d.ts +66 -0
- package/dist/utils/constants.js +73 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/errorHandling.d.ts +47 -0
- package/dist/utils/errorHandling.js +54 -0
- package/dist/utils/errorHandling.js.map +1 -0
- package/dist/utils/errorUtils.d.ts +89 -0
- package/dist/utils/errorUtils.js +264 -0
- package/dist/utils/errorUtils.js.map +1 -0
- package/dist/utils/initializationState.d.ts +129 -0
- package/dist/utils/initializationState.js +220 -0
- package/dist/utils/initializationState.js.map +1 -0
- package/dist/utils/jsonUtils.d.ts +21 -0
- package/dist/utils/jsonUtils.js +67 -0
- package/dist/utils/jsonUtils.js.map +1 -0
- package/dist/utils/logger.d.ts +27 -0
- package/dist/utils/logger.js +50 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/mmkvKeyManager.d.ts +57 -0
- package/dist/utils/mmkvKeyManager.js +214 -0
- package/dist/utils/mmkvKeyManager.js.map +1 -0
- package/dist/utils/mnemonicUtils.d.ts +17 -0
- package/dist/utils/mnemonicUtils.js +28 -0
- package/dist/utils/mnemonicUtils.js.map +1 -0
- package/dist/utils/operationMutex.d.ts +69 -0
- package/dist/utils/operationMutex.js +150 -0
- package/dist/utils/operationMutex.js.map +1 -0
- package/dist/utils/result.d.ts +34 -0
- package/dist/utils/result.js +43 -0
- package/dist/utils/result.js.map +1 -0
- package/dist/utils/schemas.d.ts +365 -0
- package/dist/utils/schemas.js +152 -0
- package/dist/utils/schemas.js.map +1 -0
- package/dist/utils/storeHelpers.d.ts +112 -0
- package/dist/utils/storeHelpers.js +198 -0
- package/dist/utils/storeHelpers.js.map +1 -0
- package/dist/utils/typeGuards.d.ts +70 -0
- package/dist/utils/typeGuards.js +95 -0
- package/dist/utils/typeGuards.js.map +1 -0
- package/dist/utils/validation.d.ts +53 -0
- package/dist/utils/validation.js +152 -0
- package/dist/utils/validation.js.map +1 -0
- package/dist/utils/walletStateHelpers.d.ts +62 -0
- package/dist/utils/walletStateHelpers.js +81 -0
- package/dist/utils/walletStateHelpers.js.map +1 -0
- package/dist/utils/walletUtils.d.ts +38 -0
- package/dist/utils/walletUtils.js +87 -0
- package/dist/utils/walletUtils.js.map +1 -0
- package/package.json +79 -0
- package/src/__mocks__/react.ts +34 -0
- package/src/__mocks__/secureStorage.ts +87 -0
- package/src/__tests__/hooks/useBalance.test.ts +286 -0
- package/src/__tests__/hooks/useWallet.test.ts +122 -0
- package/src/__tests__/hooks/useWalletManager.test.ts +271 -0
- package/src/__tests__/hooks/useWdkApp.test.tsx +59 -0
- package/src/__tests__/hooks/useWorklet.test.ts +195 -0
- package/src/__tests__/provider/WdkAppProvider.test.tsx +67 -0
- package/src/__tests__/services/accountService.test.ts +337 -0
- package/src/__tests__/services/addressService.test.ts +312 -0
- package/src/__tests__/services/balanceService.test.ts +411 -0
- package/src/__tests__/services/walletSetupService.test.ts +463 -0
- package/src/__tests__/services/walletSwitchingService.test.ts +258 -0
- package/src/__tests__/services/workletLifecycleService.test.ts +514 -0
- package/src/__tests__/setup.ts +54 -0
- package/src/__tests__/storage/mmkvStorage.test.ts +325 -0
- package/src/__tests__/store/walletStore.test.ts +101 -0
- package/src/__tests__/store/workletStore.test.ts +329 -0
- package/src/__tests__/types/hrpc.test.ts +125 -0
- package/src/__tests__/utils/balanceUtils.test.ts +151 -0
- package/src/__tests__/utils/errorHandling.test.ts +147 -0
- package/src/__tests__/utils/errorUtils.test.ts +170 -0
- package/src/__tests__/utils/initializationState.test.ts +337 -0
- package/src/__tests__/utils/jsonUtils.test.ts +131 -0
- package/src/__tests__/utils/mmkvKeyManager.test.ts +205 -0
- package/src/__tests__/utils/mnemonicUtils.test.ts +48 -0
- package/src/__tests__/utils/raceConditions.test.ts +292 -0
- package/src/__tests__/utils/result.test.ts +73 -0
- package/src/__tests__/utils/schemas.test.ts +82 -0
- package/src/__tests__/utils/storeHelpers.test.ts +323 -0
- package/src/__tests__/utils/typeGuards.test.ts +209 -0
- package/src/__tests__/utils/validation.test.ts +152 -0
- package/src/__tests__/utils/walletUtils.test.ts +195 -0
- package/src/hooks/useBalance.ts +597 -0
- package/src/hooks/useWallet.ts +288 -0
- package/src/hooks/useWalletManager.ts +654 -0
- package/src/hooks/useWdkApp.ts +78 -0
- package/src/hooks/useWorklet.ts +109 -0
- package/src/index.ts +112 -0
- package/src/provider/WdkAppProvider.tsx +764 -0
- package/src/services/accountService.ts +134 -0
- package/src/services/addressService.ts +125 -0
- package/src/services/balanceService.ts +291 -0
- package/src/services/walletSetupService.ts +695 -0
- package/src/services/walletSwitchingService.ts +157 -0
- package/src/services/workletLifecycleService.ts +561 -0
- package/src/storage/mmkvStorage.ts +417 -0
- package/src/store/walletStore.ts +301 -0
- package/src/store/workletStore.ts +340 -0
- package/src/types/hrpc.ts +78 -0
- package/src/types.ts +188 -0
- package/src/utils/balanceUtils.ts +96 -0
- package/src/utils/constants.ts +84 -0
- package/src/utils/errorHandling.md +163 -0
- package/src/utils/errorHandling.ts +61 -0
- package/src/utils/errorUtils.ts +300 -0
- package/src/utils/initializationState.ts +242 -0
- package/src/utils/jsonUtils.ts +75 -0
- package/src/utils/logger.ts +54 -0
- package/src/utils/mmkvKeyManager.ts +256 -0
- package/src/utils/mnemonicUtils.ts +35 -0
- package/src/utils/operationMutex.ts +181 -0
- package/src/utils/result.ts +57 -0
- package/src/utils/schemas.ts +190 -0
- package/src/utils/storeHelpers.ts +236 -0
- package/src/utils/typeGuards.ts +129 -0
- package/src/utils/validation.ts +174 -0
- package/src/utils/walletStateHelpers.ts +104 -0
- package/src/utils/walletUtils.ts +107 -0
|
@@ -0,0 +1,514 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for WorkletLifecycleService
|
|
3
|
+
*
|
|
4
|
+
* Tests worklet initialization with various network configurations
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { WorkletLifecycleService } from '../../services/workletLifecycleService'
|
|
8
|
+
import { getWorkletStore } from '../../store/workletStore'
|
|
9
|
+
import type { NetworkConfigs } from '../../types'
|
|
10
|
+
|
|
11
|
+
// Mock dependencies
|
|
12
|
+
const mockWorkletInstance = {
|
|
13
|
+
start: jest.fn(),
|
|
14
|
+
IPC: {
|
|
15
|
+
send: jest.fn(),
|
|
16
|
+
on: jest.fn(),
|
|
17
|
+
},
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
jest.mock('@spacesops/react-native-bare-kit', () => ({
|
|
21
|
+
Worklet: jest.fn().mockImplementation(() => mockWorkletInstance),
|
|
22
|
+
}))
|
|
23
|
+
|
|
24
|
+
const mockHRPCInstance = {
|
|
25
|
+
workletStart: jest.fn(() => Promise.resolve({ status: 'success' })),
|
|
26
|
+
ipc: mockWorkletInstance.IPC,
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Mock @spacesops/pear-wrk-wdk with proper module structure
|
|
30
|
+
// Note: We create the mock HRPC inside the factory to avoid hoisting issues
|
|
31
|
+
jest.mock('@spacesops/pear-wrk-wdk', () => {
|
|
32
|
+
const mockHRPC = jest.fn().mockImplementation(() => ({
|
|
33
|
+
workletStart: jest.fn(() => Promise.resolve({ status: 'success' })),
|
|
34
|
+
ipc: mockWorkletInstance.IPC,
|
|
35
|
+
}))
|
|
36
|
+
return {
|
|
37
|
+
__esModule: true,
|
|
38
|
+
default: {
|
|
39
|
+
bundle: 'mock-bundle',
|
|
40
|
+
},
|
|
41
|
+
HRPC: mockHRPC,
|
|
42
|
+
bundle: 'mock-bundle',
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Create a shared mock store that will be returned by getWorkletStore
|
|
47
|
+
let sharedMockStore: any
|
|
48
|
+
|
|
49
|
+
// Mock workletStore
|
|
50
|
+
jest.mock('../../store/workletStore', () => ({
|
|
51
|
+
getWorkletStore: jest.fn(() => {
|
|
52
|
+
if (!sharedMockStore) {
|
|
53
|
+
sharedMockStore = {
|
|
54
|
+
getState: jest.fn(() => ({
|
|
55
|
+
isWorkletStarted: false,
|
|
56
|
+
isInitialized: false,
|
|
57
|
+
isLoading: false,
|
|
58
|
+
worklet: null,
|
|
59
|
+
hrpc: null,
|
|
60
|
+
error: null,
|
|
61
|
+
})),
|
|
62
|
+
setState: jest.fn(),
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return sharedMockStore
|
|
66
|
+
}),
|
|
67
|
+
}))
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Real-world network configuration for testing
|
|
71
|
+
* This matches the configuration used in production
|
|
72
|
+
* Note: Some fields like safeModulesVersion, paymasterToken, and network are extensions
|
|
73
|
+
* beyond the base NetworkConfig type but are valid in practice
|
|
74
|
+
*/
|
|
75
|
+
const defaultNetworkConfigs = {
|
|
76
|
+
sepolia: {
|
|
77
|
+
chainId: 11155111,
|
|
78
|
+
blockchain: 'sepolia',
|
|
79
|
+
provider: 'https://sepolia.gateway.tenderly.co',
|
|
80
|
+
bundlerUrl: 'https://api.candide.dev/public/v3/sepolia',
|
|
81
|
+
paymasterUrl: 'https://api.candide.dev/public/v3/sepolia',
|
|
82
|
+
paymasterAddress: '0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba',
|
|
83
|
+
entryPointAddress: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
|
|
84
|
+
safeModulesVersion: '0.3.0',
|
|
85
|
+
paymasterToken: {
|
|
86
|
+
address: '0xd077A400968890Eacc75cdc901F0356c943e4fDb',
|
|
87
|
+
},
|
|
88
|
+
transferMaxFee: 100000,
|
|
89
|
+
},
|
|
90
|
+
ethereum: {
|
|
91
|
+
chainId: 1,
|
|
92
|
+
blockchain: 'ethereum',
|
|
93
|
+
provider: 'https://wallet-ap7ha02ezs.rumble.com/eth',
|
|
94
|
+
bundlerUrl: 'https://api.candide.dev/public/v3/ethereum',
|
|
95
|
+
paymasterUrl: 'https://api.candide.dev/public/v3/ethereum',
|
|
96
|
+
paymasterAddress: '0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba',
|
|
97
|
+
entryPointAddress: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
|
|
98
|
+
safeModulesVersion: '0.3.0',
|
|
99
|
+
paymasterToken: {
|
|
100
|
+
address: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
|
|
101
|
+
},
|
|
102
|
+
transferMaxFee: 100000,
|
|
103
|
+
},
|
|
104
|
+
polygon: {
|
|
105
|
+
chainId: 137,
|
|
106
|
+
blockchain: 'polygon',
|
|
107
|
+
provider: 'https://wallet-ap7ha02ezs.rumble.com/pol',
|
|
108
|
+
bundlerUrl: 'https://api.candide.dev/public/v3/polygon',
|
|
109
|
+
paymasterUrl: 'https://api.candide.dev/public/v3/polygon',
|
|
110
|
+
paymasterAddress: '0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba',
|
|
111
|
+
entryPointAddress: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
|
|
112
|
+
safeModulesVersion: '0.3.0',
|
|
113
|
+
paymasterToken: {
|
|
114
|
+
address: '0xc2132D05D31c914a87C6611C10748AEb04B58e8F',
|
|
115
|
+
},
|
|
116
|
+
transferMaxFee: 100000,
|
|
117
|
+
},
|
|
118
|
+
arbitrum: {
|
|
119
|
+
chainId: 42161,
|
|
120
|
+
blockchain: 'arbitrum',
|
|
121
|
+
provider: 'https://wallet-ap7ha02ezs.rumble.com/arb',
|
|
122
|
+
bundlerUrl: 'https://public.pimlico.io/v2/42161/rpc',
|
|
123
|
+
paymasterUrl: 'https://public.pimlico.io/v2/42161/rpc',
|
|
124
|
+
paymasterAddress: '0x777777777777AeC03fd955926DbF81597e66834C',
|
|
125
|
+
entryPointAddress: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
|
|
126
|
+
safeModulesVersion: '0.3.0',
|
|
127
|
+
paymasterToken: {
|
|
128
|
+
address: '0xFd086bC7CD5C481DCC9C85ebE478A1C0b69FCbb9',
|
|
129
|
+
},
|
|
130
|
+
transferMaxFee: 100000,
|
|
131
|
+
},
|
|
132
|
+
plasma: {
|
|
133
|
+
chainId: 9745,
|
|
134
|
+
blockchain: 'plasma',
|
|
135
|
+
provider: 'https://rpc.plasma.to',
|
|
136
|
+
bundlerUrl: 'https://api.candide.dev/public/v3/9745',
|
|
137
|
+
paymasterUrl: 'https://api.candide.dev/public/v3/9745',
|
|
138
|
+
paymasterAddress: '0x8b1f6cb5d062aa2ce8d581942bbb960420d875ba',
|
|
139
|
+
entryPointAddress: '0x0000000071727De22E5E9d8BAf0edAc6f37da032',
|
|
140
|
+
safeModulesVersion: '0.3.0',
|
|
141
|
+
paymasterToken: {
|
|
142
|
+
address: '0xB8CE59FC3717ada4C02eaDF9682A9e934F625ebb',
|
|
143
|
+
},
|
|
144
|
+
transferMaxFee: 100000,
|
|
145
|
+
},
|
|
146
|
+
spark: {
|
|
147
|
+
chainId: 99999,
|
|
148
|
+
blockchain: 'spark',
|
|
149
|
+
network: 'MAINNET', // Spark network type (MAINNET, TESTNET)
|
|
150
|
+
},
|
|
151
|
+
} as NetworkConfigs
|
|
152
|
+
|
|
153
|
+
describe('WorkletLifecycleService', () => {
|
|
154
|
+
let mockStore: ReturnType<typeof getWorkletStore>
|
|
155
|
+
|
|
156
|
+
beforeEach(() => {
|
|
157
|
+
jest.clearAllMocks()
|
|
158
|
+
|
|
159
|
+
// Reset mock implementations
|
|
160
|
+
mockWorkletInstance.start.mockClear()
|
|
161
|
+
mockHRPCInstance.workletStart.mockResolvedValue({ status: 'success' })
|
|
162
|
+
|
|
163
|
+
// Reset HRPC constructor mock
|
|
164
|
+
const { HRPC } = require('@spacesops/pear-wrk-wdk')
|
|
165
|
+
if (HRPC && typeof HRPC.mockImplementation === 'function') {
|
|
166
|
+
HRPC.mockImplementation(() => mockHRPCInstance)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// Setup mock store - get the shared instance
|
|
170
|
+
mockStore = getWorkletStore() as any
|
|
171
|
+
const defaultState = {
|
|
172
|
+
isWorkletStarted: false,
|
|
173
|
+
isInitialized: false,
|
|
174
|
+
isLoading: false,
|
|
175
|
+
worklet: null,
|
|
176
|
+
hrpc: null,
|
|
177
|
+
ipc: null,
|
|
178
|
+
error: null,
|
|
179
|
+
encryptedSeed: null,
|
|
180
|
+
encryptionKey: null,
|
|
181
|
+
networkConfigs: null,
|
|
182
|
+
workletStartResult: null,
|
|
183
|
+
wdkInitResult: null,
|
|
184
|
+
}
|
|
185
|
+
// Update the shared mock store
|
|
186
|
+
sharedMockStore.getState = jest.fn(() => defaultState)
|
|
187
|
+
sharedMockStore.setState = jest.fn()
|
|
188
|
+
})
|
|
189
|
+
|
|
190
|
+
describe('startWorklet', () => {
|
|
191
|
+
it('should start worklet with default network configuration', async () => {
|
|
192
|
+
await WorkletLifecycleService.startWorklet(defaultNetworkConfigs)
|
|
193
|
+
|
|
194
|
+
// Verify worklet was created
|
|
195
|
+
const { Worklet } = require('@spacesops/react-native-bare-kit')
|
|
196
|
+
expect(Worklet).toHaveBeenCalled()
|
|
197
|
+
|
|
198
|
+
// Verify worklet.start was called with bundle
|
|
199
|
+
expect(mockWorkletInstance.start).toHaveBeenCalledWith('/wdk-worklet.bundle', 'mock-bundle')
|
|
200
|
+
|
|
201
|
+
// Verify HRPC was created
|
|
202
|
+
const { HRPC } = require('@spacesops/pear-wrk-wdk')
|
|
203
|
+
expect(HRPC).toHaveBeenCalledWith(mockWorkletInstance.IPC)
|
|
204
|
+
|
|
205
|
+
// Verify workletStart was called with serialized config
|
|
206
|
+
expect(mockHRPCInstance.workletStart).toHaveBeenCalledWith({
|
|
207
|
+
config: JSON.stringify(defaultNetworkConfigs),
|
|
208
|
+
})
|
|
209
|
+
|
|
210
|
+
// Verify store state was updated (check that setState was called at least once)
|
|
211
|
+
expect(mockStore.setState).toHaveBeenCalled()
|
|
212
|
+
|
|
213
|
+
// Verify the final state update contains the expected values
|
|
214
|
+
const setStateMock = mockStore.setState as jest.Mock
|
|
215
|
+
const finalStateCall = setStateMock.mock.calls[setStateMock.mock.calls.length - 1]
|
|
216
|
+
if (finalStateCall && typeof finalStateCall[0] === 'function') {
|
|
217
|
+
const prevState = mockStore.getState()
|
|
218
|
+
const newState = finalStateCall[0](prevState)
|
|
219
|
+
expect(newState.isWorkletStarted).toBe(true)
|
|
220
|
+
expect(newState.isLoading).toBe(false)
|
|
221
|
+
expect(newState.networkConfigs).toEqual(defaultNetworkConfigs)
|
|
222
|
+
expect(newState.worklet).toBe(mockWorkletInstance)
|
|
223
|
+
expect(newState.hrpc).toBe(mockHRPCInstance)
|
|
224
|
+
expect(newState.error).toBeNull()
|
|
225
|
+
}
|
|
226
|
+
})
|
|
227
|
+
|
|
228
|
+
it('should serialize network configuration correctly', async () => {
|
|
229
|
+
await WorkletLifecycleService.startWorklet(defaultNetworkConfigs)
|
|
230
|
+
|
|
231
|
+
// Verify the config was serialized to JSON
|
|
232
|
+
const calls = mockHRPCInstance.workletStart.mock.calls
|
|
233
|
+
expect(calls.length).toBeGreaterThan(0)
|
|
234
|
+
const workletStartCall = calls[0]
|
|
235
|
+
const configString = (workletStartCall as any)[0].config
|
|
236
|
+
const parsedConfig = JSON.parse(configString)
|
|
237
|
+
|
|
238
|
+
// Verify all networks are present
|
|
239
|
+
expect(parsedConfig).toHaveProperty('sepolia')
|
|
240
|
+
expect(parsedConfig).toHaveProperty('ethereum')
|
|
241
|
+
expect(parsedConfig).toHaveProperty('polygon')
|
|
242
|
+
expect(parsedConfig).toHaveProperty('arbitrum')
|
|
243
|
+
expect(parsedConfig).toHaveProperty('plasma')
|
|
244
|
+
expect(parsedConfig).toHaveProperty('spark')
|
|
245
|
+
|
|
246
|
+
// Verify network properties
|
|
247
|
+
expect(parsedConfig.ethereum).toMatchObject({
|
|
248
|
+
chainId: 1,
|
|
249
|
+
blockchain: 'ethereum',
|
|
250
|
+
provider: 'https://wallet-ap7ha02ezs.rumble.com/eth',
|
|
251
|
+
})
|
|
252
|
+
|
|
253
|
+
expect(parsedConfig.polygon).toMatchObject({
|
|
254
|
+
chainId: 137,
|
|
255
|
+
blockchain: 'polygon',
|
|
256
|
+
provider: 'https://wallet-ap7ha02ezs.rumble.com/pol',
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
expect(parsedConfig.arbitrum).toMatchObject({
|
|
260
|
+
chainId: 42161,
|
|
261
|
+
blockchain: 'arbitrum',
|
|
262
|
+
provider: 'https://wallet-ap7ha02ezs.rumble.com/arb',
|
|
263
|
+
})
|
|
264
|
+
|
|
265
|
+
// Verify extended properties are preserved
|
|
266
|
+
expect(parsedConfig.ethereum).toHaveProperty('safeModulesVersion', '0.3.0')
|
|
267
|
+
expect(parsedConfig.ethereum).toHaveProperty('paymasterToken')
|
|
268
|
+
expect(parsedConfig.ethereum.paymasterToken).toHaveProperty('address')
|
|
269
|
+
expect(parsedConfig.spark).toHaveProperty('network', 'MAINNET')
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
it('should handle all network types in the configuration', async () => {
|
|
273
|
+
await WorkletLifecycleService.startWorklet(defaultNetworkConfigs)
|
|
274
|
+
|
|
275
|
+
const calls = mockHRPCInstance.workletStart.mock.calls
|
|
276
|
+
expect(calls.length).toBeGreaterThan(0)
|
|
277
|
+
const workletStartCall = calls[0]
|
|
278
|
+
const configString = (workletStartCall as any)[0].config
|
|
279
|
+
const parsedConfig = JSON.parse(configString)
|
|
280
|
+
|
|
281
|
+
// Verify each network has required fields
|
|
282
|
+
const networks = ['sepolia', 'ethereum', 'polygon', 'arbitrum', 'plasma', 'spark']
|
|
283
|
+
|
|
284
|
+
for (const network of networks) {
|
|
285
|
+
expect(parsedConfig).toHaveProperty(network)
|
|
286
|
+
expect(parsedConfig[network]).toHaveProperty('chainId')
|
|
287
|
+
expect(parsedConfig[network]).toHaveProperty('blockchain')
|
|
288
|
+
expect(typeof parsedConfig[network].chainId).toBe('number')
|
|
289
|
+
expect(typeof parsedConfig[network].blockchain).toBe('string')
|
|
290
|
+
}
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
it('should preserve optional fields in network configuration', async () => {
|
|
294
|
+
await WorkletLifecycleService.startWorklet(defaultNetworkConfigs)
|
|
295
|
+
|
|
296
|
+
const calls = mockHRPCInstance.workletStart.mock.calls
|
|
297
|
+
expect(calls.length).toBeGreaterThan(0)
|
|
298
|
+
const workletStartCall = calls[0]
|
|
299
|
+
const configString = (workletStartCall as any)[0].config
|
|
300
|
+
const parsedConfig = JSON.parse(configString)
|
|
301
|
+
|
|
302
|
+
// Verify optional fields are preserved for networks that have them
|
|
303
|
+
const ethereumConfig = parsedConfig.ethereum
|
|
304
|
+
expect(ethereumConfig).toHaveProperty('bundlerUrl')
|
|
305
|
+
expect(ethereumConfig).toHaveProperty('paymasterUrl')
|
|
306
|
+
expect(ethereumConfig).toHaveProperty('paymasterAddress')
|
|
307
|
+
expect(ethereumConfig).toHaveProperty('entryPointAddress')
|
|
308
|
+
expect(ethereumConfig).toHaveProperty('transferMaxFee')
|
|
309
|
+
expect(ethereumConfig).toHaveProperty('safeModulesVersion')
|
|
310
|
+
expect(ethereumConfig).toHaveProperty('paymasterToken')
|
|
311
|
+
|
|
312
|
+
// Verify spark has its network field
|
|
313
|
+
expect(parsedConfig.spark).toHaveProperty('network', 'MAINNET')
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
it('should not start worklet if already started', async () => {
|
|
317
|
+
// Clear previous calls
|
|
318
|
+
mockHRPCInstance.workletStart.mockClear()
|
|
319
|
+
const { Worklet: WorkletConstructor } = require('@spacesops/react-native-bare-kit')
|
|
320
|
+
WorkletConstructor.mockClear()
|
|
321
|
+
;(mockStore.setState as jest.Mock).mockClear()
|
|
322
|
+
|
|
323
|
+
// Set up mock store to return "already started" state
|
|
324
|
+
const alreadyStartedState = {
|
|
325
|
+
isWorkletStarted: true,
|
|
326
|
+
isInitialized: false,
|
|
327
|
+
isLoading: false,
|
|
328
|
+
worklet: mockWorkletInstance,
|
|
329
|
+
hrpc: mockHRPCInstance,
|
|
330
|
+
ipc: mockWorkletInstance.IPC,
|
|
331
|
+
error: null,
|
|
332
|
+
encryptedSeed: null,
|
|
333
|
+
encryptionKey: null,
|
|
334
|
+
networkConfigs: defaultNetworkConfigs,
|
|
335
|
+
workletStartResult: null,
|
|
336
|
+
wdkInitResult: null,
|
|
337
|
+
}
|
|
338
|
+
;(mockStore as any).getState = jest.fn(() => alreadyStartedState)
|
|
339
|
+
|
|
340
|
+
await WorkletLifecycleService.startWorklet(defaultNetworkConfigs)
|
|
341
|
+
|
|
342
|
+
// Should not call workletStart again (early return should happen)
|
|
343
|
+
expect(mockHRPCInstance.workletStart).not.toHaveBeenCalled()
|
|
344
|
+
// Should not create new worklet
|
|
345
|
+
expect(WorkletConstructor).not.toHaveBeenCalled()
|
|
346
|
+
// Should not call setState (early return before any state changes)
|
|
347
|
+
expect(mockStore.setState).not.toHaveBeenCalled()
|
|
348
|
+
})
|
|
349
|
+
|
|
350
|
+
it('should not start worklet if already loading', async () => {
|
|
351
|
+
// Clear previous calls
|
|
352
|
+
mockHRPCInstance.workletStart.mockClear()
|
|
353
|
+
const { Worklet: WorkletConstructor } = require('@spacesops/react-native-bare-kit')
|
|
354
|
+
WorkletConstructor.mockClear()
|
|
355
|
+
;(mockStore.setState as jest.Mock).mockClear()
|
|
356
|
+
|
|
357
|
+
// Set up mock store to return "already loading" state
|
|
358
|
+
const alreadyLoadingState = {
|
|
359
|
+
isWorkletStarted: false,
|
|
360
|
+
isInitialized: false,
|
|
361
|
+
isLoading: true,
|
|
362
|
+
worklet: null,
|
|
363
|
+
hrpc: null,
|
|
364
|
+
ipc: null,
|
|
365
|
+
error: null,
|
|
366
|
+
encryptedSeed: null,
|
|
367
|
+
encryptionKey: null,
|
|
368
|
+
networkConfigs: null,
|
|
369
|
+
workletStartResult: null,
|
|
370
|
+
wdkInitResult: null,
|
|
371
|
+
}
|
|
372
|
+
;(mockStore as any).getState = jest.fn(() => alreadyLoadingState)
|
|
373
|
+
|
|
374
|
+
await WorkletLifecycleService.startWorklet(defaultNetworkConfigs)
|
|
375
|
+
|
|
376
|
+
// Should not call workletStart (early return should happen)
|
|
377
|
+
expect(mockHRPCInstance.workletStart).not.toHaveBeenCalled()
|
|
378
|
+
// Should not create new worklet
|
|
379
|
+
expect(WorkletConstructor).not.toHaveBeenCalled()
|
|
380
|
+
// Should not call setState (early return before any state changes)
|
|
381
|
+
expect(mockStore.setState).not.toHaveBeenCalled()
|
|
382
|
+
})
|
|
383
|
+
|
|
384
|
+
it('should handle errors during worklet initialization', async () => {
|
|
385
|
+
// Make workletStart fail to simulate an error
|
|
386
|
+
mockHRPCInstance.workletStart.mockRejectedValueOnce(new Error('Failed to start worklet'))
|
|
387
|
+
|
|
388
|
+
await expect(
|
|
389
|
+
WorkletLifecycleService.startWorklet(defaultNetworkConfigs)
|
|
390
|
+
).rejects.toThrow()
|
|
391
|
+
|
|
392
|
+
// Verify setState was called (at least for loading state and error state)
|
|
393
|
+
expect(mockStore.setState).toHaveBeenCalled()
|
|
394
|
+
|
|
395
|
+
// Verify error state was set in the last call
|
|
396
|
+
const setStateMock = mockStore.setState as jest.Mock
|
|
397
|
+
const allCalls = setStateMock.mock.calls
|
|
398
|
+
expect(allCalls.length).toBeGreaterThan(0)
|
|
399
|
+
|
|
400
|
+
// Check if any call sets error state
|
|
401
|
+
let errorStateFound = false
|
|
402
|
+
for (const call of allCalls) {
|
|
403
|
+
if (typeof call[0] === 'function') {
|
|
404
|
+
const prevState = mockStore.getState()
|
|
405
|
+
const newState = call[0](prevState)
|
|
406
|
+
if (newState.error !== null && newState.isLoading === false) {
|
|
407
|
+
errorStateFound = true
|
|
408
|
+
break
|
|
409
|
+
}
|
|
410
|
+
} else if (call[0] && typeof call[0] === 'object' && call[0].error !== null) {
|
|
411
|
+
errorStateFound = true
|
|
412
|
+
break
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
expect(errorStateFound).toBe(true)
|
|
416
|
+
})
|
|
417
|
+
|
|
418
|
+
it('should cleanup existing worklet before starting new one', async () => {
|
|
419
|
+
const existingWorklet = {
|
|
420
|
+
start: jest.fn(),
|
|
421
|
+
IPC: mockWorkletInstance.IPC,
|
|
422
|
+
cleanup: jest.fn(),
|
|
423
|
+
} as any
|
|
424
|
+
|
|
425
|
+
const existingHRPC = {
|
|
426
|
+
workletStart: jest.fn(() => Promise.resolve({ status: 'success' })),
|
|
427
|
+
ipc: mockWorkletInstance.IPC,
|
|
428
|
+
cleanup: jest.fn(),
|
|
429
|
+
} as any
|
|
430
|
+
|
|
431
|
+
;(mockStore as any).getState = jest.fn().mockReturnValue({
|
|
432
|
+
isWorkletStarted: false,
|
|
433
|
+
isInitialized: false,
|
|
434
|
+
isLoading: false,
|
|
435
|
+
worklet: existingWorklet,
|
|
436
|
+
hrpc: existingHRPC,
|
|
437
|
+
ipc: existingWorklet.IPC,
|
|
438
|
+
error: null,
|
|
439
|
+
encryptedSeed: null,
|
|
440
|
+
encryptionKey: null,
|
|
441
|
+
networkConfigs: null,
|
|
442
|
+
workletStartResult: null,
|
|
443
|
+
wdkInitResult: null,
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
await WorkletLifecycleService.startWorklet(defaultNetworkConfigs)
|
|
447
|
+
|
|
448
|
+
// Verify new worklet was created (old one should be cleaned up)
|
|
449
|
+
const { Worklet } = require('@spacesops/react-native-bare-kit')
|
|
450
|
+
expect(Worklet).toHaveBeenCalled()
|
|
451
|
+
})
|
|
452
|
+
|
|
453
|
+
it('should handle minimal network configuration', async () => {
|
|
454
|
+
const minimalConfig: NetworkConfigs = {
|
|
455
|
+
ethereum: {
|
|
456
|
+
chainId: 1,
|
|
457
|
+
blockchain: 'ethereum',
|
|
458
|
+
},
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
await WorkletLifecycleService.startWorklet(minimalConfig)
|
|
462
|
+
|
|
463
|
+
expect(mockHRPCInstance.workletStart).toHaveBeenCalled()
|
|
464
|
+
const calls = mockHRPCInstance.workletStart.mock.calls
|
|
465
|
+
expect(calls.length).toBeGreaterThan(0)
|
|
466
|
+
const workletStartCall = calls[0]
|
|
467
|
+
expect(workletStartCall).toBeDefined()
|
|
468
|
+
const configString = (workletStartCall as any)[0].config
|
|
469
|
+
const parsedConfig = JSON.parse(configString)
|
|
470
|
+
|
|
471
|
+
expect(parsedConfig.ethereum).toMatchObject({
|
|
472
|
+
chainId: 1,
|
|
473
|
+
blockchain: 'ethereum',
|
|
474
|
+
})
|
|
475
|
+
})
|
|
476
|
+
|
|
477
|
+
it('should handle network configuration with all optional fields', async () => {
|
|
478
|
+
const fullConfig: NetworkConfigs = {
|
|
479
|
+
testnet: {
|
|
480
|
+
chainId: 12345,
|
|
481
|
+
blockchain: 'testnet',
|
|
482
|
+
provider: 'https://testnet.example.com',
|
|
483
|
+
bundlerUrl: 'https://bundler.example.com',
|
|
484
|
+
paymasterUrl: 'https://paymaster.example.com',
|
|
485
|
+
paymasterAddress: '0x1234567890123456789012345678901234567890',
|
|
486
|
+
entryPointAddress: '0x0987654321098765432109876543210987654321',
|
|
487
|
+
transferMaxFee: 50000,
|
|
488
|
+
},
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
await WorkletLifecycleService.startWorklet(fullConfig)
|
|
492
|
+
|
|
493
|
+
expect(mockHRPCInstance.workletStart).toHaveBeenCalled()
|
|
494
|
+
const calls = mockHRPCInstance.workletStart.mock.calls
|
|
495
|
+
expect(calls.length).toBeGreaterThan(0)
|
|
496
|
+
const workletStartCall = calls[0]
|
|
497
|
+
expect(workletStartCall).toBeDefined()
|
|
498
|
+
const configString = (workletStartCall as any)[0].config
|
|
499
|
+
const parsedConfig = JSON.parse(configString)
|
|
500
|
+
|
|
501
|
+
expect(parsedConfig.testnet).toMatchObject({
|
|
502
|
+
chainId: 12345,
|
|
503
|
+
blockchain: 'testnet',
|
|
504
|
+
provider: 'https://testnet.example.com',
|
|
505
|
+
bundlerUrl: 'https://bundler.example.com',
|
|
506
|
+
paymasterUrl: 'https://paymaster.example.com',
|
|
507
|
+
paymasterAddress: '0x1234567890123456789012345678901234567890',
|
|
508
|
+
entryPointAddress: '0x0987654321098765432109876543210987654321',
|
|
509
|
+
transferMaxFee: 50000,
|
|
510
|
+
})
|
|
511
|
+
})
|
|
512
|
+
})
|
|
513
|
+
})
|
|
514
|
+
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Jest setup file for test configuration
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
// Mock React Native modules
|
|
6
|
+
jest.mock('react-native-mmkv', () => ({
|
|
7
|
+
MMKV: jest.fn().mockImplementation(() => ({
|
|
8
|
+
set: jest.fn(),
|
|
9
|
+
getString: jest.fn(),
|
|
10
|
+
getNumber: jest.fn(),
|
|
11
|
+
getBoolean: jest.fn(),
|
|
12
|
+
delete: jest.fn(),
|
|
13
|
+
clearAll: jest.fn(),
|
|
14
|
+
getAllKeys: jest.fn(() => []),
|
|
15
|
+
contains: jest.fn(),
|
|
16
|
+
})),
|
|
17
|
+
}))
|
|
18
|
+
|
|
19
|
+
// Mock expo-crypto
|
|
20
|
+
jest.mock('expo-crypto', () => ({
|
|
21
|
+
digestStringAsync: jest.fn(),
|
|
22
|
+
getRandomBytesAsync: jest.fn(() => Promise.resolve(new Uint8Array(32))),
|
|
23
|
+
}))
|
|
24
|
+
|
|
25
|
+
// Mock @spacesops/pear-wrk-wdk
|
|
26
|
+
jest.mock('@spacesops/pear-wrk-wdk', () => ({
|
|
27
|
+
Worklet: jest.fn(),
|
|
28
|
+
createWorklet: jest.fn(),
|
|
29
|
+
}))
|
|
30
|
+
|
|
31
|
+
// Mock @spacesops/react-native-bare-kit
|
|
32
|
+
jest.mock('@spacesops/react-native-bare-kit', () => ({
|
|
33
|
+
createBareKit: jest.fn(),
|
|
34
|
+
}))
|
|
35
|
+
|
|
36
|
+
// Suppress console.error in tests (we test error cases, but don't need the noise)
|
|
37
|
+
const originalError = console.error
|
|
38
|
+
beforeAll(() => {
|
|
39
|
+
console.error = jest.fn()
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
afterAll(() => {
|
|
43
|
+
console.error = originalError
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
// Reset all mocks before each test
|
|
47
|
+
beforeEach(() => {
|
|
48
|
+
jest.clearAllMocks()
|
|
49
|
+
// Clear mock secure storage between tests
|
|
50
|
+
const { mockSecureStorage } = require('../__mocks__/secureStorage')
|
|
51
|
+
if (typeof mockSecureStorage._clearStorage === 'function') {
|
|
52
|
+
mockSecureStorage._clearStorage()
|
|
53
|
+
}
|
|
54
|
+
})
|