tempo.ts 0.10.2 → 0.10.4

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 (51) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/chains.d.ts +3 -0
  3. package/dist/chains.d.ts.map +1 -1
  4. package/dist/chains.js +5 -1
  5. package/dist/chains.js.map +1 -1
  6. package/dist/viem/Actions/index.d.ts +1 -0
  7. package/dist/viem/Actions/index.d.ts.map +1 -1
  8. package/dist/viem/Actions/index.js +1 -0
  9. package/dist/viem/Actions/index.js.map +1 -1
  10. package/dist/viem/Actions/nonce.d.ts +257 -0
  11. package/dist/viem/Actions/nonce.d.ts.map +1 -0
  12. package/dist/viem/Actions/nonce.js +226 -0
  13. package/dist/viem/Actions/nonce.js.map +1 -0
  14. package/dist/viem/Addresses.d.ts +1 -0
  15. package/dist/viem/Addresses.d.ts.map +1 -1
  16. package/dist/viem/Addresses.js +1 -0
  17. package/dist/viem/Addresses.js.map +1 -1
  18. package/dist/viem/Chain.d.ts +0 -6
  19. package/dist/viem/Chain.d.ts.map +1 -1
  20. package/dist/viem/Chain.js +0 -6
  21. package/dist/viem/Chain.js.map +1 -1
  22. package/dist/wagmi/Actions/index.d.ts +1 -0
  23. package/dist/wagmi/Actions/index.d.ts.map +1 -1
  24. package/dist/wagmi/Actions/index.js +1 -0
  25. package/dist/wagmi/Actions/index.js.map +1 -1
  26. package/dist/wagmi/Actions/nonce.d.ts +147 -0
  27. package/dist/wagmi/Actions/nonce.d.ts.map +1 -0
  28. package/dist/wagmi/Actions/nonce.js +169 -0
  29. package/dist/wagmi/Actions/nonce.js.map +1 -0
  30. package/dist/wagmi/Hooks/index.d.ts +1 -0
  31. package/dist/wagmi/Hooks/index.d.ts.map +1 -1
  32. package/dist/wagmi/Hooks/index.js +1 -0
  33. package/dist/wagmi/Hooks/index.js.map +1 -1
  34. package/dist/wagmi/Hooks/nonce.d.ts +110 -0
  35. package/dist/wagmi/Hooks/nonce.d.ts.map +1 -0
  36. package/dist/wagmi/Hooks/nonce.js +144 -0
  37. package/dist/wagmi/Hooks/nonce.js.map +1 -0
  38. package/package.json +1 -1
  39. package/src/chains.ts +5 -1
  40. package/src/viem/Actions/index.ts +1 -0
  41. package/src/viem/Actions/nonce.test.ts +193 -0
  42. package/src/viem/Actions/nonce.ts +345 -0
  43. package/src/viem/Addresses.ts +1 -0
  44. package/src/viem/Chain.test.ts +9 -9
  45. package/src/viem/Chain.ts +0 -6
  46. package/src/wagmi/Actions/index.ts +1 -0
  47. package/src/wagmi/Actions/nonce.test.ts +141 -0
  48. package/src/wagmi/Actions/nonce.ts +271 -0
  49. package/src/wagmi/Hooks/index.ts +1 -0
  50. package/src/wagmi/Hooks/nonce.test.ts +207 -0
  51. package/src/wagmi/Hooks/nonce.ts +230 -0
@@ -0,0 +1,345 @@
1
+ import type {
2
+ Account,
3
+ Address,
4
+ Chain,
5
+ Client,
6
+ ExtractAbiItem,
7
+ GetEventArgs,
8
+ ReadContractReturnType,
9
+ Transport,
10
+ Log as viem_Log,
11
+ WatchContractEventParameters,
12
+ } from 'viem'
13
+ import { readContract, watchContractEvent } from 'viem/actions'
14
+ import type { UnionOmit } from '../../internal/types.js'
15
+ import * as Abis from '../Abis.js'
16
+ import * as Addresses from '../Addresses.js'
17
+ import type { ReadParameters } from '../internal/types.js'
18
+ import { defineCall } from '../internal/utils.js'
19
+
20
+ /**
21
+ * Gets the nonce for an account and nonce key.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { createClient, http } from 'viem'
26
+ * import { tempo } from 'tempo.ts/chains'
27
+ * import { Actions } from 'tempo.ts/viem'
28
+ *
29
+ * const client = createClient({
30
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
31
+ * transport: http(),
32
+ * })
33
+ *
34
+ * const nonce = await Actions.nonce.getNonce(client, {
35
+ * account: '0x...',
36
+ * nonceKey: 1n,
37
+ * })
38
+ * ```
39
+ *
40
+ * @param client - Client.
41
+ * @param parameters - Parameters.
42
+ * @returns The nonce value.
43
+ */
44
+ export async function getNonce<
45
+ chain extends Chain | undefined,
46
+ account extends Account | undefined,
47
+ >(
48
+ client: Client<Transport, chain, account>,
49
+ parameters: getNonce.Parameters,
50
+ ): Promise<getNonce.ReturnValue> {
51
+ return readContract(client, {
52
+ ...parameters,
53
+ ...getNonce.call(parameters),
54
+ })
55
+ }
56
+
57
+ export namespace getNonce {
58
+ export type Parameters = ReadParameters & Args
59
+
60
+ export type Args = {
61
+ /** Account address. */
62
+ account: Address
63
+ /** Nonce key (must be > 0, key 0 is reserved for protocol nonces). */
64
+ nonceKey: bigint
65
+ }
66
+
67
+ export type ReturnValue = ReadContractReturnType<
68
+ typeof Abis.nonce,
69
+ 'getNonce',
70
+ never
71
+ >
72
+
73
+ /**
74
+ * Defines a call to the `getNonce` function.
75
+ *
76
+ * Can be passed as a parameter to:
77
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
78
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
79
+ * - [`multicall`](https://viem.sh/docs/contract/multicall): execute multiple calls in parallel
80
+ *
81
+ * @example
82
+ * ```ts
83
+ * import { createClient, http } from 'viem'
84
+ * import { tempo } from 'tempo.ts/chains'
85
+ * import { Actions } from 'tempo.ts/viem'
86
+ *
87
+ * const client = createClient({
88
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
89
+ * transport: http(),
90
+ * })
91
+ *
92
+ * const result = await client.multicall({
93
+ * contracts: [
94
+ * Actions.nonce.getNonce.call({ account: '0x...', nonceKey: 1n }),
95
+ * Actions.nonce.getNonce.call({ account: '0x...', nonceKey: 2n }),
96
+ * ],
97
+ * })
98
+ * ```
99
+ *
100
+ * @param args - Arguments.
101
+ * @returns The call.
102
+ */
103
+ export function call(args: Args) {
104
+ const { account, nonceKey } = args
105
+ return defineCall({
106
+ address: Addresses.nonceManager,
107
+ abi: Abis.nonce,
108
+ args: [account, nonceKey],
109
+ functionName: 'getNonce',
110
+ })
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Gets the number of active nonce keys for an account.
116
+ *
117
+ * @example
118
+ * ```ts
119
+ * import { createClient, http } from 'viem'
120
+ * import { tempo } from 'tempo.ts/chains'
121
+ * import { Actions } from 'tempo.ts/viem'
122
+ *
123
+ * const client = createClient({
124
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
125
+ * transport: http(),
126
+ * })
127
+ *
128
+ * const count = await Actions.nonce.getNonceKeyCount(client, {
129
+ * account: '0x...',
130
+ * })
131
+ * ```
132
+ *
133
+ * @param client - Client.
134
+ * @param parameters - Parameters.
135
+ * @returns The number of active nonce keys.
136
+ */
137
+ export async function getNonceKeyCount<
138
+ chain extends Chain | undefined,
139
+ account extends Account | undefined,
140
+ >(
141
+ client: Client<Transport, chain, account>,
142
+ parameters: getNonceKeyCount.Parameters,
143
+ ): Promise<getNonceKeyCount.ReturnValue> {
144
+ return readContract(client, {
145
+ ...parameters,
146
+ ...getNonceKeyCount.call(parameters),
147
+ })
148
+ }
149
+
150
+ export namespace getNonceKeyCount {
151
+ export type Parameters = ReadParameters & Args
152
+
153
+ export type Args = {
154
+ /** Account address. */
155
+ account: Address
156
+ }
157
+
158
+ export type ReturnValue = ReadContractReturnType<
159
+ typeof Abis.nonce,
160
+ 'getActiveNonceKeyCount',
161
+ never
162
+ >
163
+
164
+ /**
165
+ * Defines a call to the `getNonceKeyCount` function.
166
+ *
167
+ * Can be passed as a parameter to:
168
+ * - [`estimateContractGas`](https://viem.sh/docs/contract/estimateContractGas): estimate the gas cost of the call
169
+ * - [`simulateContract`](https://viem.sh/docs/contract/simulateContract): simulate the call
170
+ * - [`multicall`](https://viem.sh/docs/contract/multicall): execute multiple calls in parallel
171
+ *
172
+ * @example
173
+ * ```ts
174
+ * import { createClient, http } from 'viem'
175
+ * import { tempo } from 'tempo.ts/chains'
176
+ * import { Actions } from 'tempo.ts/viem'
177
+ *
178
+ * const client = createClient({
179
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
180
+ * transport: http(),
181
+ * })
182
+ *
183
+ * const result = await client.multicall({
184
+ * contracts: [
185
+ * Actions.nonce.getNonceKeyCount.call({ account: '0x...' }),
186
+ * Actions.nonce.getNonceKeyCount.call({ account: '0x...' }),
187
+ * ],
188
+ * })
189
+ * ```
190
+ *
191
+ * @param args - Arguments.
192
+ * @returns The call.
193
+ */
194
+ export function call(args: Args) {
195
+ const { account } = args
196
+ return defineCall({
197
+ address: Addresses.nonceManager,
198
+ abi: Abis.nonce,
199
+ args: [account],
200
+ functionName: 'getActiveNonceKeyCount',
201
+ })
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Watches for nonce incremented events.
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * import { createClient, http } from 'viem'
211
+ * import { tempo } from 'tempo.ts/chains'
212
+ * import { Actions } from 'tempo.ts/viem'
213
+ *
214
+ * const client = createClient({
215
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
216
+ * transport: http(),
217
+ * })
218
+ *
219
+ * const unwatch = Actions.nonce.watchNonceIncremented(client, {
220
+ * onNonceIncremented: (args, log) => {
221
+ * console.log('Nonce incremented:', args)
222
+ * },
223
+ * })
224
+ * ```
225
+ *
226
+ * @param client - Client.
227
+ * @param parameters - Parameters.
228
+ * @returns A function to unsubscribe from the event.
229
+ */
230
+ export function watchNonceIncremented<
231
+ chain extends Chain | undefined,
232
+ account extends Account | undefined,
233
+ >(
234
+ client: Client<Transport, chain, account>,
235
+ parameters: watchNonceIncremented.Parameters,
236
+ ) {
237
+ const { onNonceIncremented, ...rest } = parameters
238
+ return watchContractEvent(client, {
239
+ ...rest,
240
+ address: Addresses.nonceManager,
241
+ abi: Abis.nonce,
242
+ eventName: 'NonceIncremented',
243
+ onLogs: (logs) => {
244
+ for (const log of logs) onNonceIncremented(log.args, log)
245
+ },
246
+ strict: true,
247
+ })
248
+ }
249
+
250
+ export declare namespace watchNonceIncremented {
251
+ export type Args = GetEventArgs<
252
+ typeof Abis.nonce,
253
+ 'NonceIncremented',
254
+ { IndexedOnly: false; Required: true }
255
+ >
256
+
257
+ export type Log = viem_Log<
258
+ bigint,
259
+ number,
260
+ false,
261
+ ExtractAbiItem<typeof Abis.nonce, 'NonceIncremented'>,
262
+ true
263
+ >
264
+
265
+ export type Parameters = UnionOmit<
266
+ WatchContractEventParameters<typeof Abis.nonce, 'NonceIncremented', true>,
267
+ 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
268
+ > & {
269
+ /** Callback to invoke when a nonce is incremented. */
270
+ onNonceIncremented: (args: Args, log: Log) => void
271
+ }
272
+ }
273
+
274
+ /**
275
+ * Watches for active key count changed events.
276
+ *
277
+ * @example
278
+ * ```ts
279
+ * import { createClient, http } from 'viem'
280
+ * import { tempo } from 'tempo.ts/chains'
281
+ * import { Actions } from 'tempo.ts/viem'
282
+ *
283
+ * const client = createClient({
284
+ * chain: tempo({ feeToken: '0x20c0000000000000000000000000000000000001' }),
285
+ * transport: http(),
286
+ * })
287
+ *
288
+ * const unwatch = Actions.nonce.watchActiveKeyCountChanged(client, {
289
+ * onActiveKeyCountChanged: (args, log) => {
290
+ * console.log('Active key count changed:', args)
291
+ * },
292
+ * })
293
+ * ```
294
+ *
295
+ * @param client - Client.
296
+ * @param parameters - Parameters.
297
+ * @returns A function to unsubscribe from the event.
298
+ */
299
+ export function watchActiveKeyCountChanged<
300
+ chain extends Chain | undefined,
301
+ account extends Account | undefined,
302
+ >(
303
+ client: Client<Transport, chain, account>,
304
+ parameters: watchActiveKeyCountChanged.Parameters,
305
+ ) {
306
+ const { onActiveKeyCountChanged, ...rest } = parameters
307
+ return watchContractEvent(client, {
308
+ ...rest,
309
+ address: Addresses.nonceManager,
310
+ abi: Abis.nonce,
311
+ eventName: 'ActiveKeyCountChanged',
312
+ onLogs: (logs) => {
313
+ for (const log of logs) onActiveKeyCountChanged(log.args, log)
314
+ },
315
+ strict: true,
316
+ })
317
+ }
318
+
319
+ export declare namespace watchActiveKeyCountChanged {
320
+ export type Args = GetEventArgs<
321
+ typeof Abis.nonce,
322
+ 'ActiveKeyCountChanged',
323
+ { IndexedOnly: false; Required: true }
324
+ >
325
+
326
+ export type Log = viem_Log<
327
+ bigint,
328
+ number,
329
+ false,
330
+ ExtractAbiItem<typeof Abis.nonce, 'ActiveKeyCountChanged'>,
331
+ true
332
+ >
333
+
334
+ export type Parameters = UnionOmit<
335
+ WatchContractEventParameters<
336
+ typeof Abis.nonce,
337
+ 'ActiveKeyCountChanged',
338
+ true
339
+ >,
340
+ 'abi' | 'address' | 'batch' | 'eventName' | 'onLogs' | 'strict'
341
+ > & {
342
+ /** Callback to invoke when the active key count changes. */
343
+ onActiveKeyCountChanged: (args: Args, log: Log) => void
344
+ }
345
+ }
@@ -2,6 +2,7 @@ export const accountImplementation =
2
2
  '0x7702c00000000000000000000000000000000000'
3
3
  export const accountRegistrar = '0x7702ac0000000000000000000000000000000000'
4
4
  export const feeManager = '0xfeec000000000000000000000000000000000000'
5
+ export const nonceManager = '0x4e4F4E4345000000000000000000000000000000'
5
6
  export const pathUsd = '0x20c0000000000000000000000000000000000000'
6
7
  export const stablecoinExchange = '0xdec0000000000000000000000000000000000000'
7
8
  export const tip20Factory = '0x20fc000000000000000000000000000000000000'
@@ -14,7 +14,7 @@ describe('chain.prepareTransactionRequest', () => {
14
14
  chain.prepareTransactionRequest({ feePayer: true } as never),
15
15
  ])
16
16
 
17
- expect((requests[0] as any)?.nonceKey).toBe(0n)
17
+ expect((requests[0] as any)?.nonceKey).toBe(undefined)
18
18
  expect((requests[1] as any)?.nonceKey).toBeGreaterThan(0n)
19
19
  expect((requests[2] as any)?.nonceKey).toBeGreaterThan(0n)
20
20
  })
@@ -25,7 +25,7 @@ describe('chain.prepareTransactionRequest', () => {
25
25
  chain.prepareTransactionRequest({ feePayer: true } as never),
26
26
  ])
27
27
 
28
- expect((requests1[0] as any)?.nonceKey).toBe(0n)
28
+ expect((requests1[0] as any)?.nonceKey).toBe(undefined)
29
29
  expect((requests1[1] as any)?.nonceKey).toBeGreaterThan(0n)
30
30
 
31
31
  // Wait for microtask queue to flush
@@ -37,7 +37,7 @@ describe('chain.prepareTransactionRequest', () => {
37
37
  ])
38
38
 
39
39
  // Counter should have reset
40
- expect((requests2[0] as any)?.nonceKey).toBe(0n)
40
+ expect((requests2[0] as any)?.nonceKey).toBe(undefined)
41
41
  expect((requests2[1] as any)?.nonceKey).toBeGreaterThan(0n)
42
42
  })
43
43
 
@@ -55,13 +55,13 @@ describe('chain.prepareTransactionRequest', () => {
55
55
  ])
56
56
 
57
57
  expect((requests[0] as any)?.nonceKey).toBe(42n)
58
- expect((requests[1] as any)?.nonceKey).toBe(0n)
58
+ expect((requests[1] as any)?.nonceKey).toBe(undefined)
59
59
  expect((requests[2] as any)?.nonceKey).toBe(100n)
60
60
  })
61
61
 
62
62
  test('behavior: default nonceKey when feePayer is not true', async () => {
63
63
  const request = await chain.prepareTransactionRequest({} as never)
64
- expect((request as any)?.nonceKey).toBe(0n)
64
+ expect((request as any)?.nonceKey).toBe(undefined)
65
65
  })
66
66
 
67
67
  test('behavior: nonce with sequential nonceKey', async () => {
@@ -73,7 +73,7 @@ describe('chain.prepareTransactionRequest', () => {
73
73
 
74
74
  // Note: 0n is falsy, so first request has nonce undefined
75
75
  expect((requests[0] as any)?.nonce).toBe(undefined)
76
- expect((requests[0] as any)?.nonceKey).toBe(0n)
76
+ expect((requests[0] as any)?.nonceKey).toBe(undefined)
77
77
 
78
78
  // nonceKey >= 1n is truthy, so nonce is 0
79
79
  expect((requests[1] as any)?.nonce).toBe(0)
@@ -89,12 +89,12 @@ describe('chain.prepareTransactionRequest', () => {
89
89
  nonce: 123,
90
90
  } as never)
91
91
  expect((request as any)?.nonce).toBe(123)
92
- expect((request as any)?.nonceKey).toBe(0n)
92
+ expect((request as any)?.nonceKey).toBe(undefined)
93
93
  })
94
94
 
95
95
  test('behavior: default nonceKey is 0n (falsy)', async () => {
96
96
  const request = await chain.prepareTransactionRequest({} as never)
97
- expect((request as any)?.nonceKey).toBe(0n)
97
+ expect((request as any)?.nonceKey).toBe(undefined)
98
98
  expect((request as any)?.nonce).toBe(undefined)
99
99
  })
100
100
 
@@ -132,7 +132,7 @@ describe('chain.prepareTransactionRequest', () => {
132
132
  to: '0x0000000000000000000000000000000000000000',
133
133
  }),
134
134
  ])
135
- expect(request.nonceKey).toBe(0n)
135
+ expect(request.nonceKey).toBe(undefined)
136
136
  expect(request2.nonceKey).toBeGreaterThan(0n)
137
137
  expect(request3.nonceKey).toBeGreaterThan(0n)
138
138
  })
package/src/viem/Chain.ts CHANGED
@@ -47,12 +47,6 @@ function config<const chain extends Chain>(chain: chain) {
47
47
 
48
48
  return {
49
49
  blockTime: 1_000,
50
- contracts: {
51
- multicall3: {
52
- address: '0xca11bde05977b3631167028862be2a173976ca11',
53
- blockCreated: 0,
54
- },
55
- },
56
50
  formatters: {
57
51
  transaction: defineTransaction({
58
52
  exclude: ['aaAuthorizationList' as never],
@@ -2,6 +2,7 @@ export * as amm from './amm.js'
2
2
  export * as dex from './dex.js'
3
3
  export * as faucet from './faucet.js'
4
4
  export * as fee from './fee.js'
5
+ export * as nonce from './nonce.js'
5
6
  export * as policy from './policy.js'
6
7
  export * as reward from './reward.js'
7
8
  export * as token from './token.js'
@@ -0,0 +1,141 @@
1
+ import { connect } from '@wagmi/core'
2
+ import { afterEach, describe, expect, test } from 'vitest'
3
+ import { rpcUrl } from '../../../test/config.js'
4
+ import { accounts } from '../../../test/viem/config.js'
5
+ import { config, queryClient } from '../../../test/wagmi/config.js'
6
+ import * as nonce from './nonce.js'
7
+ import * as token from './token.js'
8
+
9
+ const { getNonceKeyCount, getNonce } = nonce
10
+
11
+ const account = accounts[0]
12
+ const account2 = accounts[1]
13
+
14
+ afterEach(async () => {
15
+ await fetch(`${rpcUrl}/restart`)
16
+ })
17
+
18
+ describe('getNonce', () => {
19
+ test('default', async () => {
20
+ const result = await getNonce(config, {
21
+ account: account.address,
22
+ nonceKey: 1n,
23
+ })
24
+ expect(result).toBe(1n)
25
+ })
26
+
27
+ describe('queryOptions', () => {
28
+ test('default', async () => {
29
+ const options = getNonce.queryOptions(config, {
30
+ account: account.address,
31
+ nonceKey: 1n,
32
+ })
33
+ const result = await queryClient.fetchQuery(options)
34
+ expect(result).toBe(1n)
35
+ })
36
+ })
37
+ })
38
+
39
+ describe('getNonceKeyCount', () => {
40
+ test('default', async () => {
41
+ const result = await getNonceKeyCount(config, {
42
+ account: account.address,
43
+ })
44
+ expect(result).toBe(0n)
45
+ })
46
+
47
+ describe('queryOptions', () => {
48
+ test('default', async () => {
49
+ const options = getNonceKeyCount.queryOptions(config, {
50
+ account: account.address,
51
+ })
52
+ expect(await queryClient.fetchQuery(options)).toBe(0n)
53
+ })
54
+ })
55
+ })
56
+
57
+ describe('watchNonceIncremented', () => {
58
+ test('default', async () => {
59
+ await connect(config, {
60
+ connector: config.connectors[0]!,
61
+ })
62
+
63
+ const events: any[] = []
64
+ const unwatch = nonce.watchNonceIncremented(config, {
65
+ onNonceIncremented: (args) => {
66
+ events.push(args)
67
+ },
68
+ args: {
69
+ account: account.address,
70
+ nonceKey: 5n,
71
+ },
72
+ })
73
+
74
+ // Have to manually set nonce because eth_FillTransaction does not support nonce keys
75
+ await token.transferSync(config, {
76
+ to: account2.address,
77
+ amount: 1n,
78
+ token: 1n,
79
+ nonceKey: 5n,
80
+ nonce: 0,
81
+ })
82
+
83
+ await token.transferSync(config, {
84
+ to: account2.address,
85
+ amount: 1n,
86
+ token: 1n,
87
+ nonceKey: 5n,
88
+ nonce: 1,
89
+ })
90
+
91
+ await new Promise((resolve) => setTimeout(resolve, 1000))
92
+
93
+ expect(events).toHaveLength(2)
94
+ expect(events[0]?.account).toBe(account.address)
95
+ expect(events[0]?.nonceKey).toBe(5n)
96
+ expect(events[0]?.newNonce).toBe(1n)
97
+ expect(events[1]?.newNonce).toBe(2n)
98
+ unwatch()
99
+ })
100
+ })
101
+
102
+ describe('watchActiveKeyCountChanged', () => {
103
+ test('default', async () => {
104
+ await connect(config, {
105
+ connector: config.connectors[0]!,
106
+ })
107
+
108
+ const events: any[] = []
109
+ const unwatch = nonce.watchActiveKeyCountChanged(config, {
110
+ onActiveKeyCountChanged: (args) => {
111
+ events.push(args)
112
+ },
113
+ })
114
+
115
+ // First use of nonceKey 10 should increment active key count
116
+ await token.transferSync(config, {
117
+ to: account2.address,
118
+ amount: 1n,
119
+ token: 1n,
120
+ nonceKey: 10n,
121
+ nonce: 0,
122
+ })
123
+
124
+ // First use of nonceKey 11 should increment again
125
+ await token.transferSync(config, {
126
+ to: account2.address,
127
+ amount: 1n,
128
+ token: 1n,
129
+ nonceKey: 11n,
130
+ nonce: 0,
131
+ })
132
+
133
+ await new Promise((resolve) => setTimeout(resolve, 1000))
134
+
135
+ expect(events).toHaveLength(2)
136
+ expect(events[0]?.account).toBe(account.address)
137
+ expect(events[0]?.newCount).toBe(1n)
138
+ expect(events[1]?.newCount).toBe(2n)
139
+ unwatch()
140
+ })
141
+ })