-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Expand file tree
/
Copy pathuseSimulateContract.test-d.ts
More file actions
101 lines (92 loc) · 2.56 KB
/
Copy pathuseSimulateContract.test-d.ts
File metadata and controls
101 lines (92 loc) · 2.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
import { type abi, config as testConfig } from '@wagmi/test'
import {
type UseSimulateContractParameters,
useSimulateContract,
} from '@wagmi/vue'
import { celo, mainnet, optimism } from '@wagmi/vue/chains'
import type { SimulateContractOptions } from '@wagmi/vue/query'
import type { Address } from 'viem'
import { expectTypeOf, test } from 'vitest'
import type { ChainId, config } from './config.js'
test('chain formatters', () => {
const { data } = useSimulateContract({
feeCurrency: '0x',
})
if (data.value && data.value.chainId === celo.id) {
expectTypeOf(data.value.request.feeCurrency).toEqualTypeOf<
`0x${string}` | undefined
>()
}
const { data: data2 } = useSimulateContract({
chainId: celo.id,
feeCurrency: '0x',
})
if (data2.value) {
expectTypeOf(data2.value.request.feeCurrency).toEqualTypeOf<
`0x${string}` | undefined
>()
}
useSimulateContract({
chainId: mainnet.id,
// @ts-expect-error
feeCurrency: '0x',
})
useSimulateContract({
chainId: optimism.id,
// @ts-expect-error
feeCurrency: '0x',
})
})
test('UseSimulateContractParameters', () => {
type Result = UseSimulateContractParameters<
typeof abi.erc20,
'transferFrom',
[Address, Address, bigint],
typeof config
>
const res = {} as Result
expectTypeOf(res.value?.functionName).toEqualTypeOf<
'approve' | 'transfer' | 'transferFrom' | undefined
>()
if (res.value?.args) {
expectTypeOf(res.value.args[0]).toEqualTypeOf<Address>()
expectTypeOf(res.value.args[1]).toEqualTypeOf<Address>()
expectTypeOf(res.value.args[2]).toEqualTypeOf<bigint>()
}
expectTypeOf(res.value?.chainId).toEqualTypeOf<ChainId | undefined>()
type Result2 = UseSimulateContractParameters<
typeof abi.erc20,
'transferFrom',
[Address, Address, bigint],
typeof config,
typeof celo.id
>
expectTypeOf(({} as Result2).value?.chainId).toEqualTypeOf<
ChainId | undefined
>()
type Result3 = UseSimulateContractParameters<
typeof abi.erc20,
'transferFrom',
[Address, Address, bigint],
typeof config,
typeof celo.id
>
expectTypeOf(({} as Result3).value?.chainId).toEqualTypeOf<
ChainId | undefined
>()
type Result4 = SimulateContractOptions<
typeof abi.erc20,
'transferFrom',
[Address, Address, bigint],
typeof config,
typeof celo.id
>
expectTypeOf<Result4['chainId']>().toEqualTypeOf<ChainId | undefined>()
})
test('parameters: config', async () => {
useSimulateContract({
config: testConfig,
// @ts-expect-error
feeCurrency: '0x',
})
})