tempo.ts 0.5.0 → 0.5.2

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.
Files changed (44) hide show
  1. package/dist/viem/Actions/policy.d.ts +9 -1
  2. package/dist/viem/Actions/policy.d.ts.map +1 -1
  3. package/dist/viem/Actions/policy.js.map +1 -1
  4. package/dist/viem/Chain.d.ts.map +1 -1
  5. package/dist/viem/Chain.js +3 -1
  6. package/dist/viem/Chain.js.map +1 -1
  7. package/dist/viem/Formatters.js +1 -1
  8. package/dist/viem/Formatters.js.map +1 -1
  9. package/dist/viem/Transport.d.ts +8 -0
  10. package/dist/viem/Transport.d.ts.map +1 -1
  11. package/dist/viem/Transport.js +87 -1
  12. package/dist/viem/Transport.js.map +1 -1
  13. package/dist/wagmi/Actions/index.d.ts +1 -0
  14. package/dist/wagmi/Actions/index.d.ts.map +1 -1
  15. package/dist/wagmi/Actions/index.js +1 -0
  16. package/dist/wagmi/Actions/index.js.map +1 -1
  17. package/dist/wagmi/Actions/policy.d.ts +481 -0
  18. package/dist/wagmi/Actions/policy.d.ts.map +1 -0
  19. package/dist/wagmi/Actions/policy.js +530 -0
  20. package/dist/wagmi/Actions/policy.js.map +1 -0
  21. package/dist/wagmi/Connector.d.ts +1 -1
  22. package/dist/wagmi/Connector.d.ts.map +1 -1
  23. package/dist/wagmi/Connector.js +3 -85
  24. package/dist/wagmi/Connector.js.map +1 -1
  25. package/dist/wagmi/Hooks/index.d.ts +1 -0
  26. package/dist/wagmi/Hooks/index.d.ts.map +1 -1
  27. package/dist/wagmi/Hooks/index.js +1 -0
  28. package/dist/wagmi/Hooks/index.js.map +1 -1
  29. package/dist/wagmi/Hooks/policy.d.ts +424 -0
  30. package/dist/wagmi/Hooks/policy.d.ts.map +1 -0
  31. package/dist/wagmi/Hooks/policy.js +510 -0
  32. package/dist/wagmi/Hooks/policy.js.map +1 -0
  33. package/package.json +2 -2
  34. package/src/viem/Actions/policy.ts +25 -0
  35. package/src/viem/Chain.ts +3 -1
  36. package/src/viem/Formatters.ts +1 -1
  37. package/src/viem/Transport.ts +107 -1
  38. package/src/wagmi/Actions/index.ts +1 -0
  39. package/src/wagmi/Actions/policy.test.ts +461 -0
  40. package/src/wagmi/Actions/policy.ts +819 -0
  41. package/src/wagmi/Connector.ts +4 -112
  42. package/src/wagmi/Hooks/index.ts +1 -0
  43. package/src/wagmi/Hooks/policy.test.ts +665 -0
  44. package/src/wagmi/Hooks/policy.ts +875 -0
@@ -0,0 +1,665 @@
1
+ import type { Address } from 'viem'
2
+ import { describe, expect, test, vi } from 'vitest'
3
+ import { useConnect } from 'wagmi'
4
+ import { accounts } from '../../../test/viem/config.js'
5
+ import { config, queryClient, renderHook } from '../../../test/wagmi/config.js'
6
+ import * as Actions from '../Actions/policy.js'
7
+ import * as hooks from './policy.js'
8
+
9
+ const account = accounts[0]
10
+ const account2 = accounts[1]
11
+
12
+ describe('useCreate', () => {
13
+ test('default', async () => {
14
+ const { result } = await renderHook(() => ({
15
+ connect: useConnect(),
16
+ createSync: hooks.useCreateSync(),
17
+ }))
18
+
19
+ await result.current.connect.connectAsync({
20
+ connector: config.connectors[0]!,
21
+ })
22
+
23
+ // create whitelist policy
24
+ const { receipt, ...createResult } =
25
+ await result.current.createSync.mutateAsync({
26
+ type: 'whitelist',
27
+ })
28
+ expect(receipt).toBeDefined()
29
+ expect(createResult).toMatchInlineSnapshot(`
30
+ {
31
+ "policyId": 2n,
32
+ "policyType": 0,
33
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
34
+ }
35
+ `)
36
+
37
+ const { policyId } = createResult
38
+
39
+ // verify policy was created
40
+ const data = await Actions.getData(config, {
41
+ policyId,
42
+ })
43
+ expect(data.admin).toBe(account.address)
44
+ expect(data.type).toBe('whitelist')
45
+ })
46
+
47
+ test('behavior: blacklist', async () => {
48
+ const { result } = await renderHook(() => ({
49
+ connect: useConnect(),
50
+ createSync: hooks.useCreateSync(),
51
+ }))
52
+
53
+ await result.current.connect.connectAsync({
54
+ connector: config.connectors[0]!,
55
+ })
56
+
57
+ // create blacklist policy
58
+ const { receipt: blacklistReceipt, ...blacklistResult } =
59
+ await result.current.createSync.mutateAsync({
60
+ type: 'blacklist',
61
+ })
62
+ expect(blacklistReceipt).toBeDefined()
63
+ expect(blacklistResult).toMatchInlineSnapshot(`
64
+ {
65
+ "policyId": 3n,
66
+ "policyType": 1,
67
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
68
+ }
69
+ `)
70
+
71
+ const { policyId } = blacklistResult
72
+
73
+ // verify policy was created
74
+ const data = await Actions.getData(config, {
75
+ policyId,
76
+ })
77
+ expect(data.admin).toBe(account.address)
78
+ expect(data.type).toBe('blacklist')
79
+ })
80
+ })
81
+
82
+ describe('useSetAdmin', () => {
83
+ test('default', async () => {
84
+ const { result } = await renderHook(() => ({
85
+ connect: useConnect(),
86
+ createSync: hooks.useCreateSync(),
87
+ setAdminSync: hooks.useSetAdminSync(),
88
+ }))
89
+
90
+ await result.current.connect.connectAsync({
91
+ connector: config.connectors[0]!,
92
+ })
93
+
94
+ // create policy
95
+ const { policyId } = await result.current.createSync.mutateAsync({
96
+ type: 'whitelist',
97
+ })
98
+
99
+ // set new admin
100
+ const { receipt: setAdminReceipt, ...setAdminResult } =
101
+ await result.current.setAdminSync.mutateAsync({
102
+ policyId,
103
+ admin: account2.address,
104
+ })
105
+ expect(setAdminReceipt).toBeDefined()
106
+ expect(setAdminResult).toMatchInlineSnapshot(`
107
+ {
108
+ "admin": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
109
+ "policyId": 4n,
110
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
111
+ }
112
+ `)
113
+
114
+ {
115
+ // verify new admin
116
+ const data = await Actions.getData(config, { policyId })
117
+ expect(data.admin).toBe(account2.address)
118
+ }
119
+ })
120
+ })
121
+
122
+ describe('useModifyWhitelist', () => {
123
+ test('default', async () => {
124
+ const { result } = await renderHook(() => ({
125
+ connect: useConnect(),
126
+ createSync: hooks.useCreateSync(),
127
+ modifyWhitelistSync: hooks.useModifyWhitelistSync(),
128
+ }))
129
+
130
+ await result.current.connect.connectAsync({
131
+ connector: config.connectors[0]!,
132
+ })
133
+
134
+ // create whitelist policy
135
+ const { policyId } = await result.current.createSync.mutateAsync({
136
+ type: 'whitelist',
137
+ })
138
+
139
+ // verify account2 is not authorized
140
+ {
141
+ const isAuthorized = await Actions.isAuthorized(config, {
142
+ policyId,
143
+ user: account2.address,
144
+ })
145
+ expect(isAuthorized).toBe(false)
146
+ }
147
+
148
+ // add account2 to whitelist
149
+ const { receipt: addReceipt, ...addResult } =
150
+ await result.current.modifyWhitelistSync.mutateAsync({
151
+ policyId,
152
+ address: account2.address,
153
+ allowed: true,
154
+ })
155
+ expect(addReceipt).toBeDefined()
156
+ expect(addResult).toMatchInlineSnapshot(`
157
+ {
158
+ "account": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
159
+ "allowed": true,
160
+ "policyId": 5n,
161
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
162
+ }
163
+ `)
164
+
165
+ // verify account2 is authorized
166
+ {
167
+ const isAuthorized = await Actions.isAuthorized(config, {
168
+ policyId,
169
+ user: account2.address,
170
+ })
171
+ expect(isAuthorized).toBe(true)
172
+ }
173
+
174
+ // remove account2 from whitelist
175
+ const { receipt: removeReceipt, ...removeResult } =
176
+ await result.current.modifyWhitelistSync.mutateAsync({
177
+ policyId,
178
+ address: account2.address,
179
+ allowed: false,
180
+ })
181
+ expect(removeReceipt).toBeDefined()
182
+ expect(removeResult).toMatchInlineSnapshot(`
183
+ {
184
+ "account": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
185
+ "allowed": false,
186
+ "policyId": 5n,
187
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
188
+ }
189
+ `)
190
+
191
+ // verify account2 is no longer authorized
192
+ {
193
+ const isAuthorized = await Actions.isAuthorized(config, {
194
+ policyId,
195
+ user: account2.address,
196
+ })
197
+ expect(isAuthorized).toBe(false)
198
+ }
199
+ })
200
+ })
201
+
202
+ describe('useModifyBlacklist', () => {
203
+ test('default', async () => {
204
+ const { result } = await renderHook(() => ({
205
+ connect: useConnect(),
206
+ createSync: hooks.useCreateSync(),
207
+ modifyBlacklistSync: hooks.useModifyBlacklistSync(),
208
+ }))
209
+
210
+ await result.current.connect.connectAsync({
211
+ connector: config.connectors[0]!,
212
+ })
213
+
214
+ // create blacklist policy
215
+ const { policyId } = await result.current.createSync.mutateAsync({
216
+ type: 'blacklist',
217
+ })
218
+
219
+ // verify account2 is authorized (not blacklisted)
220
+ {
221
+ const isAuthorized = await Actions.isAuthorized(config, {
222
+ policyId,
223
+ user: account2.address,
224
+ })
225
+ expect(isAuthorized).toBe(true)
226
+ }
227
+
228
+ // add account2 to blacklist
229
+ const { receipt: addBlacklistReceipt, ...addBlacklistResult } =
230
+ await result.current.modifyBlacklistSync.mutateAsync({
231
+ policyId,
232
+ address: account2.address,
233
+ restricted: true,
234
+ })
235
+ expect(addBlacklistReceipt).toBeDefined()
236
+ expect(addBlacklistResult).toMatchInlineSnapshot(`
237
+ {
238
+ "account": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
239
+ "policyId": 6n,
240
+ "restricted": true,
241
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
242
+ }
243
+ `)
244
+
245
+ // verify account2 is not authorized (blacklisted)
246
+ {
247
+ const isAuthorized = await Actions.isAuthorized(config, {
248
+ policyId,
249
+ user: account2.address,
250
+ })
251
+ expect(isAuthorized).toBe(false)
252
+ }
253
+
254
+ // remove account2 from blacklist
255
+ const removeResult = await result.current.modifyBlacklistSync.mutateAsync({
256
+ policyId,
257
+ address: account2.address,
258
+ restricted: false,
259
+ })
260
+
261
+ expect(removeResult.receipt).toBeDefined()
262
+ expect(removeResult.policyId).toBe(policyId)
263
+ expect(removeResult.account).toBe(account2.address)
264
+ expect(removeResult.restricted).toBe(false)
265
+ expect(removeResult.updater).toBe(account.address)
266
+
267
+ // verify account2 is authorized again
268
+ {
269
+ const isAuthorized = await Actions.isAuthorized(config, {
270
+ policyId,
271
+ user: account2.address,
272
+ })
273
+ expect(isAuthorized).toBe(true)
274
+ }
275
+ })
276
+ })
277
+
278
+ describe('useGetData', () => {
279
+ test('default', async () => {
280
+ const { result: setupResult } = await renderHook(() => ({
281
+ connect: useConnect(),
282
+ createSync: hooks.useCreateSync(),
283
+ }))
284
+
285
+ await setupResult.current.connect.connectAsync({
286
+ connector: config.connectors[0]!,
287
+ })
288
+
289
+ // create policy
290
+ const { policyId } = await setupResult.current.createSync.mutateAsync({
291
+ type: 'whitelist',
292
+ })
293
+
294
+ {
295
+ // get policy data
296
+ const { result } = await renderHook(() => hooks.useGetData({ policyId }))
297
+
298
+ await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
299
+
300
+ expect(result.current.data?.admin).toBe(account.address)
301
+ expect(result.current.data?.type).toBe('whitelist')
302
+ }
303
+ })
304
+
305
+ test('behavior: blacklist', async () => {
306
+ const { result: setupResult } = await renderHook(() => ({
307
+ connect: useConnect(),
308
+ createSync: hooks.useCreateSync(),
309
+ }))
310
+
311
+ await setupResult.current.connect.connectAsync({
312
+ connector: config.connectors[0]!,
313
+ })
314
+
315
+ // create blacklist policy
316
+ const { policyId } = await setupResult.current.createSync.mutateAsync({
317
+ type: 'blacklist',
318
+ })
319
+
320
+ {
321
+ // get policy data
322
+ const { result } = await renderHook(() => hooks.useGetData({ policyId }))
323
+
324
+ await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
325
+
326
+ expect(result.current.data?.admin).toBe(account.address)
327
+ expect(result.current.data?.type).toBe('blacklist')
328
+ }
329
+ })
330
+
331
+ test('reactivity: policyId parameter', async () => {
332
+ const { result: setupResult } = await renderHook(() => ({
333
+ connect: useConnect(),
334
+ createSync: hooks.useCreateSync(),
335
+ }))
336
+
337
+ await setupResult.current.connect.connectAsync({
338
+ connector: config.connectors[0]!,
339
+ })
340
+
341
+ // Create policy
342
+ const { policyId } = await setupResult.current.createSync.mutateAsync({
343
+ type: 'whitelist',
344
+ })
345
+
346
+ // Query with undefined policyId initially
347
+ const { result, rerender } = await renderHook(
348
+ (props) => hooks.useGetData({ policyId: props?.policyId }),
349
+ { initialProps: { policyId: undefined as bigint | undefined } },
350
+ )
351
+
352
+ await vi.waitFor(() => result.current.fetchStatus === 'fetching')
353
+
354
+ // Should be disabled when policyId is undefined
355
+ expect(result.current.data).toBeUndefined()
356
+ expect(result.current.isPending).toBe(true)
357
+ expect(result.current.isEnabled).toBe(false)
358
+
359
+ // Set policyId
360
+ rerender({ policyId })
361
+
362
+ await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
363
+
364
+ // Should now be enabled and have data
365
+ expect(result.current.isEnabled).toBe(true)
366
+ expect(result.current.data?.admin).toBe(account.address)
367
+ expect(result.current.data?.type).toBe('whitelist')
368
+ })
369
+
370
+ describe('queryOptions', () => {
371
+ test('default', async () => {
372
+ const { result: setupResult } = await renderHook(() => ({
373
+ connect: useConnect(),
374
+ createSync: hooks.useCreateSync(),
375
+ }))
376
+
377
+ await setupResult.current.connect.connectAsync({
378
+ connector: config.connectors[0]!,
379
+ })
380
+
381
+ // create policy
382
+ const { policyId } = await setupResult.current.createSync.mutateAsync({
383
+ type: 'whitelist',
384
+ })
385
+
386
+ const options = Actions.getData.queryOptions(config, { policyId })
387
+ const data = await queryClient.fetchQuery(options)
388
+
389
+ expect(data.admin).toBe(account.address)
390
+ expect(data.type).toBe('whitelist')
391
+ })
392
+ })
393
+ })
394
+
395
+ describe('useIsAuthorized', () => {
396
+ test('special policy: always-reject (policyId 0)', async () => {
397
+ const { result } = await renderHook(() =>
398
+ hooks.useIsAuthorized({
399
+ policyId: 0n,
400
+ user: account.address,
401
+ }),
402
+ )
403
+
404
+ await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
405
+
406
+ expect(result.current.data).toBe(false)
407
+ })
408
+
409
+ test('special policy: always-allow (policyId 1)', async () => {
410
+ const { result } = await renderHook(() =>
411
+ hooks.useIsAuthorized({
412
+ policyId: 1n,
413
+ user: account.address,
414
+ }),
415
+ )
416
+
417
+ await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
418
+
419
+ expect(result.current.data).toBe(true)
420
+ })
421
+
422
+ test('reactivity: policyId and user parameters', async () => {
423
+ const { result: setupResult } = await renderHook(() => ({
424
+ connect: useConnect(),
425
+ createSync: hooks.useCreateSync(),
426
+ modifyWhitelistSync: hooks.useModifyWhitelistSync(),
427
+ }))
428
+
429
+ await setupResult.current.connect.connectAsync({
430
+ connector: config.connectors[0]!,
431
+ })
432
+
433
+ // Create whitelist policy
434
+ const { policyId } = await setupResult.current.createSync.mutateAsync({
435
+ type: 'whitelist',
436
+ })
437
+
438
+ // Add account2 to whitelist
439
+ await setupResult.current.modifyWhitelistSync.mutateAsync({
440
+ policyId,
441
+ address: account2.address,
442
+ allowed: true,
443
+ })
444
+
445
+ // Query with undefined parameters initially
446
+ const { result, rerender } = await renderHook(
447
+ (props) =>
448
+ hooks.useIsAuthorized({
449
+ policyId: props?.policyId,
450
+ user: props?.user,
451
+ }),
452
+ {
453
+ initialProps: {
454
+ policyId: undefined as bigint | undefined,
455
+ user: undefined as Address | undefined,
456
+ },
457
+ },
458
+ )
459
+
460
+ await vi.waitFor(() => result.current.fetchStatus === 'fetching')
461
+
462
+ // Should be disabled when parameters are undefined
463
+ expect(result.current.data).toBeUndefined()
464
+ expect(result.current.isPending).toBe(true)
465
+ expect(result.current.isEnabled).toBe(false)
466
+
467
+ // Set parameters
468
+ rerender({ policyId, user: account2.address })
469
+
470
+ await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
471
+
472
+ // Should now be enabled and have data
473
+ expect(result.current.isEnabled).toBe(true)
474
+ expect(result.current.data).toBe(true)
475
+ })
476
+
477
+ describe('queryOptions', () => {
478
+ test('default', async () => {
479
+ const options = Actions.isAuthorized.queryOptions(config, {
480
+ policyId: 1n,
481
+ user: account.address,
482
+ })
483
+ const isAuthorized = await queryClient.fetchQuery(options)
484
+
485
+ expect(isAuthorized).toBe(true)
486
+ })
487
+ })
488
+ })
489
+
490
+ describe('useWatchCreate', () => {
491
+ test('default', async () => {
492
+ const { result: connectResult } = await renderHook(() => ({
493
+ connect: useConnect(),
494
+ createSync: hooks.useCreateSync(),
495
+ }))
496
+
497
+ await connectResult.current.connect.connectAsync({
498
+ connector: config.connectors[0]!,
499
+ })
500
+
501
+ const events: any[] = []
502
+ await renderHook(() =>
503
+ hooks.useWatchCreate({
504
+ onPolicyCreated(args) {
505
+ events.push(args)
506
+ },
507
+ }),
508
+ )
509
+
510
+ // Create policy
511
+ await connectResult.current.createSync.mutateAsync({
512
+ type: 'whitelist',
513
+ })
514
+
515
+ await vi.waitUntil(() => events.length >= 1)
516
+
517
+ expect(events.length).toBeGreaterThanOrEqual(1)
518
+ expect(events[0]?.policyId).toBeDefined()
519
+ expect(events[0]?.updater).toBe(account.address)
520
+ expect(events[0]?.type).toBe('whitelist')
521
+ })
522
+ })
523
+
524
+ describe('useWatchAdminUpdated', () => {
525
+ test('default', async () => {
526
+ const { result: connectResult } = await renderHook(() => ({
527
+ connect: useConnect(),
528
+ createSync: hooks.useCreateSync(),
529
+ setAdminSync: hooks.useSetAdminSync(),
530
+ }))
531
+
532
+ await connectResult.current.connect.connectAsync({
533
+ connector: config.connectors[0]!,
534
+ })
535
+
536
+ // Create policy
537
+ const { policyId } = await connectResult.current.createSync.mutateAsync({
538
+ type: 'whitelist',
539
+ })
540
+
541
+ const events: any[] = []
542
+ await renderHook(() =>
543
+ hooks.useWatchAdminUpdated({
544
+ onAdminUpdated(args) {
545
+ events.push(args)
546
+ },
547
+ }),
548
+ )
549
+
550
+ // Set new admin
551
+ await connectResult.current.setAdminSync.mutateAsync({
552
+ policyId,
553
+ admin: account2.address,
554
+ })
555
+
556
+ await vi.waitUntil(() => events.length >= 1)
557
+
558
+ expect(events.length).toBeGreaterThanOrEqual(1)
559
+ expect(events[0]?.policyId).toBe(policyId)
560
+ expect(events[0]?.updater).toBe(account.address)
561
+ expect(events[0]?.admin).toBe(account2.address)
562
+ })
563
+ })
564
+
565
+ describe('useWatchWhitelistUpdated', () => {
566
+ test('default', async () => {
567
+ const { result: connectResult } = await renderHook(() => ({
568
+ connect: useConnect(),
569
+ createSync: hooks.useCreateSync(),
570
+ modifyWhitelistSync: hooks.useModifyWhitelistSync(),
571
+ }))
572
+
573
+ await connectResult.current.connect.connectAsync({
574
+ connector: config.connectors[0]!,
575
+ })
576
+
577
+ // Create whitelist policy
578
+ const { policyId } = await connectResult.current.createSync.mutateAsync({
579
+ type: 'whitelist',
580
+ })
581
+
582
+ const events: any[] = []
583
+ await renderHook(() =>
584
+ hooks.useWatchWhitelistUpdated({
585
+ onWhitelistUpdated(args) {
586
+ events.push(args)
587
+ },
588
+ }),
589
+ )
590
+
591
+ // Add address to whitelist
592
+ await connectResult.current.modifyWhitelistSync.mutateAsync({
593
+ policyId,
594
+ address: account2.address,
595
+ allowed: true,
596
+ })
597
+
598
+ // Remove address from whitelist
599
+ await connectResult.current.modifyWhitelistSync.mutateAsync({
600
+ policyId,
601
+ address: account2.address,
602
+ allowed: false,
603
+ })
604
+
605
+ await vi.waitUntil(() => events.length >= 2)
606
+
607
+ expect(events.length).toBeGreaterThanOrEqual(2)
608
+ expect(events[0]?.policyId).toBe(policyId)
609
+ expect(events[0]?.updater).toBe(account.address)
610
+ expect(events[0]?.account).toBe(account2.address)
611
+ expect(events[0]?.allowed).toBe(true)
612
+ expect(events[1]?.allowed).toBe(false)
613
+ })
614
+ })
615
+
616
+ describe('useWatchBlacklistUpdated', () => {
617
+ test('default', async () => {
618
+ const { result: connectResult } = await renderHook(() => ({
619
+ connect: useConnect(),
620
+ createSync: hooks.useCreateSync(),
621
+ modifyBlacklistSync: hooks.useModifyBlacklistSync(),
622
+ }))
623
+
624
+ await connectResult.current.connect.connectAsync({
625
+ connector: config.connectors[0]!,
626
+ })
627
+
628
+ // Create blacklist policy
629
+ const { policyId } = await connectResult.current.createSync.mutateAsync({
630
+ type: 'blacklist',
631
+ })
632
+
633
+ const events: any[] = []
634
+ await renderHook(() =>
635
+ hooks.useWatchBlacklistUpdated({
636
+ onBlacklistUpdated(args) {
637
+ events.push(args)
638
+ },
639
+ }),
640
+ )
641
+
642
+ // Add address to blacklist
643
+ await connectResult.current.modifyBlacklistSync.mutateAsync({
644
+ policyId,
645
+ address: account2.address,
646
+ restricted: true,
647
+ })
648
+
649
+ // Remove address from blacklist
650
+ await connectResult.current.modifyBlacklistSync.mutateAsync({
651
+ policyId,
652
+ address: account2.address,
653
+ restricted: false,
654
+ })
655
+
656
+ await vi.waitUntil(() => events.length >= 2)
657
+
658
+ expect(events.length).toBeGreaterThanOrEqual(2)
659
+ expect(events[0]?.policyId).toBe(policyId)
660
+ expect(events[0]?.updater).toBe(account.address)
661
+ expect(events[0]?.account).toBe(account2.address)
662
+ expect(events[0]?.restricted).toBe(true)
663
+ expect(events[1]?.restricted).toBe(false)
664
+ })
665
+ })