tempo.ts 0.12.0 → 0.13.0
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/CHANGELOG.md +26 -0
- package/README.md +28 -34
- package/package.json +2 -28
- package/dist/wagmi/Actions/amm.d.ts +0 -418
- package/dist/wagmi/Actions/amm.d.ts.map +0 -1
- package/dist/wagmi/Actions/amm.js +0 -462
- package/dist/wagmi/Actions/amm.js.map +0 -1
- package/dist/wagmi/Actions/dex.d.ts +0 -864
- package/dist/wagmi/Actions/dex.d.ts.map +0 -1
- package/dist/wagmi/Actions/dex.js +0 -968
- package/dist/wagmi/Actions/dex.js.map +0 -1
- package/dist/wagmi/Actions/faucet.d.ts +0 -66
- package/dist/wagmi/Actions/faucet.d.ts.map +0 -1
- package/dist/wagmi/Actions/faucet.js +0 -64
- package/dist/wagmi/Actions/faucet.js.map +0 -1
- package/dist/wagmi/Actions/fee.d.ts +0 -111
- package/dist/wagmi/Actions/fee.d.ts.map +0 -1
- package/dist/wagmi/Actions/fee.js +0 -126
- package/dist/wagmi/Actions/fee.js.map +0 -1
- package/dist/wagmi/Actions/index.d.ts +0 -9
- package/dist/wagmi/Actions/index.d.ts.map +0 -1
- package/dist/wagmi/Actions/index.js +0 -9
- package/dist/wagmi/Actions/index.js.map +0 -1
- package/dist/wagmi/Actions/nonce.d.ts +0 -77
- package/dist/wagmi/Actions/nonce.d.ts.map +0 -1
- package/dist/wagmi/Actions/nonce.js +0 -87
- package/dist/wagmi/Actions/nonce.js.map +0 -1
- package/dist/wagmi/Actions/policy.d.ts +0 -480
- package/dist/wagmi/Actions/policy.d.ts.map +0 -1
- package/dist/wagmi/Actions/policy.js +0 -530
- package/dist/wagmi/Actions/policy.js.map +0 -1
- package/dist/wagmi/Actions/reward.d.ts +0 -346
- package/dist/wagmi/Actions/reward.d.ts.map +0 -1
- package/dist/wagmi/Actions/reward.js +0 -382
- package/dist/wagmi/Actions/reward.js.map +0 -1
- package/dist/wagmi/Actions/token.d.ts +0 -1546
- package/dist/wagmi/Actions/token.d.ts.map +0 -1
- package/dist/wagmi/Actions/token.js +0 -1712
- package/dist/wagmi/Actions/token.js.map +0 -1
- package/dist/wagmi/Connector.d.ts +0 -91
- package/dist/wagmi/Connector.d.ts.map +0 -1
- package/dist/wagmi/Connector.js +0 -473
- package/dist/wagmi/Connector.js.map +0 -1
- package/dist/wagmi/Hooks/amm.d.ts +0 -411
- package/dist/wagmi/Hooks/amm.d.ts.map +0 -1
- package/dist/wagmi/Hooks/amm.js +0 -494
- package/dist/wagmi/Hooks/amm.js.map +0 -1
- package/dist/wagmi/Hooks/dex.d.ts +0 -773
- package/dist/wagmi/Hooks/dex.d.ts.map +0 -1
- package/dist/wagmi/Hooks/dex.js +0 -921
- package/dist/wagmi/Hooks/dex.js.map +0 -1
- package/dist/wagmi/Hooks/faucet.d.ts +0 -71
- package/dist/wagmi/Hooks/faucet.d.ts.map +0 -1
- package/dist/wagmi/Hooks/faucet.js +0 -76
- package/dist/wagmi/Hooks/faucet.js.map +0 -1
- package/dist/wagmi/Hooks/fee.d.ts +0 -97
- package/dist/wagmi/Hooks/fee.d.ts.map +0 -1
- package/dist/wagmi/Hooks/fee.js +0 -109
- package/dist/wagmi/Hooks/fee.js.map +0 -1
- package/dist/wagmi/Hooks/index.d.ts +0 -9
- package/dist/wagmi/Hooks/index.d.ts.map +0 -1
- package/dist/wagmi/Hooks/index.js +0 -9
- package/dist/wagmi/Hooks/index.js.map +0 -1
- package/dist/wagmi/Hooks/nonce.d.ts +0 -59
- package/dist/wagmi/Hooks/nonce.d.ts.map +0 -1
- package/dist/wagmi/Hooks/nonce.js +0 -75
- package/dist/wagmi/Hooks/nonce.js.map +0 -1
- package/dist/wagmi/Hooks/policy.d.ts +0 -423
- package/dist/wagmi/Hooks/policy.d.ts.map +0 -1
- package/dist/wagmi/Hooks/policy.js +0 -510
- package/dist/wagmi/Hooks/policy.js.map +0 -1
- package/dist/wagmi/Hooks/reward.d.ts +0 -305
- package/dist/wagmi/Hooks/reward.d.ts.map +0 -1
- package/dist/wagmi/Hooks/reward.js +0 -368
- package/dist/wagmi/Hooks/reward.js.map +0 -1
- package/dist/wagmi/Hooks/token.d.ts +0 -1388
- package/dist/wagmi/Hooks/token.d.ts.map +0 -1
- package/dist/wagmi/Hooks/token.js +0 -1657
- package/dist/wagmi/Hooks/token.js.map +0 -1
- package/dist/wagmi/KeyManager.d.ts +0 -60
- package/dist/wagmi/KeyManager.d.ts.map +0 -1
- package/dist/wagmi/KeyManager.js +0 -106
- package/dist/wagmi/KeyManager.js.map +0 -1
- package/dist/wagmi/index.d.ts +0 -5
- package/dist/wagmi/index.d.ts.map +0 -1
- package/dist/wagmi/index.js +0 -5
- package/dist/wagmi/index.js.map +0 -1
- package/src/wagmi/Actions/amm.test.ts +0 -208
- package/src/wagmi/Actions/amm.ts +0 -690
- package/src/wagmi/Actions/dex.test.ts +0 -1482
- package/src/wagmi/Actions/dex.ts +0 -1540
- package/src/wagmi/Actions/faucet.ts +0 -89
- package/src/wagmi/Actions/fee.test.ts +0 -63
- package/src/wagmi/Actions/fee.ts +0 -211
- package/src/wagmi/Actions/index.ts +0 -8
- package/src/wagmi/Actions/nonce.test.ts +0 -82
- package/src/wagmi/Actions/nonce.ts +0 -139
- package/src/wagmi/Actions/policy.test.ts +0 -461
- package/src/wagmi/Actions/policy.ts +0 -817
- package/src/wagmi/Actions/reward.test.ts +0 -216
- package/src/wagmi/Actions/reward.ts +0 -613
- package/src/wagmi/Actions/token.test.ts +0 -1309
- package/src/wagmi/Actions/token.ts +0 -2644
- package/src/wagmi/Connector.test.ts +0 -56
- package/src/wagmi/Connector.ts +0 -670
- package/src/wagmi/Hooks/amm.test.ts +0 -564
- package/src/wagmi/Hooks/amm.ts +0 -796
- package/src/wagmi/Hooks/dex.test.ts +0 -992
- package/src/wagmi/Hooks/dex.ts +0 -1598
- package/src/wagmi/Hooks/faucet.ts +0 -144
- package/src/wagmi/Hooks/fee.test.ts +0 -166
- package/src/wagmi/Hooks/fee.ts +0 -206
- package/src/wagmi/Hooks/index.ts +0 -8
- package/src/wagmi/Hooks/nonce.test.ts +0 -142
- package/src/wagmi/Hooks/nonce.ts +0 -117
- package/src/wagmi/Hooks/policy.test.ts +0 -665
- package/src/wagmi/Hooks/policy.ts +0 -873
- package/src/wagmi/Hooks/reward.test.ts +0 -249
- package/src/wagmi/Hooks/reward.ts +0 -645
- package/src/wagmi/Hooks/token.test.ts +0 -1183
- package/src/wagmi/Hooks/token.ts +0 -2906
- package/src/wagmi/KeyManager.ts +0 -172
- package/src/wagmi/index.ts +0 -7
|
@@ -1,1183 +0,0 @@
|
|
|
1
|
-
import { type Address, parseUnits } from 'viem'
|
|
2
|
-
import { describe, expect, test, vi } from 'vitest'
|
|
3
|
-
import { useConnect } from 'wagmi'
|
|
4
|
-
import { addresses } from '../../../test/config.js'
|
|
5
|
-
import { accounts } from '../../../test/viem/config.js'
|
|
6
|
-
import { config, renderHook } from '../../../test/wagmi/config.js'
|
|
7
|
-
import * as hooks from './token.js'
|
|
8
|
-
|
|
9
|
-
const account = accounts[0]
|
|
10
|
-
const account2 = accounts[1]
|
|
11
|
-
|
|
12
|
-
describe('useGetAllowance', () => {
|
|
13
|
-
test('default', async () => {
|
|
14
|
-
const { result } = await renderHook(() =>
|
|
15
|
-
hooks.useGetAllowance({
|
|
16
|
-
account: account.address,
|
|
17
|
-
spender: account2.address,
|
|
18
|
-
token: addresses.alphaUsd,
|
|
19
|
-
}),
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy(), {
|
|
23
|
-
timeout: 5000,
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
expect(result.current.data).toBeDefined()
|
|
27
|
-
expect(typeof result.current.data).toBe('bigint')
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
test('reactivity: account parameter', async () => {
|
|
31
|
-
let accountAddress: Address | undefined
|
|
32
|
-
let spenderAddress: Address | undefined
|
|
33
|
-
|
|
34
|
-
const { result, rerender } = await renderHook(() =>
|
|
35
|
-
hooks.useGetAllowance({
|
|
36
|
-
account: accountAddress,
|
|
37
|
-
spender: spenderAddress,
|
|
38
|
-
token: addresses.alphaUsd,
|
|
39
|
-
}),
|
|
40
|
-
)
|
|
41
|
-
|
|
42
|
-
await vi.waitFor(() => result.current.fetchStatus === 'fetching')
|
|
43
|
-
|
|
44
|
-
// Should be disabled when account or spender is undefined
|
|
45
|
-
expect(result.current.data).toBeUndefined()
|
|
46
|
-
expect(result.current.isPending).toBe(true)
|
|
47
|
-
expect(result.current.isEnabled).toBe(false)
|
|
48
|
-
|
|
49
|
-
// Set account but not spender
|
|
50
|
-
accountAddress = account.address
|
|
51
|
-
rerender()
|
|
52
|
-
|
|
53
|
-
await vi.waitFor(() => result.current.fetchStatus === 'fetching')
|
|
54
|
-
|
|
55
|
-
// Still disabled when spender is undefined
|
|
56
|
-
expect(result.current.isEnabled).toBe(false)
|
|
57
|
-
|
|
58
|
-
// Set spender
|
|
59
|
-
spenderAddress = account2.address
|
|
60
|
-
rerender()
|
|
61
|
-
|
|
62
|
-
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
63
|
-
|
|
64
|
-
// Should now be enabled and have data
|
|
65
|
-
expect(result.current.isEnabled).toBe(true)
|
|
66
|
-
expect(result.current.data).toBeDefined()
|
|
67
|
-
expect(typeof result.current.data).toBe('bigint')
|
|
68
|
-
})
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
describe('useGetBalance', () => {
|
|
72
|
-
test('default', async () => {
|
|
73
|
-
const { result } = await renderHook(() =>
|
|
74
|
-
hooks.useGetBalance({
|
|
75
|
-
account: account.address,
|
|
76
|
-
token: addresses.alphaUsd,
|
|
77
|
-
}),
|
|
78
|
-
)
|
|
79
|
-
|
|
80
|
-
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
81
|
-
|
|
82
|
-
expect(result.current.data).toBeDefined()
|
|
83
|
-
expect(typeof result.current.data).toBe('bigint')
|
|
84
|
-
expect(result.current.data).toBeGreaterThan(0n)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
test('reactivity: account parameter', async () => {
|
|
88
|
-
let accountAddress: Address | undefined
|
|
89
|
-
|
|
90
|
-
const { result, rerender } = await renderHook(() =>
|
|
91
|
-
hooks.useGetBalance({
|
|
92
|
-
account: accountAddress,
|
|
93
|
-
token: addresses.alphaUsd,
|
|
94
|
-
}),
|
|
95
|
-
)
|
|
96
|
-
|
|
97
|
-
await vi.waitFor(() => result.current.fetchStatus === 'fetching')
|
|
98
|
-
|
|
99
|
-
// Should be disabled when account is undefined
|
|
100
|
-
expect(result.current.data).toBeUndefined()
|
|
101
|
-
expect(result.current.isPending).toBe(true)
|
|
102
|
-
expect(result.current.isEnabled).toBe(false)
|
|
103
|
-
|
|
104
|
-
// Set account
|
|
105
|
-
accountAddress = account.address
|
|
106
|
-
rerender()
|
|
107
|
-
|
|
108
|
-
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
109
|
-
|
|
110
|
-
// Should now be enabled and have data
|
|
111
|
-
expect(result.current.isEnabled).toBe(true)
|
|
112
|
-
expect(result.current.data).toBeDefined()
|
|
113
|
-
expect(typeof result.current.data).toBe('bigint')
|
|
114
|
-
expect(result.current.data).toBeGreaterThan(0n)
|
|
115
|
-
})
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
describe('useGetMetadata', () => {
|
|
119
|
-
test('default', async () => {
|
|
120
|
-
const { result } = await renderHook(() =>
|
|
121
|
-
hooks.useGetMetadata({
|
|
122
|
-
token: addresses.alphaUsd,
|
|
123
|
-
}),
|
|
124
|
-
)
|
|
125
|
-
|
|
126
|
-
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
127
|
-
|
|
128
|
-
expect(result.current.data).toBeDefined()
|
|
129
|
-
expect(result.current.data?.name).toBeDefined()
|
|
130
|
-
expect(result.current.data?.symbol).toBeDefined()
|
|
131
|
-
expect(result.current.data?.decimals).toBeDefined()
|
|
132
|
-
})
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
describe('useGetRoleAdmin', () => {
|
|
136
|
-
test('default', async () => {
|
|
137
|
-
const { result: connectResult } = await renderHook(() => ({
|
|
138
|
-
connect: useConnect(),
|
|
139
|
-
createSync: hooks.useCreateSync(),
|
|
140
|
-
}))
|
|
141
|
-
|
|
142
|
-
await connectResult.current.connect.connectAsync({
|
|
143
|
-
connector: config.connectors[0]!,
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
// Create a token where we're the admin
|
|
147
|
-
const createData = await connectResult.current.createSync.mutateAsync({
|
|
148
|
-
currency: 'USD',
|
|
149
|
-
name: 'GetRoleAdmin Hook Test',
|
|
150
|
-
symbol: 'GRAHTEST',
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
const { result } = await renderHook(() =>
|
|
154
|
-
hooks.useGetRoleAdmin({
|
|
155
|
-
token: createData.token,
|
|
156
|
-
role: 'issuer',
|
|
157
|
-
}),
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
161
|
-
|
|
162
|
-
expect(result.current.data).toBeDefined()
|
|
163
|
-
expect(typeof result.current.data).toBe('string')
|
|
164
|
-
})
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
describe('useHasRole', () => {
|
|
168
|
-
test('default', async () => {
|
|
169
|
-
const { result: connectResult } = await renderHook(() => ({
|
|
170
|
-
connect: useConnect(),
|
|
171
|
-
createSync: hooks.useCreateSync(),
|
|
172
|
-
}))
|
|
173
|
-
|
|
174
|
-
await connectResult.current.connect.connectAsync({
|
|
175
|
-
connector: config.connectors[0]!,
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
// Create a token where we're the admin
|
|
179
|
-
const createData = await connectResult.current.createSync.mutateAsync({
|
|
180
|
-
currency: 'USD',
|
|
181
|
-
name: 'HasRole Hook Test',
|
|
182
|
-
symbol: 'HRHTEST',
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
const { result } = await renderHook(() =>
|
|
186
|
-
hooks.useHasRole({
|
|
187
|
-
account: account.address,
|
|
188
|
-
token: createData.token,
|
|
189
|
-
role: 'defaultAdmin',
|
|
190
|
-
}),
|
|
191
|
-
)
|
|
192
|
-
|
|
193
|
-
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
194
|
-
|
|
195
|
-
expect(result.current.data).toBe(true)
|
|
196
|
-
})
|
|
197
|
-
|
|
198
|
-
test('reactivity: account parameter', async () => {
|
|
199
|
-
const { result: connectResult } = await renderHook(() => ({
|
|
200
|
-
connect: useConnect(),
|
|
201
|
-
createSync: hooks.useCreateSync(),
|
|
202
|
-
}))
|
|
203
|
-
|
|
204
|
-
await connectResult.current.connect.connectAsync({
|
|
205
|
-
connector: config.connectors[0]!,
|
|
206
|
-
})
|
|
207
|
-
|
|
208
|
-
// Create a token where we're the admin
|
|
209
|
-
const createData = await connectResult.current.createSync.mutateAsync({
|
|
210
|
-
currency: 'USD',
|
|
211
|
-
name: 'HasRole Hook Reactivity Test',
|
|
212
|
-
symbol: 'HRHRTEST',
|
|
213
|
-
})
|
|
214
|
-
|
|
215
|
-
let accountAddress: Address | undefined
|
|
216
|
-
|
|
217
|
-
const { result, rerender } = await renderHook(() =>
|
|
218
|
-
hooks.useHasRole({
|
|
219
|
-
account: accountAddress,
|
|
220
|
-
token: createData.token,
|
|
221
|
-
role: 'defaultAdmin',
|
|
222
|
-
}),
|
|
223
|
-
)
|
|
224
|
-
|
|
225
|
-
await vi.waitFor(() => result.current.fetchStatus === 'fetching')
|
|
226
|
-
|
|
227
|
-
// Should be disabled when account is undefined
|
|
228
|
-
expect(result.current.data).toBeUndefined()
|
|
229
|
-
expect(result.current.isPending).toBe(true)
|
|
230
|
-
expect(result.current.isEnabled).toBe(false)
|
|
231
|
-
|
|
232
|
-
// Set account
|
|
233
|
-
accountAddress = account.address
|
|
234
|
-
rerender()
|
|
235
|
-
|
|
236
|
-
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
237
|
-
|
|
238
|
-
// Should now be enabled and have data
|
|
239
|
-
expect(result.current.isEnabled).toBe(true)
|
|
240
|
-
expect(result.current.data).toBe(true)
|
|
241
|
-
})
|
|
242
|
-
})
|
|
243
|
-
|
|
244
|
-
describe('useApproveSync', () => {
|
|
245
|
-
test('default', async () => {
|
|
246
|
-
const { result } = await renderHook(() => ({
|
|
247
|
-
connect: useConnect(),
|
|
248
|
-
approve: hooks.useApproveSync(),
|
|
249
|
-
}))
|
|
250
|
-
|
|
251
|
-
await result.current.connect.connectAsync({
|
|
252
|
-
connector: config.connectors[0]!,
|
|
253
|
-
})
|
|
254
|
-
|
|
255
|
-
const data = await result.current.approve.mutateAsync({
|
|
256
|
-
spender: account2.address,
|
|
257
|
-
amount: parseUnits('100', 6),
|
|
258
|
-
token: addresses.alphaUsd,
|
|
259
|
-
})
|
|
260
|
-
expect(data).toBeDefined()
|
|
261
|
-
expect(data.receipt).toBeDefined()
|
|
262
|
-
|
|
263
|
-
await vi.waitFor(() =>
|
|
264
|
-
expect(result.current.approve.isSuccess).toBeTruthy(),
|
|
265
|
-
)
|
|
266
|
-
})
|
|
267
|
-
})
|
|
268
|
-
|
|
269
|
-
describe('useBurnSync', () => {
|
|
270
|
-
test('default', async () => {
|
|
271
|
-
const { result } = await renderHook(() => ({
|
|
272
|
-
connect: useConnect(),
|
|
273
|
-
createSync: hooks.useCreateSync(),
|
|
274
|
-
grantRolesSync: hooks.useGrantRolesSync(),
|
|
275
|
-
mintSync: hooks.useMintSync(),
|
|
276
|
-
burn: hooks.useBurnSync(),
|
|
277
|
-
}))
|
|
278
|
-
|
|
279
|
-
await result.current.connect.connectAsync({
|
|
280
|
-
connector: config.connectors[0]!,
|
|
281
|
-
})
|
|
282
|
-
|
|
283
|
-
// Create a new token
|
|
284
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
285
|
-
currency: 'USD',
|
|
286
|
-
name: 'Burnable Hook Token Sync',
|
|
287
|
-
symbol: 'BURNHOOKSYNC',
|
|
288
|
-
})
|
|
289
|
-
|
|
290
|
-
// Grant issuer role
|
|
291
|
-
await result.current.grantRolesSync.mutateAsync({
|
|
292
|
-
token: tokenAddr,
|
|
293
|
-
roles: ['issuer'],
|
|
294
|
-
to: account.address,
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
// Mint some tokens
|
|
298
|
-
await result.current.mintSync.mutateAsync({
|
|
299
|
-
token: tokenAddr,
|
|
300
|
-
to: account.address,
|
|
301
|
-
amount: parseUnits('1000', 6),
|
|
302
|
-
})
|
|
303
|
-
|
|
304
|
-
const data = await result.current.burn.mutateAsync({
|
|
305
|
-
token: tokenAddr,
|
|
306
|
-
amount: parseUnits('1', 6),
|
|
307
|
-
})
|
|
308
|
-
expect(data).toBeDefined()
|
|
309
|
-
expect(data.receipt).toBeDefined()
|
|
310
|
-
|
|
311
|
-
await vi.waitFor(() => expect(result.current.burn.isSuccess).toBeTruthy())
|
|
312
|
-
})
|
|
313
|
-
})
|
|
314
|
-
|
|
315
|
-
describe('useChangeTransferPolicySync', () => {
|
|
316
|
-
test('default', async () => {
|
|
317
|
-
const { result } = await renderHook(() => ({
|
|
318
|
-
connect: useConnect(),
|
|
319
|
-
createSync: hooks.useCreateSync(),
|
|
320
|
-
changeTransferPolicy: hooks.useChangeTransferPolicySync(),
|
|
321
|
-
}))
|
|
322
|
-
|
|
323
|
-
await result.current.connect.connectAsync({
|
|
324
|
-
connector: config.connectors[0]!,
|
|
325
|
-
})
|
|
326
|
-
|
|
327
|
-
// Create a new token
|
|
328
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
329
|
-
currency: 'USD',
|
|
330
|
-
name: 'Policy Hook Token Sync',
|
|
331
|
-
symbol: 'POLICYHOOKSYNC',
|
|
332
|
-
})
|
|
333
|
-
|
|
334
|
-
const data = await result.current.changeTransferPolicy.mutateAsync({
|
|
335
|
-
token: tokenAddr,
|
|
336
|
-
policyId: 0n,
|
|
337
|
-
})
|
|
338
|
-
expect(data).toBeDefined()
|
|
339
|
-
expect(data.receipt).toBeDefined()
|
|
340
|
-
|
|
341
|
-
await vi.waitFor(() =>
|
|
342
|
-
expect(result.current.changeTransferPolicy.isSuccess).toBeTruthy(),
|
|
343
|
-
)
|
|
344
|
-
})
|
|
345
|
-
})
|
|
346
|
-
|
|
347
|
-
describe('useCreateSync', () => {
|
|
348
|
-
test('default', async () => {
|
|
349
|
-
const { result } = await renderHook(() => ({
|
|
350
|
-
connect: useConnect(),
|
|
351
|
-
create: hooks.useCreateSync(),
|
|
352
|
-
}))
|
|
353
|
-
|
|
354
|
-
await result.current.connect.connectAsync({
|
|
355
|
-
connector: config.connectors[0]!,
|
|
356
|
-
})
|
|
357
|
-
|
|
358
|
-
const data = await result.current.create.mutateAsync({
|
|
359
|
-
name: 'Hook Test Token Sync',
|
|
360
|
-
symbol: 'HOOKTESTSYNC',
|
|
361
|
-
currency: 'USD',
|
|
362
|
-
})
|
|
363
|
-
expect(data).toBeDefined()
|
|
364
|
-
expect(data.receipt).toBeDefined()
|
|
365
|
-
expect(data.token).toBeDefined()
|
|
366
|
-
expect(data.name).toBe('Hook Test Token Sync')
|
|
367
|
-
|
|
368
|
-
await vi.waitFor(() => expect(result.current.create.isSuccess).toBeTruthy())
|
|
369
|
-
})
|
|
370
|
-
})
|
|
371
|
-
|
|
372
|
-
describe('useUpdateQuoteTokenSync', () => {
|
|
373
|
-
test('default', async () => {
|
|
374
|
-
const { result } = await renderHook(() => ({
|
|
375
|
-
connect: useConnect(),
|
|
376
|
-
createSync: hooks.useCreateSync(),
|
|
377
|
-
prepareUpdateQuoteTokenSync: hooks.usePrepareUpdateQuoteTokenSync(),
|
|
378
|
-
updateQuoteToken: hooks.useUpdateQuoteTokenSync(),
|
|
379
|
-
}))
|
|
380
|
-
|
|
381
|
-
await result.current.connect.connectAsync({
|
|
382
|
-
connector: config.connectors[0]!,
|
|
383
|
-
})
|
|
384
|
-
|
|
385
|
-
// Create quote token
|
|
386
|
-
const { token: quoteToken } = await result.current.createSync.mutateAsync({
|
|
387
|
-
currency: 'USD',
|
|
388
|
-
name: 'Finalize Quote Hook Sync',
|
|
389
|
-
symbol: 'FQHOOKSYNC',
|
|
390
|
-
})
|
|
391
|
-
|
|
392
|
-
// Create main token
|
|
393
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
394
|
-
currency: 'USD',
|
|
395
|
-
name: 'Finalize Main Hook Sync',
|
|
396
|
-
symbol: 'FMHOOKSYNC',
|
|
397
|
-
})
|
|
398
|
-
|
|
399
|
-
// Prepare quote token update first
|
|
400
|
-
await result.current.prepareUpdateQuoteTokenSync.mutateAsync({
|
|
401
|
-
token: tokenAddr,
|
|
402
|
-
quoteToken,
|
|
403
|
-
})
|
|
404
|
-
|
|
405
|
-
const data = await result.current.updateQuoteToken.mutateAsync({
|
|
406
|
-
token: tokenAddr,
|
|
407
|
-
})
|
|
408
|
-
expect(data).toBeDefined()
|
|
409
|
-
expect(data.receipt).toBeDefined()
|
|
410
|
-
|
|
411
|
-
await vi.waitFor(() =>
|
|
412
|
-
expect(result.current.updateQuoteToken.isSuccess).toBeTruthy(),
|
|
413
|
-
)
|
|
414
|
-
})
|
|
415
|
-
})
|
|
416
|
-
|
|
417
|
-
describe('useGrantRoles', () => {
|
|
418
|
-
test('default', async () => {
|
|
419
|
-
const { result } = await renderHook(() => ({
|
|
420
|
-
connect: useConnect(),
|
|
421
|
-
createSync: hooks.useCreateSync(),
|
|
422
|
-
grantRoles: hooks.useGrantRoles(),
|
|
423
|
-
}))
|
|
424
|
-
|
|
425
|
-
await result.current.connect.connectAsync({
|
|
426
|
-
connector: config.connectors[0]!,
|
|
427
|
-
})
|
|
428
|
-
|
|
429
|
-
// Create a new token
|
|
430
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
431
|
-
currency: 'USD',
|
|
432
|
-
name: 'Grant Hook Token',
|
|
433
|
-
symbol: 'GRANTHOOK',
|
|
434
|
-
})
|
|
435
|
-
|
|
436
|
-
const hash = await result.current.grantRoles.mutateAsync({
|
|
437
|
-
token: tokenAddr,
|
|
438
|
-
roles: ['issuer'],
|
|
439
|
-
to: account2.address,
|
|
440
|
-
})
|
|
441
|
-
expect(hash).toBeDefined()
|
|
442
|
-
|
|
443
|
-
await vi.waitFor(() =>
|
|
444
|
-
expect(result.current.grantRoles.isSuccess).toBeTruthy(),
|
|
445
|
-
)
|
|
446
|
-
})
|
|
447
|
-
})
|
|
448
|
-
|
|
449
|
-
describe('useGrantRolesSync', () => {
|
|
450
|
-
test('default', async () => {
|
|
451
|
-
const { result } = await renderHook(() => ({
|
|
452
|
-
connect: useConnect(),
|
|
453
|
-
createSync: hooks.useCreateSync(),
|
|
454
|
-
grantRoles: hooks.useGrantRolesSync(),
|
|
455
|
-
}))
|
|
456
|
-
|
|
457
|
-
await result.current.connect.connectAsync({
|
|
458
|
-
connector: config.connectors[0]!,
|
|
459
|
-
})
|
|
460
|
-
|
|
461
|
-
// Create a new token
|
|
462
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
463
|
-
currency: 'USD',
|
|
464
|
-
name: 'Grant Hook Token Sync',
|
|
465
|
-
symbol: 'GRANTHOOKSYNC',
|
|
466
|
-
})
|
|
467
|
-
|
|
468
|
-
const data = await result.current.grantRoles.mutateAsync({
|
|
469
|
-
token: tokenAddr,
|
|
470
|
-
roles: ['issuer'],
|
|
471
|
-
to: account2.address,
|
|
472
|
-
})
|
|
473
|
-
expect(data).toBeDefined()
|
|
474
|
-
expect(data.receipt).toBeDefined()
|
|
475
|
-
expect(data.value).toBeDefined()
|
|
476
|
-
|
|
477
|
-
await vi.waitFor(() =>
|
|
478
|
-
expect(result.current.grantRoles.isSuccess).toBeTruthy(),
|
|
479
|
-
)
|
|
480
|
-
})
|
|
481
|
-
})
|
|
482
|
-
|
|
483
|
-
describe('useMintSync', () => {
|
|
484
|
-
test('default', async () => {
|
|
485
|
-
const { result } = await renderHook(() => ({
|
|
486
|
-
connect: useConnect(),
|
|
487
|
-
createSync: hooks.useCreateSync(),
|
|
488
|
-
grantRolesSync: hooks.useGrantRolesSync(),
|
|
489
|
-
mint: hooks.useMintSync(),
|
|
490
|
-
}))
|
|
491
|
-
|
|
492
|
-
await result.current.connect.connectAsync({
|
|
493
|
-
connector: config.connectors[0]!,
|
|
494
|
-
})
|
|
495
|
-
|
|
496
|
-
// Create a new token
|
|
497
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
498
|
-
currency: 'USD',
|
|
499
|
-
name: 'Mint Hook Token Sync',
|
|
500
|
-
symbol: 'MINTHOOKSYNC',
|
|
501
|
-
})
|
|
502
|
-
|
|
503
|
-
// Grant issuer role
|
|
504
|
-
await result.current.grantRolesSync.mutateAsync({
|
|
505
|
-
token: tokenAddr,
|
|
506
|
-
roles: ['issuer'],
|
|
507
|
-
to: account.address,
|
|
508
|
-
})
|
|
509
|
-
|
|
510
|
-
const data = await result.current.mint.mutateAsync({
|
|
511
|
-
token: tokenAddr,
|
|
512
|
-
to: account.address,
|
|
513
|
-
amount: parseUnits('100', 6),
|
|
514
|
-
})
|
|
515
|
-
expect(data).toBeDefined()
|
|
516
|
-
expect(data.receipt).toBeDefined()
|
|
517
|
-
|
|
518
|
-
await vi.waitFor(() => expect(result.current.mint.isSuccess).toBeTruthy())
|
|
519
|
-
})
|
|
520
|
-
})
|
|
521
|
-
|
|
522
|
-
describe('usePauseSync', () => {
|
|
523
|
-
test('default', async () => {
|
|
524
|
-
const { result } = await renderHook(() => ({
|
|
525
|
-
connect: useConnect(),
|
|
526
|
-
createSync: hooks.useCreateSync(),
|
|
527
|
-
grantRolesSync: hooks.useGrantRolesSync(),
|
|
528
|
-
pause: hooks.usePauseSync(),
|
|
529
|
-
}))
|
|
530
|
-
|
|
531
|
-
await result.current.connect.connectAsync({
|
|
532
|
-
connector: config.connectors[0]!,
|
|
533
|
-
})
|
|
534
|
-
|
|
535
|
-
// Create a new token
|
|
536
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
537
|
-
currency: 'USD',
|
|
538
|
-
name: 'Pause Hook Token Sync',
|
|
539
|
-
symbol: 'PAUSEHOOKSYNC',
|
|
540
|
-
})
|
|
541
|
-
|
|
542
|
-
// Grant pause role
|
|
543
|
-
await result.current.grantRolesSync.mutateAsync({
|
|
544
|
-
token: tokenAddr,
|
|
545
|
-
roles: ['pause'],
|
|
546
|
-
to: account.address,
|
|
547
|
-
})
|
|
548
|
-
|
|
549
|
-
const data = await result.current.pause.mutateAsync({
|
|
550
|
-
token: tokenAddr,
|
|
551
|
-
})
|
|
552
|
-
expect(data).toBeDefined()
|
|
553
|
-
expect(data.receipt).toBeDefined()
|
|
554
|
-
|
|
555
|
-
await vi.waitFor(() => expect(result.current.pause.isSuccess).toBeTruthy())
|
|
556
|
-
})
|
|
557
|
-
})
|
|
558
|
-
|
|
559
|
-
describe('useRenounceRolesSync', () => {
|
|
560
|
-
test('default', async () => {
|
|
561
|
-
const { result } = await renderHook(() => ({
|
|
562
|
-
connect: useConnect(),
|
|
563
|
-
createSync: hooks.useCreateSync(),
|
|
564
|
-
grantRolesSync: hooks.useGrantRolesSync(),
|
|
565
|
-
renounceRoles: hooks.useRenounceRolesSync(),
|
|
566
|
-
}))
|
|
567
|
-
|
|
568
|
-
await result.current.connect.connectAsync({
|
|
569
|
-
connector: config.connectors[0]!,
|
|
570
|
-
})
|
|
571
|
-
|
|
572
|
-
// Create a new token
|
|
573
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
574
|
-
currency: 'USD',
|
|
575
|
-
name: 'Renounce Hook Token Sync',
|
|
576
|
-
symbol: 'RENOUNCEHOOKSYNC',
|
|
577
|
-
})
|
|
578
|
-
|
|
579
|
-
// Grant issuer role to ourselves
|
|
580
|
-
await result.current.grantRolesSync.mutateAsync({
|
|
581
|
-
token: tokenAddr,
|
|
582
|
-
roles: ['issuer'],
|
|
583
|
-
to: account.address,
|
|
584
|
-
})
|
|
585
|
-
|
|
586
|
-
const data = await result.current.renounceRoles.mutateAsync({
|
|
587
|
-
token: tokenAddr,
|
|
588
|
-
roles: ['issuer'],
|
|
589
|
-
})
|
|
590
|
-
expect(data).toBeDefined()
|
|
591
|
-
expect(data.receipt).toBeDefined()
|
|
592
|
-
expect(data.value).toBeDefined()
|
|
593
|
-
|
|
594
|
-
await vi.waitFor(() =>
|
|
595
|
-
expect(result.current.renounceRoles.isSuccess).toBeTruthy(),
|
|
596
|
-
)
|
|
597
|
-
})
|
|
598
|
-
})
|
|
599
|
-
|
|
600
|
-
describe('useRevokeRolesSync', () => {
|
|
601
|
-
test('default', async () => {
|
|
602
|
-
const { result } = await renderHook(() => ({
|
|
603
|
-
connect: useConnect(),
|
|
604
|
-
createSync: hooks.useCreateSync(),
|
|
605
|
-
grantRolesSync: hooks.useGrantRolesSync(),
|
|
606
|
-
revokeRoles: hooks.useRevokeRolesSync(),
|
|
607
|
-
}))
|
|
608
|
-
|
|
609
|
-
await result.current.connect.connectAsync({
|
|
610
|
-
connector: config.connectors[0]!,
|
|
611
|
-
})
|
|
612
|
-
|
|
613
|
-
// Create a new token
|
|
614
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
615
|
-
currency: 'USD',
|
|
616
|
-
name: 'Revoke Hook Token Sync',
|
|
617
|
-
symbol: 'REVOKEHOOKSYNC',
|
|
618
|
-
})
|
|
619
|
-
|
|
620
|
-
// Grant issuer role to account2
|
|
621
|
-
await result.current.grantRolesSync.mutateAsync({
|
|
622
|
-
token: tokenAddr,
|
|
623
|
-
roles: ['issuer'],
|
|
624
|
-
to: account2.address,
|
|
625
|
-
})
|
|
626
|
-
|
|
627
|
-
const data = await result.current.revokeRoles.mutateAsync({
|
|
628
|
-
token: tokenAddr,
|
|
629
|
-
roles: ['issuer'],
|
|
630
|
-
from: account2.address,
|
|
631
|
-
})
|
|
632
|
-
expect(data).toBeDefined()
|
|
633
|
-
expect(data.receipt).toBeDefined()
|
|
634
|
-
expect(data.value).toBeDefined()
|
|
635
|
-
|
|
636
|
-
await vi.waitFor(() =>
|
|
637
|
-
expect(result.current.revokeRoles.isSuccess).toBeTruthy(),
|
|
638
|
-
)
|
|
639
|
-
})
|
|
640
|
-
})
|
|
641
|
-
|
|
642
|
-
describe('useSetRoleAdminSync', () => {
|
|
643
|
-
test('default', async () => {
|
|
644
|
-
const { result } = await renderHook(() => ({
|
|
645
|
-
connect: useConnect(),
|
|
646
|
-
createSync: hooks.useCreateSync(),
|
|
647
|
-
setRoleAdmin: hooks.useSetRoleAdminSync(),
|
|
648
|
-
}))
|
|
649
|
-
|
|
650
|
-
await result.current.connect.connectAsync({
|
|
651
|
-
connector: config.connectors[0]!,
|
|
652
|
-
})
|
|
653
|
-
|
|
654
|
-
// Create a new token
|
|
655
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
656
|
-
currency: 'USD',
|
|
657
|
-
name: 'Role Admin Hook Token Sync',
|
|
658
|
-
symbol: 'ROLEADMINHOOKSYNC',
|
|
659
|
-
})
|
|
660
|
-
|
|
661
|
-
const data = await result.current.setRoleAdmin.mutateAsync({
|
|
662
|
-
token: tokenAddr,
|
|
663
|
-
role: 'issuer',
|
|
664
|
-
adminRole: 'pause',
|
|
665
|
-
})
|
|
666
|
-
expect(data).toBeDefined()
|
|
667
|
-
expect(data.receipt).toBeDefined()
|
|
668
|
-
|
|
669
|
-
await vi.waitFor(() =>
|
|
670
|
-
expect(result.current.setRoleAdmin.isSuccess).toBeTruthy(),
|
|
671
|
-
)
|
|
672
|
-
})
|
|
673
|
-
})
|
|
674
|
-
|
|
675
|
-
describe('useSetSupplyCapSync', () => {
|
|
676
|
-
test('default', async () => {
|
|
677
|
-
const { result } = await renderHook(() => ({
|
|
678
|
-
connect: useConnect(),
|
|
679
|
-
createSync: hooks.useCreateSync(),
|
|
680
|
-
setSupplyCap: hooks.useSetSupplyCapSync(),
|
|
681
|
-
}))
|
|
682
|
-
|
|
683
|
-
await result.current.connect.connectAsync({
|
|
684
|
-
connector: config.connectors[0]!,
|
|
685
|
-
})
|
|
686
|
-
|
|
687
|
-
// Create a new token
|
|
688
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
689
|
-
currency: 'USD',
|
|
690
|
-
name: 'Supply Cap Hook Token Sync',
|
|
691
|
-
symbol: 'SUPPLYCAPHOOKSYNC',
|
|
692
|
-
})
|
|
693
|
-
|
|
694
|
-
const data = await result.current.setSupplyCap.mutateAsync({
|
|
695
|
-
token: tokenAddr,
|
|
696
|
-
supplyCap: parseUnits('1000000', 6),
|
|
697
|
-
})
|
|
698
|
-
expect(data).toBeDefined()
|
|
699
|
-
expect(data.receipt).toBeDefined()
|
|
700
|
-
|
|
701
|
-
await vi.waitFor(() =>
|
|
702
|
-
expect(result.current.setSupplyCap.isSuccess).toBeTruthy(),
|
|
703
|
-
)
|
|
704
|
-
})
|
|
705
|
-
})
|
|
706
|
-
|
|
707
|
-
describe('useTransferSync', () => {
|
|
708
|
-
test('default', async () => {
|
|
709
|
-
const { result } = await renderHook(() => ({
|
|
710
|
-
connect: useConnect(),
|
|
711
|
-
transfer: hooks.useTransferSync(),
|
|
712
|
-
}))
|
|
713
|
-
|
|
714
|
-
await result.current.connect.connectAsync({
|
|
715
|
-
connector: config.connectors[0]!,
|
|
716
|
-
})
|
|
717
|
-
|
|
718
|
-
const data = await result.current.transfer.mutateAsync({
|
|
719
|
-
to: account2.address,
|
|
720
|
-
amount: parseUnits('1', 6),
|
|
721
|
-
token: addresses.alphaUsd,
|
|
722
|
-
})
|
|
723
|
-
expect(data).toBeDefined()
|
|
724
|
-
expect(data.receipt).toBeDefined()
|
|
725
|
-
|
|
726
|
-
await vi.waitFor(() =>
|
|
727
|
-
expect(result.current.transfer.isSuccess).toBeTruthy(),
|
|
728
|
-
)
|
|
729
|
-
})
|
|
730
|
-
})
|
|
731
|
-
|
|
732
|
-
describe('useUnpauseSync', () => {
|
|
733
|
-
test('default', async () => {
|
|
734
|
-
const { result } = await renderHook(() => ({
|
|
735
|
-
connect: useConnect(),
|
|
736
|
-
createSync: hooks.useCreateSync(),
|
|
737
|
-
grantRolesSync: hooks.useGrantRolesSync(),
|
|
738
|
-
pauseSync: hooks.usePauseSync(),
|
|
739
|
-
unpause: hooks.useUnpauseSync(),
|
|
740
|
-
}))
|
|
741
|
-
|
|
742
|
-
await result.current.connect.connectAsync({
|
|
743
|
-
connector: config.connectors[0]!,
|
|
744
|
-
})
|
|
745
|
-
|
|
746
|
-
// Create a new token
|
|
747
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
748
|
-
currency: 'USD',
|
|
749
|
-
name: 'Unpause Hook Token Sync',
|
|
750
|
-
symbol: 'UNPAUSEHOOKSYNC',
|
|
751
|
-
})
|
|
752
|
-
|
|
753
|
-
// Grant pause and unpause roles
|
|
754
|
-
await result.current.grantRolesSync.mutateAsync({
|
|
755
|
-
token: tokenAddr,
|
|
756
|
-
roles: ['pause', 'unpause'],
|
|
757
|
-
to: account.address,
|
|
758
|
-
})
|
|
759
|
-
|
|
760
|
-
// First pause it
|
|
761
|
-
await result.current.pauseSync.mutateAsync({
|
|
762
|
-
token: tokenAddr,
|
|
763
|
-
})
|
|
764
|
-
|
|
765
|
-
const data = await result.current.unpause.mutateAsync({
|
|
766
|
-
token: tokenAddr,
|
|
767
|
-
})
|
|
768
|
-
expect(data).toBeDefined()
|
|
769
|
-
expect(data.receipt).toBeDefined()
|
|
770
|
-
|
|
771
|
-
await vi.waitFor(() =>
|
|
772
|
-
expect(result.current.unpause.isSuccess).toBeTruthy(),
|
|
773
|
-
)
|
|
774
|
-
})
|
|
775
|
-
})
|
|
776
|
-
|
|
777
|
-
describe('usePrepareUpdateQuoteTokenSync', () => {
|
|
778
|
-
test('default', async () => {
|
|
779
|
-
const { result } = await renderHook(() => ({
|
|
780
|
-
connect: useConnect(),
|
|
781
|
-
createSync: hooks.useCreateSync(),
|
|
782
|
-
prepareUpdateQuoteToken: hooks.usePrepareUpdateQuoteTokenSync(),
|
|
783
|
-
}))
|
|
784
|
-
|
|
785
|
-
await result.current.connect.connectAsync({
|
|
786
|
-
connector: config.connectors[0]!,
|
|
787
|
-
})
|
|
788
|
-
|
|
789
|
-
// Create quote token
|
|
790
|
-
const { token: quoteToken } = await result.current.createSync.mutateAsync({
|
|
791
|
-
currency: 'USD',
|
|
792
|
-
name: 'Update Quote Hook Sync',
|
|
793
|
-
symbol: 'UQHOOKSYNC',
|
|
794
|
-
})
|
|
795
|
-
|
|
796
|
-
// Create main token
|
|
797
|
-
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
798
|
-
currency: 'USD',
|
|
799
|
-
name: 'Update Main Hook Sync',
|
|
800
|
-
symbol: 'UMHOOKSYNC',
|
|
801
|
-
})
|
|
802
|
-
|
|
803
|
-
const data = await result.current.prepareUpdateQuoteToken.mutateAsync({
|
|
804
|
-
token: tokenAddr,
|
|
805
|
-
quoteToken,
|
|
806
|
-
})
|
|
807
|
-
expect(data).toBeDefined()
|
|
808
|
-
expect(data.receipt).toBeDefined()
|
|
809
|
-
|
|
810
|
-
await vi.waitFor(() =>
|
|
811
|
-
expect(result.current.prepareUpdateQuoteToken.isSuccess).toBeTruthy(),
|
|
812
|
-
)
|
|
813
|
-
})
|
|
814
|
-
})
|
|
815
|
-
|
|
816
|
-
describe('useWatchAdminRole', () => {
|
|
817
|
-
test('default', async () => {
|
|
818
|
-
const { result: connectResult } = await renderHook(() => ({
|
|
819
|
-
connect: useConnect(),
|
|
820
|
-
createSync: hooks.useCreateSync(),
|
|
821
|
-
setRoleAdminSync: hooks.useSetRoleAdminSync(),
|
|
822
|
-
}))
|
|
823
|
-
|
|
824
|
-
await connectResult.current.connect.connectAsync({
|
|
825
|
-
connector: config.connectors[0]!,
|
|
826
|
-
})
|
|
827
|
-
|
|
828
|
-
// Create a new token
|
|
829
|
-
const { token: tokenAddr } =
|
|
830
|
-
await connectResult.current.createSync.mutateAsync({
|
|
831
|
-
currency: 'USD',
|
|
832
|
-
name: 'Watch Admin Role Hook Token',
|
|
833
|
-
symbol: 'WATCHADMINHOOK',
|
|
834
|
-
})
|
|
835
|
-
|
|
836
|
-
const events: any[] = []
|
|
837
|
-
await renderHook(() =>
|
|
838
|
-
hooks.useWatchAdminRole({
|
|
839
|
-
token: tokenAddr,
|
|
840
|
-
onRoleAdminUpdated(args) {
|
|
841
|
-
events.push(args)
|
|
842
|
-
},
|
|
843
|
-
}),
|
|
844
|
-
)
|
|
845
|
-
|
|
846
|
-
// Trigger event by setting a role admin
|
|
847
|
-
await connectResult.current.setRoleAdminSync.mutateAsync({
|
|
848
|
-
token: tokenAddr,
|
|
849
|
-
role: 'issuer',
|
|
850
|
-
adminRole: 'pause',
|
|
851
|
-
})
|
|
852
|
-
|
|
853
|
-
await vi.waitUntil(() => events.length >= 1)
|
|
854
|
-
|
|
855
|
-
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
856
|
-
expect(events[0]).toBeDefined()
|
|
857
|
-
})
|
|
858
|
-
})
|
|
859
|
-
|
|
860
|
-
describe('useWatchApprove', () => {
|
|
861
|
-
test('default', async () => {
|
|
862
|
-
const { result: connectResult } = await renderHook(() => ({
|
|
863
|
-
connect: useConnect(),
|
|
864
|
-
approveSync: hooks.useApproveSync(),
|
|
865
|
-
}))
|
|
866
|
-
|
|
867
|
-
await connectResult.current.connect.connectAsync({
|
|
868
|
-
connector: config.connectors[0]!,
|
|
869
|
-
})
|
|
870
|
-
|
|
871
|
-
const events: any[] = []
|
|
872
|
-
await renderHook(() =>
|
|
873
|
-
hooks.useWatchApprove({
|
|
874
|
-
onApproval(args) {
|
|
875
|
-
events.push(args)
|
|
876
|
-
},
|
|
877
|
-
token: addresses.alphaUsd,
|
|
878
|
-
}),
|
|
879
|
-
)
|
|
880
|
-
|
|
881
|
-
// Trigger approval event
|
|
882
|
-
await connectResult.current.approveSync.mutateAsync({
|
|
883
|
-
spender: account2.address,
|
|
884
|
-
amount: parseUnits('50', 6),
|
|
885
|
-
token: addresses.alphaUsd,
|
|
886
|
-
})
|
|
887
|
-
|
|
888
|
-
await vi.waitUntil(() => events.length >= 1)
|
|
889
|
-
|
|
890
|
-
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
891
|
-
expect(events[0]?.owner).toBe(account.address)
|
|
892
|
-
expect(events[0]?.spender).toBe(account2.address)
|
|
893
|
-
expect(events[0]?.amount).toBe(parseUnits('50', 6))
|
|
894
|
-
})
|
|
895
|
-
})
|
|
896
|
-
|
|
897
|
-
describe('useWatchBurn', () => {
|
|
898
|
-
test('default', async () => {
|
|
899
|
-
const { result: connectResult } = await renderHook(() => ({
|
|
900
|
-
connect: useConnect(),
|
|
901
|
-
createSync: hooks.useCreateSync(),
|
|
902
|
-
grantRolesSync: hooks.useGrantRolesSync(),
|
|
903
|
-
mintSync: hooks.useMintSync(),
|
|
904
|
-
burnSync: hooks.useBurnSync(),
|
|
905
|
-
}))
|
|
906
|
-
|
|
907
|
-
await connectResult.current.connect.connectAsync({
|
|
908
|
-
connector: config.connectors[0]!,
|
|
909
|
-
})
|
|
910
|
-
|
|
911
|
-
// Create a new token
|
|
912
|
-
const { token: tokenAddr } =
|
|
913
|
-
await connectResult.current.createSync.mutateAsync({
|
|
914
|
-
currency: 'USD',
|
|
915
|
-
name: 'Watch Burn Hook Token',
|
|
916
|
-
symbol: 'WATCHBURNHOOK',
|
|
917
|
-
})
|
|
918
|
-
|
|
919
|
-
// Grant issuer role and mint tokens
|
|
920
|
-
await connectResult.current.grantRolesSync.mutateAsync({
|
|
921
|
-
token: tokenAddr,
|
|
922
|
-
roles: ['issuer'],
|
|
923
|
-
to: account.address,
|
|
924
|
-
})
|
|
925
|
-
await connectResult.current.mintSync.mutateAsync({
|
|
926
|
-
token: tokenAddr,
|
|
927
|
-
to: account.address,
|
|
928
|
-
amount: parseUnits('1000', 6),
|
|
929
|
-
})
|
|
930
|
-
|
|
931
|
-
const events: any[] = []
|
|
932
|
-
await renderHook(() =>
|
|
933
|
-
hooks.useWatchBurn({
|
|
934
|
-
token: tokenAddr,
|
|
935
|
-
onBurn(args) {
|
|
936
|
-
events.push(args)
|
|
937
|
-
},
|
|
938
|
-
}),
|
|
939
|
-
)
|
|
940
|
-
|
|
941
|
-
// Trigger burn event
|
|
942
|
-
await connectResult.current.burnSync.mutateAsync({
|
|
943
|
-
token: tokenAddr,
|
|
944
|
-
amount: parseUnits('10', 6),
|
|
945
|
-
})
|
|
946
|
-
|
|
947
|
-
await vi.waitUntil(() => events.length >= 1)
|
|
948
|
-
|
|
949
|
-
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
950
|
-
expect(events[0]?.from).toBe(account.address)
|
|
951
|
-
expect(events[0]?.amount).toBe(parseUnits('10', 6))
|
|
952
|
-
})
|
|
953
|
-
})
|
|
954
|
-
|
|
955
|
-
describe('useWatchCreate', () => {
|
|
956
|
-
test('default', async () => {
|
|
957
|
-
const { result: connectResult } = await renderHook(() => ({
|
|
958
|
-
connect: useConnect(),
|
|
959
|
-
createSync: hooks.useCreateSync(),
|
|
960
|
-
}))
|
|
961
|
-
|
|
962
|
-
await connectResult.current.connect.connectAsync({
|
|
963
|
-
connector: config.connectors[0]!,
|
|
964
|
-
})
|
|
965
|
-
|
|
966
|
-
const events: any[] = []
|
|
967
|
-
await renderHook(() =>
|
|
968
|
-
hooks.useWatchCreate({
|
|
969
|
-
onTokenCreated(args) {
|
|
970
|
-
events.push(args)
|
|
971
|
-
},
|
|
972
|
-
}),
|
|
973
|
-
)
|
|
974
|
-
|
|
975
|
-
// Trigger token creation event
|
|
976
|
-
await connectResult.current.createSync.mutateAsync({
|
|
977
|
-
name: 'Watch Create Hook Token',
|
|
978
|
-
symbol: 'WATCHCREATEHOOK',
|
|
979
|
-
currency: 'USD',
|
|
980
|
-
})
|
|
981
|
-
|
|
982
|
-
await vi.waitUntil(() => events.length >= 1)
|
|
983
|
-
|
|
984
|
-
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
985
|
-
expect(events[0]?.name).toBe('Watch Create Hook Token')
|
|
986
|
-
expect(events[0]?.symbol).toBe('WATCHCREATEHOOK')
|
|
987
|
-
expect(events[0]?.currency).toBe('USD')
|
|
988
|
-
expect(events[0]?.admin).toBe(account.address)
|
|
989
|
-
})
|
|
990
|
-
})
|
|
991
|
-
|
|
992
|
-
describe('useWatchMint', () => {
|
|
993
|
-
test('default', async () => {
|
|
994
|
-
const { result: connectResult } = await renderHook(() => ({
|
|
995
|
-
connect: useConnect(),
|
|
996
|
-
createSync: hooks.useCreateSync(),
|
|
997
|
-
grantRolesSync: hooks.useGrantRolesSync(),
|
|
998
|
-
mintSync: hooks.useMintSync(),
|
|
999
|
-
}))
|
|
1000
|
-
|
|
1001
|
-
await connectResult.current.connect.connectAsync({
|
|
1002
|
-
connector: config.connectors[0]!,
|
|
1003
|
-
})
|
|
1004
|
-
|
|
1005
|
-
// Create a new token
|
|
1006
|
-
const { token: tokenAddr } =
|
|
1007
|
-
await connectResult.current.createSync.mutateAsync({
|
|
1008
|
-
currency: 'USD',
|
|
1009
|
-
name: 'Watch Mint Hook Token',
|
|
1010
|
-
symbol: 'WATCHMINTHOOK',
|
|
1011
|
-
})
|
|
1012
|
-
|
|
1013
|
-
// Grant issuer role
|
|
1014
|
-
await connectResult.current.grantRolesSync.mutateAsync({
|
|
1015
|
-
token: tokenAddr,
|
|
1016
|
-
roles: ['issuer'],
|
|
1017
|
-
to: account.address,
|
|
1018
|
-
})
|
|
1019
|
-
|
|
1020
|
-
const events: any[] = []
|
|
1021
|
-
await renderHook(() =>
|
|
1022
|
-
hooks.useWatchMint({
|
|
1023
|
-
token: tokenAddr,
|
|
1024
|
-
onMint(args) {
|
|
1025
|
-
events.push(args)
|
|
1026
|
-
},
|
|
1027
|
-
}),
|
|
1028
|
-
)
|
|
1029
|
-
|
|
1030
|
-
// Trigger mint event
|
|
1031
|
-
await connectResult.current.mintSync.mutateAsync({
|
|
1032
|
-
token: tokenAddr,
|
|
1033
|
-
to: account.address,
|
|
1034
|
-
amount: parseUnits('100', 6),
|
|
1035
|
-
})
|
|
1036
|
-
|
|
1037
|
-
await vi.waitUntil(() => events.length >= 1)
|
|
1038
|
-
|
|
1039
|
-
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1040
|
-
expect(events[0]?.to).toBe(account.address)
|
|
1041
|
-
expect(events[0]?.amount).toBe(parseUnits('100', 6))
|
|
1042
|
-
})
|
|
1043
|
-
})
|
|
1044
|
-
|
|
1045
|
-
describe('useWatchRole', () => {
|
|
1046
|
-
test('default', async () => {
|
|
1047
|
-
const { result: connectResult } = await renderHook(() => ({
|
|
1048
|
-
connect: useConnect(),
|
|
1049
|
-
createSync: hooks.useCreateSync(),
|
|
1050
|
-
grantRolesSync: hooks.useGrantRolesSync(),
|
|
1051
|
-
}))
|
|
1052
|
-
|
|
1053
|
-
await connectResult.current.connect.connectAsync({
|
|
1054
|
-
connector: config.connectors[0]!,
|
|
1055
|
-
})
|
|
1056
|
-
|
|
1057
|
-
// Create a new token
|
|
1058
|
-
const { token: tokenAddr } =
|
|
1059
|
-
await connectResult.current.createSync.mutateAsync({
|
|
1060
|
-
currency: 'USD',
|
|
1061
|
-
name: 'Watch Role Hook Token',
|
|
1062
|
-
symbol: 'WATCHROLEHOOK',
|
|
1063
|
-
})
|
|
1064
|
-
|
|
1065
|
-
const events: any[] = []
|
|
1066
|
-
await renderHook(() =>
|
|
1067
|
-
hooks.useWatchRole({
|
|
1068
|
-
token: tokenAddr,
|
|
1069
|
-
onRoleUpdated(args) {
|
|
1070
|
-
events.push(args)
|
|
1071
|
-
},
|
|
1072
|
-
}),
|
|
1073
|
-
)
|
|
1074
|
-
|
|
1075
|
-
// Trigger role update event by granting a role
|
|
1076
|
-
await connectResult.current.grantRolesSync.mutateAsync({
|
|
1077
|
-
token: tokenAddr,
|
|
1078
|
-
roles: ['issuer'],
|
|
1079
|
-
to: account2.address,
|
|
1080
|
-
})
|
|
1081
|
-
|
|
1082
|
-
await vi.waitUntil(() => events.length >= 1)
|
|
1083
|
-
|
|
1084
|
-
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1085
|
-
expect(events[0]?.account).toBe(account2.address)
|
|
1086
|
-
expect(events[0]?.hasRole).toBe(true)
|
|
1087
|
-
expect(events[0]?.type).toBe('granted')
|
|
1088
|
-
})
|
|
1089
|
-
})
|
|
1090
|
-
|
|
1091
|
-
describe('useWatchTransfer', () => {
|
|
1092
|
-
test('default', async () => {
|
|
1093
|
-
const { result: connectResult } = await renderHook(() => ({
|
|
1094
|
-
connect: useConnect(),
|
|
1095
|
-
transferSync: hooks.useTransferSync(),
|
|
1096
|
-
}))
|
|
1097
|
-
|
|
1098
|
-
await connectResult.current.connect.connectAsync({
|
|
1099
|
-
connector: config.connectors[0]!,
|
|
1100
|
-
})
|
|
1101
|
-
|
|
1102
|
-
const events: any[] = []
|
|
1103
|
-
await renderHook(() =>
|
|
1104
|
-
hooks.useWatchTransfer({
|
|
1105
|
-
onTransfer(args) {
|
|
1106
|
-
events.push(args)
|
|
1107
|
-
},
|
|
1108
|
-
token: addresses.alphaUsd,
|
|
1109
|
-
}),
|
|
1110
|
-
)
|
|
1111
|
-
|
|
1112
|
-
// Trigger transfer event
|
|
1113
|
-
await connectResult.current.transferSync.mutateAsync({
|
|
1114
|
-
to: account2.address,
|
|
1115
|
-
amount: parseUnits('5', 6),
|
|
1116
|
-
token: addresses.alphaUsd,
|
|
1117
|
-
})
|
|
1118
|
-
|
|
1119
|
-
await vi.waitUntil(() => events.length >= 1)
|
|
1120
|
-
|
|
1121
|
-
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1122
|
-
expect(events[0]?.from).toBe(account.address)
|
|
1123
|
-
expect(events[0]?.to).toBe(account2.address)
|
|
1124
|
-
expect(events[0]?.amount).toBe(parseUnits('5', 6))
|
|
1125
|
-
})
|
|
1126
|
-
})
|
|
1127
|
-
|
|
1128
|
-
describe('useWatchUpdateQuoteToken', () => {
|
|
1129
|
-
test('default', async () => {
|
|
1130
|
-
const { result: connectResult } = await renderHook(() => ({
|
|
1131
|
-
connect: useConnect(),
|
|
1132
|
-
createSync: hooks.useCreateSync(),
|
|
1133
|
-
prepareUpdateQuoteTokenSync: hooks.usePrepareUpdateQuoteTokenSync(),
|
|
1134
|
-
}))
|
|
1135
|
-
|
|
1136
|
-
await connectResult.current.connect.connectAsync({
|
|
1137
|
-
connector: config.connectors[0]!,
|
|
1138
|
-
})
|
|
1139
|
-
|
|
1140
|
-
// Create quote token
|
|
1141
|
-
const { token: quoteToken } =
|
|
1142
|
-
await connectResult.current.createSync.mutateAsync({
|
|
1143
|
-
currency: 'USD',
|
|
1144
|
-
name: 'Watch Quote Hook Token',
|
|
1145
|
-
symbol: 'WATCHQUOTEHOOK',
|
|
1146
|
-
})
|
|
1147
|
-
|
|
1148
|
-
// Create main token
|
|
1149
|
-
const { token: tokenAddr } =
|
|
1150
|
-
await connectResult.current.createSync.mutateAsync({
|
|
1151
|
-
currency: 'USD',
|
|
1152
|
-
name: 'Watch Main Hook Token',
|
|
1153
|
-
symbol: 'WATCHMAINHOOK',
|
|
1154
|
-
})
|
|
1155
|
-
|
|
1156
|
-
const events: any[] = []
|
|
1157
|
-
await renderHook(() =>
|
|
1158
|
-
hooks.useWatchUpdateQuoteToken({
|
|
1159
|
-
token: tokenAddr,
|
|
1160
|
-
onUpdateQuoteToken(args) {
|
|
1161
|
-
events.push(args)
|
|
1162
|
-
},
|
|
1163
|
-
}),
|
|
1164
|
-
)
|
|
1165
|
-
|
|
1166
|
-
// Trigger prepare update quote token event
|
|
1167
|
-
await connectResult.current.prepareUpdateQuoteTokenSync.mutateAsync({
|
|
1168
|
-
token: tokenAddr,
|
|
1169
|
-
quoteToken,
|
|
1170
|
-
})
|
|
1171
|
-
|
|
1172
|
-
await vi.waitUntil(() => events.length >= 1)
|
|
1173
|
-
|
|
1174
|
-
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1175
|
-
expect(events[0]?.nextQuoteToken).toBe(quoteToken)
|
|
1176
|
-
expect(events[0]?.updater).toBe(account.address)
|
|
1177
|
-
expect(events[0]?.completed).toBe(false)
|
|
1178
|
-
})
|
|
1179
|
-
})
|
|
1180
|
-
|
|
1181
|
-
describe.todo('useBurnBlocked')
|
|
1182
|
-
|
|
1183
|
-
describe.todo('useBurnBlockedSync')
|