viem 0.0.1-alpha.21 → 0.0.1-alpha.23
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-EC3NUIJE.js → chunk-7Y5QVLX7.js} +13 -13
- package/dist/{chunk-EC3NUIJE.js.map → chunk-7Y5QVLX7.js.map} +1 -1
- package/dist/{chunk-KEHGSYDO.js → chunk-BV5NTHUX.js} +14 -13
- package/dist/chunk-BV5NTHUX.js.map +1 -0
- package/dist/{chunk-46BO7YAQ.mjs → chunk-EGVXCZNJ.mjs} +4 -3
- package/dist/chunk-EGVXCZNJ.mjs.map +1 -0
- package/dist/{chunk-57ZOFERP.mjs → chunk-GX2KDAM3.mjs} +2 -2
- package/dist/{chunk-57ZOFERP.mjs.map → chunk-GX2KDAM3.mjs.map} +0 -0
- package/dist/{chunk-W7BWWAC4.js → chunk-NW6724MI.js} +14 -14
- package/dist/{chunk-W7BWWAC4.js.map → chunk-NW6724MI.js.map} +0 -0
- package/dist/{chunk-DGO77E2H.mjs → chunk-RJLUZTJS.mjs} +86 -3
- package/dist/chunk-RJLUZTJS.mjs.map +1 -0
- package/dist/{chunk-O2GYLJVD.js → chunk-SSPRUPGN.js} +405 -165
- package/dist/chunk-SSPRUPGN.js.map +1 -0
- package/dist/{chunk-DSPMAIDO.mjs → chunk-TXHOG6KU.mjs} +2 -2
- package/dist/{chunk-DSPMAIDO.mjs.map → chunk-TXHOG6KU.mjs.map} +1 -1
- package/dist/{chunk-62VTYU2V.mjs → chunk-XBUH66KN.mjs} +406 -166
- package/dist/chunk-XBUH66KN.mjs.map +1 -0
- package/dist/{chunk-KZMJR27B.js → chunk-ZKYGWITF.js} +147 -64
- package/dist/chunk-ZKYGWITF.js.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-4c3a37b3.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 +174 -113
- package/dist/index.js +16 -6
- package/dist/index.mjs +15 -5
- package/dist/normalize-ef9240c0.d.ts +33 -0
- package/dist/{parseGwei-4308ad80.d.ts → parseGwei-3411cf2d.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-57df1a13.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/constants.ts +4 -3
- package/src/_test/index.ts +4 -2
- package/src/_test/utils.ts +39 -1
- package/src/actions/index.test.ts +1 -0
- package/src/actions/index.ts +2 -0
- 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/getFilterChanges.test.ts +9 -9
- package/src/actions/public/getFilterLogs.test.ts +7 -7
- package/src/actions/public/getGasPrice.bench.ts +1 -10
- package/src/actions/public/getLogs.test.ts +7 -7
- package/src/actions/public/getTransaction.bench.ts +5 -5
- package/src/actions/public/getTransactionReceipt.bench.ts +5 -5
- package/src/actions/public/index.test.ts +1 -0
- package/src/actions/public/index.ts +3 -0
- 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 +61 -57
- package/src/actions/public/watchEvent.test.ts +42 -37
- package/src/actions/test/impersonateAccount.test.ts +4 -6
- package/src/actions/test/sendUnsignedTransaction.test.ts +2 -2
- package/src/actions/test/stopImpersonatingAccount.test.ts +5 -7
- 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 +47 -0
- package/src/index.ts +10 -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
@@ -2,96 +2,281 @@ import { describe, expect, test } from 'vitest'
|
|
2
2
|
|
3
3
|
import { accounts } from '../../_test'
|
4
4
|
import { baycContractConfig } from '../../_test/abis'
|
5
|
-
import {
|
5
|
+
import {
|
6
|
+
AbiDecodingZeroDataError,
|
7
|
+
BaseError,
|
8
|
+
RawContractError,
|
9
|
+
} from '../../errors'
|
6
10
|
import { getContractError } from './getContractError'
|
7
11
|
|
8
12
|
describe('getContractError', () => {
|
9
13
|
test('default', () => {
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
14
|
+
const error = getContractError(
|
15
|
+
new RawContractError({
|
16
|
+
message: 'execution reverted: Sale must be active to mint Ape',
|
17
|
+
data: '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f53616c65206d7573742062652061637469766520746f206d696e742041706500',
|
18
|
+
}),
|
19
|
+
{
|
20
|
+
abi: baycContractConfig.abi,
|
21
|
+
functionName: 'mintApe',
|
22
|
+
args: [1n],
|
23
|
+
sender: accounts[0].address,
|
24
|
+
},
|
25
|
+
)
|
26
|
+
expect(error).toMatchInlineSnapshot(`
|
27
|
+
[ContractFunctionExecutionError: The contract function "mintApe" reverted with the following reason:
|
28
|
+
Sale must be active to mint Ape
|
29
|
+
|
30
|
+
Function: mintApe(uint256 numberOfTokens)
|
31
|
+
Arguments: (1)
|
29
32
|
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
33
|
+
|
34
|
+
Version: viem@1.0.2]
|
35
|
+
`)
|
36
|
+
expect(error.cause).toMatchInlineSnapshot(`
|
37
|
+
[ContractFunctionRevertedError: The contract function "mintApe" reverted with the following reason:
|
38
|
+
Sale must be active to mint Ape
|
39
|
+
|
40
|
+
Version: viem@1.0.2]
|
41
|
+
`)
|
42
|
+
})
|
43
|
+
|
44
|
+
test('default: rpc', () => {
|
45
|
+
const error = getContractError(
|
46
|
+
new BaseError('An RPC error occurred', {
|
47
|
+
cause: {
|
48
|
+
code: 3,
|
49
|
+
message: 'execution reverted: Sale must be active to mint Ape',
|
50
|
+
data: '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f53616c65206d7573742062652061637469766520746f206d696e742041706500',
|
51
|
+
} as unknown as Error,
|
52
|
+
}),
|
53
|
+
{
|
54
|
+
abi: baycContractConfig.abi,
|
55
|
+
functionName: 'mintApe',
|
56
|
+
args: [1n],
|
57
|
+
sender: accounts[0].address,
|
58
|
+
},
|
59
|
+
)
|
60
|
+
expect(error).toMatchInlineSnapshot(`
|
61
|
+
[ContractFunctionExecutionError: The contract function "mintApe" reverted with the following reason:
|
62
|
+
Sale must be active to mint Ape
|
63
|
+
|
30
64
|
Function: mintApe(uint256 numberOfTokens)
|
31
65
|
Arguments: (1)
|
66
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
67
|
+
|
68
|
+
Version: viem@1.0.2]
|
69
|
+
`)
|
70
|
+
expect(error.cause).toMatchInlineSnapshot(`
|
71
|
+
[ContractFunctionRevertedError: The contract function "mintApe" reverted with the following reason:
|
72
|
+
Sale must be active to mint Ape
|
32
73
|
|
33
|
-
Details: execution reverted: Sale must be active to mint Ape
|
34
74
|
Version: viem@1.0.2]
|
35
75
|
`)
|
36
76
|
})
|
37
77
|
|
38
|
-
test('
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
78
|
+
test('no data', () => {
|
79
|
+
const error = getContractError(
|
80
|
+
new BaseError('An RPC error occurred', {
|
81
|
+
cause: {
|
82
|
+
code: 3,
|
83
|
+
message: 'ah no',
|
84
|
+
} as unknown as Error,
|
85
|
+
}),
|
86
|
+
{
|
87
|
+
abi: baycContractConfig.abi,
|
88
|
+
functionName: 'mintApe',
|
89
|
+
args: [1n],
|
90
|
+
sender: accounts[0].address,
|
91
|
+
},
|
92
|
+
)
|
93
|
+
expect(error).toMatchInlineSnapshot(`
|
94
|
+
[ContractFunctionExecutionError: The contract function "mintApe" reverted with the following reason:
|
95
|
+
ah no
|
96
|
+
|
97
|
+
Function: mintApe(uint256 numberOfTokens)
|
98
|
+
Arguments: (1)
|
58
99
|
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
59
100
|
|
60
|
-
|
101
|
+
Version: viem@1.0.2]
|
102
|
+
`)
|
103
|
+
expect(error.cause).toMatchInlineSnapshot(`
|
104
|
+
[ContractFunctionRevertedError: The contract function "mintApe" reverted with the following reason:
|
105
|
+
ah no
|
106
|
+
|
61
107
|
Version: viem@1.0.2]
|
62
108
|
`)
|
63
109
|
})
|
64
110
|
|
65
|
-
test('
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
111
|
+
test('no message', () => {
|
112
|
+
const error = getContractError(
|
113
|
+
new BaseError('An RPC error occurred', {
|
114
|
+
cause: {
|
115
|
+
code: 3,
|
116
|
+
data: '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f53616c65206d7573742062652061637469766520746f206d696e742041706500',
|
117
|
+
} as unknown as Error,
|
118
|
+
}),
|
119
|
+
{
|
120
|
+
abi: baycContractConfig.abi,
|
121
|
+
functionName: 'mintApe',
|
122
|
+
args: [1n],
|
123
|
+
sender: accounts[0].address,
|
124
|
+
},
|
125
|
+
)
|
126
|
+
expect(error).toMatchInlineSnapshot(`
|
127
|
+
[ContractFunctionExecutionError: The contract function "mintApe" reverted with the following reason:
|
128
|
+
Sale must be active to mint Ape
|
129
|
+
|
130
|
+
Function: mintApe(uint256 numberOfTokens)
|
131
|
+
Arguments: (1)
|
132
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
133
|
+
|
134
|
+
Version: viem@1.0.2]
|
135
|
+
`)
|
136
|
+
expect(error.cause).toMatchInlineSnapshot(`
|
137
|
+
[ContractFunctionRevertedError: The contract function "mintApe" reverted with the following reason:
|
138
|
+
Sale must be active to mint Ape
|
80
139
|
|
81
|
-
Details: rarararar i am an error lmaoaoo
|
82
140
|
Version: viem@1.0.2]
|
83
141
|
`)
|
84
|
-
|
85
|
-
|
142
|
+
})
|
143
|
+
|
144
|
+
test('unknown function', () => {
|
145
|
+
const error = getContractError(
|
146
|
+
new BaseError('An RPC error occurred', {
|
147
|
+
cause: {
|
148
|
+
code: 3,
|
149
|
+
message: 'execution reverted: Sale must be active to mint Ape',
|
150
|
+
data: '0x08c379a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000001f53616c65206d7573742062652061637469766520746f206d696e742041706500',
|
151
|
+
} as unknown as Error,
|
152
|
+
}),
|
153
|
+
{
|
86
154
|
abi: baycContractConfig.abi,
|
87
|
-
functionName: '
|
155
|
+
functionName: 'mintApe',
|
88
156
|
args: [1n],
|
89
157
|
sender: accounts[0].address,
|
158
|
+
},
|
159
|
+
)
|
160
|
+
expect(error).toMatchInlineSnapshot(`
|
161
|
+
[ContractFunctionExecutionError: The contract function "mintApe" reverted with the following reason:
|
162
|
+
Sale must be active to mint Ape
|
163
|
+
|
164
|
+
Function: mintApe(uint256 numberOfTokens)
|
165
|
+
Arguments: (1)
|
166
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
167
|
+
|
168
|
+
Version: viem@1.0.2]
|
169
|
+
`)
|
170
|
+
expect(error.cause).toMatchInlineSnapshot(`
|
171
|
+
[ContractFunctionRevertedError: The contract function "mintApe" reverted with the following reason:
|
172
|
+
Sale must be active to mint Ape
|
173
|
+
|
174
|
+
Version: viem@1.0.2]
|
175
|
+
`)
|
176
|
+
})
|
177
|
+
|
178
|
+
test('unknown error', () => {
|
179
|
+
const error = getContractError(
|
180
|
+
new BaseError('An RPC error occurred', {
|
181
|
+
cause: new Error('rarararar i am an error lmaoaoo'),
|
90
182
|
}),
|
91
|
-
|
183
|
+
{
|
184
|
+
abi: baycContractConfig.abi,
|
185
|
+
functionName: 'mintApe',
|
186
|
+
args: [1n],
|
187
|
+
sender: accounts[0].address,
|
188
|
+
},
|
189
|
+
)
|
190
|
+
expect(error).toMatchInlineSnapshot(`
|
191
|
+
[ContractFunctionExecutionError: An RPC error occurred
|
192
|
+
|
193
|
+
Function: mintApe(uint256 numberOfTokens)
|
194
|
+
Arguments: (1)
|
195
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
196
|
+
|
197
|
+
Details: rarararar i am an error lmaoaoo
|
198
|
+
Version: viem@1.0.2]
|
199
|
+
`)
|
200
|
+
expect(error.cause).toMatchInlineSnapshot(`
|
201
|
+
[ViemError: An RPC error occurred
|
202
|
+
|
203
|
+
Details: rarararar i am an error lmaoaoo
|
204
|
+
Version: viem@1.0.2]
|
205
|
+
`)
|
206
|
+
|
207
|
+
const error2 = getContractError(new BaseError('An RPC error occurred'), {
|
208
|
+
abi: baycContractConfig.abi,
|
209
|
+
functionName: 'mintApe',
|
210
|
+
args: [1n],
|
211
|
+
sender: accounts[0].address,
|
212
|
+
})
|
213
|
+
expect(error2).toMatchInlineSnapshot(`
|
214
|
+
[ContractFunctionExecutionError: An RPC error occurred
|
215
|
+
|
216
|
+
Function: mintApe(uint256 numberOfTokens)
|
217
|
+
Arguments: (1)
|
218
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
219
|
+
|
220
|
+
Version: viem@1.0.2]
|
221
|
+
`)
|
222
|
+
expect(error2.cause).toMatchInlineSnapshot(`
|
92
223
|
[ViemError: An RPC error occurred
|
93
224
|
|
94
225
|
Version: viem@1.0.2]
|
95
226
|
`)
|
227
|
+
|
228
|
+
const error3 = getContractError(new BaseError(''), {
|
229
|
+
abi: baycContractConfig.abi,
|
230
|
+
functionName: 'mintApe',
|
231
|
+
args: [1n],
|
232
|
+
sender: accounts[0].address,
|
233
|
+
})
|
234
|
+
expect(error3).toMatchInlineSnapshot(`
|
235
|
+
[ContractFunctionExecutionError: An unknown error occurred while executing the contract function "mintApe".
|
236
|
+
|
237
|
+
Function: mintApe(uint256 numberOfTokens)
|
238
|
+
Arguments: (1)
|
239
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
240
|
+
|
241
|
+
Version: viem@1.0.2]
|
242
|
+
`)
|
243
|
+
expect(error3.cause).toMatchInlineSnapshot(`
|
244
|
+
[ViemError: An error occurred.
|
245
|
+
|
246
|
+
Version: viem@1.0.2]
|
247
|
+
`)
|
248
|
+
})
|
249
|
+
|
250
|
+
test('zero data', () => {
|
251
|
+
const error = getContractError(new AbiDecodingZeroDataError(), {
|
252
|
+
abi: baycContractConfig.abi,
|
253
|
+
functionName: 'mintApe',
|
254
|
+
args: [1n],
|
255
|
+
sender: accounts[0].address,
|
256
|
+
})
|
257
|
+
expect(error).toMatchInlineSnapshot(`
|
258
|
+
[ContractFunctionExecutionError: The contract function "mintApe" returned no data ("0x").
|
259
|
+
|
260
|
+
This could be due to any of the following:
|
261
|
+
- The contract does not have the function "mintApe",
|
262
|
+
- The parameters passed to the contract function may be invalid, or
|
263
|
+
- The address is not a contract.
|
264
|
+
|
265
|
+
Function: mintApe(uint256 numberOfTokens)
|
266
|
+
Arguments: (1)
|
267
|
+
Sender: 0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266
|
268
|
+
|
269
|
+
Version: viem@1.0.2]
|
270
|
+
`)
|
271
|
+
expect(error.cause).toMatchInlineSnapshot(`
|
272
|
+
[ContractFunctionZeroDataError: The contract function "mintApe" returned no data ("0x").
|
273
|
+
|
274
|
+
This could be due to any of the following:
|
275
|
+
- The contract does not have the function "mintApe",
|
276
|
+
- The parameters passed to the contract function may be invalid, or
|
277
|
+
- The address is not a contract.
|
278
|
+
|
279
|
+
Version: viem@1.0.2]
|
280
|
+
`)
|
96
281
|
})
|
97
282
|
})
|
@@ -1,66 +1,58 @@
|
|
1
1
|
import { Abi } from 'abitype'
|
2
2
|
import {
|
3
3
|
AbiDecodingZeroDataError,
|
4
|
-
|
5
|
-
|
4
|
+
BaseError,
|
5
|
+
ContractFunctionExecutionError,
|
6
|
+
RawContractError,
|
6
7
|
} from '../../errors'
|
8
|
+
import {
|
9
|
+
ContractFunctionRevertedError,
|
10
|
+
ContractFunctionZeroDataError,
|
11
|
+
} from '../../errors/contract'
|
7
12
|
import { Address } from '../../types'
|
8
|
-
|
13
|
+
|
14
|
+
const EXECUTION_REVERTED_ERROR_CODE = 3
|
9
15
|
|
10
16
|
export function getContractError(
|
11
|
-
err:
|
17
|
+
err: BaseError,
|
12
18
|
{
|
13
19
|
abi,
|
14
20
|
address,
|
15
21
|
args,
|
22
|
+
docsPath,
|
16
23
|
functionName,
|
17
24
|
sender,
|
18
25
|
}: {
|
19
26
|
abi: Abi
|
20
27
|
args: any
|
21
28
|
address?: Address
|
29
|
+
docsPath?: string
|
22
30
|
functionName: string
|
23
31
|
sender?: Address
|
24
32
|
},
|
25
33
|
) {
|
26
|
-
const { code, message } =
|
27
|
-
|
28
|
-
|
29
|
-
const abiItem = getAbiItem({ abi, name: functionName })
|
30
|
-
const formattedArgs = abiItem
|
31
|
-
? formatAbiItemWithArgs({
|
32
|
-
abiItem,
|
33
|
-
args,
|
34
|
-
includeFunctionName: false,
|
35
|
-
includeName: false,
|
36
|
-
})
|
37
|
-
: undefined
|
38
|
-
const functionWithParams = abiItem
|
39
|
-
? formatAbiItem(abiItem, { includeName: true })
|
40
|
-
: undefined
|
34
|
+
const { code, data, message } = (
|
35
|
+
err instanceof RawContractError ? err : err.cause || {}
|
36
|
+
) as RawContractError
|
41
37
|
|
38
|
+
let cause = err
|
42
39
|
if (err instanceof AbiDecodingZeroDataError) {
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
cause: err as Error,
|
47
|
-
contractAddress: address,
|
48
|
-
functionName,
|
49
|
-
functionWithParams,
|
50
|
-
})
|
51
|
-
}
|
52
|
-
if (code === 3 || message?.includes('execution reverted')) {
|
53
|
-
const message_ = message?.replace('execution reverted: ', '')
|
54
|
-
return new ContractMethodExecutionError(message_, {
|
40
|
+
cause = new ContractFunctionZeroDataError({ functionName })
|
41
|
+
} else if (code === EXECUTION_REVERTED_ERROR_CODE && (data || message)) {
|
42
|
+
cause = new ContractFunctionRevertedError({
|
55
43
|
abi,
|
56
|
-
|
57
|
-
cause: err as Error,
|
58
|
-
contractAddress: address,
|
59
|
-
formattedArgs,
|
44
|
+
data,
|
60
45
|
functionName,
|
61
|
-
|
62
|
-
sender,
|
46
|
+
message,
|
63
47
|
})
|
64
48
|
}
|
65
|
-
|
49
|
+
|
50
|
+
return new ContractFunctionExecutionError(cause, {
|
51
|
+
abi,
|
52
|
+
args,
|
53
|
+
contractAddress: address,
|
54
|
+
docsPath,
|
55
|
+
functionName,
|
56
|
+
sender,
|
57
|
+
})
|
66
58
|
}
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { hexZeroPad, zeroPad } from 'ethers/lib/utils'
|
2
|
-
import { hexZeroPad as hexZeroPad2, zeroPad as zeroPad2 } from 'essential-eth'
|
3
2
|
|
4
3
|
import { bench, describe } from 'vitest'
|
5
4
|
import Web3 from 'web3'
|
@@ -18,10 +17,6 @@ describe('Pad Hex', () => {
|
|
18
17
|
bench('web3.js: `padLeft`', () => {
|
19
18
|
Web3.utils.padLeft('0xa4e12a45', 32)
|
20
19
|
})
|
21
|
-
|
22
|
-
bench('essential-eth: `hexZeroPad`', () => {
|
23
|
-
hexZeroPad2('0xa4e12a45', 32)
|
24
|
-
})
|
25
20
|
})
|
26
21
|
|
27
22
|
describe('Pad Bytes', () => {
|
@@ -32,8 +27,4 @@ describe('Pad Bytes', () => {
|
|
32
27
|
bench('ethers: `zeroPad`', () => {
|
33
28
|
zeroPad(new Uint8Array([1, 122, 51, 123]), 32)
|
34
29
|
})
|
35
|
-
|
36
|
-
bench('essential-eth: `zeroPad`', () => {
|
37
|
-
zeroPad2(new Uint8Array([1, 122, 51, 123]), 32)
|
38
|
-
})
|
39
30
|
})
|
@@ -1,8 +1,4 @@
|
|
1
1
|
import { hexStripZeros, stripZeros } from 'ethers/lib/utils'
|
2
|
-
import {
|
3
|
-
hexStripZeros as hexStripZeros2,
|
4
|
-
stripZeros as stripZeros2,
|
5
|
-
} from 'essential-eth'
|
6
2
|
|
7
3
|
import { bench, describe } from 'vitest'
|
8
4
|
|
@@ -16,10 +12,6 @@ describe('Trim Hex', () => {
|
|
16
12
|
bench('ethers: `hexStripZeros`', () => {
|
17
13
|
hexStripZeros('0x00000000000000000000000a4e12a45')
|
18
14
|
})
|
19
|
-
|
20
|
-
bench('essential-eth: `hexStripZeros`', () => {
|
21
|
-
hexStripZeros2('0x00000000000000000000000a4e12a45')
|
22
|
-
})
|
23
15
|
})
|
24
16
|
|
25
17
|
describe('Trim Bytes', () => {
|
@@ -39,12 +31,4 @@ describe('Trim Bytes', () => {
|
|
39
31
|
]),
|
40
32
|
)
|
41
33
|
})
|
42
|
-
|
43
|
-
bench('essential-eth: `stripZeros`', () => {
|
44
|
-
stripZeros2(
|
45
|
-
new Uint8Array([
|
46
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 122, 51, 123,
|
47
|
-
]),
|
48
|
-
)
|
49
|
-
})
|
50
34
|
})
|
@@ -1,8 +1,4 @@
|
|
1
1
|
import { arrayify, toUtf8Bytes } from 'ethers/lib/utils'
|
2
|
-
import {
|
3
|
-
arrayify as arrayify2,
|
4
|
-
toUtf8Bytes as toUtf8Bytes2,
|
5
|
-
} from 'essential-eth'
|
6
2
|
import { bench, describe } from 'vitest'
|
7
3
|
import Web3 from 'web3'
|
8
4
|
|
@@ -20,10 +16,6 @@ describe('Hex to Bytes', () => {
|
|
20
16
|
bench('web3.js: `hexToBytes`', () => {
|
21
17
|
Web3.utils.hexToBytes('0x48656c6c6f20576f726c6421')
|
22
18
|
})
|
23
|
-
|
24
|
-
bench('essential-eth: `arrayify`', () => {
|
25
|
-
arrayify2('0x48656c6c6f20576f726c6421')
|
26
|
-
})
|
27
19
|
})
|
28
20
|
|
29
21
|
describe('String to Bytes', () => {
|
@@ -34,8 +26,4 @@ describe('String to Bytes', () => {
|
|
34
26
|
bench('ethers: `toUtf8Bytes`', () => {
|
35
27
|
toUtf8Bytes('Hello world')
|
36
28
|
})
|
37
|
-
|
38
|
-
bench('essential-eth: `toUtf8Bytes`', () => {
|
39
|
-
toUtf8Bytes2('Hello world')
|
40
|
-
})
|
41
29
|
})
|
@@ -1,5 +1,4 @@
|
|
1
1
|
import { hexlify } from 'ethers/lib/utils'
|
2
|
-
import { hexlify as hexlify2 } from 'essential-eth'
|
3
2
|
import { bench, describe } from 'vitest'
|
4
3
|
import Web3 from 'web3'
|
5
4
|
|
@@ -17,10 +16,6 @@ describe('Number to Hex', () => {
|
|
17
16
|
bench('web3.js: `numberToHex`', () => {
|
18
17
|
Web3.utils.numberToHex(52)
|
19
18
|
})
|
20
|
-
|
21
|
-
bench('essential-eth: `hexlify`', () => {
|
22
|
-
hexlify2(52)
|
23
|
-
})
|
24
19
|
})
|
25
20
|
|
26
21
|
describe('String to Hex', () => {
|
@@ -51,10 +46,4 @@ describe('Bytes to Hex', () => {
|
|
51
46
|
72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33,
|
52
47
|
])
|
53
48
|
})
|
54
|
-
|
55
|
-
bench('essential-eth: `hexlify`', () => {
|
56
|
-
hexlify2(
|
57
|
-
new Uint8Array([72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100, 33]),
|
58
|
-
)
|
59
|
-
})
|
60
49
|
})
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { test, expect } from 'vitest'
|
2
|
+
|
3
|
+
import { labelhash } from './labelhash'
|
4
|
+
|
5
|
+
test.each([
|
6
|
+
{
|
7
|
+
label: '',
|
8
|
+
expected:
|
9
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000',
|
10
|
+
},
|
11
|
+
{
|
12
|
+
label: 'eth',
|
13
|
+
expected:
|
14
|
+
'0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0',
|
15
|
+
},
|
16
|
+
{
|
17
|
+
label: 'awkweb',
|
18
|
+
expected:
|
19
|
+
'0x7aaad03ddcacc63166440f59c14a1a2c97ee381014b59c58f55b49ab05f31a38',
|
20
|
+
},
|
21
|
+
{
|
22
|
+
label: 'awkw𝝣b',
|
23
|
+
expected:
|
24
|
+
'0x064cfb20fc5f10bd727bd17232b9b0c8021cec89e596b1c966ff1c611420c72f',
|
25
|
+
},
|
26
|
+
{
|
27
|
+
label: '\u{0061}wkweb',
|
28
|
+
expected:
|
29
|
+
'0x7aaad03ddcacc63166440f59c14a1a2c97ee381014b59c58f55b49ab05f31a38',
|
30
|
+
},
|
31
|
+
{
|
32
|
+
label: '\u{0061}wkw\u{0065}b',
|
33
|
+
expected:
|
34
|
+
'0x7aaad03ddcacc63166440f59c14a1a2c97ee381014b59c58f55b49ab05f31a38',
|
35
|
+
},
|
36
|
+
{
|
37
|
+
label: 'awkweb',
|
38
|
+
// ^ latin small "a"
|
39
|
+
expected:
|
40
|
+
'0x7aaad03ddcacc63166440f59c14a1a2c97ee381014b59c58f55b49ab05f31a38',
|
41
|
+
},
|
42
|
+
{
|
43
|
+
label: 'awkweb',
|
44
|
+
// ^ latin small "e"
|
45
|
+
expected:
|
46
|
+
'0x7aaad03ddcacc63166440f59c14a1a2c97ee381014b59c58f55b49ab05f31a38',
|
47
|
+
},
|
48
|
+
{
|
49
|
+
label: 'ʘ‿ʘ',
|
50
|
+
expected:
|
51
|
+
'0xc142daa955184f4c4992e064a059bd8950e0bff10db566df9068ae2d5379e652',
|
52
|
+
},
|
53
|
+
])("labelhash('$label') -> '$expected'", ({ label, expected }) => {
|
54
|
+
expect(labelhash(label)).toBe(expected)
|
55
|
+
})
|
@@ -0,0 +1,16 @@
|
|
1
|
+
import { bytesToHex, stringToBytes } from '../encoding'
|
2
|
+
import { keccak256 } from '../hash'
|
3
|
+
import { normalize } from './normalize'
|
4
|
+
|
5
|
+
/**
|
6
|
+
* @description Hashes ENS label
|
7
|
+
*
|
8
|
+
* @example
|
9
|
+
* labelhash('eth')
|
10
|
+
* '0x4f5b812789fc606be1b3b16908db13fc7a9adf7ca72641f84d75b47069d3d7f0'
|
11
|
+
*/
|
12
|
+
export function labelhash(label: string) {
|
13
|
+
let result = new Uint8Array(32).fill(0)
|
14
|
+
if (!label) return bytesToHex(result)
|
15
|
+
return keccak256(stringToBytes(normalize(label)))
|
16
|
+
}
|