Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / wallet / tests / fixtures / wallets.ts
blob291e89945c50f90de31c7dd1e7cca7aaf7bdef90
1 import {
2     type WasmAccount,
3     type WasmBalance,
4     WasmNetwork,
5     WasmPaymentLink,
6     type WasmTransactionDetails,
7     WasmWallet,
8 } from '@proton/andromeda';
10 import { type WalletChainDataByWalletId } from '../../types';
11 import { freeable } from '../utils/wasm';
12 import {
13     apiWalletAccountOneA,
14     apiWalletAccountOneB,
15     apiWalletAccountThree,
16     apiWalletAccountTwoA,
17     apiWalletAccountTwoB,
18     apiWalletsData,
19 } from './api';
20 import { simpleTransactions } from './transactions';
22 export const getMockedWallet = (mocked?: Partial<WasmWallet>): WasmWallet => {
23     return {
24         addAccount: vi.fn(),
25         getAccount: vi.fn(),
26         getBalance: vi.fn().mockResolvedValue({ confirmed: 0 } as WasmBalance),
27         getTransactions: vi.fn().mockResolvedValue([]),
28         getTransaction: vi.fn().mockResolvedValue(() => ({}) as WasmTransactionDetails),
29         discoverAccounts: vi.fn().mockResolvedValue([]),
30         getFingerprint: vi.fn(() => ''),
31         clearStore: vi.fn(),
32         free: vi.fn(),
33         ...mocked,
34     };
37 export const getMockedWasmAccount = (mocked?: Partial<WasmAccount>): WasmAccount => {
38     return {
39         free: vi.fn(),
40         hasSyncData: vi.fn().mockReturnValue(true),
41         owns: vi.fn().mockReturnValue(false),
42         getNextReceiveAddress: vi
43             .fn()
44             .mockReturnValue(
45                 WasmPaymentLink.tryParse('bitcoin:tb1qddqzdcxs9fp0xdd9nfycar58nfcq9s0xpsqf9h', WasmNetwork.Testnet)
46             ),
47         peekReceiveAddress: vi.fn(),
48         markReceiveAddressesUsedTo: vi.fn().mockReturnValue(0),
49         getBalance: vi.fn().mockResolvedValue({ confirmed: 0 } as WasmBalance),
50         getDerivationPath: vi.fn().mockResolvedValue("84'/1'/1'/0"),
51         getUtxos: vi.fn().mockResolvedValue([]),
52         getTransactions: vi.fn().mockResolvedValue([]),
53         getTransaction: vi.fn().mockResolvedValue({} as WasmTransactionDetails),
54         insertUnconfirmedTransaction: vi.fn(),
55         clearStore: vi.fn(),
56         bumpTransactionsFees: vi.fn(),
57         getAddress: vi.fn(),
58         getAddresses: vi.fn(),
59         ...mocked,
60     };
63 const wallet0 = new WasmWallet(WasmNetwork.Testnet, apiWalletsData[0].Wallet.Mnemonic as string);
64 const wallet1 = new WasmWallet(WasmNetwork.Testnet, apiWalletsData[1].Wallet.Mnemonic as string);
65 const wallet2 = new WasmWallet(WasmNetwork.Testnet, apiWalletsData[2].Wallet.Mnemonic as string);
67 /**
68  * Used to check UI behaviour
69  */
70 export const walletChainDataByWalletId: WalletChainDataByWalletId = {
71     [apiWalletsData[0].Wallet.ID]: {
72         wallet: wallet0,
73         accounts: {
74             [apiWalletAccountOneA.ID]: {
75                 account: getMockedWasmAccount({
76                     getBalance: vi.fn(async () =>
77                         freeable({
78                             data: { confirmed: 100067, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
79                         })
80                     ),
81                     getTransactions: vi.fn(async () =>
82                         freeable({ 0: simpleTransactions.slice(0, 4).map((d) => freeable({ Data: d })) })
83                     ),
84                     getUtxos: vi.fn(async () => freeable({ 0: [] })),
85                 }),
86                 scriptType: 2,
87                 derivationPath: "84'/1'/0'",
88                 poolSize: 3,
89             },
90             [apiWalletAccountOneB.ID]: {
91                 account: getMockedWasmAccount({
92                     getBalance: vi.fn(async () =>
93                         freeable({
94                             data: { confirmed: 11783999, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
95                         })
96                     ),
97                     getTransactions: vi.fn(async () =>
98                         freeable({ 0: simpleTransactions.slice(4, 8).map((d) => freeable({ Data: d })) })
99                     ),
100                     getUtxos: vi.fn(async () => freeable({ 0: [] })),
101                 }),
102                 scriptType: 2,
103                 derivationPath: "84'/1'/0'",
104                 poolSize: 3,
105             },
106         },
107     },
108     [apiWalletsData[1].Wallet.ID]: {
109         wallet: wallet1,
110         accounts: {
111             [apiWalletAccountTwoA.ID]: {
112                 account: getMockedWasmAccount({
113                     getBalance: vi.fn(async () =>
114                         freeable({
115                             data: { confirmed: 8287263, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
116                         })
117                     ),
118                     getTransactions: vi.fn(async () =>
119                         freeable({ 0: simpleTransactions.slice(8, 12).map((d) => freeable({ Data: d })) })
120                     ),
121                     getUtxos: vi.fn(async () => freeable({ 0: [] })),
122                 }),
123                 scriptType: 2,
124                 derivationPath: "84'/1'/0'",
125                 poolSize: 3,
126             },
127             [apiWalletAccountTwoB.ID]: {
128                 account: getMockedWasmAccount({
129                     getBalance: vi.fn(async () =>
130                         freeable({
131                             data: { confirmed: 97536, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
132                         })
133                     ),
134                     getTransactions: vi.fn(async () =>
135                         freeable({ 0: simpleTransactions.slice(12, 16).map((d) => freeable({ Data: d })) })
136                     ),
137                     getUtxos: vi.fn(async () => freeable({ 0: [] })),
138                 }),
139                 scriptType: 2,
140                 derivationPath: "84'/1'/0'",
141                 poolSize: 3,
142             },
143         },
144     },
145     [apiWalletsData[2].Wallet.ID]: {
146         wallet: wallet2,
147         accounts: {
148             [apiWalletAccountThree.ID]: {
149                 account: getMockedWasmAccount({
150                     getBalance: vi.fn(async () =>
151                         freeable({
152                             data: { confirmed: 2612374, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
153                         })
154                     ),
155                     getTransactions: vi.fn(async () =>
156                         freeable({ 0: simpleTransactions.slice(16, 20).map((d) => freeable({ Data: d })) })
157                     ),
158                     getUtxos: vi.fn(async () => freeable({ 0: [] })),
159                 }),
160                 scriptType: 2,
161                 derivationPath: "84'/1'/0'",
162                 poolSize: 3,
163             },
164         },
165     },
169  * Used to check hook behaviour
170  */
171 export const mockedWalletChainDataByWalletId: WalletChainDataByWalletId = {
172     [apiWalletsData[0].Wallet.ID]: {
173         wallet: getMockedWallet({
174             getBalance: vi.fn(async () =>
175                 freeable({
176                     data: { confirmed: 100067 + 11783999, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
177                 })
178             ),
179             getTransactions: vi.fn(async () =>
180                 freeable({ 0: simpleTransactions.slice(0, 8).map((d) => freeable({ Data: d })) })
181             ),
182         }),
183         accounts: {
184             [apiWalletAccountOneA.ID]: {
185                 account: getMockedWasmAccount({
186                     getBalance: vi.fn(async () =>
187                         freeable({
188                             data: {
189                                 confirmed: 100067,
190                                 immature: 0,
191                                 trusted_pending: 0,
192                                 untrusted_pending: 0,
193                             },
194                         })
195                     ),
196                     getTransactions: vi.fn(async () =>
197                         freeable({ 0: simpleTransactions.slice(0, 4).map((d) => freeable({ Data: d })) })
198                     ),
199                     getUtxos: vi.fn(async () => freeable({ 0: [] })),
200                 }),
201                 scriptType: 2,
202                 derivationPath: "84'/1'/0'",
203                 poolSize: 3,
204             },
205             [apiWalletAccountOneB.ID]: {
206                 account: getMockedWasmAccount({
207                     getBalance: vi.fn(async () =>
208                         freeable({
209                             data: { confirmed: 11783999, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
210                         })
211                     ),
212                     getTransactions: vi.fn(async () =>
213                         freeable({ 0: simpleTransactions.slice(4, 8).map((d) => freeable({ Data: d })) })
214                     ),
215                     getUtxos: vi.fn(async () => freeable({ 0: [] })),
216                 }),
217                 scriptType: 2,
218                 derivationPath: "84'/1'/0'",
219                 poolSize: 3,
220             },
221         },
222     },
223     [apiWalletsData[1].Wallet.ID]: {
224         wallet: getMockedWallet({
225             getBalance: vi.fn(async () =>
226                 freeable({
227                     data: { confirmed: 8287263 + 97536, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
228                 })
229             ),
230             getTransactions: vi.fn(async () =>
231                 freeable({ 0: simpleTransactions.slice(8, 16).map((d) => freeable({ Data: d })) })
232             ),
233         }),
234         accounts: {
235             [apiWalletAccountTwoA.ID]: {
236                 account: getMockedWasmAccount({
237                     getBalance: vi.fn(async () =>
238                         freeable({
239                             data: { confirmed: 8287263, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
240                         })
241                     ),
242                     getTransactions: vi.fn(async () =>
243                         freeable({ 0: simpleTransactions.slice(8, 12).map((d) => freeable({ Data: d })) })
244                     ),
245                     getUtxos: vi.fn(async () => freeable({ 0: [] })),
246                 }),
247                 scriptType: 2,
248                 derivationPath: "84'/1'/0'",
249                 poolSize: 3,
250             },
251             [apiWalletAccountTwoB.ID]: {
252                 account: getMockedWasmAccount({
253                     getBalance: vi.fn(async () =>
254                         freeable({
255                             data: { confirmed: 97536, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
256                         })
257                     ),
258                     getTransactions: vi.fn(async () =>
259                         freeable({ 0: simpleTransactions.slice(12, 16).map((d) => freeable({ Data: d })) })
260                     ),
261                     getUtxos: vi.fn(async () => freeable({ 0: [] })),
262                 }),
263                 scriptType: 2,
264                 derivationPath: "84'/1'/0'",
265                 poolSize: 3,
266             },
267         },
268     },
269     [apiWalletsData[2].Wallet.ID]: {
270         wallet: getMockedWallet({
271             getBalance: vi.fn(async () =>
272                 freeable({
273                     data: { confirmed: 2612374, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
274                 })
275             ),
276             getTransactions: vi.fn(async () =>
277                 freeable({ 0: simpleTransactions.slice(16, 20).map((d) => freeable({ Data: d })) })
278             ),
279         }),
280         accounts: {
281             [apiWalletAccountThree.ID]: {
282                 account: getMockedWasmAccount({
283                     getBalance: vi.fn(async () =>
284                         freeable({
285                             data: { confirmed: 2612374, immature: 0, trusted_pending: 0, untrusted_pending: 0 },
286                         })
287                     ),
288                     getTransactions: vi.fn(async () =>
289                         freeable({ 0: simpleTransactions.slice(16, 20).map((d) => freeable({ Data: d })) })
290                     ),
291                     getUtxos: vi.fn(async () => freeable({ 0: [] })),
292                 }),
293                 scriptType: 2,
294                 derivationPath: "84'/1'/0'",
295                 poolSize: 3,
296             },
297         },
298     },