tempo.ts 0.1.5 → 0.2.1
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/README.md +33 -2
- package/dist/chains.d.ts +509 -115
- package/dist/chains.d.ts.map +1 -1
- package/dist/chains.js +20 -9
- package/dist/chains.js.map +1 -1
- package/dist/ox/Order.d.ts +92 -0
- package/dist/ox/Order.d.ts.map +1 -0
- package/dist/ox/Order.js +88 -0
- package/dist/ox/Order.js.map +1 -0
- package/dist/ox/OrdersFilters.d.ts +72 -0
- package/dist/ox/OrdersFilters.d.ts.map +1 -0
- package/dist/ox/OrdersFilters.js +100 -0
- package/dist/ox/OrdersFilters.js.map +1 -0
- package/dist/ox/Pagination.d.ts +128 -0
- package/dist/ox/Pagination.d.ts.map +1 -0
- package/dist/ox/Pagination.js +78 -0
- package/dist/ox/Pagination.js.map +1 -0
- package/dist/ox/PoolId.d.ts +18 -0
- package/dist/ox/PoolId.d.ts.map +1 -0
- package/dist/ox/PoolId.js +13 -0
- package/dist/ox/PoolId.js.map +1 -0
- package/dist/ox/RpcSchema.d.ts +32 -0
- package/dist/ox/RpcSchema.d.ts.map +1 -0
- package/dist/ox/RpcSchema.js +2 -0
- package/dist/ox/RpcSchema.js.map +1 -0
- package/dist/ox/SignatureEnvelope.d.ts +1 -1
- package/dist/ox/SignatureEnvelope.d.ts.map +1 -1
- package/dist/ox/SignatureEnvelope.js.map +1 -1
- package/dist/{viem → ox}/Tick.d.ts +4 -0
- package/dist/ox/Tick.d.ts.map +1 -0
- package/dist/ox/Tick.js.map +1 -0
- package/dist/ox/Transaction.d.ts.map +1 -1
- package/dist/ox/Transaction.js +2 -1
- package/dist/ox/Transaction.js.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.d.ts +6 -6
- package/dist/ox/TransactionEnvelopeAA.d.ts.map +1 -1
- package/dist/ox/TransactionEnvelopeAA.js +4 -2
- package/dist/ox/TransactionEnvelopeAA.js.map +1 -1
- package/dist/ox/TransactionRequest.d.ts +4 -0
- package/dist/ox/TransactionRequest.d.ts.map +1 -1
- package/dist/ox/TransactionRequest.js.map +1 -1
- package/dist/ox/index.d.ts +6 -0
- package/dist/ox/index.d.ts.map +1 -1
- package/dist/ox/index.js +6 -0
- package/dist/ox/index.js.map +1 -1
- package/dist/prool/Instance.d.ts.map +1 -1
- package/dist/prool/Instance.js +20 -4
- package/dist/prool/Instance.js.map +1 -1
- package/dist/viem/Abis.d.ts +1469 -1082
- package/dist/viem/Abis.d.ts.map +1 -1
- package/dist/viem/Abis.js +932 -671
- package/dist/viem/Abis.js.map +1 -1
- package/dist/viem/Account.d.ts +150 -0
- package/dist/viem/Account.d.ts.map +1 -0
- package/dist/viem/Account.js +221 -0
- package/dist/viem/Account.js.map +1 -0
- package/dist/viem/Actions/amm.d.ts +144 -161
- package/dist/viem/Actions/amm.d.ts.map +1 -1
- package/dist/viem/Actions/amm.js +109 -163
- package/dist/viem/Actions/amm.js.map +1 -1
- package/dist/viem/Actions/dex.d.ts +920 -664
- package/dist/viem/Actions/dex.d.ts.map +1 -1
- package/dist/viem/Actions/dex.js +129 -30
- package/dist/viem/Actions/dex.js.map +1 -1
- package/dist/viem/Actions/faucet.d.ts +34 -0
- package/dist/viem/Actions/faucet.d.ts.map +1 -0
- package/dist/viem/Actions/faucet.js +33 -0
- package/dist/viem/Actions/faucet.js.map +1 -0
- package/dist/viem/Actions/fee.d.ts +16 -30
- package/dist/viem/Actions/fee.d.ts.map +1 -1
- package/dist/viem/Actions/fee.js +13 -13
- package/dist/viem/Actions/fee.js.map +1 -1
- package/dist/viem/Actions/index.d.ts +2 -0
- package/dist/viem/Actions/index.d.ts.map +1 -1
- package/dist/viem/Actions/index.js +2 -0
- package/dist/viem/Actions/index.js.map +1 -1
- package/dist/viem/Actions/policy.d.ts +46 -46
- package/dist/viem/Actions/policy.js +46 -46
- package/dist/viem/Actions/reward.d.ts +3236 -0
- package/dist/viem/Actions/reward.d.ts.map +1 -0
- package/dist/viem/Actions/reward.js +725 -0
- package/dist/viem/Actions/reward.js.map +1 -0
- package/dist/viem/Actions/token.d.ts +4399 -2750
- package/dist/viem/Actions/token.d.ts.map +1 -1
- package/dist/viem/Actions/token.js +361 -482
- package/dist/viem/Actions/token.js.map +1 -1
- package/dist/viem/Addresses.d.ts +1 -2
- package/dist/viem/Addresses.d.ts.map +1 -1
- package/dist/viem/Addresses.js +1 -2
- package/dist/viem/Addresses.js.map +1 -1
- package/dist/viem/Chain.d.ts +38 -12
- package/dist/viem/Chain.d.ts.map +1 -1
- package/dist/viem/Chain.js +27 -18
- package/dist/viem/Chain.js.map +1 -1
- package/dist/viem/Decorator.d.ts +1009 -428
- package/dist/viem/Decorator.d.ts.map +1 -1
- package/dist/viem/Decorator.js +17 -5
- package/dist/viem/Decorator.js.map +1 -1
- package/dist/viem/Formatters.d.ts +8 -1
- package/dist/viem/Formatters.d.ts.map +1 -1
- package/dist/viem/Formatters.js +17 -0
- package/dist/viem/Formatters.js.map +1 -1
- package/dist/viem/P256.d.ts +2 -0
- package/dist/viem/P256.d.ts.map +1 -0
- package/dist/viem/P256.js +2 -0
- package/dist/viem/P256.js.map +1 -0
- package/dist/viem/Secp256k1.d.ts +2 -0
- package/dist/viem/Secp256k1.d.ts.map +1 -0
- package/dist/viem/Secp256k1.js +2 -0
- package/dist/viem/Secp256k1.js.map +1 -0
- package/dist/viem/TokenIds.d.ts +1 -2
- package/dist/viem/TokenIds.d.ts.map +1 -1
- package/dist/viem/TokenIds.js +1 -2
- package/dist/viem/TokenIds.js.map +1 -1
- package/dist/viem/Transaction.d.ts +1 -1
- package/dist/viem/Transaction.d.ts.map +1 -1
- package/dist/viem/Transaction.js +46 -5
- package/dist/viem/Transaction.js.map +1 -1
- package/dist/viem/WebAuthnP256.d.ts +79 -0
- package/dist/viem/WebAuthnP256.d.ts.map +1 -0
- package/dist/viem/WebAuthnP256.js +95 -0
- package/dist/viem/WebAuthnP256.js.map +1 -0
- package/dist/viem/WebCryptoP256.d.ts +2 -0
- package/dist/viem/WebCryptoP256.d.ts.map +1 -0
- package/dist/viem/WebCryptoP256.js +2 -0
- package/dist/viem/WebCryptoP256.js.map +1 -0
- package/dist/viem/index.d.ts +6 -3
- package/dist/viem/index.d.ts.map +1 -1
- package/dist/viem/index.js +6 -3
- package/dist/viem/index.js.map +1 -1
- package/dist/viem/internal/account.d.ts +24 -0
- package/dist/viem/internal/account.d.ts.map +1 -0
- package/dist/viem/internal/account.js +68 -0
- package/dist/viem/internal/account.js.map +1 -0
- package/dist/viem/internal/types.d.ts +10 -0
- package/dist/viem/internal/types.d.ts.map +1 -1
- package/dist/wagmi/Actions/amm.d.ts +428 -0
- package/dist/wagmi/Actions/amm.d.ts.map +1 -0
- package/dist/wagmi/Actions/amm.js +472 -0
- package/dist/wagmi/Actions/amm.js.map +1 -0
- package/dist/wagmi/Actions/dex.d.ts +908 -0
- package/dist/wagmi/Actions/dex.d.ts.map +1 -0
- package/dist/wagmi/Actions/dex.js +1023 -0
- package/dist/wagmi/Actions/dex.js.map +1 -0
- package/dist/wagmi/Actions/faucet.d.ts +35 -0
- package/dist/wagmi/Actions/faucet.d.ts.map +1 -0
- package/dist/wagmi/Actions/faucet.js +33 -0
- package/dist/wagmi/Actions/faucet.js.map +1 -0
- package/dist/wagmi/Actions/fee.d.ts +111 -0
- package/dist/wagmi/Actions/fee.d.ts.map +1 -0
- package/dist/wagmi/Actions/fee.js +126 -0
- package/dist/wagmi/Actions/fee.js.map +1 -0
- package/dist/wagmi/Actions/index.d.ts +7 -0
- package/dist/wagmi/Actions/index.d.ts.map +1 -0
- package/dist/wagmi/Actions/index.js +7 -0
- package/dist/wagmi/Actions/index.js.map +1 -0
- package/dist/wagmi/Actions/reward.d.ts +348 -0
- package/dist/wagmi/Actions/reward.d.ts.map +1 -0
- package/dist/wagmi/Actions/reward.js +388 -0
- package/dist/wagmi/Actions/reward.js.map +1 -0
- package/dist/wagmi/Actions/token.d.ts +1546 -0
- package/dist/wagmi/Actions/token.d.ts.map +1 -0
- package/dist/wagmi/Actions/token.js +1712 -0
- package/dist/wagmi/Actions/token.js.map +1 -0
- package/dist/wagmi/Connector.d.ts +81 -0
- package/dist/wagmi/Connector.d.ts.map +1 -0
- package/dist/wagmi/Connector.js +261 -0
- package/dist/wagmi/Connector.js.map +1 -0
- package/dist/wagmi/Hooks/amm.d.ts +421 -0
- package/dist/wagmi/Hooks/amm.d.ts.map +1 -0
- package/dist/wagmi/Hooks/amm.js +504 -0
- package/dist/wagmi/Hooks/amm.js.map +1 -0
- package/dist/wagmi/Hooks/dex.d.ts +816 -0
- package/dist/wagmi/Hooks/dex.d.ts.map +1 -0
- package/dist/wagmi/Hooks/dex.js +973 -0
- package/dist/wagmi/Hooks/dex.js.map +1 -0
- package/dist/wagmi/Hooks/faucet.d.ts +39 -0
- package/dist/wagmi/Hooks/faucet.d.ts.map +1 -0
- package/dist/wagmi/Hooks/faucet.js +40 -0
- package/dist/wagmi/Hooks/faucet.js.map +1 -0
- package/dist/wagmi/Hooks/fee.d.ts +97 -0
- package/dist/wagmi/Hooks/fee.d.ts.map +1 -0
- package/dist/wagmi/Hooks/fee.js +109 -0
- package/dist/wagmi/Hooks/fee.js.map +1 -0
- package/dist/wagmi/Hooks/index.d.ts +7 -0
- package/dist/wagmi/Hooks/index.d.ts.map +1 -0
- package/dist/wagmi/Hooks/index.js +7 -0
- package/dist/wagmi/Hooks/index.js.map +1 -0
- package/dist/wagmi/Hooks/reward.d.ts +307 -0
- package/dist/wagmi/Hooks/reward.d.ts.map +1 -0
- package/dist/wagmi/Hooks/reward.js +349 -0
- package/dist/wagmi/Hooks/reward.js.map +1 -0
- package/dist/wagmi/Hooks/token.d.ts +1388 -0
- package/dist/wagmi/Hooks/token.d.ts.map +1 -0
- package/dist/wagmi/Hooks/token.js +1657 -0
- package/dist/wagmi/Hooks/token.js.map +1 -0
- package/dist/wagmi/index.d.ts +4 -0
- package/dist/wagmi/index.d.ts.map +1 -0
- package/dist/wagmi/index.js +4 -0
- package/dist/wagmi/index.js.map +1 -0
- package/package.json +54 -10
- package/src/chains.ts +21 -9
- package/src/ox/Order.test.ts +78 -0
- package/src/ox/Order.ts +125 -0
- package/src/ox/OrdersFilters.test.ts +182 -0
- package/src/ox/OrdersFilters.ts +125 -0
- package/src/ox/Pagination.test.ts +162 -0
- package/src/ox/Pagination.ts +164 -0
- package/src/ox/PoolId.test.ts +33 -0
- package/src/ox/PoolId.ts +27 -0
- package/src/ox/RpcSchema.ts +35 -0
- package/src/ox/SignatureEnvelope.ts +3 -1
- package/src/{viem → ox}/Tick.test.ts +1 -1
- package/src/{viem → ox}/Tick.ts +5 -0
- package/src/ox/Transaction.test.ts +1 -1
- package/src/ox/Transaction.ts +2 -1
- package/src/ox/TransactionEnvelopeAA.test.ts +239 -96
- package/src/ox/TransactionEnvelopeAA.ts +9 -7
- package/src/ox/TransactionRequest.ts +4 -0
- package/src/ox/index.ts +6 -0
- package/src/prool/Instance.ts +51 -37
- package/src/prool/internal/chain.json +104 -52
- package/src/tsconfig.json +9 -0
- package/src/viem/Abis.ts +972 -710
- package/src/viem/Account.ts +279 -0
- package/src/viem/Actions/__snapshots__/dex.test.ts.snap +850 -0
- package/src/viem/Actions/amm.test.ts +173 -169
- package/src/viem/Actions/amm.ts +131 -203
- package/src/viem/Actions/dex.test.ts +563 -484
- package/src/viem/Actions/dex.ts +203 -30
- package/src/viem/Actions/faucet.ts +50 -0
- package/src/viem/Actions/fee.test.ts +23 -34
- package/src/viem/Actions/fee.ts +20 -13
- package/src/viem/Actions/index.ts +2 -0
- package/src/viem/Actions/policy.test.ts +19 -33
- package/src/viem/Actions/policy.ts +46 -46
- package/src/viem/Actions/reward.test.ts +457 -0
- package/src/viem/Actions/reward.ts +999 -0
- package/src/viem/Actions/token.test.ts +453 -287
- package/src/viem/Actions/token.ts +605 -693
- package/src/viem/Addresses.ts +1 -2
- package/src/viem/Chain.bench-d.ts +12 -0
- package/src/viem/Chain.ts +70 -20
- package/src/viem/Decorator.bench-d.ts +1 -1
- package/src/viem/Decorator.test.ts +3 -1
- package/src/viem/Decorator.ts +1049 -442
- package/src/viem/Formatters.ts +31 -5
- package/src/viem/P256.ts +1 -0
- package/src/viem/Secp256k1.ts +1 -0
- package/src/viem/TokenIds.ts +1 -2
- package/src/viem/Transaction.ts +53 -7
- package/src/viem/WebAuthnP256.ts +140 -0
- package/src/viem/WebCryptoP256.ts +1 -0
- package/src/viem/e2e.test.ts +1126 -297
- package/src/viem/index.ts +6 -3
- package/src/viem/internal/account.ts +107 -0
- package/src/viem/internal/types.ts +9 -0
- package/src/wagmi/Actions/__snapshots__/dex.test.ts.snap +310 -0
- package/src/wagmi/Actions/amm.test.ts +198 -0
- package/src/wagmi/Actions/amm.ts +691 -0
- package/src/wagmi/Actions/dex.test.ts +1507 -0
- package/src/wagmi/Actions/dex.ts +1640 -0
- package/src/wagmi/Actions/faucet.ts +46 -0
- package/src/wagmi/Actions/fee.test.ts +63 -0
- package/src/wagmi/Actions/fee.ts +208 -0
- package/src/wagmi/Actions/index.ts +6 -0
- package/src/wagmi/Actions/reward.test.ts +210 -0
- package/src/wagmi/Actions/reward.ts +632 -0
- package/src/wagmi/Actions/token.test.ts +1308 -0
- package/src/wagmi/Actions/token.ts +2613 -0
- package/src/wagmi/Connector.test.ts +53 -0
- package/src/wagmi/Connector.ts +390 -0
- package/src/wagmi/Hooks/__snapshots__/dex.test.ts.snap +457 -0
- package/src/wagmi/Hooks/amm.test.ts +424 -0
- package/src/wagmi/Hooks/amm.ts +806 -0
- package/src/wagmi/Hooks/dex.test.ts +1017 -0
- package/src/wagmi/Hooks/dex.ts +1685 -0
- package/src/wagmi/Hooks/faucet.ts +76 -0
- package/src/wagmi/Hooks/fee.test.ts +166 -0
- package/src/wagmi/Hooks/fee.ts +206 -0
- package/src/wagmi/Hooks/index.ts +6 -0
- package/src/wagmi/Hooks/reward.test.ts +219 -0
- package/src/wagmi/Hooks/reward.ts +672 -0
- package/src/wagmi/Hooks/token.test.ts +1670 -0
- package/src/wagmi/Hooks/token.ts +2906 -0
- package/src/wagmi/index.ts +3 -0
- package/src/wagmi/internal/types.ts +16 -0
- package/dist/viem/Client.d.ts +0 -27
- package/dist/viem/Client.d.ts.map +0 -1
- package/dist/viem/Client.js +0 -28
- package/dist/viem/Client.js.map +0 -1
- package/dist/viem/Tick.d.ts.map +0 -1
- package/dist/viem/Tick.js.map +0 -1
- package/src/viem/Client.bench-d.ts +0 -8
- package/src/viem/Client.test.ts +0 -178
- package/src/viem/Client.ts +0 -91
- /package/dist/{viem → ox}/Tick.js +0 -0
|
@@ -0,0 +1,1670 @@
|
|
|
1
|
+
import { type Address, parseUnits } from 'viem'
|
|
2
|
+
import { describe, expect, test, vi } from 'vitest'
|
|
3
|
+
import { useConnect } from 'wagmi'
|
|
4
|
+
import { accounts, addresses } from '../../../test/viem/config.js'
|
|
5
|
+
import { config, renderHook } from '../../../test/wagmi/config.js'
|
|
6
|
+
import * as hooks from './token.js'
|
|
7
|
+
|
|
8
|
+
const account = accounts[0]
|
|
9
|
+
const account2 = accounts[1]
|
|
10
|
+
|
|
11
|
+
describe('useGetAllowance', () => {
|
|
12
|
+
test('default', async () => {
|
|
13
|
+
const { result } = await renderHook(() =>
|
|
14
|
+
hooks.useGetAllowance({
|
|
15
|
+
account: account.address,
|
|
16
|
+
spender: account2.address,
|
|
17
|
+
token: addresses.alphaUsd,
|
|
18
|
+
}),
|
|
19
|
+
)
|
|
20
|
+
|
|
21
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy(), {
|
|
22
|
+
timeout: 5000,
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
expect(result.current.data).toBeDefined()
|
|
26
|
+
expect(typeof result.current.data).toBe('bigint')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('reactivity: account parameter', async () => {
|
|
30
|
+
let accountAddress: Address | undefined
|
|
31
|
+
let spenderAddress: Address | undefined
|
|
32
|
+
|
|
33
|
+
const { result, rerender } = await renderHook(() =>
|
|
34
|
+
hooks.useGetAllowance({
|
|
35
|
+
account: accountAddress,
|
|
36
|
+
spender: spenderAddress,
|
|
37
|
+
token: addresses.alphaUsd,
|
|
38
|
+
}),
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
await vi.waitFor(() => result.current.fetchStatus === 'fetching')
|
|
42
|
+
|
|
43
|
+
// Should be disabled when account or spender is undefined
|
|
44
|
+
expect(result.current.data).toBeUndefined()
|
|
45
|
+
expect(result.current.isPending).toBe(true)
|
|
46
|
+
expect(result.current.isEnabled).toBe(false)
|
|
47
|
+
|
|
48
|
+
// Set account but not spender
|
|
49
|
+
accountAddress = account.address
|
|
50
|
+
rerender()
|
|
51
|
+
|
|
52
|
+
await vi.waitFor(() => result.current.fetchStatus === 'fetching')
|
|
53
|
+
|
|
54
|
+
// Still disabled when spender is undefined
|
|
55
|
+
expect(result.current.isEnabled).toBe(false)
|
|
56
|
+
|
|
57
|
+
// Set spender
|
|
58
|
+
spenderAddress = account2.address
|
|
59
|
+
rerender()
|
|
60
|
+
|
|
61
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
62
|
+
|
|
63
|
+
// Should now be enabled and have data
|
|
64
|
+
expect(result.current.isEnabled).toBe(true)
|
|
65
|
+
expect(result.current.data).toBeDefined()
|
|
66
|
+
expect(typeof result.current.data).toBe('bigint')
|
|
67
|
+
})
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
describe('useGetBalance', () => {
|
|
71
|
+
test('default', async () => {
|
|
72
|
+
const { result } = await renderHook(() =>
|
|
73
|
+
hooks.useGetBalance({
|
|
74
|
+
account: account.address,
|
|
75
|
+
token: addresses.alphaUsd,
|
|
76
|
+
}),
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
80
|
+
|
|
81
|
+
expect(result.current.data).toBeDefined()
|
|
82
|
+
expect(typeof result.current.data).toBe('bigint')
|
|
83
|
+
expect(result.current.data).toBeGreaterThan(0n)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('reactivity: account parameter', async () => {
|
|
87
|
+
let accountAddress: Address | undefined
|
|
88
|
+
|
|
89
|
+
const { result, rerender } = await renderHook(() =>
|
|
90
|
+
hooks.useGetBalance({
|
|
91
|
+
account: accountAddress,
|
|
92
|
+
token: addresses.alphaUsd,
|
|
93
|
+
}),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
await vi.waitFor(() => result.current.fetchStatus === 'fetching')
|
|
97
|
+
|
|
98
|
+
// Should be disabled when account is undefined
|
|
99
|
+
expect(result.current.data).toBeUndefined()
|
|
100
|
+
expect(result.current.isPending).toBe(true)
|
|
101
|
+
expect(result.current.isEnabled).toBe(false)
|
|
102
|
+
|
|
103
|
+
// Set account
|
|
104
|
+
accountAddress = account.address
|
|
105
|
+
rerender()
|
|
106
|
+
|
|
107
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
108
|
+
|
|
109
|
+
// Should now be enabled and have data
|
|
110
|
+
expect(result.current.isEnabled).toBe(true)
|
|
111
|
+
expect(result.current.data).toBeDefined()
|
|
112
|
+
expect(typeof result.current.data).toBe('bigint')
|
|
113
|
+
expect(result.current.data).toBeGreaterThan(0n)
|
|
114
|
+
})
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
describe('useGetMetadata', () => {
|
|
118
|
+
test('default', async () => {
|
|
119
|
+
const { result } = await renderHook(() =>
|
|
120
|
+
hooks.useGetMetadata({
|
|
121
|
+
token: addresses.alphaUsd,
|
|
122
|
+
}),
|
|
123
|
+
)
|
|
124
|
+
|
|
125
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
126
|
+
|
|
127
|
+
expect(result.current.data).toBeDefined()
|
|
128
|
+
expect(result.current.data?.name).toBeDefined()
|
|
129
|
+
expect(result.current.data?.symbol).toBeDefined()
|
|
130
|
+
expect(result.current.data?.decimals).toBeDefined()
|
|
131
|
+
})
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
describe('useGetRoleAdmin', () => {
|
|
135
|
+
test('default', async () => {
|
|
136
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
137
|
+
connect: useConnect(),
|
|
138
|
+
createSync: hooks.useCreateSync(),
|
|
139
|
+
}))
|
|
140
|
+
|
|
141
|
+
await connectResult.current.connect.connectAsync({
|
|
142
|
+
connector: config.connectors[0]!,
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
// Create a token where we're the admin
|
|
146
|
+
const createData = await connectResult.current.createSync.mutateAsync({
|
|
147
|
+
currency: 'USD',
|
|
148
|
+
name: 'GetRoleAdmin Hook Test',
|
|
149
|
+
symbol: 'GRAHTEST',
|
|
150
|
+
})
|
|
151
|
+
|
|
152
|
+
const { result } = await renderHook(() =>
|
|
153
|
+
hooks.useGetRoleAdmin({
|
|
154
|
+
token: createData.token,
|
|
155
|
+
role: 'issuer',
|
|
156
|
+
}),
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
160
|
+
|
|
161
|
+
expect(result.current.data).toBeDefined()
|
|
162
|
+
expect(typeof result.current.data).toBe('string')
|
|
163
|
+
})
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
describe('useHasRole', () => {
|
|
167
|
+
test('default', async () => {
|
|
168
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
169
|
+
connect: useConnect(),
|
|
170
|
+
createSync: hooks.useCreateSync(),
|
|
171
|
+
}))
|
|
172
|
+
|
|
173
|
+
await connectResult.current.connect.connectAsync({
|
|
174
|
+
connector: config.connectors[0]!,
|
|
175
|
+
})
|
|
176
|
+
|
|
177
|
+
// Create a token where we're the admin
|
|
178
|
+
const createData = await connectResult.current.createSync.mutateAsync({
|
|
179
|
+
currency: 'USD',
|
|
180
|
+
name: 'HasRole Hook Test',
|
|
181
|
+
symbol: 'HRHTEST',
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
const { result } = await renderHook(() =>
|
|
185
|
+
hooks.useHasRole({
|
|
186
|
+
account: account.address,
|
|
187
|
+
token: createData.token,
|
|
188
|
+
role: 'defaultAdmin',
|
|
189
|
+
}),
|
|
190
|
+
)
|
|
191
|
+
|
|
192
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
193
|
+
|
|
194
|
+
expect(result.current.data).toBe(true)
|
|
195
|
+
})
|
|
196
|
+
|
|
197
|
+
test('reactivity: account parameter', async () => {
|
|
198
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
199
|
+
connect: useConnect(),
|
|
200
|
+
createSync: hooks.useCreateSync(),
|
|
201
|
+
}))
|
|
202
|
+
|
|
203
|
+
await connectResult.current.connect.connectAsync({
|
|
204
|
+
connector: config.connectors[0]!,
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
// Create a token where we're the admin
|
|
208
|
+
const createData = await connectResult.current.createSync.mutateAsync({
|
|
209
|
+
currency: 'USD',
|
|
210
|
+
name: 'HasRole Hook Reactivity Test',
|
|
211
|
+
symbol: 'HRHRTEST',
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
let accountAddress: Address | undefined
|
|
215
|
+
|
|
216
|
+
const { result, rerender } = await renderHook(() =>
|
|
217
|
+
hooks.useHasRole({
|
|
218
|
+
account: accountAddress,
|
|
219
|
+
token: createData.token,
|
|
220
|
+
role: 'defaultAdmin',
|
|
221
|
+
}),
|
|
222
|
+
)
|
|
223
|
+
|
|
224
|
+
await vi.waitFor(() => result.current.fetchStatus === 'fetching')
|
|
225
|
+
|
|
226
|
+
// Should be disabled when account is undefined
|
|
227
|
+
expect(result.current.data).toBeUndefined()
|
|
228
|
+
expect(result.current.isPending).toBe(true)
|
|
229
|
+
expect(result.current.isEnabled).toBe(false)
|
|
230
|
+
|
|
231
|
+
// Set account
|
|
232
|
+
accountAddress = account.address
|
|
233
|
+
rerender()
|
|
234
|
+
|
|
235
|
+
await vi.waitFor(() => expect(result.current.isSuccess).toBeTruthy())
|
|
236
|
+
|
|
237
|
+
// Should now be enabled and have data
|
|
238
|
+
expect(result.current.isEnabled).toBe(true)
|
|
239
|
+
expect(result.current.data).toBe(true)
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
describe('useApprove', () => {
|
|
244
|
+
test('default', async () => {
|
|
245
|
+
const { result } = await renderHook(() => ({
|
|
246
|
+
connect: useConnect(),
|
|
247
|
+
approve: hooks.useApprove(),
|
|
248
|
+
}))
|
|
249
|
+
|
|
250
|
+
await result.current.connect.connectAsync({
|
|
251
|
+
connector: config.connectors[0]!,
|
|
252
|
+
})
|
|
253
|
+
|
|
254
|
+
const hash = await result.current.approve.mutateAsync({
|
|
255
|
+
spender: account2.address,
|
|
256
|
+
amount: parseUnits('100', 6),
|
|
257
|
+
token: addresses.alphaUsd,
|
|
258
|
+
})
|
|
259
|
+
expect(hash).toBeDefined()
|
|
260
|
+
|
|
261
|
+
await vi.waitFor(() =>
|
|
262
|
+
expect(result.current.approve.isSuccess).toBeTruthy(),
|
|
263
|
+
)
|
|
264
|
+
})
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
describe('useApproveSync', () => {
|
|
268
|
+
test('default', async () => {
|
|
269
|
+
const { result } = await renderHook(() => ({
|
|
270
|
+
connect: useConnect(),
|
|
271
|
+
approve: hooks.useApproveSync(),
|
|
272
|
+
}))
|
|
273
|
+
|
|
274
|
+
await result.current.connect.connectAsync({
|
|
275
|
+
connector: config.connectors[0]!,
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
const data = await result.current.approve.mutateAsync({
|
|
279
|
+
spender: account2.address,
|
|
280
|
+
amount: parseUnits('100', 6),
|
|
281
|
+
token: addresses.alphaUsd,
|
|
282
|
+
})
|
|
283
|
+
expect(data).toBeDefined()
|
|
284
|
+
expect(data.receipt).toBeDefined()
|
|
285
|
+
|
|
286
|
+
await vi.waitFor(() =>
|
|
287
|
+
expect(result.current.approve.isSuccess).toBeTruthy(),
|
|
288
|
+
)
|
|
289
|
+
})
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
describe('useBurn', () => {
|
|
293
|
+
test('default', async () => {
|
|
294
|
+
const { result } = await renderHook(() => ({
|
|
295
|
+
connect: useConnect(),
|
|
296
|
+
createSync: hooks.useCreateSync(),
|
|
297
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
298
|
+
mintSync: hooks.useMintSync(),
|
|
299
|
+
burn: hooks.useBurn(),
|
|
300
|
+
}))
|
|
301
|
+
|
|
302
|
+
await result.current.connect.connectAsync({
|
|
303
|
+
connector: config.connectors[0]!,
|
|
304
|
+
})
|
|
305
|
+
|
|
306
|
+
// Create a new token
|
|
307
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
308
|
+
currency: 'USD',
|
|
309
|
+
name: 'Burnable Hook Token',
|
|
310
|
+
symbol: 'BURNHOOK',
|
|
311
|
+
})
|
|
312
|
+
|
|
313
|
+
// Grant issuer role
|
|
314
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
315
|
+
token: tokenAddr,
|
|
316
|
+
roles: ['issuer'],
|
|
317
|
+
to: account.address,
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
// Mint some tokens
|
|
321
|
+
await result.current.mintSync.mutateAsync({
|
|
322
|
+
token: tokenAddr,
|
|
323
|
+
to: account.address,
|
|
324
|
+
amount: parseUnits('1000', 6),
|
|
325
|
+
})
|
|
326
|
+
|
|
327
|
+
const hash = await result.current.burn.mutateAsync({
|
|
328
|
+
token: tokenAddr,
|
|
329
|
+
amount: parseUnits('1', 6),
|
|
330
|
+
})
|
|
331
|
+
expect(hash).toBeDefined()
|
|
332
|
+
|
|
333
|
+
await vi.waitFor(() => expect(result.current.burn.isSuccess).toBeTruthy())
|
|
334
|
+
})
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
describe('useBurnSync', () => {
|
|
338
|
+
test('default', async () => {
|
|
339
|
+
const { result } = await renderHook(() => ({
|
|
340
|
+
connect: useConnect(),
|
|
341
|
+
createSync: hooks.useCreateSync(),
|
|
342
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
343
|
+
mintSync: hooks.useMintSync(),
|
|
344
|
+
burn: hooks.useBurnSync(),
|
|
345
|
+
}))
|
|
346
|
+
|
|
347
|
+
await result.current.connect.connectAsync({
|
|
348
|
+
connector: config.connectors[0]!,
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
// Create a new token
|
|
352
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
353
|
+
currency: 'USD',
|
|
354
|
+
name: 'Burnable Hook Token Sync',
|
|
355
|
+
symbol: 'BURNHOOKSYNC',
|
|
356
|
+
})
|
|
357
|
+
|
|
358
|
+
// Grant issuer role
|
|
359
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
360
|
+
token: tokenAddr,
|
|
361
|
+
roles: ['issuer'],
|
|
362
|
+
to: account.address,
|
|
363
|
+
})
|
|
364
|
+
|
|
365
|
+
// Mint some tokens
|
|
366
|
+
await result.current.mintSync.mutateAsync({
|
|
367
|
+
token: tokenAddr,
|
|
368
|
+
to: account.address,
|
|
369
|
+
amount: parseUnits('1000', 6),
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
const data = await result.current.burn.mutateAsync({
|
|
373
|
+
token: tokenAddr,
|
|
374
|
+
amount: parseUnits('1', 6),
|
|
375
|
+
})
|
|
376
|
+
expect(data).toBeDefined()
|
|
377
|
+
expect(data.receipt).toBeDefined()
|
|
378
|
+
|
|
379
|
+
await vi.waitFor(() => expect(result.current.burn.isSuccess).toBeTruthy())
|
|
380
|
+
})
|
|
381
|
+
})
|
|
382
|
+
|
|
383
|
+
describe('useChangeTransferPolicy', () => {
|
|
384
|
+
test('default', async () => {
|
|
385
|
+
const { result } = await renderHook(() => ({
|
|
386
|
+
connect: useConnect(),
|
|
387
|
+
createSync: hooks.useCreateSync(),
|
|
388
|
+
changeTransferPolicy: hooks.useChangeTransferPolicy(),
|
|
389
|
+
}))
|
|
390
|
+
|
|
391
|
+
await result.current.connect.connectAsync({
|
|
392
|
+
connector: config.connectors[0]!,
|
|
393
|
+
})
|
|
394
|
+
|
|
395
|
+
// Create a new token
|
|
396
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
397
|
+
currency: 'USD',
|
|
398
|
+
name: 'Policy Hook Token',
|
|
399
|
+
symbol: 'POLICYHOOK',
|
|
400
|
+
})
|
|
401
|
+
|
|
402
|
+
const hash = await result.current.changeTransferPolicy.mutateAsync({
|
|
403
|
+
token: tokenAddr,
|
|
404
|
+
policyId: 0n,
|
|
405
|
+
})
|
|
406
|
+
expect(hash).toBeDefined()
|
|
407
|
+
|
|
408
|
+
await vi.waitFor(() =>
|
|
409
|
+
expect(result.current.changeTransferPolicy.isSuccess).toBeTruthy(),
|
|
410
|
+
)
|
|
411
|
+
})
|
|
412
|
+
})
|
|
413
|
+
|
|
414
|
+
describe('useChangeTransferPolicySync', () => {
|
|
415
|
+
test('default', async () => {
|
|
416
|
+
const { result } = await renderHook(() => ({
|
|
417
|
+
connect: useConnect(),
|
|
418
|
+
createSync: hooks.useCreateSync(),
|
|
419
|
+
changeTransferPolicy: hooks.useChangeTransferPolicySync(),
|
|
420
|
+
}))
|
|
421
|
+
|
|
422
|
+
await result.current.connect.connectAsync({
|
|
423
|
+
connector: config.connectors[0]!,
|
|
424
|
+
})
|
|
425
|
+
|
|
426
|
+
// Create a new token
|
|
427
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
428
|
+
currency: 'USD',
|
|
429
|
+
name: 'Policy Hook Token Sync',
|
|
430
|
+
symbol: 'POLICYHOOKSYNC',
|
|
431
|
+
})
|
|
432
|
+
|
|
433
|
+
const data = await result.current.changeTransferPolicy.mutateAsync({
|
|
434
|
+
token: tokenAddr,
|
|
435
|
+
policyId: 0n,
|
|
436
|
+
})
|
|
437
|
+
expect(data).toBeDefined()
|
|
438
|
+
expect(data.receipt).toBeDefined()
|
|
439
|
+
|
|
440
|
+
await vi.waitFor(() =>
|
|
441
|
+
expect(result.current.changeTransferPolicy.isSuccess).toBeTruthy(),
|
|
442
|
+
)
|
|
443
|
+
})
|
|
444
|
+
})
|
|
445
|
+
|
|
446
|
+
describe('useCreate', () => {
|
|
447
|
+
test('default', async () => {
|
|
448
|
+
const { result } = await renderHook(() => ({
|
|
449
|
+
connect: useConnect(),
|
|
450
|
+
create: hooks.useCreate(),
|
|
451
|
+
}))
|
|
452
|
+
|
|
453
|
+
await result.current.connect.connectAsync({
|
|
454
|
+
connector: config.connectors[0]!,
|
|
455
|
+
})
|
|
456
|
+
|
|
457
|
+
const hash = await result.current.create.mutateAsync({
|
|
458
|
+
name: 'Hook Test Token',
|
|
459
|
+
symbol: 'HOOKTEST',
|
|
460
|
+
currency: 'USD',
|
|
461
|
+
})
|
|
462
|
+
expect(hash).toBeDefined()
|
|
463
|
+
|
|
464
|
+
await vi.waitFor(() => expect(result.current.create.isSuccess).toBeTruthy())
|
|
465
|
+
})
|
|
466
|
+
})
|
|
467
|
+
|
|
468
|
+
describe('useCreateSync', () => {
|
|
469
|
+
test('default', async () => {
|
|
470
|
+
const { result } = await renderHook(() => ({
|
|
471
|
+
connect: useConnect(),
|
|
472
|
+
create: hooks.useCreateSync(),
|
|
473
|
+
}))
|
|
474
|
+
|
|
475
|
+
await result.current.connect.connectAsync({
|
|
476
|
+
connector: config.connectors[0]!,
|
|
477
|
+
})
|
|
478
|
+
|
|
479
|
+
const data = await result.current.create.mutateAsync({
|
|
480
|
+
name: 'Hook Test Token Sync',
|
|
481
|
+
symbol: 'HOOKTESTSYNC',
|
|
482
|
+
currency: 'USD',
|
|
483
|
+
})
|
|
484
|
+
expect(data).toBeDefined()
|
|
485
|
+
expect(data.receipt).toBeDefined()
|
|
486
|
+
expect(data.token).toBeDefined()
|
|
487
|
+
expect(data.name).toBe('Hook Test Token Sync')
|
|
488
|
+
|
|
489
|
+
await vi.waitFor(() => expect(result.current.create.isSuccess).toBeTruthy())
|
|
490
|
+
})
|
|
491
|
+
})
|
|
492
|
+
|
|
493
|
+
describe('useUpdateQuoteToken', () => {
|
|
494
|
+
test('default', async () => {
|
|
495
|
+
const { result } = await renderHook(() => ({
|
|
496
|
+
connect: useConnect(),
|
|
497
|
+
createSync: hooks.useCreateSync(),
|
|
498
|
+
prepareUpdateQuoteTokenSync: hooks.usePrepareUpdateQuoteTokenSync(),
|
|
499
|
+
updateQuoteToken: hooks.useUpdateQuoteToken(),
|
|
500
|
+
}))
|
|
501
|
+
|
|
502
|
+
await result.current.connect.connectAsync({
|
|
503
|
+
connector: config.connectors[0]!,
|
|
504
|
+
})
|
|
505
|
+
|
|
506
|
+
// Create quote token
|
|
507
|
+
const { token: quoteToken } = await result.current.createSync.mutateAsync({
|
|
508
|
+
currency: 'USD',
|
|
509
|
+
name: 'Finalize Quote Hook',
|
|
510
|
+
symbol: 'FQHOOK',
|
|
511
|
+
})
|
|
512
|
+
|
|
513
|
+
// Create main token
|
|
514
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
515
|
+
currency: 'USD',
|
|
516
|
+
name: 'Finalize Main Hook',
|
|
517
|
+
symbol: 'FMHOOK',
|
|
518
|
+
})
|
|
519
|
+
|
|
520
|
+
// Prepare quote token update first
|
|
521
|
+
await result.current.prepareUpdateQuoteTokenSync.mutateAsync({
|
|
522
|
+
token: tokenAddr,
|
|
523
|
+
quoteToken,
|
|
524
|
+
})
|
|
525
|
+
|
|
526
|
+
const hash = await result.current.updateQuoteToken.mutateAsync({
|
|
527
|
+
token: tokenAddr,
|
|
528
|
+
})
|
|
529
|
+
expect(hash).toBeDefined()
|
|
530
|
+
|
|
531
|
+
await vi.waitFor(() =>
|
|
532
|
+
expect(result.current.updateQuoteToken.isSuccess).toBeTruthy(),
|
|
533
|
+
)
|
|
534
|
+
})
|
|
535
|
+
})
|
|
536
|
+
|
|
537
|
+
describe('useUpdateQuoteTokenSync', () => {
|
|
538
|
+
test('default', async () => {
|
|
539
|
+
const { result } = await renderHook(() => ({
|
|
540
|
+
connect: useConnect(),
|
|
541
|
+
createSync: hooks.useCreateSync(),
|
|
542
|
+
prepareUpdateQuoteTokenSync: hooks.usePrepareUpdateQuoteTokenSync(),
|
|
543
|
+
updateQuoteToken: hooks.useUpdateQuoteTokenSync(),
|
|
544
|
+
}))
|
|
545
|
+
|
|
546
|
+
await result.current.connect.connectAsync({
|
|
547
|
+
connector: config.connectors[0]!,
|
|
548
|
+
})
|
|
549
|
+
|
|
550
|
+
// Create quote token
|
|
551
|
+
const { token: quoteToken } = await result.current.createSync.mutateAsync({
|
|
552
|
+
currency: 'USD',
|
|
553
|
+
name: 'Finalize Quote Hook Sync',
|
|
554
|
+
symbol: 'FQHOOKSYNC',
|
|
555
|
+
})
|
|
556
|
+
|
|
557
|
+
// Create main token
|
|
558
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
559
|
+
currency: 'USD',
|
|
560
|
+
name: 'Finalize Main Hook Sync',
|
|
561
|
+
symbol: 'FMHOOKSYNC',
|
|
562
|
+
})
|
|
563
|
+
|
|
564
|
+
// Prepare quote token update first
|
|
565
|
+
await result.current.prepareUpdateQuoteTokenSync.mutateAsync({
|
|
566
|
+
token: tokenAddr,
|
|
567
|
+
quoteToken,
|
|
568
|
+
})
|
|
569
|
+
|
|
570
|
+
const data = await result.current.updateQuoteToken.mutateAsync({
|
|
571
|
+
token: tokenAddr,
|
|
572
|
+
})
|
|
573
|
+
expect(data).toBeDefined()
|
|
574
|
+
expect(data.receipt).toBeDefined()
|
|
575
|
+
|
|
576
|
+
await vi.waitFor(() =>
|
|
577
|
+
expect(result.current.updateQuoteToken.isSuccess).toBeTruthy(),
|
|
578
|
+
)
|
|
579
|
+
})
|
|
580
|
+
})
|
|
581
|
+
|
|
582
|
+
describe('useGrantRoles', () => {
|
|
583
|
+
test('default', async () => {
|
|
584
|
+
const { result } = await renderHook(() => ({
|
|
585
|
+
connect: useConnect(),
|
|
586
|
+
createSync: hooks.useCreateSync(),
|
|
587
|
+
grantRoles: hooks.useGrantRoles(),
|
|
588
|
+
}))
|
|
589
|
+
|
|
590
|
+
await result.current.connect.connectAsync({
|
|
591
|
+
connector: config.connectors[0]!,
|
|
592
|
+
})
|
|
593
|
+
|
|
594
|
+
// Create a new token
|
|
595
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
596
|
+
currency: 'USD',
|
|
597
|
+
name: 'Grant Hook Token',
|
|
598
|
+
symbol: 'GRANTHOOK',
|
|
599
|
+
})
|
|
600
|
+
|
|
601
|
+
const hash = await result.current.grantRoles.mutateAsync({
|
|
602
|
+
token: tokenAddr,
|
|
603
|
+
roles: ['issuer'],
|
|
604
|
+
to: account2.address,
|
|
605
|
+
})
|
|
606
|
+
expect(hash).toBeDefined()
|
|
607
|
+
|
|
608
|
+
await vi.waitFor(() =>
|
|
609
|
+
expect(result.current.grantRoles.isSuccess).toBeTruthy(),
|
|
610
|
+
)
|
|
611
|
+
})
|
|
612
|
+
})
|
|
613
|
+
|
|
614
|
+
describe('useGrantRolesSync', () => {
|
|
615
|
+
test('default', async () => {
|
|
616
|
+
const { result } = await renderHook(() => ({
|
|
617
|
+
connect: useConnect(),
|
|
618
|
+
createSync: hooks.useCreateSync(),
|
|
619
|
+
grantRoles: hooks.useGrantRolesSync(),
|
|
620
|
+
}))
|
|
621
|
+
|
|
622
|
+
await result.current.connect.connectAsync({
|
|
623
|
+
connector: config.connectors[0]!,
|
|
624
|
+
})
|
|
625
|
+
|
|
626
|
+
// Create a new token
|
|
627
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
628
|
+
currency: 'USD',
|
|
629
|
+
name: 'Grant Hook Token Sync',
|
|
630
|
+
symbol: 'GRANTHOOKSYNC',
|
|
631
|
+
})
|
|
632
|
+
|
|
633
|
+
const data = await result.current.grantRoles.mutateAsync({
|
|
634
|
+
token: tokenAddr,
|
|
635
|
+
roles: ['issuer'],
|
|
636
|
+
to: account2.address,
|
|
637
|
+
})
|
|
638
|
+
expect(data).toBeDefined()
|
|
639
|
+
expect(data.receipt).toBeDefined()
|
|
640
|
+
expect(data.value).toBeDefined()
|
|
641
|
+
|
|
642
|
+
await vi.waitFor(() =>
|
|
643
|
+
expect(result.current.grantRoles.isSuccess).toBeTruthy(),
|
|
644
|
+
)
|
|
645
|
+
})
|
|
646
|
+
})
|
|
647
|
+
|
|
648
|
+
describe('useMint', () => {
|
|
649
|
+
test('default', async () => {
|
|
650
|
+
const { result } = await renderHook(() => ({
|
|
651
|
+
connect: useConnect(),
|
|
652
|
+
createSync: hooks.useCreateSync(),
|
|
653
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
654
|
+
mint: hooks.useMint(),
|
|
655
|
+
}))
|
|
656
|
+
|
|
657
|
+
await result.current.connect.connectAsync({
|
|
658
|
+
connector: config.connectors[0]!,
|
|
659
|
+
})
|
|
660
|
+
|
|
661
|
+
// Create a new token
|
|
662
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
663
|
+
currency: 'USD',
|
|
664
|
+
name: 'Mint Hook Token',
|
|
665
|
+
symbol: 'MINTHOOK',
|
|
666
|
+
})
|
|
667
|
+
|
|
668
|
+
// Grant issuer role
|
|
669
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
670
|
+
token: tokenAddr,
|
|
671
|
+
roles: ['issuer'],
|
|
672
|
+
to: account.address,
|
|
673
|
+
})
|
|
674
|
+
|
|
675
|
+
const hash = await result.current.mint.mutateAsync({
|
|
676
|
+
token: tokenAddr,
|
|
677
|
+
to: account.address,
|
|
678
|
+
amount: parseUnits('100', 6),
|
|
679
|
+
})
|
|
680
|
+
expect(hash).toBeDefined()
|
|
681
|
+
|
|
682
|
+
await vi.waitFor(() => expect(result.current.mint.isSuccess).toBeTruthy())
|
|
683
|
+
})
|
|
684
|
+
})
|
|
685
|
+
|
|
686
|
+
describe('useMintSync', () => {
|
|
687
|
+
test('default', async () => {
|
|
688
|
+
const { result } = await renderHook(() => ({
|
|
689
|
+
connect: useConnect(),
|
|
690
|
+
createSync: hooks.useCreateSync(),
|
|
691
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
692
|
+
mint: hooks.useMintSync(),
|
|
693
|
+
}))
|
|
694
|
+
|
|
695
|
+
await result.current.connect.connectAsync({
|
|
696
|
+
connector: config.connectors[0]!,
|
|
697
|
+
})
|
|
698
|
+
|
|
699
|
+
// Create a new token
|
|
700
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
701
|
+
currency: 'USD',
|
|
702
|
+
name: 'Mint Hook Token Sync',
|
|
703
|
+
symbol: 'MINTHOOKSYNC',
|
|
704
|
+
})
|
|
705
|
+
|
|
706
|
+
// Grant issuer role
|
|
707
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
708
|
+
token: tokenAddr,
|
|
709
|
+
roles: ['issuer'],
|
|
710
|
+
to: account.address,
|
|
711
|
+
})
|
|
712
|
+
|
|
713
|
+
const data = await result.current.mint.mutateAsync({
|
|
714
|
+
token: tokenAddr,
|
|
715
|
+
to: account.address,
|
|
716
|
+
amount: parseUnits('100', 6),
|
|
717
|
+
})
|
|
718
|
+
expect(data).toBeDefined()
|
|
719
|
+
expect(data.receipt).toBeDefined()
|
|
720
|
+
|
|
721
|
+
await vi.waitFor(() => expect(result.current.mint.isSuccess).toBeTruthy())
|
|
722
|
+
})
|
|
723
|
+
})
|
|
724
|
+
|
|
725
|
+
describe('usePause', () => {
|
|
726
|
+
test('default', async () => {
|
|
727
|
+
const { result } = await renderHook(() => ({
|
|
728
|
+
connect: useConnect(),
|
|
729
|
+
createSync: hooks.useCreateSync(),
|
|
730
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
731
|
+
pause: hooks.usePause(),
|
|
732
|
+
}))
|
|
733
|
+
|
|
734
|
+
await result.current.connect.connectAsync({
|
|
735
|
+
connector: config.connectors[0]!,
|
|
736
|
+
})
|
|
737
|
+
|
|
738
|
+
// Create a new token
|
|
739
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
740
|
+
currency: 'USD',
|
|
741
|
+
name: 'Pause Hook Token',
|
|
742
|
+
symbol: 'PAUSEHOOK',
|
|
743
|
+
})
|
|
744
|
+
|
|
745
|
+
// Grant pause role
|
|
746
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
747
|
+
token: tokenAddr,
|
|
748
|
+
roles: ['pause'],
|
|
749
|
+
to: account.address,
|
|
750
|
+
})
|
|
751
|
+
|
|
752
|
+
const hash = await result.current.pause.mutateAsync({
|
|
753
|
+
token: tokenAddr,
|
|
754
|
+
})
|
|
755
|
+
expect(hash).toBeDefined()
|
|
756
|
+
|
|
757
|
+
await vi.waitFor(() => expect(result.current.pause.isSuccess).toBeTruthy())
|
|
758
|
+
})
|
|
759
|
+
})
|
|
760
|
+
|
|
761
|
+
describe('usePauseSync', () => {
|
|
762
|
+
test('default', async () => {
|
|
763
|
+
const { result } = await renderHook(() => ({
|
|
764
|
+
connect: useConnect(),
|
|
765
|
+
createSync: hooks.useCreateSync(),
|
|
766
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
767
|
+
pause: hooks.usePauseSync(),
|
|
768
|
+
}))
|
|
769
|
+
|
|
770
|
+
await result.current.connect.connectAsync({
|
|
771
|
+
connector: config.connectors[0]!,
|
|
772
|
+
})
|
|
773
|
+
|
|
774
|
+
// Create a new token
|
|
775
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
776
|
+
currency: 'USD',
|
|
777
|
+
name: 'Pause Hook Token Sync',
|
|
778
|
+
symbol: 'PAUSEHOOKSYNC',
|
|
779
|
+
})
|
|
780
|
+
|
|
781
|
+
// Grant pause role
|
|
782
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
783
|
+
token: tokenAddr,
|
|
784
|
+
roles: ['pause'],
|
|
785
|
+
to: account.address,
|
|
786
|
+
})
|
|
787
|
+
|
|
788
|
+
const data = await result.current.pause.mutateAsync({
|
|
789
|
+
token: tokenAddr,
|
|
790
|
+
})
|
|
791
|
+
expect(data).toBeDefined()
|
|
792
|
+
expect(data.receipt).toBeDefined()
|
|
793
|
+
|
|
794
|
+
await vi.waitFor(() => expect(result.current.pause.isSuccess).toBeTruthy())
|
|
795
|
+
})
|
|
796
|
+
})
|
|
797
|
+
|
|
798
|
+
describe('useRenounceRoles', () => {
|
|
799
|
+
test('default', async () => {
|
|
800
|
+
const { result } = await renderHook(() => ({
|
|
801
|
+
connect: useConnect(),
|
|
802
|
+
createSync: hooks.useCreateSync(),
|
|
803
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
804
|
+
renounceRoles: hooks.useRenounceRoles(),
|
|
805
|
+
}))
|
|
806
|
+
|
|
807
|
+
await result.current.connect.connectAsync({
|
|
808
|
+
connector: config.connectors[0]!,
|
|
809
|
+
})
|
|
810
|
+
|
|
811
|
+
// Create a new token
|
|
812
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
813
|
+
currency: 'USD',
|
|
814
|
+
name: 'Renounce Hook Token',
|
|
815
|
+
symbol: 'RENOUNCEHOOK',
|
|
816
|
+
})
|
|
817
|
+
|
|
818
|
+
// Grant issuer role to ourselves
|
|
819
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
820
|
+
token: tokenAddr,
|
|
821
|
+
roles: ['issuer'],
|
|
822
|
+
to: account.address,
|
|
823
|
+
})
|
|
824
|
+
|
|
825
|
+
const hash = await result.current.renounceRoles.mutateAsync({
|
|
826
|
+
token: tokenAddr,
|
|
827
|
+
roles: ['issuer'],
|
|
828
|
+
})
|
|
829
|
+
expect(hash).toBeDefined()
|
|
830
|
+
|
|
831
|
+
await vi.waitFor(() =>
|
|
832
|
+
expect(result.current.renounceRoles.isSuccess).toBeTruthy(),
|
|
833
|
+
)
|
|
834
|
+
})
|
|
835
|
+
})
|
|
836
|
+
|
|
837
|
+
describe('useRenounceRolesSync', () => {
|
|
838
|
+
test('default', async () => {
|
|
839
|
+
const { result } = await renderHook(() => ({
|
|
840
|
+
connect: useConnect(),
|
|
841
|
+
createSync: hooks.useCreateSync(),
|
|
842
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
843
|
+
renounceRoles: hooks.useRenounceRolesSync(),
|
|
844
|
+
}))
|
|
845
|
+
|
|
846
|
+
await result.current.connect.connectAsync({
|
|
847
|
+
connector: config.connectors[0]!,
|
|
848
|
+
})
|
|
849
|
+
|
|
850
|
+
// Create a new token
|
|
851
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
852
|
+
currency: 'USD',
|
|
853
|
+
name: 'Renounce Hook Token Sync',
|
|
854
|
+
symbol: 'RENOUNCEHOOKSYNC',
|
|
855
|
+
})
|
|
856
|
+
|
|
857
|
+
// Grant issuer role to ourselves
|
|
858
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
859
|
+
token: tokenAddr,
|
|
860
|
+
roles: ['issuer'],
|
|
861
|
+
to: account.address,
|
|
862
|
+
})
|
|
863
|
+
|
|
864
|
+
const data = await result.current.renounceRoles.mutateAsync({
|
|
865
|
+
token: tokenAddr,
|
|
866
|
+
roles: ['issuer'],
|
|
867
|
+
})
|
|
868
|
+
expect(data).toBeDefined()
|
|
869
|
+
expect(data.receipt).toBeDefined()
|
|
870
|
+
expect(data.value).toBeDefined()
|
|
871
|
+
|
|
872
|
+
await vi.waitFor(() =>
|
|
873
|
+
expect(result.current.renounceRoles.isSuccess).toBeTruthy(),
|
|
874
|
+
)
|
|
875
|
+
})
|
|
876
|
+
})
|
|
877
|
+
|
|
878
|
+
describe('useRevokeRoles', () => {
|
|
879
|
+
test('default', async () => {
|
|
880
|
+
const { result } = await renderHook(() => ({
|
|
881
|
+
connect: useConnect(),
|
|
882
|
+
createSync: hooks.useCreateSync(),
|
|
883
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
884
|
+
revokeRoles: hooks.useRevokeRoles(),
|
|
885
|
+
}))
|
|
886
|
+
|
|
887
|
+
await result.current.connect.connectAsync({
|
|
888
|
+
connector: config.connectors[0]!,
|
|
889
|
+
})
|
|
890
|
+
|
|
891
|
+
// Create a new token
|
|
892
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
893
|
+
currency: 'USD',
|
|
894
|
+
name: 'Revoke Hook Token',
|
|
895
|
+
symbol: 'REVOKEHOOK',
|
|
896
|
+
})
|
|
897
|
+
|
|
898
|
+
// Grant issuer role to account2
|
|
899
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
900
|
+
token: tokenAddr,
|
|
901
|
+
roles: ['issuer'],
|
|
902
|
+
to: account2.address,
|
|
903
|
+
})
|
|
904
|
+
|
|
905
|
+
const hash = await result.current.revokeRoles.mutateAsync({
|
|
906
|
+
token: tokenAddr,
|
|
907
|
+
roles: ['issuer'],
|
|
908
|
+
from: account2.address,
|
|
909
|
+
})
|
|
910
|
+
expect(hash).toBeDefined()
|
|
911
|
+
|
|
912
|
+
await vi.waitFor(() =>
|
|
913
|
+
expect(result.current.revokeRoles.isSuccess).toBeTruthy(),
|
|
914
|
+
)
|
|
915
|
+
})
|
|
916
|
+
})
|
|
917
|
+
|
|
918
|
+
describe('useRevokeRolesSync', () => {
|
|
919
|
+
test('default', async () => {
|
|
920
|
+
const { result } = await renderHook(() => ({
|
|
921
|
+
connect: useConnect(),
|
|
922
|
+
createSync: hooks.useCreateSync(),
|
|
923
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
924
|
+
revokeRoles: hooks.useRevokeRolesSync(),
|
|
925
|
+
}))
|
|
926
|
+
|
|
927
|
+
await result.current.connect.connectAsync({
|
|
928
|
+
connector: config.connectors[0]!,
|
|
929
|
+
})
|
|
930
|
+
|
|
931
|
+
// Create a new token
|
|
932
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
933
|
+
currency: 'USD',
|
|
934
|
+
name: 'Revoke Hook Token Sync',
|
|
935
|
+
symbol: 'REVOKEHOOKSYNC',
|
|
936
|
+
})
|
|
937
|
+
|
|
938
|
+
// Grant issuer role to account2
|
|
939
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
940
|
+
token: tokenAddr,
|
|
941
|
+
roles: ['issuer'],
|
|
942
|
+
to: account2.address,
|
|
943
|
+
})
|
|
944
|
+
|
|
945
|
+
const data = await result.current.revokeRoles.mutateAsync({
|
|
946
|
+
token: tokenAddr,
|
|
947
|
+
roles: ['issuer'],
|
|
948
|
+
from: account2.address,
|
|
949
|
+
})
|
|
950
|
+
expect(data).toBeDefined()
|
|
951
|
+
expect(data.receipt).toBeDefined()
|
|
952
|
+
expect(data.value).toBeDefined()
|
|
953
|
+
|
|
954
|
+
await vi.waitFor(() =>
|
|
955
|
+
expect(result.current.revokeRoles.isSuccess).toBeTruthy(),
|
|
956
|
+
)
|
|
957
|
+
})
|
|
958
|
+
})
|
|
959
|
+
|
|
960
|
+
describe('useSetRoleAdmin', () => {
|
|
961
|
+
test('default', async () => {
|
|
962
|
+
const { result } = await renderHook(() => ({
|
|
963
|
+
connect: useConnect(),
|
|
964
|
+
createSync: hooks.useCreateSync(),
|
|
965
|
+
setRoleAdmin: hooks.useSetRoleAdmin(),
|
|
966
|
+
}))
|
|
967
|
+
|
|
968
|
+
await result.current.connect.connectAsync({
|
|
969
|
+
connector: config.connectors[0]!,
|
|
970
|
+
})
|
|
971
|
+
|
|
972
|
+
// Create a new token
|
|
973
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
974
|
+
currency: 'USD',
|
|
975
|
+
name: 'Role Admin Hook Token',
|
|
976
|
+
symbol: 'ROLEADMINHOOK',
|
|
977
|
+
})
|
|
978
|
+
|
|
979
|
+
const hash = await result.current.setRoleAdmin.mutateAsync({
|
|
980
|
+
token: tokenAddr,
|
|
981
|
+
role: 'issuer',
|
|
982
|
+
adminRole: 'pause',
|
|
983
|
+
})
|
|
984
|
+
expect(hash).toBeDefined()
|
|
985
|
+
|
|
986
|
+
await vi.waitFor(() =>
|
|
987
|
+
expect(result.current.setRoleAdmin.isSuccess).toBeTruthy(),
|
|
988
|
+
)
|
|
989
|
+
})
|
|
990
|
+
})
|
|
991
|
+
|
|
992
|
+
describe('useSetRoleAdminSync', () => {
|
|
993
|
+
test('default', async () => {
|
|
994
|
+
const { result } = await renderHook(() => ({
|
|
995
|
+
connect: useConnect(),
|
|
996
|
+
createSync: hooks.useCreateSync(),
|
|
997
|
+
setRoleAdmin: hooks.useSetRoleAdminSync(),
|
|
998
|
+
}))
|
|
999
|
+
|
|
1000
|
+
await result.current.connect.connectAsync({
|
|
1001
|
+
connector: config.connectors[0]!,
|
|
1002
|
+
})
|
|
1003
|
+
|
|
1004
|
+
// Create a new token
|
|
1005
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
1006
|
+
currency: 'USD',
|
|
1007
|
+
name: 'Role Admin Hook Token Sync',
|
|
1008
|
+
symbol: 'ROLEADMINHOOKSYNC',
|
|
1009
|
+
})
|
|
1010
|
+
|
|
1011
|
+
const data = await result.current.setRoleAdmin.mutateAsync({
|
|
1012
|
+
token: tokenAddr,
|
|
1013
|
+
role: 'issuer',
|
|
1014
|
+
adminRole: 'pause',
|
|
1015
|
+
})
|
|
1016
|
+
expect(data).toBeDefined()
|
|
1017
|
+
expect(data.receipt).toBeDefined()
|
|
1018
|
+
|
|
1019
|
+
await vi.waitFor(() =>
|
|
1020
|
+
expect(result.current.setRoleAdmin.isSuccess).toBeTruthy(),
|
|
1021
|
+
)
|
|
1022
|
+
})
|
|
1023
|
+
})
|
|
1024
|
+
|
|
1025
|
+
describe('useSetSupplyCap', () => {
|
|
1026
|
+
test('default', async () => {
|
|
1027
|
+
const { result } = await renderHook(() => ({
|
|
1028
|
+
connect: useConnect(),
|
|
1029
|
+
createSync: hooks.useCreateSync(),
|
|
1030
|
+
setSupplyCap: hooks.useSetSupplyCap(),
|
|
1031
|
+
}))
|
|
1032
|
+
|
|
1033
|
+
await result.current.connect.connectAsync({
|
|
1034
|
+
connector: config.connectors[0]!,
|
|
1035
|
+
})
|
|
1036
|
+
|
|
1037
|
+
// Create a new token
|
|
1038
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
1039
|
+
currency: 'USD',
|
|
1040
|
+
name: 'Supply Cap Hook Token',
|
|
1041
|
+
symbol: 'SUPPLYCAPHOOK',
|
|
1042
|
+
})
|
|
1043
|
+
|
|
1044
|
+
const hash = await result.current.setSupplyCap.mutateAsync({
|
|
1045
|
+
token: tokenAddr,
|
|
1046
|
+
supplyCap: parseUnits('1000000', 6),
|
|
1047
|
+
})
|
|
1048
|
+
expect(hash).toBeDefined()
|
|
1049
|
+
|
|
1050
|
+
await vi.waitFor(() =>
|
|
1051
|
+
expect(result.current.setSupplyCap.isSuccess).toBeTruthy(),
|
|
1052
|
+
)
|
|
1053
|
+
})
|
|
1054
|
+
})
|
|
1055
|
+
|
|
1056
|
+
describe('useSetSupplyCapSync', () => {
|
|
1057
|
+
test('default', async () => {
|
|
1058
|
+
const { result } = await renderHook(() => ({
|
|
1059
|
+
connect: useConnect(),
|
|
1060
|
+
createSync: hooks.useCreateSync(),
|
|
1061
|
+
setSupplyCap: hooks.useSetSupplyCapSync(),
|
|
1062
|
+
}))
|
|
1063
|
+
|
|
1064
|
+
await result.current.connect.connectAsync({
|
|
1065
|
+
connector: config.connectors[0]!,
|
|
1066
|
+
})
|
|
1067
|
+
|
|
1068
|
+
// Create a new token
|
|
1069
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
1070
|
+
currency: 'USD',
|
|
1071
|
+
name: 'Supply Cap Hook Token Sync',
|
|
1072
|
+
symbol: 'SUPPLYCAPHOOKSYNC',
|
|
1073
|
+
})
|
|
1074
|
+
|
|
1075
|
+
const data = await result.current.setSupplyCap.mutateAsync({
|
|
1076
|
+
token: tokenAddr,
|
|
1077
|
+
supplyCap: parseUnits('1000000', 6),
|
|
1078
|
+
})
|
|
1079
|
+
expect(data).toBeDefined()
|
|
1080
|
+
expect(data.receipt).toBeDefined()
|
|
1081
|
+
|
|
1082
|
+
await vi.waitFor(() =>
|
|
1083
|
+
expect(result.current.setSupplyCap.isSuccess).toBeTruthy(),
|
|
1084
|
+
)
|
|
1085
|
+
})
|
|
1086
|
+
})
|
|
1087
|
+
|
|
1088
|
+
describe('useTransfer', () => {
|
|
1089
|
+
test('default', async () => {
|
|
1090
|
+
const { result } = await renderHook(() => ({
|
|
1091
|
+
connect: useConnect(),
|
|
1092
|
+
transfer: hooks.useTransfer(),
|
|
1093
|
+
}))
|
|
1094
|
+
|
|
1095
|
+
await result.current.connect.connectAsync({
|
|
1096
|
+
connector: config.connectors[0]!,
|
|
1097
|
+
})
|
|
1098
|
+
|
|
1099
|
+
const hash = await result.current.transfer.mutateAsync({
|
|
1100
|
+
to: account2.address,
|
|
1101
|
+
amount: parseUnits('1', 6),
|
|
1102
|
+
token: addresses.alphaUsd,
|
|
1103
|
+
})
|
|
1104
|
+
expect(hash).toBeDefined()
|
|
1105
|
+
|
|
1106
|
+
await vi.waitFor(() =>
|
|
1107
|
+
expect(result.current.transfer.isSuccess).toBeTruthy(),
|
|
1108
|
+
)
|
|
1109
|
+
})
|
|
1110
|
+
})
|
|
1111
|
+
|
|
1112
|
+
describe('useTransferSync', () => {
|
|
1113
|
+
test('default', async () => {
|
|
1114
|
+
const { result } = await renderHook(() => ({
|
|
1115
|
+
connect: useConnect(),
|
|
1116
|
+
transfer: hooks.useTransferSync(),
|
|
1117
|
+
}))
|
|
1118
|
+
|
|
1119
|
+
await result.current.connect.connectAsync({
|
|
1120
|
+
connector: config.connectors[0]!,
|
|
1121
|
+
})
|
|
1122
|
+
|
|
1123
|
+
const data = await result.current.transfer.mutateAsync({
|
|
1124
|
+
to: account2.address,
|
|
1125
|
+
amount: parseUnits('1', 6),
|
|
1126
|
+
token: addresses.alphaUsd,
|
|
1127
|
+
})
|
|
1128
|
+
expect(data).toBeDefined()
|
|
1129
|
+
expect(data.receipt).toBeDefined()
|
|
1130
|
+
|
|
1131
|
+
await vi.waitFor(() =>
|
|
1132
|
+
expect(result.current.transfer.isSuccess).toBeTruthy(),
|
|
1133
|
+
)
|
|
1134
|
+
})
|
|
1135
|
+
})
|
|
1136
|
+
|
|
1137
|
+
describe('useUnpause', () => {
|
|
1138
|
+
test('default', async () => {
|
|
1139
|
+
const { result } = await renderHook(() => ({
|
|
1140
|
+
connect: useConnect(),
|
|
1141
|
+
createSync: hooks.useCreateSync(),
|
|
1142
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
1143
|
+
pauseSync: hooks.usePauseSync(),
|
|
1144
|
+
unpause: hooks.useUnpause(),
|
|
1145
|
+
}))
|
|
1146
|
+
|
|
1147
|
+
await result.current.connect.connectAsync({
|
|
1148
|
+
connector: config.connectors[0]!,
|
|
1149
|
+
})
|
|
1150
|
+
|
|
1151
|
+
// Create a new token
|
|
1152
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
1153
|
+
currency: 'USD',
|
|
1154
|
+
name: 'Unpause Hook Token',
|
|
1155
|
+
symbol: 'UNPAUSEHOOK',
|
|
1156
|
+
})
|
|
1157
|
+
|
|
1158
|
+
// Grant pause and unpause roles
|
|
1159
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
1160
|
+
token: tokenAddr,
|
|
1161
|
+
roles: ['pause', 'unpause'],
|
|
1162
|
+
to: account.address,
|
|
1163
|
+
})
|
|
1164
|
+
|
|
1165
|
+
// First pause it
|
|
1166
|
+
await result.current.pauseSync.mutateAsync({
|
|
1167
|
+
token: tokenAddr,
|
|
1168
|
+
})
|
|
1169
|
+
|
|
1170
|
+
const hash = await result.current.unpause.mutateAsync({
|
|
1171
|
+
token: tokenAddr,
|
|
1172
|
+
})
|
|
1173
|
+
expect(hash).toBeDefined()
|
|
1174
|
+
|
|
1175
|
+
await vi.waitFor(() =>
|
|
1176
|
+
expect(result.current.unpause.isSuccess).toBeTruthy(),
|
|
1177
|
+
)
|
|
1178
|
+
})
|
|
1179
|
+
})
|
|
1180
|
+
|
|
1181
|
+
describe('useUnpauseSync', () => {
|
|
1182
|
+
test('default', async () => {
|
|
1183
|
+
const { result } = await renderHook(() => ({
|
|
1184
|
+
connect: useConnect(),
|
|
1185
|
+
createSync: hooks.useCreateSync(),
|
|
1186
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
1187
|
+
pauseSync: hooks.usePauseSync(),
|
|
1188
|
+
unpause: hooks.useUnpauseSync(),
|
|
1189
|
+
}))
|
|
1190
|
+
|
|
1191
|
+
await result.current.connect.connectAsync({
|
|
1192
|
+
connector: config.connectors[0]!,
|
|
1193
|
+
})
|
|
1194
|
+
|
|
1195
|
+
// Create a new token
|
|
1196
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
1197
|
+
currency: 'USD',
|
|
1198
|
+
name: 'Unpause Hook Token Sync',
|
|
1199
|
+
symbol: 'UNPAUSEHOOKSYNC',
|
|
1200
|
+
})
|
|
1201
|
+
|
|
1202
|
+
// Grant pause and unpause roles
|
|
1203
|
+
await result.current.grantRolesSync.mutateAsync({
|
|
1204
|
+
token: tokenAddr,
|
|
1205
|
+
roles: ['pause', 'unpause'],
|
|
1206
|
+
to: account.address,
|
|
1207
|
+
})
|
|
1208
|
+
|
|
1209
|
+
// First pause it
|
|
1210
|
+
await result.current.pauseSync.mutateAsync({
|
|
1211
|
+
token: tokenAddr,
|
|
1212
|
+
})
|
|
1213
|
+
|
|
1214
|
+
const data = await result.current.unpause.mutateAsync({
|
|
1215
|
+
token: tokenAddr,
|
|
1216
|
+
})
|
|
1217
|
+
expect(data).toBeDefined()
|
|
1218
|
+
expect(data.receipt).toBeDefined()
|
|
1219
|
+
|
|
1220
|
+
await vi.waitFor(() =>
|
|
1221
|
+
expect(result.current.unpause.isSuccess).toBeTruthy(),
|
|
1222
|
+
)
|
|
1223
|
+
})
|
|
1224
|
+
})
|
|
1225
|
+
|
|
1226
|
+
describe('usePrepareUpdateQuoteToken', () => {
|
|
1227
|
+
test('default', async () => {
|
|
1228
|
+
const { result } = await renderHook(() => ({
|
|
1229
|
+
connect: useConnect(),
|
|
1230
|
+
createSync: hooks.useCreateSync(),
|
|
1231
|
+
prepareUpdateQuoteToken: hooks.usePrepareUpdateQuoteToken(),
|
|
1232
|
+
}))
|
|
1233
|
+
|
|
1234
|
+
await result.current.connect.connectAsync({
|
|
1235
|
+
connector: config.connectors[0]!,
|
|
1236
|
+
})
|
|
1237
|
+
|
|
1238
|
+
// Create quote token
|
|
1239
|
+
const { token: quoteToken } = await result.current.createSync.mutateAsync({
|
|
1240
|
+
currency: 'USD',
|
|
1241
|
+
name: 'Update Quote Hook',
|
|
1242
|
+
symbol: 'UQHOOK',
|
|
1243
|
+
})
|
|
1244
|
+
|
|
1245
|
+
// Create main token
|
|
1246
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
1247
|
+
currency: 'USD',
|
|
1248
|
+
name: 'Update Main Hook',
|
|
1249
|
+
symbol: 'UMHOOK',
|
|
1250
|
+
})
|
|
1251
|
+
|
|
1252
|
+
const hash = await result.current.prepareUpdateQuoteToken.mutateAsync({
|
|
1253
|
+
token: tokenAddr,
|
|
1254
|
+
quoteToken,
|
|
1255
|
+
})
|
|
1256
|
+
expect(hash).toBeDefined()
|
|
1257
|
+
|
|
1258
|
+
await vi.waitFor(() =>
|
|
1259
|
+
expect(result.current.prepareUpdateQuoteToken.isSuccess).toBeTruthy(),
|
|
1260
|
+
)
|
|
1261
|
+
})
|
|
1262
|
+
})
|
|
1263
|
+
|
|
1264
|
+
describe('usePrepareUpdateQuoteTokenSync', () => {
|
|
1265
|
+
test('default', async () => {
|
|
1266
|
+
const { result } = await renderHook(() => ({
|
|
1267
|
+
connect: useConnect(),
|
|
1268
|
+
createSync: hooks.useCreateSync(),
|
|
1269
|
+
prepareUpdateQuoteToken: hooks.usePrepareUpdateQuoteTokenSync(),
|
|
1270
|
+
}))
|
|
1271
|
+
|
|
1272
|
+
await result.current.connect.connectAsync({
|
|
1273
|
+
connector: config.connectors[0]!,
|
|
1274
|
+
})
|
|
1275
|
+
|
|
1276
|
+
// Create quote token
|
|
1277
|
+
const { token: quoteToken } = await result.current.createSync.mutateAsync({
|
|
1278
|
+
currency: 'USD',
|
|
1279
|
+
name: 'Update Quote Hook Sync',
|
|
1280
|
+
symbol: 'UQHOOKSYNC',
|
|
1281
|
+
})
|
|
1282
|
+
|
|
1283
|
+
// Create main token
|
|
1284
|
+
const { token: tokenAddr } = await result.current.createSync.mutateAsync({
|
|
1285
|
+
currency: 'USD',
|
|
1286
|
+
name: 'Update Main Hook Sync',
|
|
1287
|
+
symbol: 'UMHOOKSYNC',
|
|
1288
|
+
})
|
|
1289
|
+
|
|
1290
|
+
const data = await result.current.prepareUpdateQuoteToken.mutateAsync({
|
|
1291
|
+
token: tokenAddr,
|
|
1292
|
+
quoteToken,
|
|
1293
|
+
})
|
|
1294
|
+
expect(data).toBeDefined()
|
|
1295
|
+
expect(data.receipt).toBeDefined()
|
|
1296
|
+
|
|
1297
|
+
await vi.waitFor(() =>
|
|
1298
|
+
expect(result.current.prepareUpdateQuoteToken.isSuccess).toBeTruthy(),
|
|
1299
|
+
)
|
|
1300
|
+
})
|
|
1301
|
+
})
|
|
1302
|
+
|
|
1303
|
+
describe('useWatchAdminRole', () => {
|
|
1304
|
+
test('default', async () => {
|
|
1305
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
1306
|
+
connect: useConnect(),
|
|
1307
|
+
createSync: hooks.useCreateSync(),
|
|
1308
|
+
setRoleAdminSync: hooks.useSetRoleAdminSync(),
|
|
1309
|
+
}))
|
|
1310
|
+
|
|
1311
|
+
await connectResult.current.connect.connectAsync({
|
|
1312
|
+
connector: config.connectors[0]!,
|
|
1313
|
+
})
|
|
1314
|
+
|
|
1315
|
+
// Create a new token
|
|
1316
|
+
const { token: tokenAddr } =
|
|
1317
|
+
await connectResult.current.createSync.mutateAsync({
|
|
1318
|
+
currency: 'USD',
|
|
1319
|
+
name: 'Watch Admin Role Hook Token',
|
|
1320
|
+
symbol: 'WATCHADMINHOOK',
|
|
1321
|
+
})
|
|
1322
|
+
|
|
1323
|
+
const events: any[] = []
|
|
1324
|
+
await renderHook(() =>
|
|
1325
|
+
hooks.useWatchAdminRole({
|
|
1326
|
+
token: tokenAddr,
|
|
1327
|
+
onRoleAdminUpdated(args) {
|
|
1328
|
+
events.push(args)
|
|
1329
|
+
},
|
|
1330
|
+
}),
|
|
1331
|
+
)
|
|
1332
|
+
|
|
1333
|
+
// Trigger event by setting a role admin
|
|
1334
|
+
await connectResult.current.setRoleAdminSync.mutateAsync({
|
|
1335
|
+
token: tokenAddr,
|
|
1336
|
+
role: 'issuer',
|
|
1337
|
+
adminRole: 'pause',
|
|
1338
|
+
})
|
|
1339
|
+
|
|
1340
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
1341
|
+
|
|
1342
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1343
|
+
expect(events[0]).toBeDefined()
|
|
1344
|
+
})
|
|
1345
|
+
})
|
|
1346
|
+
|
|
1347
|
+
describe('useWatchApprove', () => {
|
|
1348
|
+
test('default', async () => {
|
|
1349
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
1350
|
+
connect: useConnect(),
|
|
1351
|
+
approveSync: hooks.useApproveSync(),
|
|
1352
|
+
}))
|
|
1353
|
+
|
|
1354
|
+
await connectResult.current.connect.connectAsync({
|
|
1355
|
+
connector: config.connectors[0]!,
|
|
1356
|
+
})
|
|
1357
|
+
|
|
1358
|
+
const events: any[] = []
|
|
1359
|
+
await renderHook(() =>
|
|
1360
|
+
hooks.useWatchApprove({
|
|
1361
|
+
onApproval(args) {
|
|
1362
|
+
events.push(args)
|
|
1363
|
+
},
|
|
1364
|
+
token: addresses.alphaUsd,
|
|
1365
|
+
}),
|
|
1366
|
+
)
|
|
1367
|
+
|
|
1368
|
+
// Trigger approval event
|
|
1369
|
+
await connectResult.current.approveSync.mutateAsync({
|
|
1370
|
+
spender: account2.address,
|
|
1371
|
+
amount: parseUnits('50', 6),
|
|
1372
|
+
token: addresses.alphaUsd,
|
|
1373
|
+
})
|
|
1374
|
+
|
|
1375
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
1376
|
+
|
|
1377
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1378
|
+
expect(events[0]?.owner).toBe(account.address)
|
|
1379
|
+
expect(events[0]?.spender).toBe(account2.address)
|
|
1380
|
+
expect(events[0]?.amount).toBe(parseUnits('50', 6))
|
|
1381
|
+
})
|
|
1382
|
+
})
|
|
1383
|
+
|
|
1384
|
+
describe('useWatchBurn', () => {
|
|
1385
|
+
test('default', async () => {
|
|
1386
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
1387
|
+
connect: useConnect(),
|
|
1388
|
+
createSync: hooks.useCreateSync(),
|
|
1389
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
1390
|
+
mintSync: hooks.useMintSync(),
|
|
1391
|
+
burnSync: hooks.useBurnSync(),
|
|
1392
|
+
}))
|
|
1393
|
+
|
|
1394
|
+
await connectResult.current.connect.connectAsync({
|
|
1395
|
+
connector: config.connectors[0]!,
|
|
1396
|
+
})
|
|
1397
|
+
|
|
1398
|
+
// Create a new token
|
|
1399
|
+
const { token: tokenAddr } =
|
|
1400
|
+
await connectResult.current.createSync.mutateAsync({
|
|
1401
|
+
currency: 'USD',
|
|
1402
|
+
name: 'Watch Burn Hook Token',
|
|
1403
|
+
symbol: 'WATCHBURNHOOK',
|
|
1404
|
+
})
|
|
1405
|
+
|
|
1406
|
+
// Grant issuer role and mint tokens
|
|
1407
|
+
await connectResult.current.grantRolesSync.mutateAsync({
|
|
1408
|
+
token: tokenAddr,
|
|
1409
|
+
roles: ['issuer'],
|
|
1410
|
+
to: account.address,
|
|
1411
|
+
})
|
|
1412
|
+
await connectResult.current.mintSync.mutateAsync({
|
|
1413
|
+
token: tokenAddr,
|
|
1414
|
+
to: account.address,
|
|
1415
|
+
amount: parseUnits('1000', 6),
|
|
1416
|
+
})
|
|
1417
|
+
|
|
1418
|
+
const events: any[] = []
|
|
1419
|
+
await renderHook(() =>
|
|
1420
|
+
hooks.useWatchBurn({
|
|
1421
|
+
token: tokenAddr,
|
|
1422
|
+
onBurn(args) {
|
|
1423
|
+
events.push(args)
|
|
1424
|
+
},
|
|
1425
|
+
}),
|
|
1426
|
+
)
|
|
1427
|
+
|
|
1428
|
+
// Trigger burn event
|
|
1429
|
+
await connectResult.current.burnSync.mutateAsync({
|
|
1430
|
+
token: tokenAddr,
|
|
1431
|
+
amount: parseUnits('10', 6),
|
|
1432
|
+
})
|
|
1433
|
+
|
|
1434
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
1435
|
+
|
|
1436
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1437
|
+
expect(events[0]?.from).toBe(account.address)
|
|
1438
|
+
expect(events[0]?.amount).toBe(parseUnits('10', 6))
|
|
1439
|
+
})
|
|
1440
|
+
})
|
|
1441
|
+
|
|
1442
|
+
describe('useWatchCreate', () => {
|
|
1443
|
+
test('default', async () => {
|
|
1444
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
1445
|
+
connect: useConnect(),
|
|
1446
|
+
createSync: hooks.useCreateSync(),
|
|
1447
|
+
}))
|
|
1448
|
+
|
|
1449
|
+
await connectResult.current.connect.connectAsync({
|
|
1450
|
+
connector: config.connectors[0]!,
|
|
1451
|
+
})
|
|
1452
|
+
|
|
1453
|
+
const events: any[] = []
|
|
1454
|
+
await renderHook(() =>
|
|
1455
|
+
hooks.useWatchCreate({
|
|
1456
|
+
onTokenCreated(args) {
|
|
1457
|
+
events.push(args)
|
|
1458
|
+
},
|
|
1459
|
+
}),
|
|
1460
|
+
)
|
|
1461
|
+
|
|
1462
|
+
// Trigger token creation event
|
|
1463
|
+
await connectResult.current.createSync.mutateAsync({
|
|
1464
|
+
name: 'Watch Create Hook Token',
|
|
1465
|
+
symbol: 'WATCHCREATEHOOK',
|
|
1466
|
+
currency: 'USD',
|
|
1467
|
+
})
|
|
1468
|
+
|
|
1469
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
1470
|
+
|
|
1471
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1472
|
+
expect(events[0]?.name).toBe('Watch Create Hook Token')
|
|
1473
|
+
expect(events[0]?.symbol).toBe('WATCHCREATEHOOK')
|
|
1474
|
+
expect(events[0]?.currency).toBe('USD')
|
|
1475
|
+
expect(events[0]?.admin).toBe(account.address)
|
|
1476
|
+
})
|
|
1477
|
+
})
|
|
1478
|
+
|
|
1479
|
+
describe('useWatchMint', () => {
|
|
1480
|
+
test('default', async () => {
|
|
1481
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
1482
|
+
connect: useConnect(),
|
|
1483
|
+
createSync: hooks.useCreateSync(),
|
|
1484
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
1485
|
+
mintSync: hooks.useMintSync(),
|
|
1486
|
+
}))
|
|
1487
|
+
|
|
1488
|
+
await connectResult.current.connect.connectAsync({
|
|
1489
|
+
connector: config.connectors[0]!,
|
|
1490
|
+
})
|
|
1491
|
+
|
|
1492
|
+
// Create a new token
|
|
1493
|
+
const { token: tokenAddr } =
|
|
1494
|
+
await connectResult.current.createSync.mutateAsync({
|
|
1495
|
+
currency: 'USD',
|
|
1496
|
+
name: 'Watch Mint Hook Token',
|
|
1497
|
+
symbol: 'WATCHMINTHOOK',
|
|
1498
|
+
})
|
|
1499
|
+
|
|
1500
|
+
// Grant issuer role
|
|
1501
|
+
await connectResult.current.grantRolesSync.mutateAsync({
|
|
1502
|
+
token: tokenAddr,
|
|
1503
|
+
roles: ['issuer'],
|
|
1504
|
+
to: account.address,
|
|
1505
|
+
})
|
|
1506
|
+
|
|
1507
|
+
const events: any[] = []
|
|
1508
|
+
await renderHook(() =>
|
|
1509
|
+
hooks.useWatchMint({
|
|
1510
|
+
token: tokenAddr,
|
|
1511
|
+
onMint(args) {
|
|
1512
|
+
events.push(args)
|
|
1513
|
+
},
|
|
1514
|
+
}),
|
|
1515
|
+
)
|
|
1516
|
+
|
|
1517
|
+
// Trigger mint event
|
|
1518
|
+
await connectResult.current.mintSync.mutateAsync({
|
|
1519
|
+
token: tokenAddr,
|
|
1520
|
+
to: account.address,
|
|
1521
|
+
amount: parseUnits('100', 6),
|
|
1522
|
+
})
|
|
1523
|
+
|
|
1524
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
1525
|
+
|
|
1526
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1527
|
+
expect(events[0]?.to).toBe(account.address)
|
|
1528
|
+
expect(events[0]?.amount).toBe(parseUnits('100', 6))
|
|
1529
|
+
})
|
|
1530
|
+
})
|
|
1531
|
+
|
|
1532
|
+
describe('useWatchRole', () => {
|
|
1533
|
+
test('default', async () => {
|
|
1534
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
1535
|
+
connect: useConnect(),
|
|
1536
|
+
createSync: hooks.useCreateSync(),
|
|
1537
|
+
grantRolesSync: hooks.useGrantRolesSync(),
|
|
1538
|
+
}))
|
|
1539
|
+
|
|
1540
|
+
await connectResult.current.connect.connectAsync({
|
|
1541
|
+
connector: config.connectors[0]!,
|
|
1542
|
+
})
|
|
1543
|
+
|
|
1544
|
+
// Create a new token
|
|
1545
|
+
const { token: tokenAddr } =
|
|
1546
|
+
await connectResult.current.createSync.mutateAsync({
|
|
1547
|
+
currency: 'USD',
|
|
1548
|
+
name: 'Watch Role Hook Token',
|
|
1549
|
+
symbol: 'WATCHROLEHOOK',
|
|
1550
|
+
})
|
|
1551
|
+
|
|
1552
|
+
const events: any[] = []
|
|
1553
|
+
await renderHook(() =>
|
|
1554
|
+
hooks.useWatchRole({
|
|
1555
|
+
token: tokenAddr,
|
|
1556
|
+
onRoleUpdated(args) {
|
|
1557
|
+
events.push(args)
|
|
1558
|
+
},
|
|
1559
|
+
}),
|
|
1560
|
+
)
|
|
1561
|
+
|
|
1562
|
+
// Trigger role update event by granting a role
|
|
1563
|
+
await connectResult.current.grantRolesSync.mutateAsync({
|
|
1564
|
+
token: tokenAddr,
|
|
1565
|
+
roles: ['issuer'],
|
|
1566
|
+
to: account2.address,
|
|
1567
|
+
})
|
|
1568
|
+
|
|
1569
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
1570
|
+
|
|
1571
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1572
|
+
expect(events[0]?.account).toBe(account2.address)
|
|
1573
|
+
expect(events[0]?.hasRole).toBe(true)
|
|
1574
|
+
expect(events[0]?.type).toBe('granted')
|
|
1575
|
+
})
|
|
1576
|
+
})
|
|
1577
|
+
|
|
1578
|
+
describe('useWatchTransfer', () => {
|
|
1579
|
+
test('default', async () => {
|
|
1580
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
1581
|
+
connect: useConnect(),
|
|
1582
|
+
transferSync: hooks.useTransferSync(),
|
|
1583
|
+
}))
|
|
1584
|
+
|
|
1585
|
+
await connectResult.current.connect.connectAsync({
|
|
1586
|
+
connector: config.connectors[0]!,
|
|
1587
|
+
})
|
|
1588
|
+
|
|
1589
|
+
const events: any[] = []
|
|
1590
|
+
await renderHook(() =>
|
|
1591
|
+
hooks.useWatchTransfer({
|
|
1592
|
+
onTransfer(args) {
|
|
1593
|
+
events.push(args)
|
|
1594
|
+
},
|
|
1595
|
+
token: addresses.alphaUsd,
|
|
1596
|
+
}),
|
|
1597
|
+
)
|
|
1598
|
+
|
|
1599
|
+
// Trigger transfer event
|
|
1600
|
+
await connectResult.current.transferSync.mutateAsync({
|
|
1601
|
+
to: account2.address,
|
|
1602
|
+
amount: parseUnits('5', 6),
|
|
1603
|
+
token: addresses.alphaUsd,
|
|
1604
|
+
})
|
|
1605
|
+
|
|
1606
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
1607
|
+
|
|
1608
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1609
|
+
expect(events[0]?.from).toBe(account.address)
|
|
1610
|
+
expect(events[0]?.to).toBe(account2.address)
|
|
1611
|
+
expect(events[0]?.amount).toBe(parseUnits('5', 6))
|
|
1612
|
+
})
|
|
1613
|
+
})
|
|
1614
|
+
|
|
1615
|
+
describe('useWatchUpdateQuoteToken', () => {
|
|
1616
|
+
test('default', async () => {
|
|
1617
|
+
const { result: connectResult } = await renderHook(() => ({
|
|
1618
|
+
connect: useConnect(),
|
|
1619
|
+
createSync: hooks.useCreateSync(),
|
|
1620
|
+
prepareUpdateQuoteTokenSync: hooks.usePrepareUpdateQuoteTokenSync(),
|
|
1621
|
+
}))
|
|
1622
|
+
|
|
1623
|
+
await connectResult.current.connect.connectAsync({
|
|
1624
|
+
connector: config.connectors[0]!,
|
|
1625
|
+
})
|
|
1626
|
+
|
|
1627
|
+
// Create quote token
|
|
1628
|
+
const { token: quoteToken } =
|
|
1629
|
+
await connectResult.current.createSync.mutateAsync({
|
|
1630
|
+
currency: 'USD',
|
|
1631
|
+
name: 'Watch Quote Hook Token',
|
|
1632
|
+
symbol: 'WATCHQUOTEHOOK',
|
|
1633
|
+
})
|
|
1634
|
+
|
|
1635
|
+
// Create main token
|
|
1636
|
+
const { token: tokenAddr } =
|
|
1637
|
+
await connectResult.current.createSync.mutateAsync({
|
|
1638
|
+
currency: 'USD',
|
|
1639
|
+
name: 'Watch Main Hook Token',
|
|
1640
|
+
symbol: 'WATCHMAINHOOK',
|
|
1641
|
+
})
|
|
1642
|
+
|
|
1643
|
+
const events: any[] = []
|
|
1644
|
+
await renderHook(() =>
|
|
1645
|
+
hooks.useWatchUpdateQuoteToken({
|
|
1646
|
+
token: tokenAddr,
|
|
1647
|
+
onUpdateQuoteToken(args) {
|
|
1648
|
+
events.push(args)
|
|
1649
|
+
},
|
|
1650
|
+
}),
|
|
1651
|
+
)
|
|
1652
|
+
|
|
1653
|
+
// Trigger prepare update quote token event
|
|
1654
|
+
await connectResult.current.prepareUpdateQuoteTokenSync.mutateAsync({
|
|
1655
|
+
token: tokenAddr,
|
|
1656
|
+
quoteToken,
|
|
1657
|
+
})
|
|
1658
|
+
|
|
1659
|
+
await vi.waitUntil(() => events.length >= 1)
|
|
1660
|
+
|
|
1661
|
+
expect(events.length).toBeGreaterThanOrEqual(1)
|
|
1662
|
+
expect(events[0]?.nextQuoteToken).toBe(quoteToken)
|
|
1663
|
+
expect(events[0]?.updater).toBe(account.address)
|
|
1664
|
+
expect(events[0]?.completed).toBe(false)
|
|
1665
|
+
})
|
|
1666
|
+
})
|
|
1667
|
+
|
|
1668
|
+
describe.todo('useBurnBlocked')
|
|
1669
|
+
|
|
1670
|
+
describe.todo('useBurnBlockedSync')
|