viem 0.0.1-alpha.21 → 0.0.1-alpha.22
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/dist/{chain-32f56cfa.d.ts → chain-4b39613a.d.ts} +2 -2
- package/dist/{chain-f12cdc7f.d.ts → chain-aa4898d0.d.ts} +1 -1
- package/dist/chains.d.ts +3 -3
- package/dist/chains.js +46 -46
- package/dist/chains.mjs +1 -1
- package/dist/{chunk-46BO7YAQ.mjs → chunk-JMFNAGCD.mjs} +4 -3
- package/dist/chunk-JMFNAGCD.mjs.map +1 -0
- package/dist/{chunk-KZMJR27B.js → chunk-MVD4Y3AE.js} +67 -63
- package/dist/chunk-MVD4Y3AE.js.map +1 -0
- package/dist/{chunk-57ZOFERP.mjs → chunk-OZIBQJYR.mjs} +2 -2
- package/dist/{chunk-57ZOFERP.mjs.map → chunk-OZIBQJYR.mjs.map} +0 -0
- package/dist/{chunk-KEHGSYDO.js → chunk-PMPJGAHY.js} +14 -13
- package/dist/chunk-PMPJGAHY.js.map +1 -0
- package/dist/{chunk-W7BWWAC4.js → chunk-QA3IE5DU.js} +14 -14
- package/dist/{chunk-W7BWWAC4.js.map → chunk-QA3IE5DU.js.map} +0 -0
- package/dist/{chunk-DSPMAIDO.mjs → chunk-QN2NCTEN.mjs} +2 -2
- package/dist/{chunk-DSPMAIDO.mjs.map → chunk-QN2NCTEN.mjs.map} +1 -1
- package/dist/{chunk-EC3NUIJE.js → chunk-S77NLWHO.js} +13 -13
- package/dist/{chunk-EC3NUIJE.js.map → chunk-S77NLWHO.js.map} +1 -1
- package/dist/{chunk-O2GYLJVD.js → chunk-V5U5S7PQ.js} +403 -165
- package/dist/chunk-V5U5S7PQ.js.map +1 -0
- package/dist/{chunk-62VTYU2V.mjs → chunk-WWJ5YPTJ.mjs} +404 -166
- package/dist/chunk-WWJ5YPTJ.mjs.map +1 -0
- package/dist/{chunk-DGO77E2H.mjs → chunk-ZXXEENRD.mjs} +7 -3
- package/dist/chunk-ZXXEENRD.mjs.map +1 -0
- package/dist/clients/index.d.ts +7 -7
- package/dist/clients/index.js +3 -3
- package/dist/clients/index.mjs +2 -2
- package/dist/{contract-9af4608b.d.ts → contract-74f34ac9.d.ts} +14 -3
- package/dist/{createClient-5d316c7e.d.ts → createClient-55a04188.d.ts} +2 -2
- package/dist/{createPublicClient-9d2b42e1.d.ts → createPublicClient-3b27b282.d.ts} +3 -3
- package/dist/{createTestClient-79498dab.d.ts → createTestClient-93f9eac6.d.ts} +3 -3
- package/dist/{createWalletClient-f69a5230.d.ts → createWalletClient-c10df94d.d.ts} +3 -3
- package/dist/{eip1193-6c485d63.d.ts → eip1193-4c24765a.d.ts} +1 -1
- package/dist/ens.d.ts +1 -0
- package/dist/ens.js +11 -0
- package/dist/ens.js.map +1 -0
- package/dist/ens.mjs +11 -0
- package/dist/ens.mjs.map +1 -0
- package/dist/index.d.ts +125 -113
- package/dist/index.js +14 -6
- package/dist/index.mjs +13 -5
- package/dist/normalize-ef9240c0.d.ts +33 -0
- package/dist/{parseGwei-4308ad80.d.ts → parseGwei-b323fb0a.d.ts} +101 -37
- package/dist/public.d.ts +9 -9
- package/dist/public.js +4 -4
- package/dist/public.mjs +3 -3
- package/dist/{sendTransaction-1c8290a9.d.ts → sendTransaction-f17a2389.d.ts} +3 -3
- package/dist/{stopImpersonatingAccount-7781842a.d.ts → stopImpersonatingAccount-afb26486.d.ts} +2 -2
- package/dist/test.d.ts +5 -5
- package/dist/test.js +3 -3
- package/dist/test.mjs +2 -2
- package/dist/{transactionRequest-341b6ed2.d.ts → transactionRequest-93e9f001.d.ts} +2 -2
- package/dist/utils/index.d.ts +14 -16
- package/dist/utils/index.js +8 -2
- package/dist/utils/index.mjs +7 -1
- package/dist/wallet.d.ts +7 -7
- package/dist/wallet.js +3 -3
- package/dist/wallet.mjs +2 -2
- package/dist/{watchAsset-afaad3c7.d.ts → watchAsset-efd3dd05.d.ts} +3 -3
- package/dist/{watchPendingTransactions-3b722547.d.ts → watchPendingTransactions-a8688b26.d.ts} +17 -27
- package/dist/{webSocket-b180e679.d.ts → webSocket-d2e7bd0e.d.ts} +2 -2
- package/dist/window.d.ts +2 -2
- package/package.json +8 -2
- package/src/_test/abis.ts +7 -0
- package/src/_test/bench.ts +4 -4
- package/src/_test/index.ts +3 -1
- package/src/_test/utils.ts +39 -1
- package/src/actions/public/call.bench.ts +5 -5
- package/src/actions/public/deployContract.ts +4 -4
- package/src/actions/public/estimateGas.bench.ts +6 -6
- package/src/actions/public/getBlock.bench.ts +5 -5
- package/src/actions/public/getBlockNumber.bench.ts +5 -5
- package/src/actions/public/getGasPrice.bench.ts +1 -10
- package/src/actions/public/getTransaction.bench.ts +5 -5
- package/src/actions/public/getTransactionReceipt.bench.ts +5 -5
- package/src/actions/public/multicall.test.ts +452 -0
- package/src/actions/public/multicall.ts +103 -0
- package/src/actions/public/readContract.test.ts +226 -26
- package/src/actions/public/readContract.ts +13 -27
- package/src/actions/public/simulateContract.bench.ts +10 -0
- package/src/actions/public/simulateContract.test.ts +209 -37
- package/src/actions/public/simulateContract.ts +17 -21
- package/src/actions/public/watchContractEvent.test.ts +36 -32
- package/src/actions/public/watchEvent.test.ts +34 -29
- package/src/actions/wallet/signMessage.test.ts +0 -1
- package/src/actions/wallet/switchChain.test.ts +1 -2
- package/src/actions/wallet/watchAsset.test.ts +1 -2
- package/src/actions/wallet/writeContract.test.ts +37 -7
- package/src/actions/wallet/writeContract.ts +5 -14
- package/src/clients/transports/fallback.test.ts +34 -0
- package/src/clients/transports/fallback.ts +3 -1
- package/src/clients/transports/http.test.ts +0 -1
- package/src/clients/transports/webSocket.test.ts +0 -1
- package/src/constants/abis.test.ts +53 -0
- package/src/constants/abis.ts +44 -0
- package/src/constants/index.test.ts +14 -0
- package/src/constants/index.ts +3 -0
- package/src/constants/solidity.test.ts +41 -0
- package/src/constants/solidity.ts +35 -0
- package/src/ens.ts +5 -0
- package/src/errors/abi.test.ts +0 -2
- package/src/errors/base.test.ts +44 -2
- package/src/errors/base.ts +12 -12
- package/src/errors/block.test.ts +6 -6
- package/src/errors/contract.test.ts +233 -0
- package/src/errors/contract.ts +133 -80
- package/src/errors/index.ts +4 -2
- package/src/errors/request.test.ts +3 -4
- package/src/errors/request.ts +17 -17
- package/src/errors/rpc.test.ts +1 -2
- package/src/errors/transaction.test.ts +12 -12
- package/src/errors/transport.test.ts +0 -1
- package/src/index.test.ts +46 -0
- package/src/index.ts +8 -0
- package/src/types/contract.ts +55 -4
- package/src/types/index.ts +5 -0
- package/src/types/multicall.ts +82 -0
- package/src/utils/abi/decodeAbi.test.ts +1 -2
- package/src/utils/abi/decodeAbi.ts +11 -7
- package/src/utils/abi/decodeDeployData.test.ts +7 -15
- package/src/utils/abi/decodeDeployData.ts +10 -7
- package/src/utils/abi/decodeErrorResult.test.ts +103 -3
- package/src/utils/abi/decodeErrorResult.ts +30 -13
- package/src/utils/abi/decodeFunctionData.test.ts +0 -1
- package/src/utils/abi/decodeFunctionResult.test.ts +80 -9
- package/src/utils/abi/decodeFunctionResult.ts +15 -11
- package/src/utils/abi/encodeAbi.test.ts +3 -4
- package/src/utils/abi/encodeAbi.ts +19 -10
- package/src/utils/abi/encodeDeployData.test.ts +6 -13
- package/src/utils/abi/encodeDeployData.ts +10 -7
- package/src/utils/abi/encodeErrorResult.test.ts +2 -7
- package/src/utils/abi/encodeErrorResult.ts +18 -11
- package/src/utils/abi/encodeEventTopics.test.ts +11 -14
- package/src/utils/abi/encodeEventTopics.ts +15 -9
- package/src/utils/abi/encodeFunctionData.test.ts +5 -7
- package/src/utils/abi/encodeFunctionData.ts +16 -9
- package/src/utils/abi/encodeFunctionResult.test.ts +10 -15
- package/src/utils/abi/encodeFunctionResult.ts +9 -7
- package/src/utils/abi/getAbiItem.test.ts +547 -0
- package/src/utils/abi/getAbiItem.ts +93 -3
- package/src/utils/abi/index.ts +5 -1
- package/src/utils/address/getAddress.test.ts +6 -6
- package/src/utils/contract/getContractError.test.ts +247 -62
- package/src/utils/contract/getContractError.ts +30 -38
- package/src/utils/data/pad.bench.ts +0 -9
- package/src/utils/data/trim.bench.ts +0 -16
- package/src/utils/encoding/encodeBytes.bench.ts +0 -12
- package/src/utils/encoding/encodeHex.bench.ts +0 -11
- package/src/utils/ens/index.test.ts +13 -0
- package/src/utils/ens/index.ts +5 -0
- package/src/utils/ens/labelhash.test.ts +55 -0
- package/src/utils/ens/labelhash.ts +16 -0
- package/src/utils/ens/namehash.test.ts +65 -0
- package/src/utils/ens/namehash.ts +28 -0
- package/src/utils/ens/normalize.bench.ts +14 -0
- package/src/utils/ens/normalize.test.ts +35 -0
- package/src/utils/ens/normalize.ts +14 -0
- package/src/utils/hash/keccak256.ts +3 -5
- package/src/utils/index.test.ts +3 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/rpc.test.ts +3 -6
- package/src/utils/unit/formatUnit.bench.ts +0 -5
- package/src/utils/unit/parseUnit.bench.ts +0 -5
- package/dist/chunk-46BO7YAQ.mjs.map +0 -1
- package/dist/chunk-62VTYU2V.mjs.map +0 -1
- package/dist/chunk-DGO77E2H.mjs.map +0 -1
- package/dist/chunk-KEHGSYDO.js.map +0 -1
- package/dist/chunk-KZMJR27B.js.map +0 -1
- package/dist/chunk-O2GYLJVD.js.map +0 -1
@@ -11,6 +11,7 @@
|
|
11
11
|
import { describe, expect, test } from 'vitest'
|
12
12
|
import {
|
13
13
|
accounts,
|
14
|
+
deployBAYC,
|
14
15
|
publicClient,
|
15
16
|
testClient,
|
16
17
|
wagmiContractConfig,
|
@@ -21,9 +22,9 @@ import { encodeFunctionData } from '../../utils'
|
|
21
22
|
import { mine } from '../test'
|
22
23
|
import { sendTransaction } from '../wallet'
|
23
24
|
|
24
|
-
import { deployContract } from './deployContract'
|
25
|
-
import { getTransactionReceipt } from './getTransactionReceipt'
|
26
25
|
import { simulateContract } from './simulateContract'
|
26
|
+
import { deployErrorExample } from '../../_test/utils'
|
27
|
+
import { errorsExampleABI } from '../../_test/generated'
|
27
28
|
|
28
29
|
describe('wagmi', () => {
|
29
30
|
test('default', async () => {
|
@@ -53,6 +54,18 @@ describe('wagmi', () => {
|
|
53
54
|
).toEqual(undefined)
|
54
55
|
})
|
55
56
|
|
57
|
+
test('overloaded function', async () => {
|
58
|
+
expect(
|
59
|
+
(
|
60
|
+
await simulateContract(publicClient, {
|
61
|
+
...wagmiContractConfig,
|
62
|
+
from: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
|
63
|
+
functionName: 'mint',
|
64
|
+
})
|
65
|
+
).result,
|
66
|
+
).toEqual(undefined)
|
67
|
+
})
|
68
|
+
|
56
69
|
test('revert', async () => {
|
57
70
|
await expect(() =>
|
58
71
|
simulateContract(publicClient, {
|
@@ -62,14 +75,15 @@ describe('wagmi', () => {
|
|
62
75
|
from: accounts[0].address,
|
63
76
|
}),
|
64
77
|
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
65
|
-
"
|
66
|
-
|
67
|
-
|
78
|
+
"The contract function \\"approve\\" reverted with the following reason:
|
79
|
+
ERC721: approval to current owner
|
80
|
+
|
68
81
|
Contract: 0x0000000000000000000000000000000000000000
|
69
82
|
Function: approve(address to, uint256 tokenId)
|
70
83
|
Arguments: (0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC, 420)
|
84
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
71
85
|
|
72
|
-
|
86
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
73
87
|
Version: viem@1.0.2"
|
74
88
|
`)
|
75
89
|
await expect(() =>
|
@@ -80,14 +94,15 @@ describe('wagmi', () => {
|
|
80
94
|
from: accounts[0].address,
|
81
95
|
}),
|
82
96
|
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
83
|
-
"
|
84
|
-
|
85
|
-
|
97
|
+
"The contract function \\"mint\\" reverted with the following reason:
|
98
|
+
Token ID is taken
|
99
|
+
|
86
100
|
Contract: 0x0000000000000000000000000000000000000000
|
87
101
|
Function: mint(uint256 tokenId)
|
88
102
|
Arguments: (1)
|
103
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
89
104
|
|
90
|
-
|
105
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
91
106
|
Version: viem@1.0.2"
|
92
107
|
`)
|
93
108
|
await expect(() =>
|
@@ -102,14 +117,15 @@ describe('wagmi', () => {
|
|
102
117
|
],
|
103
118
|
}),
|
104
119
|
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
105
|
-
"
|
106
|
-
|
107
|
-
|
120
|
+
"The contract function \\"safeTransferFrom\\" reverted with the following reason:
|
121
|
+
ERC721: transfer caller is not owner nor approved
|
122
|
+
|
108
123
|
Contract: 0x0000000000000000000000000000000000000000
|
109
124
|
Function: safeTransferFrom(address from, address to, uint256 tokenId)
|
110
125
|
Arguments: (0x1a1E021A302C237453D3D45c7B82B19cEEB7E2e6, 0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC, 1)
|
126
|
+
Sender: 0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC
|
111
127
|
|
112
|
-
|
128
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
113
129
|
Version: viem@1.0.2"
|
114
130
|
`)
|
115
131
|
})
|
@@ -178,20 +194,188 @@ describe('BAYC', () => {
|
|
178
194
|
args: [1n],
|
179
195
|
}),
|
180
196
|
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
181
|
-
"
|
182
|
-
|
183
|
-
|
197
|
+
"The contract function \\"mintApe\\" reverted with the following reason:
|
198
|
+
Sale must be active to mint Ape
|
199
|
+
|
184
200
|
Contract: 0x0000000000000000000000000000000000000000
|
185
201
|
Function: mintApe(uint256 numberOfTokens)
|
186
202
|
Arguments: (1)
|
203
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
187
204
|
|
188
|
-
|
205
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
189
206
|
Version: viem@1.0.2"
|
190
207
|
`)
|
191
208
|
})
|
192
209
|
})
|
193
210
|
})
|
194
211
|
|
212
|
+
describe('contract errors', () => {
|
213
|
+
test('revert', async () => {
|
214
|
+
const { contractAddress } = await deployErrorExample()
|
215
|
+
|
216
|
+
await expect(() =>
|
217
|
+
simulateContract(publicClient, {
|
218
|
+
abi: errorsExampleABI,
|
219
|
+
address: contractAddress!,
|
220
|
+
functionName: 'revertWrite',
|
221
|
+
from: accounts[0].address,
|
222
|
+
}),
|
223
|
+
).rejects.toMatchInlineSnapshot(`
|
224
|
+
[ContractFunctionExecutionError: The contract function "revertWrite" reverted with the following reason:
|
225
|
+
This is a revert message
|
226
|
+
|
227
|
+
Contract: 0x0000000000000000000000000000000000000000
|
228
|
+
Function: revertWrite()
|
229
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
230
|
+
|
231
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
232
|
+
Version: viem@1.0.2]
|
233
|
+
`)
|
234
|
+
})
|
235
|
+
|
236
|
+
test('assert', async () => {
|
237
|
+
const { contractAddress } = await deployErrorExample()
|
238
|
+
|
239
|
+
await expect(() =>
|
240
|
+
simulateContract(publicClient, {
|
241
|
+
abi: errorsExampleABI,
|
242
|
+
address: contractAddress!,
|
243
|
+
functionName: 'assertWrite',
|
244
|
+
from: accounts[0].address,
|
245
|
+
}),
|
246
|
+
).rejects.toMatchInlineSnapshot(`
|
247
|
+
[ContractFunctionExecutionError: The contract function "assertWrite" reverted with the following reason:
|
248
|
+
An \`assert\` condition failed.
|
249
|
+
|
250
|
+
Contract: 0x0000000000000000000000000000000000000000
|
251
|
+
Function: assertWrite()
|
252
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
253
|
+
|
254
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
255
|
+
Version: viem@1.0.2]
|
256
|
+
`)
|
257
|
+
})
|
258
|
+
|
259
|
+
test('overflow', async () => {
|
260
|
+
const { contractAddress } = await deployErrorExample()
|
261
|
+
|
262
|
+
await expect(() =>
|
263
|
+
simulateContract(publicClient, {
|
264
|
+
abi: errorsExampleABI,
|
265
|
+
address: contractAddress!,
|
266
|
+
functionName: 'overflowWrite',
|
267
|
+
from: accounts[0].address,
|
268
|
+
}),
|
269
|
+
).rejects.toMatchInlineSnapshot(`
|
270
|
+
[ContractFunctionExecutionError: The contract function "overflowWrite" reverted with the following reason:
|
271
|
+
Arithmic operation resulted in underflow or overflow.
|
272
|
+
|
273
|
+
Contract: 0x0000000000000000000000000000000000000000
|
274
|
+
Function: overflowWrite()
|
275
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
276
|
+
|
277
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
278
|
+
Version: viem@1.0.2]
|
279
|
+
`)
|
280
|
+
})
|
281
|
+
|
282
|
+
test('divide by zero', async () => {
|
283
|
+
const { contractAddress } = await deployErrorExample()
|
284
|
+
|
285
|
+
await expect(() =>
|
286
|
+
simulateContract(publicClient, {
|
287
|
+
abi: errorsExampleABI,
|
288
|
+
address: contractAddress!,
|
289
|
+
functionName: 'divideByZeroWrite',
|
290
|
+
from: accounts[0].address,
|
291
|
+
}),
|
292
|
+
).rejects.toMatchInlineSnapshot(`
|
293
|
+
[ContractFunctionExecutionError: The contract function "divideByZeroWrite" reverted with the following reason:
|
294
|
+
Division or modulo by zero (e.g. \`5 / 0\` or \`23 % 0\`).
|
295
|
+
|
296
|
+
Contract: 0x0000000000000000000000000000000000000000
|
297
|
+
Function: divideByZeroWrite()
|
298
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
299
|
+
|
300
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
301
|
+
Version: viem@1.0.2]
|
302
|
+
`)
|
303
|
+
})
|
304
|
+
|
305
|
+
test('require', async () => {
|
306
|
+
const { contractAddress } = await deployErrorExample()
|
307
|
+
|
308
|
+
await expect(() =>
|
309
|
+
simulateContract(publicClient, {
|
310
|
+
abi: errorsExampleABI,
|
311
|
+
address: contractAddress!,
|
312
|
+
functionName: 'requireWrite',
|
313
|
+
from: accounts[0].address,
|
314
|
+
}),
|
315
|
+
).rejects.toMatchInlineSnapshot(`
|
316
|
+
[ContractFunctionExecutionError: The contract function "requireWrite" reverted with the following reason:
|
317
|
+
execution reverted
|
318
|
+
|
319
|
+
Contract: 0x0000000000000000000000000000000000000000
|
320
|
+
Function: requireWrite()
|
321
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
322
|
+
|
323
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
324
|
+
Version: viem@1.0.2]
|
325
|
+
`)
|
326
|
+
})
|
327
|
+
|
328
|
+
test('custom error: simple', async () => {
|
329
|
+
const { contractAddress } = await deployErrorExample()
|
330
|
+
|
331
|
+
await expect(() =>
|
332
|
+
simulateContract(publicClient, {
|
333
|
+
abi: errorsExampleABI,
|
334
|
+
address: contractAddress!,
|
335
|
+
functionName: 'simpleCustomWrite',
|
336
|
+
from: accounts[0].address,
|
337
|
+
}),
|
338
|
+
).rejects.toMatchInlineSnapshot(`
|
339
|
+
[ContractFunctionExecutionError: The contract function "simpleCustomWrite" reverted.
|
340
|
+
|
341
|
+
Error: SimpleError(string message)
|
342
|
+
Arguments: (bugger)
|
343
|
+
|
344
|
+
Contract: 0x0000000000000000000000000000000000000000
|
345
|
+
Function: simpleCustomWrite()
|
346
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
347
|
+
|
348
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
349
|
+
Version: viem@1.0.2]
|
350
|
+
`)
|
351
|
+
})
|
352
|
+
|
353
|
+
test('custom error: complex', async () => {
|
354
|
+
const { contractAddress } = await deployErrorExample()
|
355
|
+
|
356
|
+
await expect(() =>
|
357
|
+
simulateContract(publicClient, {
|
358
|
+
abi: errorsExampleABI,
|
359
|
+
address: contractAddress!,
|
360
|
+
functionName: 'complexCustomWrite',
|
361
|
+
from: accounts[0].address,
|
362
|
+
}),
|
363
|
+
).rejects.toMatchInlineSnapshot(`
|
364
|
+
[ContractFunctionExecutionError: The contract function "complexCustomWrite" reverted.
|
365
|
+
|
366
|
+
Error: ComplexError((address sender, uint256 bar), string message, uint256 number)
|
367
|
+
Arguments: ({"sender":"0x0000000000000000000000000000000000000000","bar":"69"}, bugger, 69)
|
368
|
+
|
369
|
+
Contract: 0x0000000000000000000000000000000000000000
|
370
|
+
Function: complexCustomWrite()
|
371
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
372
|
+
|
373
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
374
|
+
Version: viem@1.0.2]
|
375
|
+
`)
|
376
|
+
})
|
377
|
+
})
|
378
|
+
|
195
379
|
test('fake contract address', async () => {
|
196
380
|
await expect(() =>
|
197
381
|
simulateContract(publicClient, {
|
@@ -207,32 +391,20 @@ test('fake contract address', async () => {
|
|
207
391
|
address: '0x0000000000000000000000000000000000000069',
|
208
392
|
functionName: 'mint',
|
209
393
|
from: accounts[0].address,
|
210
|
-
args: [],
|
211
394
|
}),
|
212
395
|
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
213
|
-
"The contract
|
396
|
+
"The contract function \\"mint\\" returned no data (\\"0x\\").
|
397
|
+
|
398
|
+
This could be due to any of the following:
|
214
399
|
- The contract does not have the function \\"mint\\",
|
215
400
|
- The parameters passed to the contract function may be invalid, or
|
216
401
|
- The address is not a contract.
|
217
402
|
|
218
|
-
Contract:
|
219
|
-
Function:
|
220
|
-
|
403
|
+
Contract: 0x0000000000000000000000000000000000000000
|
404
|
+
Function: mint()
|
405
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
221
406
|
|
407
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
222
408
|
Version: viem@1.0.2"
|
223
409
|
`)
|
224
410
|
})
|
225
|
-
|
226
|
-
// Deploy BAYC Contract
|
227
|
-
async function deployBAYC() {
|
228
|
-
const hash = await deployContract(walletClient, {
|
229
|
-
...baycContractConfig,
|
230
|
-
args: ['Bored Ape Wagmi Club', 'BAYC', 69420n, 0n],
|
231
|
-
from: accounts[0].address,
|
232
|
-
})
|
233
|
-
await mine(testClient, { blocks: 1 })
|
234
|
-
const { contractAddress } = await getTransactionReceipt(publicClient, {
|
235
|
-
hash,
|
236
|
-
})
|
237
|
-
return { contractAddress }
|
238
|
-
}
|
@@ -1,9 +1,11 @@
|
|
1
|
-
import { Abi } from 'abitype'
|
1
|
+
import { Abi, Narrow } from 'abitype'
|
2
2
|
|
3
3
|
import type { PublicClient } from '../../clients'
|
4
|
+
import { BaseError } from '../../errors'
|
4
5
|
import type {
|
5
6
|
Address,
|
6
7
|
Chain,
|
8
|
+
ContractConfig,
|
7
9
|
ExtractArgsFromAbi,
|
8
10
|
ExtractResultFromAbi,
|
9
11
|
ExtractFunctionNameFromAbi,
|
@@ -14,6 +16,7 @@ import {
|
|
14
16
|
decodeFunctionResult,
|
15
17
|
encodeFunctionData,
|
16
18
|
getContractError,
|
19
|
+
DecodeFunctionResultArgs,
|
17
20
|
} from '../../utils'
|
18
21
|
import { WriteContractArgs } from '../wallet'
|
19
22
|
import { call, CallArgs } from './call'
|
@@ -22,16 +25,10 @@ export type SimulateContractArgs<
|
|
22
25
|
TChain extends Chain = Chain,
|
23
26
|
TAbi extends Abi | readonly unknown[] = Abi,
|
24
27
|
TFunctionName extends string = any,
|
25
|
-
> = Omit<CallArgs<TChain>, 'to' | 'data' | 'value'> &
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
TAbi,
|
30
|
-
TFunctionName,
|
31
|
-
'payable' | 'nonpayable'
|
32
|
-
>
|
33
|
-
value?: GetValue<TAbi, TFunctionName, CallArgs<TChain>['value']>
|
34
|
-
} & ExtractArgsFromAbi<TAbi, TFunctionName>
|
28
|
+
> = Omit<CallArgs<TChain>, 'to' | 'data' | 'value'> &
|
29
|
+
ContractConfig<TAbi, TFunctionName, 'payable' | 'nonpayable'> & {
|
30
|
+
value?: GetValue<TAbi, TFunctionName, CallArgs<TChain>['value']>
|
31
|
+
}
|
35
32
|
|
36
33
|
export type SimulateContractResponse<
|
37
34
|
TChain extends Chain = Chain,
|
@@ -39,17 +36,14 @@ export type SimulateContractResponse<
|
|
39
36
|
TFunctionName extends string = string,
|
40
37
|
> = {
|
41
38
|
result: ExtractResultFromAbi<TAbi, TFunctionName>
|
42
|
-
request: WriteContractArgs<TChain, TAbi, TFunctionName> &
|
43
|
-
|
44
|
-
abi: TAbi
|
45
|
-
functionName: ExtractFunctionNameFromAbi<TAbi, TFunctionName>
|
46
|
-
} & ExtractArgsFromAbi<TAbi, TFunctionName>
|
39
|
+
request: WriteContractArgs<TChain, TAbi, TFunctionName> &
|
40
|
+
ContractConfig<TAbi, TFunctionName, 'payable' | 'nonpayable'>
|
47
41
|
}
|
48
42
|
|
49
43
|
export async function simulateContract<
|
50
44
|
TChain extends Chain,
|
51
|
-
TAbi extends Abi
|
52
|
-
TFunctionName extends string
|
45
|
+
TAbi extends Abi | readonly unknown[],
|
46
|
+
TFunctionName extends string,
|
53
47
|
>(
|
54
48
|
client: PublicClient,
|
55
49
|
{
|
@@ -73,9 +67,10 @@ export async function simulateContract<
|
|
73
67
|
} as unknown as CallArgs<TChain>)
|
74
68
|
const result = decodeFunctionResult({
|
75
69
|
abi,
|
70
|
+
args,
|
76
71
|
functionName,
|
77
72
|
data: data || '0x',
|
78
|
-
})
|
73
|
+
} as DecodeFunctionResultArgs)
|
79
74
|
return {
|
80
75
|
result,
|
81
76
|
request: {
|
@@ -87,10 +82,11 @@ export async function simulateContract<
|
|
87
82
|
},
|
88
83
|
} as unknown as SimulateContractResponse<TChain, TAbi, TFunctionName>
|
89
84
|
} catch (err) {
|
90
|
-
throw getContractError(err, {
|
91
|
-
abi,
|
85
|
+
throw getContractError(err as BaseError, {
|
86
|
+
abi: abi as Abi,
|
92
87
|
address,
|
93
88
|
args,
|
89
|
+
docsPath: '/docs/contract/simulateContract',
|
94
90
|
functionName,
|
95
91
|
sender: callRequest.from,
|
96
92
|
})
|
@@ -32,41 +32,45 @@ afterAll(async () => {
|
|
32
32
|
})
|
33
33
|
})
|
34
34
|
|
35
|
-
test(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
35
|
+
test(
|
36
|
+
'default',
|
37
|
+
async () => {
|
38
|
+
let logs: OnLogsResponse[] = []
|
39
|
+
|
40
|
+
const unwatch = watchContractEvent(publicClient, {
|
41
|
+
...usdcContractConfig,
|
42
|
+
onLogs: (logs_) => logs.push(logs_),
|
43
|
+
})
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
45
|
+
await writeContract(walletClient, {
|
46
|
+
...usdcContractConfig,
|
47
|
+
from: vitalikAddress,
|
48
|
+
functionName: 'transfer',
|
49
|
+
args: [vitalikAddress, 1n],
|
50
|
+
})
|
51
|
+
await writeContract(walletClient, {
|
52
|
+
...usdcContractConfig,
|
53
|
+
from: vitalikAddress,
|
54
|
+
functionName: 'transfer',
|
55
|
+
args: [vitalikAddress, 1n],
|
56
|
+
})
|
57
|
+
await wait(1000)
|
58
|
+
await writeContract(walletClient, {
|
59
|
+
...usdcContractConfig,
|
60
|
+
from: vitalikAddress,
|
61
|
+
functionName: 'approve',
|
62
|
+
args: [vitalikAddress, 1n],
|
63
|
+
})
|
62
64
|
|
63
|
-
|
64
|
-
|
65
|
+
await wait(2000)
|
66
|
+
unwatch()
|
65
67
|
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
}
|
68
|
+
expect(logs.length).toBe(2)
|
69
|
+
expect(logs[0].length).toBe(2)
|
70
|
+
expect(logs[1].length).toBe(1)
|
71
|
+
},
|
72
|
+
{ retry: 3 },
|
73
|
+
)
|
70
74
|
|
71
75
|
test('args: batch', async () => {
|
72
76
|
let logs: OnLogsResponse[] = []
|
@@ -9,7 +9,7 @@ import {
|
|
9
9
|
vitalikAddress,
|
10
10
|
walletClient,
|
11
11
|
} from '../../_test'
|
12
|
-
import { impersonateAccount, stopImpersonatingAccount } from '../test'
|
12
|
+
import { impersonateAccount, mine, stopImpersonatingAccount } from '../test'
|
13
13
|
import { sendTransaction } from '../wallet'
|
14
14
|
import * as createEventFilter from './createEventFilter'
|
15
15
|
import * as getFilterChanges from './getFilterChanges'
|
@@ -19,6 +19,7 @@ beforeAll(async () => {
|
|
19
19
|
await impersonateAccount(testClient, {
|
20
20
|
address: vitalikAddress,
|
21
21
|
})
|
22
|
+
await mine(testClient, { blocks: 1 })
|
22
23
|
})
|
23
24
|
|
24
25
|
afterAll(async () => {
|
@@ -27,37 +28,41 @@ afterAll(async () => {
|
|
27
28
|
})
|
28
29
|
})
|
29
30
|
|
30
|
-
test(
|
31
|
-
|
31
|
+
test(
|
32
|
+
'default',
|
33
|
+
async () => {
|
34
|
+
let logs: OnLogsResponse[] = []
|
32
35
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
+
const unwatch = watchEvent(publicClient, {
|
37
|
+
onLogs: (logs_) => logs.push(logs_),
|
38
|
+
})
|
36
39
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
40
|
+
await wait(1000)
|
41
|
+
await sendTransaction(walletClient, {
|
42
|
+
from: vitalikAddress,
|
43
|
+
to: usdcContractConfig.address,
|
44
|
+
data: transfer1Data(accounts[0].address),
|
45
|
+
})
|
46
|
+
await sendTransaction(walletClient, {
|
47
|
+
from: vitalikAddress,
|
48
|
+
to: usdcContractConfig.address,
|
49
|
+
data: transfer1Data(accounts[0].address),
|
50
|
+
})
|
51
|
+
await wait(1000)
|
52
|
+
await sendTransaction(walletClient, {
|
53
|
+
from: vitalikAddress,
|
54
|
+
to: usdcContractConfig.address,
|
55
|
+
data: transfer1Data(accounts[1].address),
|
56
|
+
})
|
57
|
+
await wait(2000)
|
58
|
+
unwatch()
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
}
|
60
|
+
expect(logs.length).toBe(2)
|
61
|
+
expect(logs[0].length).toBe(2)
|
62
|
+
expect(logs[1].length).toBe(1)
|
63
|
+
},
|
64
|
+
{ retry: 3 },
|
65
|
+
)
|
61
66
|
|
62
67
|
test('args: batch', async () => {
|
63
68
|
let logs: OnLogsResponse[] = []
|
@@ -35,7 +35,6 @@ test('errors: unsupported type', async () => {
|
|
35
35
|
Double check you have provided the correct parameters.
|
36
36
|
|
37
37
|
Details: Token type ERC721 not supported.
|
38
|
-
Version: viem@1.0.2
|
39
|
-
Internal Error: {\\"code\\":-32602,\\"details\\":\\"Token type ERC721 not supported.\\"}"
|
38
|
+
Version: viem@1.0.2"
|
40
39
|
`)
|
41
40
|
})
|
@@ -12,6 +12,16 @@ import { mine } from '../test'
|
|
12
12
|
import { writeContract } from './writeContract'
|
13
13
|
|
14
14
|
test('default', async () => {
|
15
|
+
expect(
|
16
|
+
await writeContract(walletClient, {
|
17
|
+
...wagmiContractConfig,
|
18
|
+
from: accounts[0].address,
|
19
|
+
functionName: 'mint',
|
20
|
+
}),
|
21
|
+
).toBeDefined()
|
22
|
+
})
|
23
|
+
|
24
|
+
test('overloaded function', async () => {
|
15
25
|
expect(
|
16
26
|
await writeContract(walletClient, {
|
17
27
|
...wagmiContractConfig,
|
@@ -27,7 +37,26 @@ test('w/ simulateContract', async () => {
|
|
27
37
|
...wagmiContractConfig,
|
28
38
|
from: accounts[0].address,
|
29
39
|
functionName: 'mint',
|
30
|
-
|
40
|
+
})
|
41
|
+
expect(await writeContract(walletClient, request)).toBeDefined()
|
42
|
+
|
43
|
+
await mine(testClient, { blocks: 1 })
|
44
|
+
|
45
|
+
expect(
|
46
|
+
await simulateContract(publicClient, {
|
47
|
+
...wagmiContractConfig,
|
48
|
+
from: accounts[0].address,
|
49
|
+
functionName: 'mint',
|
50
|
+
}),
|
51
|
+
).toBeDefined()
|
52
|
+
})
|
53
|
+
|
54
|
+
test('w/ simulateContract (overloaded)', async () => {
|
55
|
+
const { request } = await simulateContract(publicClient, {
|
56
|
+
...wagmiContractConfig,
|
57
|
+
from: accounts[0].address,
|
58
|
+
functionName: 'mint',
|
59
|
+
args: [69421n],
|
31
60
|
})
|
32
61
|
expect(await writeContract(walletClient, request)).toBeDefined()
|
33
62
|
|
@@ -38,17 +67,18 @@ test('w/ simulateContract', async () => {
|
|
38
67
|
...wagmiContractConfig,
|
39
68
|
from: accounts[0].address,
|
40
69
|
functionName: 'mint',
|
41
|
-
args: [
|
70
|
+
args: [69421n],
|
42
71
|
}),
|
43
72
|
).rejects.toThrowErrorMatchingInlineSnapshot(`
|
44
|
-
"
|
45
|
-
|
46
|
-
|
73
|
+
"The contract function \\"mint\\" reverted with the following reason:
|
74
|
+
Token ID is taken
|
75
|
+
|
47
76
|
Contract: 0x0000000000000000000000000000000000000000
|
48
77
|
Function: mint(uint256 tokenId)
|
49
|
-
Arguments: (
|
78
|
+
Arguments: (69421)
|
79
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
50
80
|
|
51
|
-
|
81
|
+
Docs: https://viem.sh/docs/contract/simulateContract
|
52
82
|
Version: viem@1.0.2"
|
53
83
|
`)
|
54
84
|
})
|