@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,152 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for validation utilities
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
validateNetworkConfigs,
|
|
7
|
+
validateTokenConfigs,
|
|
8
|
+
validateBalanceRefreshInterval,
|
|
9
|
+
validateRequiredMethods,
|
|
10
|
+
validateAccountIndex,
|
|
11
|
+
validateNetworkName,
|
|
12
|
+
validateTokenAddress,
|
|
13
|
+
validateBalance,
|
|
14
|
+
} from '../../utils/validation'
|
|
15
|
+
import type { NetworkConfigs, TokenConfigs } from '../../types'
|
|
16
|
+
|
|
17
|
+
describe('validation', () => {
|
|
18
|
+
describe('validateNetworkConfigs', () => {
|
|
19
|
+
it('should not throw for valid network configs', () => {
|
|
20
|
+
const validConfigs: NetworkConfigs = {
|
|
21
|
+
ethereum: {
|
|
22
|
+
chainId: 1,
|
|
23
|
+
blockchain: 'ethereum',
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
expect(() => validateNetworkConfigs(validConfigs)).not.toThrow()
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('should throw for invalid network configs', () => {
|
|
30
|
+
expect(() => validateNetworkConfigs({} as NetworkConfigs)).toThrow()
|
|
31
|
+
expect(() => validateNetworkConfigs(null as unknown as NetworkConfigs)).toThrow()
|
|
32
|
+
expect(() => validateNetworkConfigs([] as unknown as NetworkConfigs)).toThrow()
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
describe('validateTokenConfigs', () => {
|
|
37
|
+
it('should not throw for valid token configs', () => {
|
|
38
|
+
const validConfigs: TokenConfigs = {
|
|
39
|
+
ethereum: {
|
|
40
|
+
native: {
|
|
41
|
+
symbol: 'ETH',
|
|
42
|
+
name: 'Ethereum',
|
|
43
|
+
decimals: 18,
|
|
44
|
+
address: null,
|
|
45
|
+
},
|
|
46
|
+
tokens: [],
|
|
47
|
+
},
|
|
48
|
+
}
|
|
49
|
+
expect(() => validateTokenConfigs(validConfigs)).not.toThrow()
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
it('should throw for invalid token configs', () => {
|
|
53
|
+
expect(() => validateTokenConfigs({} as TokenConfigs)).toThrow()
|
|
54
|
+
expect(() => validateTokenConfigs(null as unknown as TokenConfigs)).toThrow()
|
|
55
|
+
expect(() => validateTokenConfigs([] as unknown as TokenConfigs)).toThrow()
|
|
56
|
+
})
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
describe('validateBalanceRefreshInterval', () => {
|
|
60
|
+
it('should not throw for valid intervals', () => {
|
|
61
|
+
expect(() => validateBalanceRefreshInterval(0)).not.toThrow()
|
|
62
|
+
expect(() => validateBalanceRefreshInterval(1000)).not.toThrow()
|
|
63
|
+
expect(() => validateBalanceRefreshInterval(undefined)).not.toThrow()
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
it('should throw for invalid intervals', () => {
|
|
67
|
+
expect(() => validateBalanceRefreshInterval(-1)).toThrow()
|
|
68
|
+
expect(() => validateBalanceRefreshInterval(NaN)).toThrow()
|
|
69
|
+
expect(() => validateBalanceRefreshInterval(Infinity)).toThrow()
|
|
70
|
+
expect(() => validateBalanceRefreshInterval('1000' as unknown as number)).toThrow()
|
|
71
|
+
})
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
describe('validateRequiredMethods', () => {
|
|
75
|
+
it('should not throw for object with required methods', () => {
|
|
76
|
+
const obj = {
|
|
77
|
+
method1: jest.fn(),
|
|
78
|
+
method2: jest.fn(),
|
|
79
|
+
}
|
|
80
|
+
expect(() => validateRequiredMethods(obj, ['method1', 'method2'], 'TestObject')).not.toThrow()
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
it('should throw for object without required methods', () => {
|
|
84
|
+
const obj = {
|
|
85
|
+
method1: jest.fn(),
|
|
86
|
+
}
|
|
87
|
+
expect(() => validateRequiredMethods(obj, ['method1', 'method2'], 'TestObject')).toThrow()
|
|
88
|
+
expect(() => validateRequiredMethods(null, ['method1'], 'TestObject')).toThrow()
|
|
89
|
+
expect(() => validateRequiredMethods('string', ['method1'], 'TestObject')).toThrow()
|
|
90
|
+
})
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
describe('validateAccountIndex', () => {
|
|
94
|
+
it('should not throw for valid account indices', () => {
|
|
95
|
+
expect(() => validateAccountIndex(0)).not.toThrow()
|
|
96
|
+
expect(() => validateAccountIndex(1)).not.toThrow()
|
|
97
|
+
expect(() => validateAccountIndex(100)).not.toThrow()
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('should throw for invalid account indices', () => {
|
|
101
|
+
expect(() => validateAccountIndex(-1)).toThrow()
|
|
102
|
+
expect(() => validateAccountIndex(1.5)).toThrow()
|
|
103
|
+
expect(() => validateAccountIndex(NaN)).toThrow()
|
|
104
|
+
})
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
describe('validateNetworkName', () => {
|
|
108
|
+
it('should not throw for valid network names', () => {
|
|
109
|
+
expect(() => validateNetworkName('ethereum')).not.toThrow()
|
|
110
|
+
expect(() => validateNetworkName('polygon-mainnet')).not.toThrow()
|
|
111
|
+
expect(() => validateNetworkName('network_1')).not.toThrow()
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('should throw for invalid network names', () => {
|
|
115
|
+
expect(() => validateNetworkName('')).toThrow()
|
|
116
|
+
expect(() => validateNetworkName(' ')).toThrow()
|
|
117
|
+
expect(() => validateNetworkName('network with spaces')).toThrow()
|
|
118
|
+
expect(() => validateNetworkName('network@invalid')).toThrow()
|
|
119
|
+
})
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
describe('validateTokenAddress', () => {
|
|
123
|
+
it('should not throw for valid token addresses', () => {
|
|
124
|
+
expect(() => validateTokenAddress(null)).not.toThrow()
|
|
125
|
+
expect(() => validateTokenAddress('0x1234567890123456789012345678901234567890')).not.toThrow()
|
|
126
|
+
expect(() => validateTokenAddress('0xABCDEFabcdef1234567890123456789012345678')).not.toThrow()
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
it('should throw for invalid token addresses', () => {
|
|
130
|
+
expect(() => validateTokenAddress('invalid')).toThrow()
|
|
131
|
+
expect(() => validateTokenAddress('0x123')).toThrow()
|
|
132
|
+
expect(() => validateTokenAddress('0x123456789012345678901234567890123456789')).toThrow()
|
|
133
|
+
expect(() => validateTokenAddress('')).toThrow()
|
|
134
|
+
})
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
describe('validateBalance', () => {
|
|
138
|
+
it('should not throw for valid balances', () => {
|
|
139
|
+
expect(() => validateBalance('0')).not.toThrow()
|
|
140
|
+
expect(() => validateBalance('100')).not.toThrow()
|
|
141
|
+
expect(() => validateBalance('100.5')).not.toThrow()
|
|
142
|
+
expect(() => validateBalance('-100')).not.toThrow()
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
it('should throw for invalid balances', () => {
|
|
146
|
+
expect(() => validateBalance('')).toThrow()
|
|
147
|
+
expect(() => validateBalance('abc')).toThrow()
|
|
148
|
+
expect(() => validateBalance('100.5.5')).toThrow()
|
|
149
|
+
expect(() => validateBalance('100a')).toThrow()
|
|
150
|
+
})
|
|
151
|
+
})
|
|
152
|
+
})
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for wallet utility functions
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import {
|
|
6
|
+
getWalletAddresses,
|
|
7
|
+
createBaseWalletStore,
|
|
8
|
+
} from '../../utils/walletUtils'
|
|
9
|
+
import { getWorkletStore } from '../../store/workletStore'
|
|
10
|
+
import { getWalletStore } from '../../store/walletStore'
|
|
11
|
+
import { AccountService } from '../../services/accountService'
|
|
12
|
+
|
|
13
|
+
// Mock stores and services
|
|
14
|
+
jest.mock('../../store/workletStore', () => ({
|
|
15
|
+
getWorkletStore: jest.fn(),
|
|
16
|
+
}))
|
|
17
|
+
|
|
18
|
+
jest.mock('../../store/walletStore', () => ({
|
|
19
|
+
getWalletStore: jest.fn(),
|
|
20
|
+
}))
|
|
21
|
+
|
|
22
|
+
jest.mock('../../services/accountService', () => ({
|
|
23
|
+
AccountService: {
|
|
24
|
+
callAccountMethod: jest.fn(),
|
|
25
|
+
},
|
|
26
|
+
}))
|
|
27
|
+
|
|
28
|
+
describe('walletUtils', () => {
|
|
29
|
+
let mockWalletStore: any
|
|
30
|
+
let mockWorkletStore: any
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
jest.clearAllMocks()
|
|
34
|
+
|
|
35
|
+
mockWalletStore = {
|
|
36
|
+
getState: jest.fn(() => ({
|
|
37
|
+
addresses: {},
|
|
38
|
+
activeWalletId: 'test-wallet-1',
|
|
39
|
+
})),
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
mockWorkletStore = {
|
|
43
|
+
getState: jest.fn(() => ({
|
|
44
|
+
isInitialized: true,
|
|
45
|
+
})),
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
;(getWalletStore as jest.Mock).mockReturnValue(mockWalletStore)
|
|
49
|
+
;(getWorkletStore as jest.Mock).mockReturnValue(mockWorkletStore)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
describe('getWalletAddresses', () => {
|
|
53
|
+
it('should return empty object when no addresses exist', () => {
|
|
54
|
+
const result = getWalletAddresses(mockWalletStore, 0)
|
|
55
|
+
expect(result).toEqual({})
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
it('should return addresses for specific account index', () => {
|
|
59
|
+
mockWalletStore.getState = jest.fn(() => ({
|
|
60
|
+
addresses: {
|
|
61
|
+
'test-wallet-1': {
|
|
62
|
+
ethereum: {
|
|
63
|
+
0: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
64
|
+
},
|
|
65
|
+
polygon: {
|
|
66
|
+
0: '0x842d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
activeWalletId: 'test-wallet-1',
|
|
71
|
+
}))
|
|
72
|
+
|
|
73
|
+
const result = getWalletAddresses(mockWalletStore, 0)
|
|
74
|
+
expect(result).toEqual({
|
|
75
|
+
ethereum: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
76
|
+
polygon: '0x842d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
77
|
+
})
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('should only return addresses for specified account index', () => {
|
|
81
|
+
mockWalletStore.getState = jest.fn(() => ({
|
|
82
|
+
addresses: {
|
|
83
|
+
'test-wallet-1': {
|
|
84
|
+
ethereum: {
|
|
85
|
+
0: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
86
|
+
1: '0x942d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
87
|
+
},
|
|
88
|
+
},
|
|
89
|
+
},
|
|
90
|
+
activeWalletId: 'test-wallet-1',
|
|
91
|
+
}))
|
|
92
|
+
|
|
93
|
+
const result = getWalletAddresses(mockWalletStore, 0)
|
|
94
|
+
expect(result).toEqual({
|
|
95
|
+
ethereum: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
96
|
+
})
|
|
97
|
+
expect(result.ethereum).not.toBe('0x942d35Cc6634C0532925a3b844Bc9e7595f0bEb0')
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('should handle missing account index gracefully', () => {
|
|
101
|
+
mockWalletStore.getState = jest.fn(() => ({
|
|
102
|
+
addresses: {
|
|
103
|
+
'test-wallet-1': {
|
|
104
|
+
ethereum: {
|
|
105
|
+
0: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
activeWalletId: 'test-wallet-1',
|
|
110
|
+
}))
|
|
111
|
+
|
|
112
|
+
const result = getWalletAddresses(mockWalletStore, 1)
|
|
113
|
+
expect(result).toEqual({})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('should handle undefined network addresses', () => {
|
|
117
|
+
mockWalletStore.getState = jest.fn(() => ({
|
|
118
|
+
addresses: {
|
|
119
|
+
'test-wallet-1': {
|
|
120
|
+
ethereum: undefined,
|
|
121
|
+
polygon: {
|
|
122
|
+
0: '0x842d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
activeWalletId: 'test-wallet-1',
|
|
127
|
+
}))
|
|
128
|
+
|
|
129
|
+
const result = getWalletAddresses(mockWalletStore, 0)
|
|
130
|
+
expect(result).toEqual({
|
|
131
|
+
polygon: '0x842d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
132
|
+
})
|
|
133
|
+
})
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
describe('createBaseWalletStore', () => {
|
|
137
|
+
it('should create wallet store with callAccountMethod', async () => {
|
|
138
|
+
const mockResult = { balance: '100' }
|
|
139
|
+
;(AccountService.callAccountMethod as jest.Mock).mockResolvedValue(
|
|
140
|
+
mockResult
|
|
141
|
+
)
|
|
142
|
+
|
|
143
|
+
const store = createBaseWalletStore()
|
|
144
|
+
const result = await store.callAccountMethod('ethereum', 0, 'getBalance')
|
|
145
|
+
|
|
146
|
+
expect(result).toBe(mockResult)
|
|
147
|
+
expect(AccountService.callAccountMethod).toHaveBeenCalledWith(
|
|
148
|
+
'ethereum',
|
|
149
|
+
0,
|
|
150
|
+
'getBalance',
|
|
151
|
+
undefined
|
|
152
|
+
)
|
|
153
|
+
})
|
|
154
|
+
|
|
155
|
+
it('should create wallet store with isWalletInitialized', () => {
|
|
156
|
+
const store = createBaseWalletStore()
|
|
157
|
+
const isInitialized = store.isWalletInitialized()
|
|
158
|
+
|
|
159
|
+
expect(isInitialized).toBe(true)
|
|
160
|
+
expect(getWorkletStore).toHaveBeenCalled()
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
it('should create wallet store with getWalletAddresses', () => {
|
|
164
|
+
mockWalletStore.getState = jest.fn(() => ({
|
|
165
|
+
addresses: {
|
|
166
|
+
'test-wallet-1': {
|
|
167
|
+
ethereum: {
|
|
168
|
+
0: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
169
|
+
},
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
activeWalletId: 'test-wallet-1',
|
|
173
|
+
}))
|
|
174
|
+
|
|
175
|
+
const store = createBaseWalletStore()
|
|
176
|
+
const addresses = store.getWalletAddresses(0)
|
|
177
|
+
|
|
178
|
+
expect(addresses).toEqual({
|
|
179
|
+
ethereum: '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb0',
|
|
180
|
+
})
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
it('should return false for isWalletInitialized when not initialized', () => {
|
|
184
|
+
mockWorkletStore.getState = jest.fn(() => ({
|
|
185
|
+
isInitialized: false,
|
|
186
|
+
}))
|
|
187
|
+
|
|
188
|
+
const store = createBaseWalletStore()
|
|
189
|
+
const isInitialized = store.isWalletInitialized()
|
|
190
|
+
|
|
191
|
+
expect(isInitialized).toBe(false)
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
})
|
|
195
|
+
|