tempo.ts 0.0.0 → 0.0.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 (153) hide show
  1. package/README.md +92 -0
  2. package/dist/chains.d.ts +1477 -0
  3. package/dist/chains.d.ts.map +1 -0
  4. package/dist/chains.js +43 -0
  5. package/dist/chains.js.map +1 -0
  6. package/dist/index.d.ts +2 -0
  7. package/dist/index.d.ts.map +1 -0
  8. package/dist/index.js +2 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/internal/types.d.ts +284 -0
  11. package/dist/internal/types.d.ts.map +1 -0
  12. package/dist/internal/types.js +2 -0
  13. package/dist/internal/types.js.map +1 -0
  14. package/dist/ox/TokenId.d.ts +18 -0
  15. package/dist/ox/TokenId.d.ts.map +1 -0
  16. package/dist/ox/TokenId.js +29 -0
  17. package/dist/ox/TokenId.js.map +1 -0
  18. package/dist/ox/TokenRole.d.ts +11 -0
  19. package/dist/ox/TokenRole.d.ts.map +1 -0
  20. package/dist/ox/TokenRole.js +22 -0
  21. package/dist/ox/TokenRole.js.map +1 -0
  22. package/dist/ox/Transaction.d.ts +161 -0
  23. package/dist/ox/Transaction.d.ts.map +1 -0
  24. package/dist/ox/Transaction.js +117 -0
  25. package/dist/ox/Transaction.js.map +1 -0
  26. package/dist/ox/TransactionEnvelopeFeeToken.d.ts +393 -0
  27. package/dist/ox/TransactionEnvelopeFeeToken.d.ts.map +1 -0
  28. package/dist/ox/TransactionEnvelopeFeeToken.js +452 -0
  29. package/dist/ox/TransactionEnvelopeFeeToken.js.map +1 -0
  30. package/dist/ox/TransactionRequest.d.ts +62 -0
  31. package/dist/ox/TransactionRequest.d.ts.map +1 -0
  32. package/dist/ox/TransactionRequest.js +66 -0
  33. package/dist/ox/TransactionRequest.js.map +1 -0
  34. package/dist/ox/index.d.ts +5 -0
  35. package/dist/ox/index.d.ts.map +1 -0
  36. package/dist/ox/index.js +5 -0
  37. package/dist/ox/index.js.map +1 -0
  38. package/dist/prool/Instance.d.ts +92 -0
  39. package/dist/prool/Instance.d.ts.map +1 -0
  40. package/dist/prool/Instance.js +96 -0
  41. package/dist/prool/Instance.js.map +1 -0
  42. package/dist/prool/index.d.ts +2 -0
  43. package/dist/prool/index.d.ts.map +1 -0
  44. package/dist/prool/index.js +2 -0
  45. package/dist/prool/index.js.map +1 -0
  46. package/dist/viem/abis.d.ts +2058 -0
  47. package/dist/viem/abis.d.ts.map +1 -0
  48. package/dist/viem/abis.js +1599 -0
  49. package/dist/viem/abis.js.map +1 -0
  50. package/dist/viem/actions/amm.d.ts +2091 -0
  51. package/dist/viem/actions/amm.d.ts.map +1 -0
  52. package/dist/viem/actions/amm.js +876 -0
  53. package/dist/viem/actions/amm.js.map +1 -0
  54. package/dist/viem/actions/fee.d.ts +727 -0
  55. package/dist/viem/actions/fee.d.ts.map +1 -0
  56. package/dist/viem/actions/fee.js +230 -0
  57. package/dist/viem/actions/fee.js.map +1 -0
  58. package/dist/viem/actions/index.d.ts +5 -0
  59. package/dist/viem/actions/index.d.ts.map +1 -0
  60. package/dist/viem/actions/index.js +5 -0
  61. package/dist/viem/actions/index.js.map +1 -0
  62. package/dist/viem/actions/policy.d.ts +1900 -0
  63. package/dist/viem/actions/policy.d.ts.map +1 -0
  64. package/dist/viem/actions/policy.js +841 -0
  65. package/dist/viem/actions/policy.js.map +1 -0
  66. package/dist/viem/actions/token.d.ts +13759 -0
  67. package/dist/viem/actions/token.d.ts.map +1 -0
  68. package/dist/viem/actions/token.js +2579 -0
  69. package/dist/viem/actions/token.js.map +1 -0
  70. package/dist/viem/addresses.d.ts +8 -0
  71. package/dist/viem/addresses.d.ts.map +1 -0
  72. package/dist/viem/addresses.js +8 -0
  73. package/dist/viem/addresses.js.map +1 -0
  74. package/dist/viem/chain.d.ts +341 -0
  75. package/dist/viem/chain.d.ts.map +1 -0
  76. package/dist/viem/chain.js +22 -0
  77. package/dist/viem/chain.js.map +1 -0
  78. package/dist/viem/client.d.ts +27 -0
  79. package/dist/viem/client.d.ts.map +1 -0
  80. package/dist/viem/client.js +28 -0
  81. package/dist/viem/client.js.map +1 -0
  82. package/dist/viem/decorator.d.ts +1636 -0
  83. package/dist/viem/decorator.d.ts.map +1 -0
  84. package/dist/viem/decorator.js +95 -0
  85. package/dist/viem/decorator.js.map +1 -0
  86. package/dist/viem/formatters.d.ts +4 -0
  87. package/dist/viem/formatters.d.ts.map +1 -0
  88. package/dist/viem/formatters.js +69 -0
  89. package/dist/viem/formatters.js.map +1 -0
  90. package/dist/viem/index.d.ts +10 -0
  91. package/dist/viem/index.d.ts.map +1 -0
  92. package/dist/viem/index.js +10 -0
  93. package/dist/viem/index.js.map +1 -0
  94. package/dist/viem/transaction.d.ts +54 -0
  95. package/dist/viem/transaction.d.ts.map +1 -0
  96. package/dist/viem/transaction.js +108 -0
  97. package/dist/viem/transaction.js.map +1 -0
  98. package/dist/viem/transport.d.ts +16 -0
  99. package/dist/viem/transport.d.ts.map +1 -0
  100. package/dist/viem/transport.js +33 -0
  101. package/dist/viem/transport.js.map +1 -0
  102. package/dist/viem/types.d.ts +10 -0
  103. package/dist/viem/types.d.ts.map +1 -0
  104. package/dist/viem/types.js +2 -0
  105. package/dist/viem/types.js.map +1 -0
  106. package/dist/viem/utils.d.ts +8 -0
  107. package/dist/viem/utils.d.ts.map +1 -0
  108. package/dist/viem/utils.js +9 -0
  109. package/dist/viem/utils.js.map +1 -0
  110. package/package.json +100 -2
  111. package/src/chains.ts +46 -0
  112. package/src/index.ts +1 -0
  113. package/src/internal/types.ts +414 -0
  114. package/src/ox/TokenId.test.ts +29 -0
  115. package/src/ox/TokenId.ts +35 -0
  116. package/src/ox/TokenRole.test.ts +20 -0
  117. package/src/ox/TokenRole.ts +27 -0
  118. package/src/ox/Transaction.test.ts +257 -0
  119. package/src/ox/Transaction.ts +247 -0
  120. package/src/ox/TransactionEnvelopeFeeToken.test.ts +1119 -0
  121. package/src/ox/TransactionEnvelopeFeeToken.ts +717 -0
  122. package/src/ox/TransactionRequest.ts +100 -0
  123. package/src/ox/index.ts +4 -0
  124. package/src/prool/Instance.test.ts +43 -0
  125. package/src/prool/Instance.ts +190 -0
  126. package/src/prool/index.ts +1 -0
  127. package/src/prool/internal/chain.json +106 -0
  128. package/src/prool/internal/consensus.toml +32 -0
  129. package/src/viem/abis.ts +1606 -0
  130. package/src/viem/actions/amm.test.ts +425 -0
  131. package/src/viem/actions/amm.ts +1308 -0
  132. package/src/viem/actions/fee.test.ts +281 -0
  133. package/src/viem/actions/fee.ts +362 -0
  134. package/src/viem/actions/index.ts +4 -0
  135. package/src/viem/actions/policy.test.ts +514 -0
  136. package/src/viem/actions/policy.ts +1284 -0
  137. package/src/viem/actions/token.test.ts +2172 -0
  138. package/src/viem/actions/token.ts +3830 -0
  139. package/src/viem/addresses.ts +10 -0
  140. package/src/viem/chain.ts +27 -0
  141. package/src/viem/client.bench-d.ts +8 -0
  142. package/src/viem/client.test.ts +152 -0
  143. package/src/viem/client.ts +91 -0
  144. package/src/viem/decorator.bench-d.ts +11 -0
  145. package/src/viem/decorator.test.ts +35 -0
  146. package/src/viem/decorator.ts +1914 -0
  147. package/src/viem/e2e.test.ts +410 -0
  148. package/src/viem/formatters.ts +100 -0
  149. package/src/viem/index.ts +9 -0
  150. package/src/viem/transaction.ts +253 -0
  151. package/src/viem/transport.ts +47 -0
  152. package/src/viem/types.ts +55 -0
  153. package/src/viem/utils.ts +37 -0
@@ -0,0 +1,514 @@
1
+ import { setTimeout } from 'node:timers/promises'
2
+ import * as actions from 'tempo.ts/viem/actions'
3
+ import { publicActions } from 'viem'
4
+ import { mnemonicToAccount } from 'viem/accounts'
5
+ import { describe, expect, test } from 'vitest'
6
+ import { tempoTest } from '../../../test/viem/config.js'
7
+ import { createTempoClient } from '../client.js'
8
+
9
+ const account = mnemonicToAccount(
10
+ 'test test test test test test test test test test test junk',
11
+ )
12
+ const account2 = mnemonicToAccount(
13
+ 'test test test test test test test test test test test junk',
14
+ { accountIndex: 1 },
15
+ )
16
+ const account3 = mnemonicToAccount(
17
+ 'test test test test test test test test test test test junk',
18
+ { accountIndex: 2 },
19
+ )
20
+
21
+ const client = createTempoClient({
22
+ account,
23
+ chain: tempoTest,
24
+ pollingInterval: 100,
25
+ }).extend(publicActions)
26
+
27
+ describe('create', () => {
28
+ test('default', async () => {
29
+ // create whitelist policy
30
+ const { receipt, ...result } = await actions.policy.createSync(client, {
31
+ type: 'whitelist',
32
+ })
33
+ expect(receipt).toBeDefined()
34
+ expect(result).toMatchInlineSnapshot(`
35
+ {
36
+ "policyId": 2n,
37
+ "policyType": 0,
38
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
39
+ }
40
+ `)
41
+
42
+ const { policyId } = result
43
+
44
+ // verify policy was created
45
+ const data = await actions.policy.getData(client, {
46
+ policyId,
47
+ })
48
+ expect(data.admin).toBe(account.address)
49
+ expect(data.type).toBe('whitelist')
50
+ })
51
+
52
+ test('behavior: blacklist', async () => {
53
+ // create blacklist policy
54
+ const { receipt: blacklistReceipt, ...blacklistResult } =
55
+ await actions.policy.createSync(client, {
56
+ type: 'blacklist',
57
+ })
58
+ expect(blacklistReceipt).toBeDefined()
59
+ expect(blacklistResult).toMatchInlineSnapshot(`
60
+ {
61
+ "policyId": 2n,
62
+ "policyType": 1,
63
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
64
+ }
65
+ `)
66
+
67
+ const { policyId } = blacklistResult
68
+
69
+ // verify policy was created
70
+ const data = await actions.policy.getData(client, {
71
+ policyId,
72
+ })
73
+ expect(data.admin).toBe(account.address)
74
+ expect(data.type).toBe('blacklist')
75
+ })
76
+
77
+ test.skip('behavior: with initial addresses', async () => {
78
+ // create policy with initial addresses
79
+ const { policyId } = await actions.policy.createSync(client, {
80
+ type: 'whitelist',
81
+ addresses: [account2.address, account3.address],
82
+ })
83
+
84
+ // verify addresses are whitelisted
85
+ const isAuthorized2 = await actions.policy.isAuthorized(client, {
86
+ policyId,
87
+ user: account2.address,
88
+ })
89
+ expect(isAuthorized2).toBe(true)
90
+
91
+ const isAuthorized3 = await actions.policy.isAuthorized(client, {
92
+ policyId,
93
+ user: account3.address,
94
+ })
95
+ expect(isAuthorized3).toBe(true)
96
+
97
+ // verify other address is not whitelisted
98
+ const isAuthorized = await actions.policy.isAuthorized(client, {
99
+ policyId,
100
+ user: account.address,
101
+ })
102
+ expect(isAuthorized).toBe(false)
103
+ })
104
+ })
105
+
106
+ describe('setAdmin', () => {
107
+ test('default', async () => {
108
+ // create policy
109
+ const { policyId } = await actions.policy.createSync(client, {
110
+ type: 'whitelist',
111
+ })
112
+
113
+ // set new admin
114
+ const { receipt: setAdminReceipt, ...setAdminResult } =
115
+ await actions.policy.setAdminSync(client, {
116
+ policyId,
117
+ admin: account2.address,
118
+ })
119
+ expect(setAdminReceipt).toBeDefined()
120
+ expect(setAdminResult).toMatchInlineSnapshot(`
121
+ {
122
+ "admin": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
123
+ "policyId": 2n,
124
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
125
+ }
126
+ `)
127
+
128
+ {
129
+ // verify new admin
130
+ const data = await actions.policy.getData(client, {
131
+ policyId,
132
+ })
133
+ expect(data.admin).toBe(account2.address)
134
+ }
135
+ })
136
+ })
137
+
138
+ describe('modifyWhitelist', () => {
139
+ test('default', async () => {
140
+ // create whitelist policy
141
+ const { policyId } = await actions.policy.createSync(client, {
142
+ type: 'whitelist',
143
+ })
144
+
145
+ {
146
+ // verify account2 is not authorized
147
+ const isAuthorized = await actions.policy.isAuthorized(client, {
148
+ policyId,
149
+ user: account2.address,
150
+ })
151
+ expect(isAuthorized).toBe(false)
152
+ }
153
+
154
+ // add account2 to whitelist
155
+ const { receipt: addReceipt, ...addResult } =
156
+ await actions.policy.modifyWhitelistSync(client, {
157
+ policyId,
158
+ address: account2.address,
159
+ allowed: true,
160
+ })
161
+ expect(addReceipt).toBeDefined()
162
+ expect(addResult).toMatchInlineSnapshot(`
163
+ {
164
+ "account": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
165
+ "allowed": true,
166
+ "policyId": 2n,
167
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
168
+ }
169
+ `)
170
+
171
+ {
172
+ // verify account2 is authorized
173
+ const isAuthorized = await actions.policy.isAuthorized(client, {
174
+ policyId,
175
+ user: account2.address,
176
+ })
177
+ expect(isAuthorized).toBe(true)
178
+ }
179
+
180
+ // remove account2 from whitelist
181
+ const { receipt: removeReceipt, ...removeResult } =
182
+ await actions.policy.modifyWhitelistSync(client, {
183
+ policyId,
184
+ address: account2.address,
185
+ allowed: false,
186
+ })
187
+ expect(removeReceipt).toBeDefined()
188
+ expect(removeResult).toMatchInlineSnapshot(`
189
+ {
190
+ "account": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
191
+ "allowed": false,
192
+ "policyId": 2n,
193
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
194
+ }
195
+ `)
196
+
197
+ {
198
+ // verify account2 is no longer authorized
199
+ const isAuthorized = await actions.policy.isAuthorized(client, {
200
+ policyId,
201
+ user: account2.address,
202
+ })
203
+ expect(isAuthorized).toBe(false)
204
+ }
205
+ })
206
+ })
207
+
208
+ describe('modifyBlacklist', () => {
209
+ test('default', async () => {
210
+ // create blacklist policy
211
+ const { policyId } = await actions.policy.createSync(client, {
212
+ type: 'blacklist',
213
+ })
214
+
215
+ {
216
+ // verify account2 is authorized (not blacklisted)
217
+ const isAuthorized = await actions.policy.isAuthorized(client, {
218
+ policyId,
219
+ user: account2.address,
220
+ })
221
+ expect(isAuthorized).toBe(true)
222
+ }
223
+
224
+ // add account2 to blacklist
225
+ const { receipt: addBlacklistReceipt, ...addBlacklistResult } =
226
+ await actions.policy.modifyBlacklistSync(client, {
227
+ policyId,
228
+ address: account2.address,
229
+ restricted: true,
230
+ })
231
+ expect(addBlacklistReceipt).toBeDefined()
232
+ expect(addBlacklistResult).toMatchInlineSnapshot(`
233
+ {
234
+ "account": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
235
+ "policyId": 2n,
236
+ "restricted": true,
237
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
238
+ }
239
+ `)
240
+
241
+ {
242
+ // verify account2 is not authorized (blacklisted)
243
+ const isAuthorized = await actions.policy.isAuthorized(client, {
244
+ policyId,
245
+ user: account2.address,
246
+ })
247
+ expect(isAuthorized).toBe(false)
248
+ }
249
+
250
+ // remove account2 from blacklist
251
+ const { receipt: removeBlacklistReceipt, ...removeBlacklistResult } =
252
+ await actions.policy.modifyBlacklistSync(client, {
253
+ policyId,
254
+ address: account2.address,
255
+ restricted: false,
256
+ })
257
+ expect(removeBlacklistReceipt).toBeDefined()
258
+ expect(removeBlacklistResult).toMatchInlineSnapshot(`
259
+ {
260
+ "account": "0x8C8d35429F74ec245F8Ef2f4Fd1e551cFF97d650",
261
+ "policyId": 2n,
262
+ "restricted": false,
263
+ "updater": "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266",
264
+ }
265
+ `)
266
+
267
+ {
268
+ // verify account2 is authorized again
269
+ const isAuthorized = await actions.policy.isAuthorized(client, {
270
+ policyId,
271
+ user: account2.address,
272
+ })
273
+ expect(isAuthorized).toBe(true)
274
+ }
275
+ })
276
+ })
277
+
278
+ describe('getData', () => {
279
+ test('default', async () => {
280
+ // create policy
281
+ const { policyId } = await actions.policy.createSync(client, {
282
+ type: 'whitelist',
283
+ })
284
+
285
+ {
286
+ // get policy data
287
+ const data = await actions.policy.getData(client, {
288
+ policyId,
289
+ })
290
+ expect(data.admin).toBe(account.address)
291
+ expect(data.type).toBe('whitelist')
292
+ }
293
+ })
294
+
295
+ test('behavior: blacklist', async () => {
296
+ // create blacklist policy
297
+ const { policyId } = await actions.policy.createSync(client, {
298
+ type: 'blacklist',
299
+ })
300
+
301
+ {
302
+ // get policy data
303
+ const data = await actions.policy.getData(client, {
304
+ policyId,
305
+ })
306
+ expect(data.admin).toBe(account.address)
307
+ expect(data.type).toBe('blacklist')
308
+ }
309
+ })
310
+ })
311
+
312
+ describe('isAuthorized', () => {
313
+ test('special policy: always-reject (policyId 0)', async () => {
314
+ const isAuthorized = await actions.policy.isAuthorized(client, {
315
+ policyId: 0n,
316
+ user: account.address,
317
+ })
318
+ expect(isAuthorized).toBe(false)
319
+ })
320
+
321
+ test('special policy: always-allow (policyId 1)', async () => {
322
+ const isAuthorized = await actions.policy.isAuthorized(client, {
323
+ policyId: 1n,
324
+ user: account.address,
325
+ })
326
+ expect(isAuthorized).toBe(true)
327
+ })
328
+
329
+ test.skip('whitelist policy', async () => {
330
+ // create whitelist policy
331
+ const { policyId } = await actions.policy.createSync(client, {
332
+ type: 'whitelist',
333
+ addresses: [account2.address],
334
+ })
335
+
336
+ {
337
+ // verify whitelisted address is authorized
338
+ const isAuthorized = await actions.policy.isAuthorized(client, {
339
+ policyId,
340
+ user: account2.address,
341
+ })
342
+ expect(isAuthorized).toBe(true)
343
+ }
344
+
345
+ {
346
+ // verify non-whitelisted address is not authorized
347
+ const isAuthorized = await actions.policy.isAuthorized(client, {
348
+ policyId,
349
+ user: account.address,
350
+ })
351
+ expect(isAuthorized).toBe(false)
352
+ }
353
+ })
354
+
355
+ test.skip('blacklist policy', async () => {
356
+ // create blacklist policy
357
+ const { policyId } = await actions.policy.createSync(client, {
358
+ type: 'blacklist',
359
+ addresses: [account2.address],
360
+ })
361
+
362
+ {
363
+ // verify blacklisted address is not authorized
364
+ const isAuthorized = await actions.policy.isAuthorized(client, {
365
+ policyId,
366
+ user: account2.address,
367
+ })
368
+ expect(isAuthorized).toBe(false)
369
+ }
370
+
371
+ {
372
+ // verify non-blacklisted address is authorized
373
+ const isAuthorized = await actions.policy.isAuthorized(client, {
374
+ policyId,
375
+ user: account.address,
376
+ })
377
+ expect(isAuthorized).toBe(true)
378
+ }
379
+ })
380
+ })
381
+
382
+ describe('watchCreate', () => {
383
+ test('default', async () => {
384
+ const logs: any[] = []
385
+ const unwatch = actions.policy.watchCreate(client, {
386
+ onPolicyCreated: (args, log) => {
387
+ logs.push({ args, log })
388
+ },
389
+ })
390
+
391
+ // create policy
392
+ await actions.policy.createSync(client, {
393
+ type: 'whitelist',
394
+ })
395
+
396
+ await setTimeout(500)
397
+ unwatch()
398
+
399
+ expect(logs.length).toBe(1)
400
+ expect(logs[0].args.policyId).toBe(2n)
401
+ expect(logs[0].args.updater).toBe(account.address)
402
+ expect(logs[0].args.type).toBe('whitelist')
403
+ })
404
+ })
405
+
406
+ describe('watchAdminUpdated', () => {
407
+ test('default', async () => {
408
+ // create policy
409
+ const { policyId } = await actions.policy.createSync(client, {
410
+ type: 'whitelist',
411
+ })
412
+
413
+ const logs: any[] = []
414
+ const unwatch = actions.policy.watchAdminUpdated(client, {
415
+ onAdminUpdated: (args, log) => {
416
+ logs.push({ args, log })
417
+ },
418
+ })
419
+
420
+ // set new admin
421
+ await actions.policy.setAdminSync(client, {
422
+ policyId,
423
+ admin: account2.address,
424
+ })
425
+
426
+ await setTimeout(500)
427
+ unwatch()
428
+
429
+ expect(logs.length).toBe(1)
430
+ expect(logs[0].args.policyId).toBe(2n)
431
+ expect(logs[0].args.updater).toBe(account.address)
432
+ expect(logs[0].args.admin).toBe(account2.address)
433
+ })
434
+ })
435
+
436
+ describe('watchWhitelistUpdated', () => {
437
+ test('default', async () => {
438
+ // create whitelist policy
439
+ const { policyId } = await actions.policy.createSync(client, {
440
+ type: 'whitelist',
441
+ })
442
+
443
+ const logs: any[] = []
444
+ const unwatch = actions.policy.watchWhitelistUpdated(client, {
445
+ onWhitelistUpdated: (args, log) => {
446
+ logs.push({ args, log })
447
+ },
448
+ })
449
+
450
+ // add address to whitelist
451
+ await actions.policy.modifyWhitelistSync(client, {
452
+ policyId,
453
+ address: account2.address,
454
+ allowed: true,
455
+ })
456
+
457
+ // remove address from whitelist
458
+ await actions.policy.modifyWhitelistSync(client, {
459
+ policyId,
460
+ address: account2.address,
461
+ allowed: false,
462
+ })
463
+
464
+ await setTimeout(500)
465
+ unwatch()
466
+
467
+ expect(logs.length).toBe(2)
468
+ expect(logs[0].args.policyId).toBe(2n)
469
+ expect(logs[0].args.updater).toBe(account.address)
470
+ expect(logs[0].args.account).toBe(account2.address)
471
+ expect(logs[0].args.allowed).toBe(true)
472
+ expect(logs[1].args.allowed).toBe(false)
473
+ })
474
+ })
475
+
476
+ describe('watchBlacklistUpdated', () => {
477
+ test('default', async () => {
478
+ // create blacklist policy
479
+ const { policyId } = await actions.policy.createSync(client, {
480
+ type: 'blacklist',
481
+ })
482
+
483
+ const logs: any[] = []
484
+ const unwatch = actions.policy.watchBlacklistUpdated(client, {
485
+ onBlacklistUpdated: (args, log) => {
486
+ logs.push({ args, log })
487
+ },
488
+ })
489
+
490
+ // add address to blacklist
491
+ await actions.policy.modifyBlacklistSync(client, {
492
+ policyId,
493
+ address: account2.address,
494
+ restricted: true,
495
+ })
496
+
497
+ // remove address from blacklist
498
+ await actions.policy.modifyBlacklistSync(client, {
499
+ policyId,
500
+ address: account2.address,
501
+ restricted: false,
502
+ })
503
+
504
+ await setTimeout(500)
505
+ unwatch()
506
+
507
+ expect(logs.length).toBe(2)
508
+ expect(logs[0].args.policyId).toBe(2n)
509
+ expect(logs[0].args.updater).toBe(account.address)
510
+ expect(logs[0].args.account).toBe(account2.address)
511
+ expect(logs[0].args.restricted).toBe(true)
512
+ expect(logs[1].args.restricted).toBe(false)
513
+ })
514
+ })