viem 0.0.1-alpha.14 → 0.0.1-alpha.16

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.
Files changed (456) hide show
  1. package/dist/chains.js +6 -5
  2. package/dist/chains.js.map +1 -0
  3. package/dist/chains.mjs +2 -1
  4. package/dist/chains.mjs.map +1 -0
  5. package/dist/chunk-4XREGFHD.js +153 -0
  6. package/dist/chunk-4XREGFHD.js.map +1 -0
  7. package/dist/{chunk-DUNJAMH5.mjs → chunk-B7A2CAHU.mjs} +95 -480
  8. package/dist/chunk-B7A2CAHU.mjs.map +1 -0
  9. package/dist/{chunk-6Z62LPKB.js → chunk-EWTLCB3N.js} +18 -6
  10. package/dist/chunk-EWTLCB3N.js.map +1 -0
  11. package/dist/chunk-KCMYVU3Z.mjs +153 -0
  12. package/dist/chunk-KCMYVU3Z.mjs.map +1 -0
  13. package/dist/{chunk-KB6CBNKW.mjs → chunk-KM6AFT2K.mjs} +18 -6
  14. package/dist/chunk-KM6AFT2K.mjs.map +1 -0
  15. package/dist/chunk-LQXQPPTU.js +256 -0
  16. package/dist/chunk-LQXQPPTU.js.map +1 -0
  17. package/dist/{chunk-5TCPFLFT.mjs → chunk-TSJ3OOJW.mjs} +2 -1
  18. package/dist/chunk-TSJ3OOJW.mjs.map +1 -0
  19. package/dist/chunk-U7QDLGQL.mjs +256 -0
  20. package/dist/chunk-U7QDLGQL.mjs.map +1 -0
  21. package/dist/{chunk-VUNR7KGG.js → chunk-WTXKCAG7.js} +146 -531
  22. package/dist/chunk-WTXKCAG7.js.map +1 -0
  23. package/dist/{chunk-E7IQYTLV.js → chunk-XJKOJIX3.js} +12 -11
  24. package/dist/chunk-XJKOJIX3.js.map +1 -0
  25. package/dist/clients/index.d.ts +6 -3
  26. package/dist/clients/index.js +4 -3
  27. package/dist/clients/index.js.map +1 -0
  28. package/dist/clients/index.mjs +3 -2
  29. package/dist/clients/index.mjs.map +1 -0
  30. package/dist/createClient-cd948138.d.ts +62 -0
  31. package/dist/createPublicClient-989a0556.d.ts +19 -0
  32. package/dist/createTestClient-81507f58.d.ts +34 -0
  33. package/dist/createWalletClient-43f801b9.d.ts +30 -0
  34. package/dist/{eip1193-c001fcd5.d.ts → eip1193-4330b722.d.ts} +1 -1
  35. package/dist/index.d.ts +13 -6
  36. package/dist/index.js +9 -4
  37. package/dist/index.js.map +1 -0
  38. package/dist/index.mjs +34 -29
  39. package/dist/index.mjs.map +1 -0
  40. package/dist/{parseGwei-21f98a29.d.ts → parseGwei-f2d23de6.d.ts} +1 -1
  41. package/dist/public.d.ts +12 -0
  42. package/dist/public.js +59 -0
  43. package/dist/public.js.map +1 -0
  44. package/dist/public.mjs +59 -0
  45. package/dist/public.mjs.map +1 -0
  46. package/dist/sendTransaction-7a9d241a.d.ts +13 -0
  47. package/dist/stopImpersonatingAccount-8113150e.d.ts +156 -0
  48. package/dist/test.d.ts +7 -0
  49. package/dist/test.js +60 -0
  50. package/dist/test.js.map +1 -0
  51. package/dist/test.mjs +60 -0
  52. package/dist/test.mjs.map +1 -0
  53. package/dist/{transactionRequest-1d4e4385.d.ts → transactionReceipt-5d332aab.d.ts} +4 -32
  54. package/dist/transactionRequest-327eb7c2.d.ts +33 -0
  55. package/dist/utils/index.d.ts +4 -3
  56. package/dist/utils/index.js +3 -2
  57. package/dist/utils/index.js.map +1 -0
  58. package/dist/utils/index.mjs +2 -1
  59. package/dist/utils/index.mjs.map +1 -0
  60. package/dist/wallet.d.ts +9 -0
  61. package/dist/wallet.js +24 -0
  62. package/dist/wallet.js.map +1 -0
  63. package/dist/wallet.mjs +24 -0
  64. package/dist/wallet.mjs.map +1 -0
  65. package/dist/watchAsset-0088384c.d.ts +39 -0
  66. package/dist/{stopImpersonatingAccount-fcc5a678.d.ts → watchPendingTransactions-670a7ca3.d.ts} +7 -197
  67. package/dist/{webSocket-3385e295.d.ts → webSocket-9a3b0b26.d.ts} +1 -1
  68. package/dist/window.d.ts +1 -1
  69. package/dist/window.js +1 -1
  70. package/dist/window.js.map +1 -0
  71. package/dist/window.mjs +1 -0
  72. package/dist/window.mjs.map +1 -0
  73. package/package.json +18 -6
  74. package/src/_test/abis.ts +1225 -0
  75. package/src/_test/bench.ts +15 -0
  76. package/src/_test/constants.ts +63 -0
  77. package/src/_test/globalSetup.ts +11 -0
  78. package/src/_test/index.ts +20 -0
  79. package/src/_test/setup.ts +8 -0
  80. package/src/_test/utils.ts +112 -0
  81. package/src/actions/index.test.ts +72 -0
  82. package/src/actions/index.ts +156 -0
  83. package/src/actions/public/call.bench.ts +48 -0
  84. package/src/actions/public/call.test.ts +99 -0
  85. package/src/actions/public/call.ts +96 -0
  86. package/src/actions/public/callContract.bench.ts +24 -0
  87. package/src/actions/public/callContract.test.ts +285 -0
  88. package/src/actions/public/callContract.ts +80 -0
  89. package/src/actions/public/createBlockFilter.bench.ts +11 -0
  90. package/src/actions/public/createBlockFilter.test.ts +9 -0
  91. package/src/actions/public/createBlockFilter.ts +14 -0
  92. package/src/actions/public/createEventFilter.test.ts +245 -0
  93. package/src/actions/public/createEventFilter.ts +81 -0
  94. package/src/actions/public/createPendingTransactionFilter.bench.ts +11 -0
  95. package/src/actions/public/createPendingTransactionFilter.test.ts +9 -0
  96. package/src/actions/public/createPendingTransactionFilter.ts +14 -0
  97. package/src/actions/public/deployContract.test.ts +56 -0
  98. package/src/actions/public/deployContract.ts +39 -0
  99. package/src/actions/public/estimateGas.bench.ts +46 -0
  100. package/src/actions/public/estimateGas.test.ts +92 -0
  101. package/src/actions/public/estimateGas.ts +61 -0
  102. package/src/actions/public/getBalance.test.ts +83 -0
  103. package/src/actions/public/getBalance.ts +37 -0
  104. package/src/actions/public/getBlock.bench.ts +28 -0
  105. package/src/actions/public/getBlock.test.ts +575 -0
  106. package/src/actions/public/getBlock.ts +66 -0
  107. package/src/actions/public/getBlockNumber.bench.ts +28 -0
  108. package/src/actions/public/getBlockNumber.test.ts +27 -0
  109. package/src/actions/public/getBlockNumber.ts +32 -0
  110. package/src/actions/public/getBlockTransactionCount.bench.ts +15 -0
  111. package/src/actions/public/getBlockTransactionCount.test.ts +57 -0
  112. package/src/actions/public/getBlockTransactionCount.ts +53 -0
  113. package/src/actions/public/getBytecode.test.ts +27 -0
  114. package/src/actions/public/getBytecode.ts +32 -0
  115. package/src/actions/public/getChainId.bench.ts +15 -0
  116. package/src/actions/public/getChainId.test.ts +8 -0
  117. package/src/actions/public/getChainId.ts +7 -0
  118. package/src/actions/public/getFeeHistory.bench.ts +18 -0
  119. package/src/actions/public/getFeeHistory.test.ts +137 -0
  120. package/src/actions/public/getFeeHistory.ts +44 -0
  121. package/src/actions/public/getFilterChanges.bench.ts +13 -0
  122. package/src/actions/public/getFilterChanges.test.ts +187 -0
  123. package/src/actions/public/getFilterChanges.ts +23 -0
  124. package/src/actions/public/getFilterLogs.test.ts +102 -0
  125. package/src/actions/public/getFilterLogs.ts +20 -0
  126. package/src/actions/public/getGasPrice.bench.ts +28 -0
  127. package/src/actions/public/getGasPrice.test.ts +8 -0
  128. package/src/actions/public/getGasPrice.ts +15 -0
  129. package/src/actions/public/getTransaction.bench.ts +33 -0
  130. package/src/actions/public/getTransaction.test.ts +311 -0
  131. package/src/actions/public/getTransaction.ts +96 -0
  132. package/src/actions/public/getTransactionConfirmations.test.ts +69 -0
  133. package/src/actions/public/getTransactionConfirmations.ts +39 -0
  134. package/src/actions/public/getTransactionCount.test.ts +56 -0
  135. package/src/actions/public/getTransactionCount.ts +34 -0
  136. package/src/actions/public/getTransactionReceipt.bench.ts +33 -0
  137. package/src/actions/public/getTransactionReceipt.test.ts +217 -0
  138. package/src/actions/public/getTransactionReceipt.ts +35 -0
  139. package/src/actions/public/index.test.ts +36 -0
  140. package/src/actions/public/index.ts +120 -0
  141. package/src/actions/public/uninstallFilter.bench.ts +13 -0
  142. package/src/actions/public/uninstallFilter.test.ts +65 -0
  143. package/src/actions/public/uninstallFilter.ts +17 -0
  144. package/src/actions/public/waitForTransactionReceipt.test.ts +322 -0
  145. package/src/actions/public/waitForTransactionReceipt.ts +171 -0
  146. package/src/actions/public/watchBlockNumber.test.ts +166 -0
  147. package/src/actions/public/watchBlockNumber.ts +79 -0
  148. package/src/actions/public/watchBlocks.test.ts +185 -0
  149. package/src/actions/public/watchBlocks.ts +95 -0
  150. package/src/actions/public/watchPendingTransactions.test.ts +116 -0
  151. package/src/actions/public/watchPendingTransactions.ts +73 -0
  152. package/src/actions/test/dropTransaction.test.ts +34 -0
  153. package/src/actions/test/dropTransaction.ts +17 -0
  154. package/src/actions/test/getAutomine.test.ts +14 -0
  155. package/src/actions/test/getAutomine.ts +11 -0
  156. package/src/actions/test/getTxpoolContent.test.ts +45 -0
  157. package/src/actions/test/getTxpoolContent.ts +7 -0
  158. package/src/actions/test/getTxpoolStatus.test.ts +41 -0
  159. package/src/actions/test/getTxpoolStatus.ts +12 -0
  160. package/src/actions/test/impersonateAccount.test.ts +28 -0
  161. package/src/actions/test/impersonateAccount.ts +17 -0
  162. package/src/actions/test/increaseTime.test.ts +18 -0
  163. package/src/actions/test/increaseTime.ts +17 -0
  164. package/src/actions/test/index.test.ts +38 -0
  165. package/src/actions/test/index.ts +77 -0
  166. package/src/actions/test/inspectTxpool.test.ts +50 -0
  167. package/src/actions/test/inspectTxpool.ts +7 -0
  168. package/src/actions/test/mine.test.ts +20 -0
  169. package/src/actions/test/mine.ts +16 -0
  170. package/src/actions/test/removeBlockTimestampInterval.test.ts +23 -0
  171. package/src/actions/test/removeBlockTimestampInterval.ts +7 -0
  172. package/src/actions/test/reset.test.ts +19 -0
  173. package/src/actions/test/reset.ts +18 -0
  174. package/src/actions/test/revert.test.ts +39 -0
  175. package/src/actions/test/revert.ts +14 -0
  176. package/src/actions/test/sendUnsignedTransaction.test.ts +52 -0
  177. package/src/actions/test/sendUnsignedTransaction.ts +19 -0
  178. package/src/actions/test/setAutomine.test.ts +14 -0
  179. package/src/actions/test/setAutomine.ts +8 -0
  180. package/src/actions/test/setBalance.test.ts +29 -0
  181. package/src/actions/test/setBalance.ts +20 -0
  182. package/src/actions/test/setBlockGasLimit.test.ts +21 -0
  183. package/src/actions/test/setBlockGasLimit.ts +17 -0
  184. package/src/actions/test/setBlockTimestampInterval.test.ts +23 -0
  185. package/src/actions/test/setBlockTimestampInterval.ts +16 -0
  186. package/src/actions/test/setCode.test.ts +26 -0
  187. package/src/actions/test/setCode.ts +19 -0
  188. package/src/actions/test/setCoinbase.test.ts +11 -0
  189. package/src/actions/test/setCoinbase.ts +17 -0
  190. package/src/actions/test/setIntervalMining.test.ts +30 -0
  191. package/src/actions/test/setIntervalMining.ts +16 -0
  192. package/src/actions/test/setLoggingEnabled.test.ts +10 -0
  193. package/src/actions/test/setLoggingEnabled.ts +8 -0
  194. package/src/actions/test/setMinGasPrice.test.ts +22 -0
  195. package/src/actions/test/setMinGasPrice.ts +17 -0
  196. package/src/actions/test/setNextBlockBaseFeePerGas.test.ts +23 -0
  197. package/src/actions/test/setNextBlockBaseFeePerGas.ts +17 -0
  198. package/src/actions/test/setNextBlockTimestamp.test.ts +19 -0
  199. package/src/actions/test/setNextBlockTimestamp.ts +17 -0
  200. package/src/actions/test/setNonce.test.ts +28 -0
  201. package/src/actions/test/setNonce.ts +20 -0
  202. package/src/actions/test/setRpcUrl.test.ts +9 -0
  203. package/src/actions/test/setRpcUrl.ts +8 -0
  204. package/src/actions/test/setStorageAt.test.ts +36 -0
  205. package/src/actions/test/setStorageAt.ts +26 -0
  206. package/src/actions/test/snapshot.test.ts +18 -0
  207. package/src/actions/test/snapshot.ts +7 -0
  208. package/src/actions/test/stopImpersonatingAccount.test.ts +31 -0
  209. package/src/actions/test/stopImpersonatingAccount.ts +17 -0
  210. package/src/actions/wallet/addChain.test.ts +14 -0
  211. package/src/actions/wallet/addChain.ts +21 -0
  212. package/src/actions/wallet/getAccounts.test.ts +22 -0
  213. package/src/actions/wallet/getAccounts.ts +7 -0
  214. package/src/actions/wallet/getPermissions.test.ts +24 -0
  215. package/src/actions/wallet/getPermissions.ts +9 -0
  216. package/src/actions/wallet/index.test.ts +19 -0
  217. package/src/actions/wallet/index.ts +27 -0
  218. package/src/actions/wallet/requestAccounts.test.ts +13 -0
  219. package/src/actions/wallet/requestAccounts.ts +7 -0
  220. package/src/actions/wallet/requestPermissions.test.ts +26 -0
  221. package/src/actions/wallet/requestPermissions.ts +19 -0
  222. package/src/actions/wallet/sendTransaction.bench.ts +57 -0
  223. package/src/actions/wallet/sendTransaction.test.ts +440 -0
  224. package/src/actions/wallet/sendTransaction.ts +76 -0
  225. package/src/actions/wallet/signMessage.test.ts +62 -0
  226. package/src/actions/wallet/signMessage.ts +35 -0
  227. package/src/actions/wallet/switchChain.test.ts +22 -0
  228. package/src/actions/wallet/switchChain.ts +19 -0
  229. package/src/actions/wallet/watchAsset.test.ts +41 -0
  230. package/src/actions/wallet/watchAsset.ts +16 -0
  231. package/src/chains.test.ts +1134 -0
  232. package/src/chains.ts +167 -0
  233. package/src/clients/createClient.test.ts +295 -0
  234. package/src/clients/createClient.ts +81 -0
  235. package/src/clients/createPublicClient.test.ts +165 -0
  236. package/src/clients/createPublicClient.ts +49 -0
  237. package/src/clients/createTestClient.test.ts +145 -0
  238. package/src/clients/createTestClient.ts +72 -0
  239. package/src/clients/createWalletClient.test.ts +121 -0
  240. package/src/clients/createWalletClient.ts +54 -0
  241. package/src/clients/index.test.ts +19 -0
  242. package/src/clients/index.ts +31 -0
  243. package/src/clients/transports/createTransport.test.ts +58 -0
  244. package/src/clients/transports/createTransport.ts +48 -0
  245. package/src/clients/transports/custom.test.ts +98 -0
  246. package/src/clients/transports/custom.ts +34 -0
  247. package/src/clients/transports/fallback.test.ts +223 -0
  248. package/src/clients/transports/fallback.ts +48 -0
  249. package/src/clients/transports/http.test.ts +110 -0
  250. package/src/clients/transports/http.ts +51 -0
  251. package/src/clients/transports/index.test.ts +15 -0
  252. package/src/clients/transports/index.ts +17 -0
  253. package/src/clients/transports/webSocket.test.ts +164 -0
  254. package/src/clients/transports/webSocket.ts +117 -0
  255. package/src/constants.test.ts +27 -0
  256. package/src/constants.ts +18 -0
  257. package/src/errors/abi.test.ts +83 -0
  258. package/src/errors/abi.ts +238 -0
  259. package/src/errors/address.test.ts +14 -0
  260. package/src/errors/address.ts +9 -0
  261. package/src/errors/base.test.ts +72 -0
  262. package/src/errors/base.ts +57 -0
  263. package/src/errors/block.test.ts +24 -0
  264. package/src/errors/block.ts +18 -0
  265. package/src/errors/contract.ts +125 -0
  266. package/src/errors/data.ts +20 -0
  267. package/src/errors/encoding.ts +60 -0
  268. package/src/errors/index.ts +77 -0
  269. package/src/errors/log.ts +8 -0
  270. package/src/errors/request.test.ts +331 -0
  271. package/src/errors/request.ts +163 -0
  272. package/src/errors/rpc.test.ts +88 -0
  273. package/src/errors/rpc.ts +113 -0
  274. package/src/errors/transaction.test.ts +83 -0
  275. package/src/errors/transaction.ts +54 -0
  276. package/src/errors/transport.test.ts +12 -0
  277. package/src/errors/transport.ts +12 -0
  278. package/src/index.test.ts +208 -0
  279. package/src/index.ts +353 -0
  280. package/src/public.ts +80 -0
  281. package/src/test.ts +51 -0
  282. package/src/types/block.ts +71 -0
  283. package/src/types/contract.ts +327 -0
  284. package/src/types/eip1193.ts +1038 -0
  285. package/src/types/fee.ts +47 -0
  286. package/src/types/filter.ts +8 -0
  287. package/src/types/index.ts +72 -0
  288. package/src/types/log.ts +22 -0
  289. package/src/types/misc.ts +4 -0
  290. package/src/types/rpc.ts +35 -0
  291. package/src/types/transaction.ts +145 -0
  292. package/src/types/utils.ts +67 -0
  293. package/src/types/window.ts +9 -0
  294. package/src/utils/abi/decodeAbi.bench.ts +135 -0
  295. package/src/utils/abi/decodeAbi.test.ts +1615 -0
  296. package/src/utils/abi/decodeAbi.ts +296 -0
  297. package/src/utils/abi/decodeDeployData.test.ts +159 -0
  298. package/src/utils/abi/decodeDeployData.ts +41 -0
  299. package/src/utils/abi/decodeErrorResult.test.ts +130 -0
  300. package/src/utils/abi/decodeErrorResult.ts +28 -0
  301. package/src/utils/abi/decodeFunctionData.test.ts +140 -0
  302. package/src/utils/abi/decodeFunctionData.ts +29 -0
  303. package/src/utils/abi/decodeFunctionResult.test.ts +262 -0
  304. package/src/utils/abi/decodeFunctionResult.ts +53 -0
  305. package/src/utils/abi/encodeAbi.bench.ts +163 -0
  306. package/src/utils/abi/encodeAbi.test.ts +1414 -0
  307. package/src/utils/abi/encodeAbi.ts +258 -0
  308. package/src/utils/abi/encodeDeployData.test.ts +131 -0
  309. package/src/utils/abi/encodeDeployData.ts +37 -0
  310. package/src/utils/abi/encodeErrorResult.test.ts +197 -0
  311. package/src/utils/abi/encodeErrorResult.ts +40 -0
  312. package/src/utils/abi/encodeEventTopics.test.ts +348 -0
  313. package/src/utils/abi/encodeEventTopics.ts +69 -0
  314. package/src/utils/abi/encodeFunctionData.test.ts +140 -0
  315. package/src/utils/abi/encodeFunctionData.ts +38 -0
  316. package/src/utils/abi/encodeFunctionResult.test.ts +284 -0
  317. package/src/utils/abi/encodeFunctionResult.ts +39 -0
  318. package/src/utils/abi/formatAbiItemWithArgs.test.ts +291 -0
  319. package/src/utils/abi/formatAbiItemWithArgs.ts +27 -0
  320. package/src/utils/abi/formatAbiItemWithParams.test.ts +335 -0
  321. package/src/utils/abi/formatAbiItemWithParams.ts +41 -0
  322. package/src/utils/abi/getAbiItem.ts +5 -0
  323. package/src/utils/abi/index.test.ts +23 -0
  324. package/src/utils/abi/index.ts +38 -0
  325. package/src/utils/address/getAddress.bench.ts +22 -0
  326. package/src/utils/address/getAddress.test.ts +46 -0
  327. package/src/utils/address/getAddress.ts +28 -0
  328. package/src/utils/address/getContractAddress.bench.ts +20 -0
  329. package/src/utils/address/getContractAddress.test.ts +78 -0
  330. package/src/utils/address/getContractAddress.ts +59 -0
  331. package/src/utils/address/index.test.ts +17 -0
  332. package/src/utils/address/index.ts +16 -0
  333. package/src/utils/address/isAddress.test.ts +10 -0
  334. package/src/utils/address/isAddress.ts +10 -0
  335. package/src/utils/address/isAddressEqual.test.ts +55 -0
  336. package/src/utils/address/isAddressEqual.ts +6 -0
  337. package/src/utils/buildRequest.test.ts +365 -0
  338. package/src/utils/buildRequest.ts +45 -0
  339. package/src/utils/contract/extractFunctionParts.test.ts +109 -0
  340. package/src/utils/contract/extractFunctionParts.ts +27 -0
  341. package/src/utils/contract/getContractError.test.ts +97 -0
  342. package/src/utils/contract/getContractError.ts +70 -0
  343. package/src/utils/contract/index.test.ts +15 -0
  344. package/src/utils/contract/index.ts +8 -0
  345. package/src/utils/data/concat.test.ts +35 -0
  346. package/src/utils/data/concat.ts +34 -0
  347. package/src/utils/data/index.test.ts +23 -0
  348. package/src/utils/data/index.ts +13 -0
  349. package/src/utils/data/isBytes.test.ts +9 -0
  350. package/src/utils/data/isBytes.ts +7 -0
  351. package/src/utils/data/isHex.test.ts +13 -0
  352. package/src/utils/data/isHex.ts +5 -0
  353. package/src/utils/data/pad.bench.ts +39 -0
  354. package/src/utils/data/pad.test.ts +367 -0
  355. package/src/utils/data/pad.ts +53 -0
  356. package/src/utils/data/size.test.ts +18 -0
  357. package/src/utils/data/size.ts +13 -0
  358. package/src/utils/data/slice.test.ts +203 -0
  359. package/src/utils/data/slice.ts +60 -0
  360. package/src/utils/data/trim.bench.ts +50 -0
  361. package/src/utils/data/trim.test.ts +175 -0
  362. package/src/utils/data/trim.ts +33 -0
  363. package/src/utils/encoding/decodeBytes.bench.ts +40 -0
  364. package/src/utils/encoding/decodeBytes.test.ts +144 -0
  365. package/src/utils/encoding/decodeBytes.ts +63 -0
  366. package/src/utils/encoding/decodeHex.bench.ts +24 -0
  367. package/src/utils/encoding/decodeHex.test.ts +167 -0
  368. package/src/utils/encoding/decodeHex.ts +76 -0
  369. package/src/utils/encoding/decodeRlp.bench.ts +34 -0
  370. package/src/utils/encoding/decodeRlp.test.ts +350 -0
  371. package/src/utils/encoding/decodeRlp.ts +121 -0
  372. package/src/utils/encoding/encodeBytes.bench.ts +41 -0
  373. package/src/utils/encoding/encodeBytes.test.ts +676 -0
  374. package/src/utils/encoding/encodeBytes.ts +59 -0
  375. package/src/utils/encoding/encodeHex.bench.ts +60 -0
  376. package/src/utils/encoding/encodeHex.test.ts +232 -0
  377. package/src/utils/encoding/encodeHex.ts +104 -0
  378. package/src/utils/encoding/encodeRlp.bench.ts +54 -0
  379. package/src/utils/encoding/encodeRlp.test.ts +254 -0
  380. package/src/utils/encoding/encodeRlp.ts +48 -0
  381. package/src/utils/encoding/index.test.ts +32 -0
  382. package/src/utils/encoding/index.ts +36 -0
  383. package/src/utils/formatters/block.bench.ts +51 -0
  384. package/src/utils/formatters/block.test.ts +115 -0
  385. package/src/utils/formatters/block.ts +36 -0
  386. package/src/utils/formatters/extract.test.ts +14 -0
  387. package/src/utils/formatters/extract.ts +18 -0
  388. package/src/utils/formatters/feeHistory.test.ts +66 -0
  389. package/src/utils/formatters/feeHistory.ts +12 -0
  390. package/src/utils/formatters/format.test.ts +93 -0
  391. package/src/utils/formatters/format.ts +53 -0
  392. package/src/utils/formatters/index.test.ts +17 -0
  393. package/src/utils/formatters/index.ts +24 -0
  394. package/src/utils/formatters/log.test.ts +79 -0
  395. package/src/utils/formatters/log.ts +12 -0
  396. package/src/utils/formatters/transaction.test.ts +271 -0
  397. package/src/utils/formatters/transaction.ts +51 -0
  398. package/src/utils/formatters/transactionReceipt.bench.ts +73 -0
  399. package/src/utils/formatters/transactionReceipt.test.ts +151 -0
  400. package/src/utils/formatters/transactionReceipt.ts +54 -0
  401. package/src/utils/formatters/transactionRequest.bench.ts +29 -0
  402. package/src/utils/formatters/transactionRequest.test.ts +237 -0
  403. package/src/utils/formatters/transactionRequest.ts +47 -0
  404. package/src/utils/hash/getEventSignature.test.ts +61 -0
  405. package/src/utils/hash/getEventSignature.ts +4 -0
  406. package/src/utils/hash/getFunctionSignature.test.ts +22 -0
  407. package/src/utils/hash/getFunctionSignature.ts +5 -0
  408. package/src/utils/hash/hashFunction.test.ts +65 -0
  409. package/src/utils/hash/hashFunction.ts +12 -0
  410. package/src/utils/hash/index.test.ts +13 -0
  411. package/src/utils/hash/index.ts +5 -0
  412. package/src/utils/hash/keccak256.test.ts +59 -0
  413. package/src/utils/hash/keccak256.ts +23 -0
  414. package/src/utils/index.test.ts +87 -0
  415. package/src/utils/index.ts +126 -0
  416. package/src/utils/observe.test.ts +176 -0
  417. package/src/utils/observe.ts +66 -0
  418. package/src/utils/poll.test.ts +127 -0
  419. package/src/utils/poll.ts +42 -0
  420. package/src/utils/promise/index.test.ts +14 -0
  421. package/src/utils/promise/index.ts +3 -0
  422. package/src/utils/promise/withCache.test.ts +97 -0
  423. package/src/utils/promise/withCache.ts +73 -0
  424. package/src/utils/promise/withRetry.test.ts +231 -0
  425. package/src/utils/promise/withRetry.ts +61 -0
  426. package/src/utils/promise/withTimeout.test.ts +37 -0
  427. package/src/utils/promise/withTimeout.ts +39 -0
  428. package/src/utils/rpc.test.ts +992 -0
  429. package/src/utils/rpc.ts +292 -0
  430. package/src/utils/stringify.test.ts +13 -0
  431. package/src/utils/stringify.ts +5 -0
  432. package/src/utils/uid.ts +14 -0
  433. package/src/utils/unit/formatEther.test.ts +75 -0
  434. package/src/utils/unit/formatEther.ts +6 -0
  435. package/src/utils/unit/formatGwei.test.ts +32 -0
  436. package/src/utils/unit/formatGwei.ts +6 -0
  437. package/src/utils/unit/formatUnit.bench.ts +26 -0
  438. package/src/utils/unit/formatUnit.test.ts +40 -0
  439. package/src/utils/unit/formatUnit.ts +16 -0
  440. package/src/utils/unit/index.test.ts +16 -0
  441. package/src/utils/unit/index.ts +6 -0
  442. package/src/utils/unit/parseEther.test.ts +126 -0
  443. package/src/utils/unit/parseEther.ts +6 -0
  444. package/src/utils/unit/parseGwei.test.ts +50 -0
  445. package/src/utils/unit/parseGwei.ts +6 -0
  446. package/src/utils/unit/parseUnit.bench.ts +26 -0
  447. package/src/utils/unit/parseUnit.test.ts +54 -0
  448. package/src/utils/unit/parseUnit.ts +27 -0
  449. package/src/utils/wait.ts +3 -0
  450. package/src/wallet.ts +23 -0
  451. package/src/window.ts +1 -0
  452. package/actions/package.json +0 -4
  453. package/dist/actions/index.d.ts +0 -8
  454. package/dist/actions/index.js +0 -129
  455. package/dist/actions/index.mjs +0 -129
  456. package/dist/createWalletClient-3f9fa8b6.d.ts +0 -130
@@ -0,0 +1,1414 @@
1
+ import { describe, expect, test } from 'vitest'
2
+
3
+ import { encodeAbi, getArrayComponents } from './encodeAbi'
4
+
5
+ describe('static', () => {
6
+ test('blank', () => {
7
+ expect(
8
+ encodeAbi({
9
+ params: [],
10
+ values: [],
11
+ }),
12
+ ).toBe('0x')
13
+ })
14
+
15
+ test('uint', () => {
16
+ expect(
17
+ encodeAbi({
18
+ params: [
19
+ {
20
+ internalType: 'uint256',
21
+ name: 'xIn',
22
+ type: 'uint256',
23
+ },
24
+ ],
25
+ values: [69420n],
26
+ }),
27
+ ).toBe('0x0000000000000000000000000000000000000000000000000000000000010f2c')
28
+ })
29
+
30
+ describe('uint8', () => {
31
+ test('default', () => {
32
+ expect(
33
+ encodeAbi({
34
+ params: [
35
+ {
36
+ internalType: 'uint8',
37
+ name: 'xIn',
38
+ type: 'uint8',
39
+ },
40
+ ],
41
+ values: [32],
42
+ }),
43
+ ).toBe(
44
+ '0x0000000000000000000000000000000000000000000000000000000000000020',
45
+ )
46
+ })
47
+
48
+ test('invalid value', () => {
49
+ try {
50
+ encodeAbi({
51
+ params: [
52
+ {
53
+ internalType: 'uint8',
54
+ name: 'xIn',
55
+ type: 'uint8',
56
+ },
57
+ ],
58
+ // @ts-expect-error
59
+ values: [69420n],
60
+ })
61
+ encodeAbi({
62
+ params: [
63
+ {
64
+ internalType: 'uint8',
65
+ name: 'xIn',
66
+ type: 'uint8',
67
+ },
68
+ ],
69
+ // @ts-expect-error
70
+ values: ['lol'],
71
+ })
72
+ } catch {}
73
+ })
74
+ })
75
+
76
+ describe('uint32', () => {
77
+ test('default', () => {
78
+ expect(
79
+ encodeAbi({
80
+ params: [
81
+ {
82
+ internalType: 'uint32',
83
+ name: 'xIn',
84
+ type: 'uint32',
85
+ },
86
+ ],
87
+ values: [69420],
88
+ }),
89
+ ).toBe(
90
+ '0x0000000000000000000000000000000000000000000000000000000000010f2c',
91
+ )
92
+ })
93
+
94
+ test('invalid value', () => {
95
+ try {
96
+ encodeAbi({
97
+ params: [
98
+ {
99
+ internalType: 'uint32',
100
+ name: 'xIn',
101
+ type: 'uint32',
102
+ },
103
+ ],
104
+ // @ts-expect-error
105
+ values: [69420n],
106
+ })
107
+ encodeAbi({
108
+ params: [
109
+ {
110
+ internalType: 'uint32',
111
+ name: 'xIn',
112
+ type: 'uint32',
113
+ },
114
+ ],
115
+ // @ts-expect-error
116
+ values: ['lol'],
117
+ })
118
+ } catch {}
119
+ })
120
+ })
121
+
122
+ describe('int', () => {
123
+ test('default', () => {
124
+ expect(
125
+ encodeAbi({
126
+ params: [
127
+ {
128
+ internalType: 'int256',
129
+ name: 'xIn',
130
+ type: 'int256',
131
+ },
132
+ ],
133
+ values: [69420n],
134
+ }),
135
+ ).toBe(
136
+ '0x0000000000000000000000000000000000000000000000000000000000010f2c',
137
+ )
138
+ })
139
+
140
+ test('negative (twos compliment)', () => {
141
+ expect(
142
+ encodeAbi({
143
+ params: [
144
+ {
145
+ internalType: 'int256',
146
+ name: 'xIn',
147
+ type: 'int256',
148
+ },
149
+ ],
150
+ values: [-69420n],
151
+ }),
152
+ ).toBe(
153
+ '0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffffffef0d4',
154
+ )
155
+ })
156
+ })
157
+
158
+ describe('int8', () => {
159
+ test('default', () => {
160
+ expect(
161
+ encodeAbi({
162
+ params: [
163
+ {
164
+ internalType: 'int8',
165
+ name: 'xIn',
166
+ type: 'int8',
167
+ },
168
+ ],
169
+ values: [127],
170
+ }),
171
+ ).toBe(
172
+ '0x000000000000000000000000000000000000000000000000000000000000007f',
173
+ )
174
+ })
175
+
176
+ test('negative (twos compliment)', () => {
177
+ expect(
178
+ encodeAbi({
179
+ params: [
180
+ {
181
+ internalType: 'int8',
182
+ name: 'xIn',
183
+ type: 'int8',
184
+ },
185
+ ],
186
+ values: [-128],
187
+ }),
188
+ ).toBe(
189
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff80',
190
+ )
191
+ })
192
+
193
+ test('invalid value', () => {
194
+ try {
195
+ encodeAbi({
196
+ params: [
197
+ {
198
+ internalType: 'int8',
199
+ name: 'xIn',
200
+ type: 'int8',
201
+ },
202
+ ],
203
+ // @ts-expect-error
204
+ values: [69420n],
205
+ })
206
+ encodeAbi({
207
+ params: [
208
+ {
209
+ internalType: 'int8',
210
+ name: 'xIn',
211
+ type: 'int8',
212
+ },
213
+ ],
214
+ // @ts-expect-error
215
+ values: ['lol'],
216
+ })
217
+ } catch {}
218
+ })
219
+ })
220
+
221
+ describe('int32', () => {
222
+ test('default', () => {
223
+ expect(
224
+ encodeAbi({
225
+ params: [
226
+ {
227
+ internalType: 'int32',
228
+ name: 'xIn',
229
+ type: 'int32',
230
+ },
231
+ ],
232
+ values: [2147483647],
233
+ }),
234
+ ).toBe(
235
+ '0x000000000000000000000000000000000000000000000000000000007fffffff',
236
+ )
237
+ })
238
+
239
+ test('negative (twos compliment)', () => {
240
+ expect(
241
+ encodeAbi({
242
+ params: [
243
+ {
244
+ internalType: 'int8',
245
+ name: 'xIn',
246
+ type: 'int8',
247
+ },
248
+ ],
249
+ values: [-2147483648],
250
+ }),
251
+ ).toBe(
252
+ '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffff80000000',
253
+ )
254
+ })
255
+
256
+ test('invalid value', () => {
257
+ try {
258
+ encodeAbi({
259
+ params: [
260
+ {
261
+ internalType: 'int32',
262
+ name: 'xIn',
263
+ type: 'int32',
264
+ },
265
+ ],
266
+ // @ts-expect-error
267
+ values: [69420n],
268
+ })
269
+ encodeAbi({
270
+ params: [
271
+ {
272
+ internalType: 'int32',
273
+ name: 'xIn',
274
+ type: 'int32',
275
+ },
276
+ ],
277
+ // @ts-expect-error
278
+ values: ['lol'],
279
+ })
280
+ } catch {}
281
+ })
282
+ })
283
+
284
+ describe('address', () => {
285
+ test('default', () => {
286
+ expect(
287
+ encodeAbi({
288
+ params: [
289
+ {
290
+ internalType: 'address',
291
+ name: 'xIn',
292
+ type: 'address',
293
+ },
294
+ ],
295
+ values: ['0x14dC79964da2C08b23698B3D3cc7Ca32193d9955'],
296
+ }),
297
+ ).toBe(
298
+ '0x00000000000000000000000014dc79964da2c08b23698b3d3cc7ca32193d9955',
299
+ )
300
+ })
301
+ })
302
+
303
+ describe('bool', () => {
304
+ test('default', () => {
305
+ expect(
306
+ encodeAbi({
307
+ params: [
308
+ {
309
+ internalType: 'bool',
310
+ name: 'xIn',
311
+ type: 'bool',
312
+ },
313
+ ],
314
+ values: [true],
315
+ }),
316
+ ).toBe(
317
+ '0x0000000000000000000000000000000000000000000000000000000000000001',
318
+ )
319
+ expect(
320
+ encodeAbi({
321
+ params: [
322
+ {
323
+ internalType: 'bool',
324
+ name: 'xIn',
325
+ type: 'bool',
326
+ },
327
+ ],
328
+ values: [false],
329
+ }),
330
+ ).toBe(
331
+ '0x0000000000000000000000000000000000000000000000000000000000000000',
332
+ )
333
+ })
334
+ })
335
+
336
+ describe('bytes8', () => {
337
+ test('default', () => {
338
+ expect(
339
+ encodeAbi({
340
+ params: [
341
+ {
342
+ internalType: 'bytes8',
343
+ name: 'xIn',
344
+ type: 'bytes8',
345
+ },
346
+ ],
347
+ values: ['0x0123456789abcdef'],
348
+ }),
349
+ ).toBe(
350
+ '0x0123456789abcdef000000000000000000000000000000000000000000000000',
351
+ )
352
+ })
353
+
354
+ test('overflow', () => {
355
+ expect(() =>
356
+ encodeAbi({
357
+ params: [
358
+ {
359
+ internalType: 'bytes8',
360
+ name: 'xIn',
361
+ type: 'bytes8',
362
+ },
363
+ ],
364
+ values: [
365
+ '0x0000000000000000000000000000000000000000000000000000000000000000000000000123456789abcdef',
366
+ ],
367
+ }),
368
+ ).toThrowErrorMatchingInlineSnapshot(`
369
+ "Hex size (44) exceeds padding size (32).
370
+
371
+ Version: viem@1.0.2"
372
+ `)
373
+ })
374
+ })
375
+
376
+ describe('bytes16', () => {
377
+ test('default', () => {
378
+ expect(
379
+ encodeAbi({
380
+ params: [
381
+ {
382
+ internalType: 'bytes16',
383
+ name: 'xIn',
384
+ type: 'bytes16',
385
+ },
386
+ ],
387
+ values: ['0x4206942069420'],
388
+ }),
389
+ ).toBe(
390
+ '0x4206942069420000000000000000000000000000000000000000000000000000',
391
+ )
392
+ })
393
+
394
+ test('overflow', () => {
395
+ expect(() =>
396
+ encodeAbi({
397
+ params: [
398
+ {
399
+ internalType: 'bytes16',
400
+ name: 'xIn',
401
+ type: 'bytes16',
402
+ },
403
+ ],
404
+ values: [
405
+ '0x00000000000000000000000000000000000000000000000000000000000000420',
406
+ ],
407
+ }),
408
+ ).toThrowErrorMatchingInlineSnapshot(`
409
+ "Hex size (33) exceeds padding size (32).
410
+
411
+ Version: viem@1.0.2"
412
+ `)
413
+ })
414
+ })
415
+
416
+ describe('uint[3]', () => {
417
+ test('default', () => {
418
+ expect(
419
+ encodeAbi({
420
+ params: [
421
+ {
422
+ internalType: 'uint256[3]',
423
+ name: 'xIn',
424
+ type: 'uint256[3]',
425
+ },
426
+ ],
427
+ values: [[69420n, 42069n, 420420420n]],
428
+ }),
429
+ ).toMatchInlineSnapshot(
430
+ '"0x0000000000000000000000000000000000000000000000000000000000010f2c000000000000000000000000000000000000000000000000000000000000a45500000000000000000000000000000000000000000000000000000000190f1b44"',
431
+ )
432
+ })
433
+ })
434
+
435
+ describe('int[3]', () => {
436
+ test('default', () => {
437
+ expect(
438
+ encodeAbi({
439
+ params: [
440
+ {
441
+ internalType: 'int256[3]',
442
+ name: 'xIn',
443
+ type: 'int256[3]',
444
+ },
445
+ ],
446
+ values: [[69420n, -42069n, 420420420n]],
447
+ }),
448
+ ).toMatchInlineSnapshot(
449
+ '"0x0000000000000000000000000000000000000000000000000000000000010f2cffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff5bab00000000000000000000000000000000000000000000000000000000190f1b44"',
450
+ )
451
+ })
452
+ })
453
+
454
+ describe('address[2]', () => {
455
+ test('default', () => {
456
+ expect(
457
+ encodeAbi({
458
+ params: [
459
+ {
460
+ internalType: 'address[2]',
461
+ name: 'xIn',
462
+ type: 'address[2]',
463
+ },
464
+ ],
465
+ values: [
466
+ [
467
+ '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b',
468
+ '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
469
+ ],
470
+ ],
471
+ }),
472
+ ).toMatchInlineSnapshot(
473
+ '"0x000000000000000000000000c961145a54c96e3ae9baa048c4f4d6b04c13916b000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac"',
474
+ )
475
+ })
476
+ })
477
+
478
+ describe('bool[2]', () => {
479
+ test('default', () => {
480
+ expect(
481
+ encodeAbi({
482
+ params: [
483
+ {
484
+ internalType: 'bool[2]',
485
+ name: 'xIn',
486
+ type: 'bool[2]',
487
+ },
488
+ ],
489
+ values: [[true, false]],
490
+ }),
491
+ ).toMatchInlineSnapshot(
492
+ '"0x00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000"',
493
+ )
494
+ })
495
+ })
496
+
497
+ describe('bytes8[2]', () => {
498
+ test('default', () => {
499
+ expect(
500
+ encodeAbi({
501
+ params: [
502
+ {
503
+ internalType: 'bytes8[2]',
504
+ name: 'xIn',
505
+ type: 'bytes8[2]',
506
+ },
507
+ ],
508
+ values: [['0x123', '0x111']],
509
+ }),
510
+ ).toMatchInlineSnapshot(
511
+ '"0x12300000000000000000000000000000000000000000000000000000000000001110000000000000000000000000000000000000000000000000000000000000"',
512
+ )
513
+ })
514
+ })
515
+
516
+ describe('uint[3][2]', () => {
517
+ test('default', () => {
518
+ expect(
519
+ encodeAbi({
520
+ params: [
521
+ {
522
+ internalType: 'uint256[3][2]',
523
+ name: 'xIn',
524
+ type: 'uint256[3][2]',
525
+ },
526
+ ],
527
+ values: [
528
+ [
529
+ [69420n, 42069n, 420420420n],
530
+ [420n, 44n, 422n],
531
+ ],
532
+ ],
533
+ }),
534
+ ).toMatchInlineSnapshot(
535
+ '"0x0000000000000000000000000000000000000000000000000000000000010f2c000000000000000000000000000000000000000000000000000000000000a45500000000000000000000000000000000000000000000000000000000190f1b4400000000000000000000000000000000000000000000000000000000000001a4000000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000001a6"',
536
+ )
537
+ })
538
+ })
539
+
540
+ describe('uint[3][2][4]', () => {
541
+ test('default', () => {
542
+ expect(
543
+ encodeAbi({
544
+ params: [
545
+ {
546
+ internalType: 'uint256[3][2][4]',
547
+ name: 'xIn',
548
+ type: 'uint256[3][2][4]',
549
+ },
550
+ ],
551
+ values: [
552
+ [
553
+ [
554
+ [1n, 2n, 3n],
555
+ [4n, 5n, 6n],
556
+ ],
557
+ [
558
+ [7n, 8n, 9n],
559
+ [10n, 11n, 12n],
560
+ ],
561
+ [
562
+ [13n, 14n, 15n],
563
+ [16n, 17n, 18n],
564
+ ],
565
+ [
566
+ [19n, 20n, 21n],
567
+ [22n, 23n, 24n],
568
+ ],
569
+ ],
570
+ ],
571
+ }),
572
+ ).toMatchInlineSnapshot(
573
+ '"0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000050000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000009000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000b000000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000d000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000f000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000110000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001300000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000001600000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000018"',
574
+ )
575
+ })
576
+ })
577
+
578
+ describe('struct: (uint256,bool,address)', () => {
579
+ test('default', () => {
580
+ expect(
581
+ // cast abi-encode "a((uint256,bool,address))" "(420,true,0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC)"
582
+ encodeAbi({
583
+ params: [
584
+ {
585
+ components: [
586
+ {
587
+ internalType: 'uint256',
588
+ name: 'x',
589
+ type: 'uint256',
590
+ },
591
+ {
592
+ internalType: 'bool',
593
+ name: 'y',
594
+ type: 'bool',
595
+ },
596
+ {
597
+ internalType: 'address',
598
+ name: 'z',
599
+ type: 'address',
600
+ },
601
+ ],
602
+ internalType: 'struct ABIExample.Foo',
603
+ name: 'fooIn',
604
+ type: 'tuple',
605
+ },
606
+ ],
607
+ values: [
608
+ {
609
+ x: 420n,
610
+ y: true,
611
+ z: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
612
+ },
613
+ ],
614
+ }),
615
+ ).toMatchInlineSnapshot(
616
+ '"0x00000000000000000000000000000000000000000000000000000000000001a40000000000000000000000000000000000000000000000000000000000000001000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac"',
617
+ )
618
+ })
619
+ })
620
+
621
+ describe('struct: (uint256,bool,address)', () => {
622
+ test('default', () => {
623
+ expect(
624
+ // cast abi-encode "a((uint256,bool,address))" "(420,true,0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC)"
625
+ encodeAbi({
626
+ params: [
627
+ {
628
+ components: [
629
+ {
630
+ internalType: 'uint256',
631
+ type: 'uint256',
632
+ },
633
+ {
634
+ internalType: 'bool',
635
+ type: 'bool',
636
+ },
637
+ {
638
+ internalType: 'address',
639
+ type: 'address',
640
+ },
641
+ ],
642
+ internalType: 'struct ABIExample.Foo',
643
+ name: 'fooOut',
644
+ type: 'tuple',
645
+ },
646
+ ],
647
+ values: [[420n, true, '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC']],
648
+ }),
649
+ ).toMatchInlineSnapshot(
650
+ '"0x00000000000000000000000000000000000000000000000000000000000001a40000000000000000000000000000000000000000000000000000000000000001000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac"',
651
+ )
652
+ })
653
+ })
654
+
655
+ describe('struct: ((uint256,bool,address),(uint256,bool,address),uint8[2])', () => {
656
+ test('default', () => {
657
+ expect(
658
+ // cast abi-encode "a(((uint256,bool,address),(uint256,bool,address),uint8[2]))" "((420,true,0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC),(69,false,0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b),[1,2])"
659
+ encodeAbi({
660
+ params: [
661
+ {
662
+ components: [
663
+ {
664
+ components: [
665
+ {
666
+ internalType: 'uint256',
667
+ name: 'x',
668
+ type: 'uint256',
669
+ },
670
+ {
671
+ internalType: 'bool',
672
+ name: 'y',
673
+ type: 'bool',
674
+ },
675
+ {
676
+ internalType: 'address',
677
+ name: 'z',
678
+ type: 'address',
679
+ },
680
+ ],
681
+ internalType: 'struct ABIExample.Foo',
682
+ name: 'foo',
683
+ type: 'tuple',
684
+ },
685
+ {
686
+ components: [
687
+ {
688
+ internalType: 'uint256',
689
+ name: 'x',
690
+ type: 'uint256',
691
+ },
692
+ {
693
+ internalType: 'bool',
694
+ name: 'y',
695
+ type: 'bool',
696
+ },
697
+ {
698
+ internalType: 'address',
699
+ name: 'z',
700
+ type: 'address',
701
+ },
702
+ ],
703
+ internalType: 'struct ABIExample.Foo',
704
+ name: 'baz',
705
+ type: 'tuple',
706
+ },
707
+ {
708
+ internalType: 'uint8[2]',
709
+ name: 'x',
710
+ type: 'uint8[2]',
711
+ },
712
+ ],
713
+ internalType: 'struct ABIExample.Bar',
714
+ name: 'barIn',
715
+ type: 'tuple',
716
+ },
717
+ ],
718
+ values: [
719
+ {
720
+ foo: {
721
+ x: 420n,
722
+ y: true,
723
+ z: '0xa5cc3c03994DB5b0d9A5eEdD10CabaB0813678AC',
724
+ },
725
+ baz: {
726
+ x: 69n,
727
+ y: false,
728
+ z: '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b',
729
+ },
730
+ x: [1, 2],
731
+ },
732
+ ],
733
+ }),
734
+ ).toMatchInlineSnapshot(
735
+ '"0x00000000000000000000000000000000000000000000000000000000000001a40000000000000000000000000000000000000000000000000000000000000001000000000000000000000000a5cc3c03994db5b0d9a5eedd10cabab0813678ac00000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000000000000000000000000000000c961145a54c96e3ae9baa048c4f4d6b04c13916b00000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000002"',
736
+ )
737
+ })
738
+ })
739
+
740
+ describe('(uint256[2],bool,string[])', () => {
741
+ test('default', () => {
742
+ expect(
743
+ encodeAbi({
744
+ params: [
745
+ { internalType: 'uint256[2]', name: 'xOut', type: 'uint256[2]' },
746
+ { internalType: 'bool', name: 'yOut', type: 'bool' },
747
+ { internalType: 'string[3]', name: 'zOut', type: 'string[3]' },
748
+ ] as any,
749
+ values: [[420n, 69n], true, ['wagmi', 'viem', 'lol']],
750
+ }),
751
+ ).toMatchInlineSnapshot(
752
+ '"0x00000000000000000000000000000000000000000000000000000000000001a4000000000000000000000000000000000000000000000000000000000000004500000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000e000000000000000000000000000000000000000000000000000000000000000057761676d6900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000047669656d0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000036c6f6c0000000000000000000000000000000000000000000000000000000000"',
753
+ )
754
+ })
755
+ })
756
+
757
+ describe('multiple params: (uint,bool,address)', () => {
758
+ test('default', () => {
759
+ expect(
760
+ encodeAbi({
761
+ params: [
762
+ {
763
+ internalType: 'uint256',
764
+ name: 'xIn',
765
+ type: 'uint256',
766
+ },
767
+ {
768
+ internalType: 'bool',
769
+ name: 'yIn',
770
+ type: 'bool',
771
+ },
772
+ {
773
+ internalType: 'address',
774
+ name: 'zIn',
775
+ type: 'address',
776
+ },
777
+ ],
778
+ values: [420n, true, '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b'],
779
+ }),
780
+ ).toMatchInlineSnapshot(
781
+ '"0x00000000000000000000000000000000000000000000000000000000000001a40000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c961145a54c96e3ae9baa048c4f4d6b04c13916b"',
782
+ )
783
+ })
784
+ })
785
+
786
+ describe('multiple params unnamed: (uint,bool,address)', () => {
787
+ test('default', () => {
788
+ expect(
789
+ encodeAbi({
790
+ params: [
791
+ {
792
+ internalType: 'uint256',
793
+ name: '',
794
+ type: 'uint256',
795
+ },
796
+ {
797
+ internalType: 'bool',
798
+ name: '',
799
+ type: 'bool',
800
+ },
801
+ {
802
+ internalType: 'address',
803
+ name: '',
804
+ type: 'address',
805
+ },
806
+ ],
807
+ values: [420n, true, '0xc961145a54C96E3aE9bAA048c4F4D6b04C13916b'],
808
+ }),
809
+ ).toMatchInlineSnapshot(
810
+ '"0x00000000000000000000000000000000000000000000000000000000000001a40000000000000000000000000000000000000000000000000000000000000001000000000000000000000000c961145a54c96e3ae9baa048c4f4d6b04c13916b"',
811
+ )
812
+ })
813
+ })
814
+ })
815
+
816
+ describe('dynamic', () => {
817
+ describe('(string)', () => {
818
+ // cast abi-encode "a(string)" "wagmi"
819
+ test('default', () => {
820
+ expect(
821
+ encodeAbi({
822
+ params: [
823
+ {
824
+ internalType: 'string',
825
+ name: 'xOut',
826
+ type: 'string',
827
+ },
828
+ ],
829
+ values: ['wagmi'],
830
+ }),
831
+ ).toMatchInlineSnapshot(
832
+ '"0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000057761676d69000000000000000000000000000000000000000000000000000000"',
833
+ )
834
+ })
835
+ })
836
+
837
+ describe('(string,uint,bool)', () => {
838
+ test('default', () => {
839
+ expect(
840
+ // cast abi-encode "a(string,uint,bool)" "wagmi" 420 true
841
+ encodeAbi({
842
+ params: [
843
+ {
844
+ internalType: 'string',
845
+ name: 'xIn',
846
+ type: 'string',
847
+ },
848
+ {
849
+ internalType: 'uint256',
850
+ name: 'yIn',
851
+ type: 'uint256',
852
+ },
853
+ {
854
+ internalType: 'bool',
855
+ name: 'zIn',
856
+ type: 'bool',
857
+ },
858
+ ],
859
+ values: ['wagmi', 420n, true],
860
+ }),
861
+ ).toMatchInlineSnapshot(
862
+ '"0x000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a4000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000057761676d69000000000000000000000000000000000000000000000000000000"',
863
+ )
864
+ })
865
+ })
866
+
867
+ describe('(uint[2],bool,string)', () => {
868
+ test('default', () => {
869
+ expect(
870
+ // cast abi-encode "a(uint[2],bool,string)" "[420,69]" true "wagmi"
871
+ encodeAbi({
872
+ params: [
873
+ {
874
+ internalType: 'uint256[2]',
875
+ name: 'xIn',
876
+ type: 'uint256[2]',
877
+ },
878
+ {
879
+ internalType: 'bool',
880
+ name: 'yIn',
881
+ type: 'bool',
882
+ },
883
+ {
884
+ internalType: 'string',
885
+ name: 'zIn',
886
+ type: 'string',
887
+ },
888
+ ] as const,
889
+ values: [[420n, 69n], true, 'wagmi'],
890
+ }),
891
+ ).toMatchInlineSnapshot(
892
+ '"0x00000000000000000000000000000000000000000000000000000000000001a400000000000000000000000000000000000000000000000000000000000000450000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000057761676d69000000000000000000000000000000000000000000000000000000"',
893
+ )
894
+ })
895
+ })
896
+
897
+ describe('(bytes)', () => {
898
+ test('default', () => {
899
+ expect(
900
+ // cast abi-encode "a(bytes)" "0x042069"
901
+ encodeAbi({
902
+ params: [
903
+ {
904
+ internalType: 'bytes',
905
+ name: 'xIn',
906
+ type: 'bytes',
907
+ },
908
+ ],
909
+ values: ['0x042069'],
910
+ }),
911
+ ).toMatchInlineSnapshot(
912
+ '"0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000030420690000000000000000000000000000000000000000000000000000000000"',
913
+ )
914
+ })
915
+ })
916
+
917
+ describe('(uint[])', () => {
918
+ test('default', () => {
919
+ expect(
920
+ // cast abi-encode "a(uint[])" "[420,69,22,55]"
921
+ encodeAbi({
922
+ params: [
923
+ {
924
+ internalType: 'uint256[]',
925
+ name: 'xIn',
926
+ type: 'uint256[]',
927
+ },
928
+ ],
929
+ values: [[420n, 69n, 22n, 55n]],
930
+ }),
931
+ ).toMatchInlineSnapshot(
932
+ '"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000001a4000000000000000000000000000000000000000000000000000000000000004500000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000037"',
933
+ )
934
+ })
935
+
936
+ test('empty', () => {
937
+ expect(
938
+ // cast abi-encode "a(uint[])" "[]"
939
+ encodeAbi({
940
+ params: [
941
+ {
942
+ internalType: 'uint256[]',
943
+ name: 'xIn',
944
+ type: 'uint256[]',
945
+ },
946
+ ],
947
+ values: [[]],
948
+ }),
949
+ ).toMatchInlineSnapshot(
950
+ '"0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"',
951
+ )
952
+ })
953
+ })
954
+
955
+ describe('(uint[][])', () => {
956
+ test('default', () => {
957
+ expect(
958
+ // cast abi-encode "a(uint[][])" "[[420,69]]"
959
+ encodeAbi({
960
+ params: [
961
+ {
962
+ internalType: 'uint256[][]',
963
+ name: 'xIn',
964
+ type: 'uint256[][]',
965
+ },
966
+ ],
967
+ values: [[[420n, 69n]]],
968
+ }),
969
+ ).toMatchInlineSnapshot(
970
+ '"0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001a40000000000000000000000000000000000000000000000000000000000000045"',
971
+ )
972
+ })
973
+
974
+ test('empty', () => {
975
+ expect(
976
+ // cast abi-encode "a(uint[][])" "[[]]"
977
+ encodeAbi({
978
+ params: [
979
+ {
980
+ internalType: 'uint256[][]',
981
+ name: 'xIn',
982
+ type: 'uint256[][]',
983
+ },
984
+ ],
985
+ values: [[[]]],
986
+ }),
987
+ ).toMatchInlineSnapshot(
988
+ '"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000"',
989
+ )
990
+ })
991
+
992
+ test('complex', () => {
993
+ expect(
994
+ // cast abi-encode "a(uint[][])" "[[420,69],[22,55,22],[51,52,66,11]]"
995
+ encodeAbi({
996
+ params: [
997
+ {
998
+ internalType: 'uint256[][]',
999
+ name: 'xIn',
1000
+ type: 'uint256[][]',
1001
+ },
1002
+ ],
1003
+ values: [
1004
+ [
1005
+ [420n, 69n],
1006
+ [22n, 55n, 22n],
1007
+ [51n, 52n, 66n, 11n],
1008
+ ],
1009
+ ],
1010
+ }),
1011
+ ).toMatchInlineSnapshot(
1012
+ '"0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000003000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000c00000000000000000000000000000000000000000000000000000000000000140000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001a4000000000000000000000000000000000000000000000000000000000000004500000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000016000000000000000000000000000000000000000000000000000000000000003700000000000000000000000000000000000000000000000000000000000000160000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000003300000000000000000000000000000000000000000000000000000000000000340000000000000000000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000000000000000000000000b"',
1013
+ )
1014
+ })
1015
+ })
1016
+
1017
+ describe('(uint[][][])', () => {
1018
+ test('default', () => {
1019
+ expect(
1020
+ // cast abi-encode "a(uint[][][])" "[[[420,69]]]"
1021
+ encodeAbi({
1022
+ params: [
1023
+ {
1024
+ internalType: 'uint256[][][]',
1025
+ name: 'xIn',
1026
+ type: 'uint256[][][]',
1027
+ },
1028
+ ],
1029
+ values: [[[[420n, 69n]]]],
1030
+ }),
1031
+ ).toMatchInlineSnapshot(
1032
+ '"0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001a40000000000000000000000000000000000000000000000000000000000000045"',
1033
+ )
1034
+ })
1035
+ })
1036
+
1037
+ describe('(string[2])', () => {
1038
+ test('default', () => {
1039
+ expect(
1040
+ // cast abi-encode "a(string[2])" "["wagmi","viem"]"
1041
+ encodeAbi({
1042
+ params: [
1043
+ {
1044
+ internalType: 'string[2]',
1045
+ name: 'xIn',
1046
+ type: 'string[2]',
1047
+ },
1048
+ ],
1049
+ values: [['wagmi', 'viem']],
1050
+ }),
1051
+ ).toMatchInlineSnapshot(
1052
+ '"0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000057761676d6900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000047669656d00000000000000000000000000000000000000000000000000000000"',
1053
+ )
1054
+ })
1055
+ })
1056
+
1057
+ describe('(string[2][3])', () => {
1058
+ test('default', () => {
1059
+ expect(
1060
+ // cast abi-encode "a(string[2][3])" "[["wagmi","viem"],["jake","tom"],["lol","haha"]]"
1061
+ encodeAbi({
1062
+ params: [
1063
+ {
1064
+ internalType: 'string[2][3]',
1065
+ name: 'xIn',
1066
+ type: 'string[2][3]',
1067
+ },
1068
+ ],
1069
+ values: [
1070
+ [
1071
+ ['wagmi', 'viem'],
1072
+ ['jake', 'tom'],
1073
+ ['lol', 'haha'],
1074
+ ],
1075
+ ],
1076
+ }),
1077
+ ).toMatchInlineSnapshot(
1078
+ '"0x00000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e00000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000057761676d6900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000047669656d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000046a616b65000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003746f6d00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000036c6f6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046861686100000000000000000000000000000000000000000000000000000000"',
1079
+ )
1080
+ })
1081
+ })
1082
+
1083
+ describe('((uint256[],bool,string[]))', () => {
1084
+ test('default', () => {
1085
+ expect(
1086
+ // cast abi-encode "a((uint256[],bool,string[]))" "([1,2,3,4],true,[hello,world])"
1087
+ encodeAbi({
1088
+ params: [
1089
+ {
1090
+ components: [
1091
+ {
1092
+ internalType: 'uint256[]',
1093
+ name: 'x',
1094
+ type: 'uint256[]',
1095
+ },
1096
+ {
1097
+ internalType: 'bool',
1098
+ name: 'y',
1099
+ type: 'bool',
1100
+ },
1101
+ {
1102
+ internalType: 'string[]',
1103
+ name: 'z',
1104
+ type: 'string[]',
1105
+ },
1106
+ ],
1107
+ internalType: 'struct ABIExample.Baz',
1108
+ name: 'bazIn',
1109
+ type: 'tuple',
1110
+ },
1111
+ ],
1112
+ values: [
1113
+ {
1114
+ x: [1n, 2n, 3n, 4n],
1115
+ y: true,
1116
+ z: ['hello', 'world'],
1117
+ },
1118
+ ],
1119
+ }),
1120
+ ).toMatchInlineSnapshot(
1121
+ '"0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000568656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005776f726c64000000000000000000000000000000000000000000000000000000"',
1122
+ )
1123
+ })
1124
+ })
1125
+
1126
+ describe('(((uint256[],bool,string[])),uint256,string[])', () => {
1127
+ test('default', () => {
1128
+ expect(
1129
+ // cast abi-encode "a(((uint256[],bool,string[]),uint256,string[]))" "(([1,2,3,4],true,[hello,world]),420,[wagmi,viem])"
1130
+ encodeAbi({
1131
+ params: [
1132
+ {
1133
+ components: [
1134
+ {
1135
+ components: [
1136
+ {
1137
+ internalType: 'uint256[]',
1138
+ name: 'x',
1139
+ type: 'uint256[]',
1140
+ },
1141
+ {
1142
+ internalType: 'bool',
1143
+ name: 'y',
1144
+ type: 'bool',
1145
+ },
1146
+ {
1147
+ internalType: 'string[]',
1148
+ name: 'z',
1149
+ type: 'string[]',
1150
+ },
1151
+ ],
1152
+ internalType: 'struct ABIExample.Baz',
1153
+ name: 'foo',
1154
+ type: 'tuple',
1155
+ },
1156
+ {
1157
+ internalType: 'uint256',
1158
+ name: 'a',
1159
+ type: 'uint256',
1160
+ },
1161
+ {
1162
+ internalType: 'string[]',
1163
+ name: 'b',
1164
+ type: 'string[]',
1165
+ },
1166
+ ],
1167
+ internalType: 'struct ABIExample.Wagmi',
1168
+ name: 'wagmiIn',
1169
+ type: 'tuple',
1170
+ },
1171
+ ] as const,
1172
+ values: [
1173
+ {
1174
+ foo: {
1175
+ x: [1n, 2n, 3n, 4n],
1176
+ y: true,
1177
+ z: ['hello', 'world'],
1178
+ },
1179
+ a: 420n,
1180
+ b: ['wagmi', 'viem'],
1181
+ },
1182
+ ],
1183
+ }),
1184
+ ).toMatchInlineSnapshot(
1185
+ '"0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a4000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000568656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005776f726c6400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000057761676d6900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000047669656d00000000000000000000000000000000000000000000000000000000"',
1186
+ )
1187
+ })
1188
+ })
1189
+
1190
+ describe('(((uint256[],bool,string[])),uint256,string[])', () => {
1191
+ test('default', () => {
1192
+ expect(
1193
+ // cast abi-encode "a((uint256[],bool,string[]),(((uint256[],bool,string),uint256,string[]),((uint256[],bool,string),uint256,string[]),uint256,string[]))" "([1,2,3,4],true,[hello, world])" "((([420,69],true,[nice,haha]),420,[wagmi,allday]),(([420,420],true,[this,is,a,param]),69420,[hello,there]),4204202,[lol,haha])"
1194
+ encodeAbi({
1195
+ params: [
1196
+ {
1197
+ components: [
1198
+ {
1199
+ internalType: 'uint256[]',
1200
+ name: 'x',
1201
+ type: 'uint256[]',
1202
+ },
1203
+ {
1204
+ internalType: 'bool',
1205
+ name: 'y',
1206
+ type: 'bool',
1207
+ },
1208
+ {
1209
+ internalType: 'string[]',
1210
+ name: 'z',
1211
+ type: 'string[]',
1212
+ },
1213
+ ],
1214
+ internalType: 'struct ABIExample.Baz',
1215
+ name: 'bazIn',
1216
+ type: 'tuple',
1217
+ },
1218
+ {
1219
+ components: [
1220
+ {
1221
+ components: [
1222
+ {
1223
+ components: [
1224
+ {
1225
+ internalType: 'uint256[]',
1226
+ name: 'x',
1227
+ type: 'uint256[]',
1228
+ },
1229
+ {
1230
+ internalType: 'bool',
1231
+ name: 'y',
1232
+ type: 'bool',
1233
+ },
1234
+ {
1235
+ internalType: 'string[]',
1236
+ name: 'z',
1237
+ type: 'string[]',
1238
+ },
1239
+ ],
1240
+ internalType: 'struct ABIExample.Baz',
1241
+ name: 'foo',
1242
+ type: 'tuple',
1243
+ },
1244
+ {
1245
+ internalType: 'uint256',
1246
+ name: 'a',
1247
+ type: 'uint256',
1248
+ },
1249
+ {
1250
+ internalType: 'string[]',
1251
+ name: 'b',
1252
+ type: 'string[]',
1253
+ },
1254
+ ],
1255
+ internalType: 'struct ABIExample.Wagmi',
1256
+ name: 'foo',
1257
+ type: 'tuple',
1258
+ },
1259
+ {
1260
+ components: [
1261
+ {
1262
+ components: [
1263
+ {
1264
+ internalType: 'uint256[]',
1265
+ name: 'x',
1266
+ type: 'uint256[]',
1267
+ },
1268
+ {
1269
+ internalType: 'bool',
1270
+ name: 'y',
1271
+ type: 'bool',
1272
+ },
1273
+ {
1274
+ internalType: 'string[]',
1275
+ name: 'z',
1276
+ type: 'string[]',
1277
+ },
1278
+ ],
1279
+ internalType: 'struct ABIExample.Baz',
1280
+ name: 'foo',
1281
+ type: 'tuple',
1282
+ },
1283
+ {
1284
+ internalType: 'uint256',
1285
+ name: 'a',
1286
+ type: 'uint256',
1287
+ },
1288
+ {
1289
+ internalType: 'string[]',
1290
+ name: 'b',
1291
+ type: 'string[]',
1292
+ },
1293
+ ],
1294
+ internalType: 'struct ABIExample.Wagmi',
1295
+ name: 'bar',
1296
+ type: 'tuple',
1297
+ },
1298
+ {
1299
+ internalType: 'uint256',
1300
+ name: 'c',
1301
+ type: 'uint256',
1302
+ },
1303
+ {
1304
+ internalType: 'string[]',
1305
+ name: 'd',
1306
+ type: 'string[]',
1307
+ },
1308
+ ],
1309
+ internalType: 'struct ABIExample.Gmi',
1310
+ name: 'gmiIn',
1311
+ type: 'tuple',
1312
+ },
1313
+ ],
1314
+ values: [
1315
+ {
1316
+ x: [1n, 2n, 3n, 4n],
1317
+ y: true,
1318
+ z: ['hello', 'world'],
1319
+ },
1320
+ {
1321
+ foo: {
1322
+ a: 420n,
1323
+ b: ['wagmi', 'allday'],
1324
+ foo: {
1325
+ x: [420n, 69n],
1326
+ y: true,
1327
+ z: ['nice', 'haha'],
1328
+ },
1329
+ },
1330
+ bar: {
1331
+ a: 69420n,
1332
+ b: ['hello', 'there'],
1333
+ foo: {
1334
+ x: [420n, 420n],
1335
+ y: true,
1336
+ z: ['this', 'is', 'a', 'param'],
1337
+ },
1338
+ },
1339
+ c: 4204202n,
1340
+ d: ['lol', 'haha'],
1341
+ },
1342
+ ],
1343
+ }),
1344
+ ).toMatchInlineSnapshot(
1345
+ '"0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000568656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005776f726c640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000036000000000000000000000000000000000000000000000000000000000004026aa0000000000000000000000000000000000000000000000000000000000000700000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000001a400000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001a4000000000000000000000000000000000000000000000000000000000000004500000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000046e696365000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000004686168610000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000057761676d690000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000006616c6c646179000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000600000000000000000000000000000000000000000000000000000000000010f2c00000000000000000000000000000000000000000000000000000000000002c00000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000001a400000000000000000000000000000000000000000000000000000000000001a40000000000000000000000000000000000000000000000000000000000000004000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000001400000000000000000000000000000000000000000000000000000000000000004746869730000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000026973000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000161000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005706172616d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000400000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000568656c6c6f0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000005746865726500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000036c6f6c000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000046861686100000000000000000000000000000000000000000000000000000000"',
1346
+ )
1347
+ })
1348
+ })
1349
+ })
1350
+
1351
+ test('invalid type', () => {
1352
+ expect(() =>
1353
+ encodeAbi({ params: [{ name: 'x', type: 'lol' }], values: [69] }),
1354
+ ).toThrowErrorMatchingInlineSnapshot(`
1355
+ "Type \\"lol\\" is not a valid encoding type.
1356
+ Please provide a valid ABI type.
1357
+
1358
+ Docs: https://viem.sh/docs/contract/encodeAbi
1359
+
1360
+ Version: viem@1.0.2"
1361
+ `)
1362
+ })
1363
+
1364
+ test('invalid params/values lengths', () => {
1365
+ expect(() =>
1366
+ encodeAbi({
1367
+ params: [{ name: 'x', type: 'uint256[3]' }],
1368
+ /* @ts-expect-error */
1369
+ values: [69, 420],
1370
+ }),
1371
+ ).toThrowErrorMatchingInlineSnapshot(`
1372
+ "ABI encoding params/values length mismatch.
1373
+ Expected length (params): 1
1374
+ Given length (values): 2
1375
+
1376
+ Version: viem@1.0.2"
1377
+ `)
1378
+ })
1379
+
1380
+ test('invalid array', () => {
1381
+ expect(() =>
1382
+ /* @ts-expect-error */
1383
+ encodeAbi({ params: [{ name: 'x', type: 'uint256[3]' }], values: [69] }),
1384
+ ).toThrowErrorMatchingInlineSnapshot(`
1385
+ "Value \\"69\\" is not a valid array.
1386
+
1387
+ Version: viem@1.0.2"
1388
+ `)
1389
+ })
1390
+
1391
+ test('invalid array lengths', () => {
1392
+ expect(() =>
1393
+ encodeAbi({
1394
+ params: [{ name: 'x', type: 'uint256[3]' }],
1395
+ /* @ts-expect-error */
1396
+ values: [[69n, 420n]],
1397
+ }),
1398
+ ).toThrowErrorMatchingInlineSnapshot(`
1399
+ "ABI encoding array length mismatch for type uint256[3].
1400
+ Expected length: 3
1401
+ Given length: 2
1402
+
1403
+ Version: viem@1.0.2"
1404
+ `)
1405
+ })
1406
+
1407
+ test('getArrayComponents', () => {
1408
+ expect(getArrayComponents('uint256[2]')).toEqual([2, 'uint256'])
1409
+ expect(getArrayComponents('uint256[2][3]')).toEqual([3, 'uint256[2]'])
1410
+ expect(getArrayComponents('uint256[][3]')).toEqual([3, 'uint256[]'])
1411
+ expect(getArrayComponents('uint256[]')).toEqual([null, 'uint256'])
1412
+ expect(getArrayComponents('uint256[][]')).toEqual([null, 'uint256[]'])
1413
+ expect(getArrayComponents('uint256')).toBeUndefined()
1414
+ })