@ledgerhq/coin-vechain 2.9.1-nightly.1 → 2.10.0-nightly.3

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 (475) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +16 -4
  3. package/CHANGELOG.md +22 -0
  4. package/lib/bridge/broadcast.d.ts.map +1 -1
  5. package/lib/bridge/broadcast.js +2 -3
  6. package/lib/bridge/broadcast.js.map +1 -1
  7. package/lib/bridge/broadcast.test.d.ts +2 -0
  8. package/lib/bridge/broadcast.test.d.ts.map +1 -0
  9. package/lib/bridge/broadcast.test.js +188 -0
  10. package/lib/bridge/broadcast.test.js.map +1 -0
  11. package/lib/bridge/buildOptimisticOperatioin.test.d.ts +2 -0
  12. package/lib/bridge/buildOptimisticOperatioin.test.d.ts.map +1 -0
  13. package/lib/bridge/buildOptimisticOperatioin.test.js +286 -0
  14. package/lib/bridge/buildOptimisticOperatioin.test.js.map +1 -0
  15. package/lib/bridge/createTransaction.d.ts.map +1 -1
  16. package/lib/bridge/createTransaction.js +2 -1
  17. package/lib/bridge/createTransaction.js.map +1 -1
  18. package/lib/bridge/createTransaction.test.d.ts +2 -0
  19. package/lib/bridge/createTransaction.test.d.ts.map +1 -0
  20. package/lib/bridge/createTransaction.test.js +167 -0
  21. package/lib/bridge/createTransaction.test.js.map +1 -0
  22. package/lib/bridge/estimateMaxSpendable.test.d.ts +2 -0
  23. package/lib/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  24. package/lib/bridge/estimateMaxSpendable.test.js +269 -0
  25. package/lib/bridge/estimateMaxSpendable.test.js.map +1 -0
  26. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  27. package/lib/bridge/getTransactionStatus.js +3 -1
  28. package/lib/bridge/getTransactionStatus.js.map +1 -1
  29. package/lib/bridge/getTransactionStatus.test.d.ts +2 -0
  30. package/lib/bridge/getTransactionStatus.test.d.ts.map +1 -0
  31. package/lib/bridge/getTransactionStatus.test.js +282 -0
  32. package/lib/bridge/getTransactionStatus.test.js.map +1 -0
  33. package/lib/bridge/helpers.test.d.ts +2 -0
  34. package/lib/bridge/helpers.test.d.ts.map +1 -0
  35. package/lib/bridge/helpers.test.js +298 -0
  36. package/lib/bridge/helpers.test.js.map +1 -0
  37. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  38. package/lib/bridge/prepareTransaction.js +10 -3
  39. package/lib/bridge/prepareTransaction.js.map +1 -1
  40. package/lib/bridge/prepareTransaction.test.d.ts +2 -0
  41. package/lib/bridge/prepareTransaction.test.d.ts.map +1 -0
  42. package/lib/bridge/prepareTransaction.test.js +277 -0
  43. package/lib/bridge/prepareTransaction.test.js.map +1 -0
  44. package/lib/bridge/signOperation.d.ts.map +1 -1
  45. package/lib/bridge/signOperation.js +3 -3
  46. package/lib/bridge/signOperation.js.map +1 -1
  47. package/lib/bridge/signOperation.test.d.ts +2 -0
  48. package/lib/bridge/signOperation.test.d.ts.map +1 -0
  49. package/lib/bridge/signOperation.test.js +295 -0
  50. package/lib/bridge/signOperation.test.js.map +1 -0
  51. package/lib/bridge/synchronisation.d.ts.map +1 -1
  52. package/lib/bridge/synchronisation.js +2 -2
  53. package/lib/bridge/synchronisation.js.map +1 -1
  54. package/lib/bridge/transaction.test.d.ts +2 -0
  55. package/lib/bridge/transaction.test.d.ts.map +1 -0
  56. package/lib/bridge/transaction.test.js +353 -0
  57. package/lib/bridge/transaction.test.js.map +1 -0
  58. package/lib/common-logic/calculateClauses.d.ts +5 -0
  59. package/lib/common-logic/calculateClauses.d.ts.map +1 -0
  60. package/lib/common-logic/{logic.js → calculateClauses.js} +7 -10
  61. package/lib/common-logic/calculateClauses.js.map +1 -0
  62. package/lib/common-logic/calculateClauses.test.d.ts +2 -0
  63. package/lib/common-logic/calculateClauses.test.d.ts.map +1 -0
  64. package/lib/common-logic/calculateClauses.test.js +156 -0
  65. package/lib/common-logic/calculateClauses.test.js.map +1 -0
  66. package/lib/common-logic/calculateGasFees.d.ts +9 -0
  67. package/lib/common-logic/calculateGasFees.d.ts.map +1 -0
  68. package/lib/common-logic/calculateGasFees.js +39 -0
  69. package/lib/common-logic/calculateGasFees.js.map +1 -0
  70. package/lib/common-logic/calculateGasFees.test.d.ts +2 -0
  71. package/lib/common-logic/calculateGasFees.test.d.ts.map +1 -0
  72. package/lib/common-logic/calculateGasFees.test.js +279 -0
  73. package/lib/common-logic/calculateGasFees.test.js.map +1 -0
  74. package/lib/common-logic/calculateTransactionInfo.d.ts +10 -0
  75. package/lib/common-logic/calculateTransactionInfo.d.ts.map +1 -0
  76. package/lib/common-logic/calculateTransactionInfo.js +81 -0
  77. package/lib/common-logic/calculateTransactionInfo.js.map +1 -0
  78. package/lib/common-logic/calculateTransactionInfo.test.d.ts +2 -0
  79. package/lib/common-logic/calculateTransactionInfo.test.d.ts.map +1 -0
  80. package/lib/common-logic/calculateTransactionInfo.test.js +314 -0
  81. package/lib/common-logic/calculateTransactionInfo.test.js.map +1 -0
  82. package/lib/common-logic/estimateGas.d.ts +10 -0
  83. package/lib/common-logic/estimateGas.d.ts.map +1 -0
  84. package/lib/common-logic/estimateGas.js +17 -0
  85. package/lib/common-logic/estimateGas.js.map +1 -0
  86. package/lib/common-logic/estimateGas.test.d.ts +2 -0
  87. package/lib/common-logic/estimateGas.test.d.ts.map +1 -0
  88. package/lib/common-logic/estimateGas.test.js +129 -0
  89. package/lib/common-logic/estimateGas.test.js.map +1 -0
  90. package/lib/common-logic/fixPrefixCase.d.ts +2 -0
  91. package/lib/common-logic/fixPrefixCase.d.ts.map +1 -0
  92. package/lib/common-logic/fixPrefixCase.js +9 -0
  93. package/lib/common-logic/fixPrefixCase.js.map +1 -0
  94. package/lib/common-logic/fixPrefixCase.test.d.ts +2 -0
  95. package/lib/common-logic/fixPrefixCase.test.d.ts.map +1 -0
  96. package/lib/common-logic/fixPrefixCase.test.js +46 -0
  97. package/lib/common-logic/fixPrefixCase.test.js.map +1 -0
  98. package/lib/common-logic/generateNonce.d.ts +6 -0
  99. package/lib/common-logic/generateNonce.d.ts.map +1 -0
  100. package/lib/common-logic/generateNonce.js +13 -0
  101. package/lib/common-logic/generateNonce.js.map +1 -0
  102. package/lib/common-logic/generateNonce.test.d.ts +2 -0
  103. package/lib/common-logic/generateNonce.test.d.ts.map +1 -0
  104. package/lib/common-logic/generateNonce.test.js +59 -0
  105. package/lib/common-logic/generateNonce.test.js.map +1 -0
  106. package/lib/common-logic/getThorClient.d.ts +7 -0
  107. package/lib/common-logic/getThorClient.d.ts.map +1 -0
  108. package/lib/common-logic/getThorClient.js +14 -0
  109. package/lib/common-logic/getThorClient.js.map +1 -0
  110. package/lib/common-logic/getThorClient.test.d.ts +2 -0
  111. package/lib/common-logic/getThorClient.test.d.ts.map +1 -0
  112. package/lib/common-logic/getThorClient.test.js +53 -0
  113. package/lib/common-logic/getThorClient.test.js.map +1 -0
  114. package/lib/common-logic/index.d.ts +8 -6
  115. package/lib/common-logic/index.d.ts.map +1 -1
  116. package/lib/common-logic/index.js +8 -6
  117. package/lib/common-logic/index.js.map +1 -1
  118. package/lib/common-logic/{mapping-utils.d.ts → mapTransfersToOperations.d.ts} +2 -2
  119. package/lib/common-logic/mapTransfersToOperations.d.ts.map +1 -0
  120. package/lib/common-logic/{mapping-utils.js → mapTransfersToOperations.js} +26 -19
  121. package/lib/common-logic/mapTransfersToOperations.js.map +1 -0
  122. package/lib/common-logic/mapTransfersToOperations.test.d.ts +2 -0
  123. package/lib/common-logic/mapTransfersToOperations.test.d.ts.map +1 -0
  124. package/lib/common-logic/mapTransfersToOperations.test.js +274 -0
  125. package/lib/common-logic/mapTransfersToOperations.test.js.map +1 -0
  126. package/lib/common-logic/{pad-address.d.ts → padAddress.d.ts} +1 -1
  127. package/lib/common-logic/padAddress.d.ts.map +1 -0
  128. package/lib/common-logic/{pad-address.js → padAddress.js} +1 -1
  129. package/lib/common-logic/padAddress.js.map +1 -0
  130. package/lib/common-logic/padAddress.test.d.ts +2 -0
  131. package/lib/common-logic/padAddress.test.d.ts.map +1 -0
  132. package/lib/common-logic/padAddress.test.js +59 -0
  133. package/lib/common-logic/padAddress.test.js.map +1 -0
  134. package/lib/common-logic/parseAddress.d.ts +7 -0
  135. package/lib/common-logic/parseAddress.d.ts.map +1 -0
  136. package/lib/common-logic/parseAddress.js +15 -0
  137. package/lib/common-logic/parseAddress.js.map +1 -0
  138. package/lib/common-logic/parseAddress.test.d.ts +2 -0
  139. package/lib/common-logic/parseAddress.test.d.ts.map +1 -0
  140. package/lib/common-logic/parseAddress.test.js +97 -0
  141. package/lib/common-logic/parseAddress.test.js.map +1 -0
  142. package/lib/constants/env.d.ts +2 -0
  143. package/lib/constants/env.d.ts.map +1 -0
  144. package/lib/constants/env.js +6 -0
  145. package/lib/constants/env.js.map +1 -0
  146. package/lib/constants/index.d.ts +2 -0
  147. package/lib/constants/index.d.ts.map +1 -0
  148. package/lib/constants/index.js +18 -0
  149. package/lib/constants/index.js.map +1 -0
  150. package/lib/network/sdk.d.ts +3 -10
  151. package/lib/network/sdk.d.ts.map +1 -1
  152. package/lib/network/sdk.js +15 -30
  153. package/lib/network/sdk.js.map +1 -1
  154. package/lib/signer/getAddress.test.d.ts +2 -0
  155. package/lib/signer/getAddress.test.d.ts.map +1 -0
  156. package/lib/signer/getAddress.test.js +357 -0
  157. package/lib/signer/getAddress.test.js.map +1 -0
  158. package/lib/signer/signMessage.d.ts.map +1 -1
  159. package/lib/signer/signMessage.js +3 -3
  160. package/lib/signer/signMessage.js.map +1 -1
  161. package/lib/signer/signMessage.test.d.ts +2 -0
  162. package/lib/signer/signMessage.test.d.ts.map +1 -0
  163. package/lib/signer/signMessage.test.js +242 -0
  164. package/lib/signer/signMessage.test.js.map +1 -0
  165. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  166. package/lib/test/bridgeDatasetTest.js +79 -53
  167. package/lib/test/bridgeDatasetTest.js.map +1 -1
  168. package/lib/test/cli.d.ts.map +1 -1
  169. package/lib/test/cli.js +5 -4
  170. package/lib/test/cli.js.map +1 -1
  171. package/lib/types/bridge.d.ts +11 -3
  172. package/lib/types/bridge.d.ts.map +1 -1
  173. package/lib/types/bridge.js +3 -0
  174. package/lib/types/bridge.js.map +1 -1
  175. package/lib/types/constants.d.ts +0 -3
  176. package/lib/types/constants.d.ts.map +1 -1
  177. package/lib/types/constants.js +1 -4
  178. package/lib/types/constants.js.map +1 -1
  179. package/lib/types/signer.d.ts +0 -2
  180. package/lib/types/signer.d.ts.map +1 -1
  181. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  182. package/lib-es/bridge/broadcast.js +2 -3
  183. package/lib-es/bridge/broadcast.js.map +1 -1
  184. package/lib-es/bridge/broadcast.test.d.ts +2 -0
  185. package/lib-es/bridge/broadcast.test.d.ts.map +1 -0
  186. package/lib-es/bridge/broadcast.test.js +183 -0
  187. package/lib-es/bridge/broadcast.test.js.map +1 -0
  188. package/lib-es/bridge/buildOptimisticOperatioin.test.d.ts +2 -0
  189. package/lib-es/bridge/buildOptimisticOperatioin.test.d.ts.map +1 -0
  190. package/lib-es/bridge/buildOptimisticOperatioin.test.js +281 -0
  191. package/lib-es/bridge/buildOptimisticOperatioin.test.js.map +1 -0
  192. package/lib-es/bridge/createTransaction.d.ts.map +1 -1
  193. package/lib-es/bridge/createTransaction.js +3 -2
  194. package/lib-es/bridge/createTransaction.js.map +1 -1
  195. package/lib-es/bridge/createTransaction.test.d.ts +2 -0
  196. package/lib-es/bridge/createTransaction.test.d.ts.map +1 -0
  197. package/lib-es/bridge/createTransaction.test.js +162 -0
  198. package/lib-es/bridge/createTransaction.test.js.map +1 -0
  199. package/lib-es/bridge/estimateMaxSpendable.test.d.ts +2 -0
  200. package/lib-es/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  201. package/lib-es/bridge/estimateMaxSpendable.test.js +264 -0
  202. package/lib-es/bridge/estimateMaxSpendable.test.js.map +1 -0
  203. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  204. package/lib-es/bridge/getTransactionStatus.js +4 -2
  205. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  206. package/lib-es/bridge/getTransactionStatus.test.d.ts +2 -0
  207. package/lib-es/bridge/getTransactionStatus.test.d.ts.map +1 -0
  208. package/lib-es/bridge/getTransactionStatus.test.js +277 -0
  209. package/lib-es/bridge/getTransactionStatus.test.js.map +1 -0
  210. package/lib-es/bridge/helpers.test.d.ts +2 -0
  211. package/lib-es/bridge/helpers.test.d.ts.map +1 -0
  212. package/lib-es/bridge/helpers.test.js +293 -0
  213. package/lib-es/bridge/helpers.test.js.map +1 -0
  214. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  215. package/lib-es/bridge/prepareTransaction.js +11 -4
  216. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  217. package/lib-es/bridge/prepareTransaction.test.d.ts +2 -0
  218. package/lib-es/bridge/prepareTransaction.test.d.ts.map +1 -0
  219. package/lib-es/bridge/prepareTransaction.test.js +272 -0
  220. package/lib-es/bridge/prepareTransaction.test.js.map +1 -0
  221. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  222. package/lib-es/bridge/signOperation.js +3 -3
  223. package/lib-es/bridge/signOperation.js.map +1 -1
  224. package/lib-es/bridge/signOperation.test.d.ts +2 -0
  225. package/lib-es/bridge/signOperation.test.d.ts.map +1 -0
  226. package/lib-es/bridge/signOperation.test.js +290 -0
  227. package/lib-es/bridge/signOperation.test.js.map +1 -0
  228. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  229. package/lib-es/bridge/synchronisation.js +1 -1
  230. package/lib-es/bridge/synchronisation.js.map +1 -1
  231. package/lib-es/bridge/transaction.test.d.ts +2 -0
  232. package/lib-es/bridge/transaction.test.d.ts.map +1 -0
  233. package/lib-es/bridge/transaction.test.js +347 -0
  234. package/lib-es/bridge/transaction.test.js.map +1 -0
  235. package/lib-es/common-logic/calculateClauses.d.ts +5 -0
  236. package/lib-es/common-logic/calculateClauses.d.ts.map +1 -0
  237. package/lib-es/common-logic/{logic.js → calculateClauses.js} +6 -6
  238. package/lib-es/common-logic/calculateClauses.js.map +1 -0
  239. package/lib-es/common-logic/calculateClauses.test.d.ts +2 -0
  240. package/lib-es/common-logic/calculateClauses.test.d.ts.map +1 -0
  241. package/lib-es/common-logic/calculateClauses.test.js +151 -0
  242. package/lib-es/common-logic/calculateClauses.test.js.map +1 -0
  243. package/lib-es/common-logic/calculateGasFees.d.ts +9 -0
  244. package/lib-es/common-logic/calculateGasFees.d.ts.map +1 -0
  245. package/lib-es/common-logic/calculateGasFees.js +32 -0
  246. package/lib-es/common-logic/calculateGasFees.js.map +1 -0
  247. package/lib-es/common-logic/calculateGasFees.test.d.ts +2 -0
  248. package/lib-es/common-logic/calculateGasFees.test.d.ts.map +1 -0
  249. package/lib-es/common-logic/calculateGasFees.test.js +274 -0
  250. package/lib-es/common-logic/calculateGasFees.test.js.map +1 -0
  251. package/lib-es/common-logic/calculateTransactionInfo.d.ts +10 -0
  252. package/lib-es/common-logic/calculateTransactionInfo.d.ts.map +1 -0
  253. package/lib-es/common-logic/calculateTransactionInfo.js +74 -0
  254. package/lib-es/common-logic/calculateTransactionInfo.js.map +1 -0
  255. package/lib-es/common-logic/calculateTransactionInfo.test.d.ts +2 -0
  256. package/lib-es/common-logic/calculateTransactionInfo.test.d.ts.map +1 -0
  257. package/lib-es/common-logic/calculateTransactionInfo.test.js +309 -0
  258. package/lib-es/common-logic/calculateTransactionInfo.test.js.map +1 -0
  259. package/lib-es/common-logic/estimateGas.d.ts +10 -0
  260. package/lib-es/common-logic/estimateGas.d.ts.map +1 -0
  261. package/lib-es/common-logic/estimateGas.js +13 -0
  262. package/lib-es/common-logic/estimateGas.js.map +1 -0
  263. package/lib-es/common-logic/estimateGas.test.d.ts +2 -0
  264. package/lib-es/common-logic/estimateGas.test.d.ts.map +1 -0
  265. package/lib-es/common-logic/estimateGas.test.js +127 -0
  266. package/lib-es/common-logic/estimateGas.test.js.map +1 -0
  267. package/lib-es/common-logic/fixPrefixCase.d.ts +2 -0
  268. package/lib-es/common-logic/fixPrefixCase.d.ts.map +1 -0
  269. package/lib-es/common-logic/fixPrefixCase.js +5 -0
  270. package/lib-es/common-logic/fixPrefixCase.js.map +1 -0
  271. package/lib-es/common-logic/fixPrefixCase.test.d.ts +2 -0
  272. package/lib-es/common-logic/fixPrefixCase.test.d.ts.map +1 -0
  273. package/lib-es/common-logic/fixPrefixCase.test.js +44 -0
  274. package/lib-es/common-logic/fixPrefixCase.test.js.map +1 -0
  275. package/lib-es/common-logic/generateNonce.d.ts +6 -0
  276. package/lib-es/common-logic/generateNonce.d.ts.map +1 -0
  277. package/lib-es/common-logic/generateNonce.js +9 -0
  278. package/lib-es/common-logic/generateNonce.js.map +1 -0
  279. package/lib-es/common-logic/generateNonce.test.d.ts +2 -0
  280. package/lib-es/common-logic/generateNonce.test.d.ts.map +1 -0
  281. package/lib-es/common-logic/generateNonce.test.js +57 -0
  282. package/lib-es/common-logic/generateNonce.test.js.map +1 -0
  283. package/lib-es/common-logic/getThorClient.d.ts +7 -0
  284. package/lib-es/common-logic/getThorClient.d.ts.map +1 -0
  285. package/lib-es/common-logic/getThorClient.js +10 -0
  286. package/lib-es/common-logic/getThorClient.js.map +1 -0
  287. package/lib-es/common-logic/getThorClient.test.d.ts +2 -0
  288. package/lib-es/common-logic/getThorClient.test.d.ts.map +1 -0
  289. package/lib-es/common-logic/getThorClient.test.js +51 -0
  290. package/lib-es/common-logic/getThorClient.test.js.map +1 -0
  291. package/lib-es/common-logic/index.d.ts +8 -6
  292. package/lib-es/common-logic/index.d.ts.map +1 -1
  293. package/lib-es/common-logic/index.js +8 -6
  294. package/lib-es/common-logic/index.js.map +1 -1
  295. package/lib-es/common-logic/{mapping-utils.d.ts → mapTransfersToOperations.d.ts} +2 -2
  296. package/lib-es/common-logic/mapTransfersToOperations.d.ts.map +1 -0
  297. package/lib-es/common-logic/mapTransfersToOperations.js +51 -0
  298. package/lib-es/common-logic/mapTransfersToOperations.js.map +1 -0
  299. package/lib-es/common-logic/mapTransfersToOperations.test.d.ts +2 -0
  300. package/lib-es/common-logic/mapTransfersToOperations.test.d.ts.map +1 -0
  301. package/lib-es/common-logic/mapTransfersToOperations.test.js +269 -0
  302. package/lib-es/common-logic/mapTransfersToOperations.test.js.map +1 -0
  303. package/lib-es/common-logic/{pad-address.d.ts → padAddress.d.ts} +1 -1
  304. package/lib-es/common-logic/padAddress.d.ts.map +1 -0
  305. package/lib-es/common-logic/{pad-address.js → padAddress.js} +1 -1
  306. package/lib-es/common-logic/padAddress.js.map +1 -0
  307. package/lib-es/common-logic/padAddress.test.d.ts +2 -0
  308. package/lib-es/common-logic/padAddress.test.d.ts.map +1 -0
  309. package/lib-es/common-logic/padAddress.test.js +57 -0
  310. package/lib-es/common-logic/padAddress.test.js.map +1 -0
  311. package/lib-es/common-logic/parseAddress.d.ts +7 -0
  312. package/lib-es/common-logic/parseAddress.d.ts.map +1 -0
  313. package/lib-es/common-logic/parseAddress.js +11 -0
  314. package/lib-es/common-logic/parseAddress.js.map +1 -0
  315. package/lib-es/common-logic/parseAddress.test.d.ts +2 -0
  316. package/lib-es/common-logic/parseAddress.test.d.ts.map +1 -0
  317. package/lib-es/common-logic/parseAddress.test.js +95 -0
  318. package/lib-es/common-logic/parseAddress.test.js.map +1 -0
  319. package/lib-es/constants/env.d.ts +2 -0
  320. package/lib-es/constants/env.d.ts.map +1 -0
  321. package/lib-es/constants/env.js +3 -0
  322. package/lib-es/constants/env.js.map +1 -0
  323. package/lib-es/constants/index.d.ts +2 -0
  324. package/lib-es/constants/index.d.ts.map +1 -0
  325. package/lib-es/constants/index.js +2 -0
  326. package/lib-es/constants/index.js.map +1 -0
  327. package/lib-es/network/sdk.d.ts +3 -10
  328. package/lib-es/network/sdk.d.ts.map +1 -1
  329. package/lib-es/network/sdk.js +5 -19
  330. package/lib-es/network/sdk.js.map +1 -1
  331. package/lib-es/signer/getAddress.test.d.ts +2 -0
  332. package/lib-es/signer/getAddress.test.d.ts.map +1 -0
  333. package/lib-es/signer/getAddress.test.js +352 -0
  334. package/lib-es/signer/getAddress.test.js.map +1 -0
  335. package/lib-es/signer/signMessage.d.ts.map +1 -1
  336. package/lib-es/signer/signMessage.js +3 -3
  337. package/lib-es/signer/signMessage.js.map +1 -1
  338. package/lib-es/signer/signMessage.test.d.ts +2 -0
  339. package/lib-es/signer/signMessage.test.d.ts.map +1 -0
  340. package/lib-es/signer/signMessage.test.js +240 -0
  341. package/lib-es/signer/signMessage.test.js.map +1 -0
  342. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  343. package/lib-es/test/bridgeDatasetTest.js +80 -54
  344. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  345. package/lib-es/test/cli.d.ts.map +1 -1
  346. package/lib-es/test/cli.js +4 -3
  347. package/lib-es/test/cli.js.map +1 -1
  348. package/lib-es/types/bridge.d.ts +11 -3
  349. package/lib-es/types/bridge.d.ts.map +1 -1
  350. package/lib-es/types/bridge.js +6 -1
  351. package/lib-es/types/bridge.js.map +1 -1
  352. package/lib-es/types/constants.d.ts +0 -3
  353. package/lib-es/types/constants.d.ts.map +1 -1
  354. package/lib-es/types/constants.js +0 -3
  355. package/lib-es/types/constants.js.map +1 -1
  356. package/lib-es/types/signer.d.ts +0 -2
  357. package/lib-es/types/signer.d.ts.map +1 -1
  358. package/package.json +9 -8
  359. package/src/bridge/broadcast.test.ts +236 -0
  360. package/src/bridge/broadcast.ts +4 -5
  361. package/src/bridge/buildOptimisticOperatioin.test.ts +364 -0
  362. package/src/bridge/createTransaction.test.ts +201 -0
  363. package/src/bridge/createTransaction.ts +3 -2
  364. package/src/bridge/estimateMaxSpendable.test.ts +319 -0
  365. package/src/bridge/getTransactionStatus.test.ts +353 -0
  366. package/src/bridge/getTransactionStatus.ts +4 -2
  367. package/src/bridge/helpers.test.ts +356 -0
  368. package/src/bridge/prepareTransaction.test.ts +345 -0
  369. package/src/bridge/prepareTransaction.ts +20 -10
  370. package/src/bridge/signOperation.test.ts +354 -0
  371. package/src/bridge/signOperation.ts +6 -3
  372. package/src/bridge/synchronisation.ts +1 -1
  373. package/src/bridge/transaction.test.ts +440 -0
  374. package/src/common-logic/calculateClauses.test.ts +186 -0
  375. package/src/common-logic/calculateClauses.ts +44 -0
  376. package/src/common-logic/calculateGasFees.test.ts +363 -0
  377. package/src/common-logic/calculateGasFees.ts +45 -0
  378. package/src/common-logic/calculateTransactionInfo.test.ts +396 -0
  379. package/src/common-logic/calculateTransactionInfo.ts +96 -0
  380. package/src/common-logic/estimateGas.test.ts +162 -0
  381. package/src/common-logic/estimateGas.ts +18 -0
  382. package/src/common-logic/fixPrefixCase.test.ts +51 -0
  383. package/src/common-logic/fixPrefixCase.ts +5 -0
  384. package/src/common-logic/generateNonce.test.ts +72 -0
  385. package/src/common-logic/generateNonce.ts +9 -0
  386. package/src/common-logic/getThorClient.test.ts +66 -0
  387. package/src/common-logic/getThorClient.ts +10 -0
  388. package/src/common-logic/index.ts +8 -6
  389. package/src/common-logic/mapTransfersToOperations.test.ts +342 -0
  390. package/src/common-logic/mapTransfersToOperations.ts +77 -0
  391. package/src/common-logic/padAddress.test.ts +65 -0
  392. package/src/common-logic/parseAddress.test.ts +130 -0
  393. package/src/common-logic/parseAddress.ts +11 -0
  394. package/src/constants/env.ts +3 -0
  395. package/src/constants/index.ts +1 -0
  396. package/src/network/sdk.ts +22 -30
  397. package/src/signer/getAddress.test.ts +454 -0
  398. package/src/signer/signMessage.test.ts +329 -0
  399. package/src/signer/signMessage.ts +4 -5
  400. package/src/test/bridgeDatasetTest.ts +86 -58
  401. package/src/test/cli.ts +4 -3
  402. package/src/types/bridge.ts +16 -3
  403. package/src/types/constants.ts +0 -3
  404. package/lib/common-logic/address-utils.d.ts +0 -2
  405. package/lib/common-logic/address-utils.d.ts.map +0 -1
  406. package/lib/common-logic/address-utils.js +0 -19
  407. package/lib/common-logic/address-utils.js.map +0 -1
  408. package/lib/common-logic/hex-utils.d.ts +0 -8
  409. package/lib/common-logic/hex-utils.d.ts.map +0 -1
  410. package/lib/common-logic/hex-utils.js +0 -52
  411. package/lib/common-logic/hex-utils.js.map +0 -1
  412. package/lib/common-logic/logic.d.ts +0 -5
  413. package/lib/common-logic/logic.d.ts.map +0 -1
  414. package/lib/common-logic/logic.js.map +0 -1
  415. package/lib/common-logic/mapping-utils.d.ts.map +0 -1
  416. package/lib/common-logic/mapping-utils.js.map +0 -1
  417. package/lib/common-logic/pad-address.d.ts.map +0 -1
  418. package/lib/common-logic/pad-address.js.map +0 -1
  419. package/lib/common-logic/transaction-utils.d.ts +0 -30
  420. package/lib/common-logic/transaction-utils.d.ts.map +0 -1
  421. package/lib/common-logic/transaction-utils.js +0 -161
  422. package/lib/common-logic/transaction-utils.js.map +0 -1
  423. package/lib/contracts/abis/VIP180.d.ts +0 -17
  424. package/lib/contracts/abis/VIP180.d.ts.map +0 -1
  425. package/lib/contracts/abis/VIP180.js +0 -265
  426. package/lib/contracts/abis/VIP180.js.map +0 -1
  427. package/lib/contracts/abis/params.d.ts +0 -8
  428. package/lib/contracts/abis/params.d.ts.map +0 -1
  429. package/lib/contracts/abis/params.js +0 -69
  430. package/lib/contracts/abis/params.js.map +0 -1
  431. package/lib/contracts/constants.d.ts +0 -6
  432. package/lib/contracts/constants.d.ts.map +0 -1
  433. package/lib/contracts/constants.js +0 -10
  434. package/lib/contracts/constants.js.map +0 -1
  435. package/lib-es/common-logic/address-utils.d.ts +0 -2
  436. package/lib-es/common-logic/address-utils.d.ts.map +0 -1
  437. package/lib-es/common-logic/address-utils.js +0 -12
  438. package/lib-es/common-logic/address-utils.js.map +0 -1
  439. package/lib-es/common-logic/hex-utils.d.ts +0 -8
  440. package/lib-es/common-logic/hex-utils.d.ts.map +0 -1
  441. package/lib-es/common-logic/hex-utils.js +0 -50
  442. package/lib-es/common-logic/hex-utils.js.map +0 -1
  443. package/lib-es/common-logic/logic.d.ts +0 -5
  444. package/lib-es/common-logic/logic.d.ts.map +0 -1
  445. package/lib-es/common-logic/logic.js.map +0 -1
  446. package/lib-es/common-logic/mapping-utils.d.ts.map +0 -1
  447. package/lib-es/common-logic/mapping-utils.js +0 -44
  448. package/lib-es/common-logic/mapping-utils.js.map +0 -1
  449. package/lib-es/common-logic/pad-address.d.ts.map +0 -1
  450. package/lib-es/common-logic/pad-address.js.map +0 -1
  451. package/lib-es/common-logic/transaction-utils.d.ts +0 -30
  452. package/lib-es/common-logic/transaction-utils.d.ts.map +0 -1
  453. package/lib-es/common-logic/transaction-utils.js +0 -150
  454. package/lib-es/common-logic/transaction-utils.js.map +0 -1
  455. package/lib-es/contracts/abis/VIP180.d.ts +0 -17
  456. package/lib-es/contracts/abis/VIP180.d.ts.map +0 -1
  457. package/lib-es/contracts/abis/VIP180.js +0 -263
  458. package/lib-es/contracts/abis/VIP180.js.map +0 -1
  459. package/lib-es/contracts/abis/params.d.ts +0 -8
  460. package/lib-es/contracts/abis/params.d.ts.map +0 -1
  461. package/lib-es/contracts/abis/params.js +0 -67
  462. package/lib-es/contracts/abis/params.js.map +0 -1
  463. package/lib-es/contracts/constants.d.ts +0 -6
  464. package/lib-es/contracts/constants.d.ts.map +0 -1
  465. package/lib-es/contracts/constants.js +0 -7
  466. package/lib-es/contracts/constants.js.map +0 -1
  467. package/src/common-logic/address-utils.ts +0 -11
  468. package/src/common-logic/hex-utils.ts +0 -53
  469. package/src/common-logic/logic.ts +0 -44
  470. package/src/common-logic/mapping-utils.ts +0 -67
  471. package/src/common-logic/transaction-utils.ts +0 -190
  472. package/src/contracts/abis/VIP180.ts +0 -265
  473. package/src/contracts/abis/params.ts +0 -70
  474. package/src/contracts/constants.ts +0 -11
  475. /package/src/common-logic/{pad-address.ts → padAddress.ts} +0 -0
@@ -0,0 +1,356 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { isAccountEmpty } from "./helpers";
3
+ import { TokenAccount } from "@ledgerhq/types-live";
4
+
5
+ describe("isAccountEmpty", () => {
6
+ const baseAccount = {
7
+ balance: new BigNumber("0"),
8
+ operationsCount: 0,
9
+ subAccounts: undefined as any,
10
+ };
11
+
12
+ describe("empty accounts", () => {
13
+ it("should return true for completely empty account", () => {
14
+ const account = {
15
+ ...baseAccount,
16
+ balance: new BigNumber("0"),
17
+ operationsCount: 0,
18
+ subAccounts: undefined as any,
19
+ };
20
+
21
+ const result = isAccountEmpty(account);
22
+
23
+ expect(result).toBe(true);
24
+ });
25
+
26
+ it("should return true for account with undefined subAccounts", () => {
27
+ const account = {
28
+ balance: new BigNumber("0"),
29
+ operationsCount: 0,
30
+ subAccounts: undefined as any,
31
+ };
32
+
33
+ const result = isAccountEmpty(account);
34
+
35
+ expect(result).toBe(true);
36
+ });
37
+
38
+ it("should return true for account with empty subAccounts array", () => {
39
+ const account = {
40
+ ...baseAccount,
41
+ balance: new BigNumber("0"),
42
+ operationsCount: 0,
43
+ subAccounts: undefined as any,
44
+ };
45
+
46
+ const result = isAccountEmpty(account);
47
+
48
+ expect(result).toBe(true);
49
+ });
50
+
51
+ it("should return true when subAccount has zero balance", () => {
52
+ const mockSubAccount: TokenAccount = {
53
+ type: "TokenAccount",
54
+ id: "vechain:1:0x123:+vtho",
55
+ parentId: "vechain:1:0x123:",
56
+ token: {} as any,
57
+ balance: new BigNumber("0"),
58
+ spendableBalance: new BigNumber("0"),
59
+ creationDate: new Date("2022-01-01"),
60
+ operationsCount: 0,
61
+ operations: [],
62
+ pendingOperations: [],
63
+ balanceHistoryCache: { HOUR: {}, DAY: {}, WEEK: {} } as any,
64
+ swapHistory: [],
65
+ };
66
+
67
+ const account = {
68
+ balance: new BigNumber("0"),
69
+ operationsCount: 0,
70
+ subAccounts: [mockSubAccount],
71
+ };
72
+
73
+ const result = isAccountEmpty(account);
74
+
75
+ expect(result).toBe(true);
76
+ });
77
+ });
78
+
79
+ describe("non-empty accounts", () => {
80
+ it("should return false when account has balance", () => {
81
+ const account = {
82
+ ...baseAccount,
83
+ balance: new BigNumber("1000000000000000000"), // 1 VET
84
+ operationsCount: 0,
85
+ subAccounts: undefined as any,
86
+ };
87
+
88
+ const result = isAccountEmpty(account);
89
+
90
+ expect(result).toBe(false);
91
+ });
92
+
93
+ it("should return false when account has operations", () => {
94
+ const account = {
95
+ ...baseAccount,
96
+ balance: new BigNumber("0"),
97
+ operationsCount: 5,
98
+ subAccounts: undefined as any,
99
+ };
100
+
101
+ const result = isAccountEmpty(account);
102
+
103
+ expect(result).toBe(false);
104
+ });
105
+
106
+ it("should return false when subAccount has balance", () => {
107
+ const mockSubAccountWithBalance: TokenAccount = {
108
+ type: "TokenAccount",
109
+ id: "vechain:1:0x123:+vtho",
110
+ parentId: "vechain:1:0x123:",
111
+ token: {} as any,
112
+ balance: new BigNumber("1000000000000000000"), // 1 VTHO
113
+ spendableBalance: new BigNumber("1000000000000000000"),
114
+ creationDate: new Date("2022-01-01"),
115
+ operationsCount: 0,
116
+ operations: [],
117
+ pendingOperations: [],
118
+ balanceHistoryCache: { HOUR: {}, DAY: {}, WEEK: {} } as any,
119
+ swapHistory: [],
120
+ };
121
+
122
+ const account = {
123
+ ...baseAccount,
124
+ balance: new BigNumber("0"),
125
+ operationsCount: 0,
126
+ subAccounts: [mockSubAccountWithBalance],
127
+ };
128
+
129
+ const result = isAccountEmpty(account);
130
+
131
+ expect(result).toBe(false);
132
+ });
133
+
134
+ it("should return false when account has both balance and operations", () => {
135
+ const account = {
136
+ ...baseAccount,
137
+ balance: new BigNumber("1000000000000000000"),
138
+ operationsCount: 3,
139
+ subAccounts: undefined as any,
140
+ };
141
+
142
+ const result = isAccountEmpty(account);
143
+
144
+ expect(result).toBe(false);
145
+ });
146
+
147
+ it("should return false when account has balance and subAccount with balance", () => {
148
+ const mockSubAccountWithBalance: TokenAccount = {
149
+ type: "TokenAccount",
150
+ id: "vechain:1:0x123:+vtho",
151
+ parentId: "vechain:1:0x123:",
152
+ token: {} as any,
153
+ balance: new BigNumber("500000000000000000"), // 0.5 VTHO
154
+ spendableBalance: new BigNumber("500000000000000000"),
155
+ creationDate: new Date("2022-01-01"),
156
+ operationsCount: 0,
157
+ operations: [],
158
+ pendingOperations: [],
159
+ balanceHistoryCache: { HOUR: {}, DAY: {}, WEEK: {} } as any,
160
+ swapHistory: [],
161
+ };
162
+
163
+ const account = {
164
+ ...baseAccount,
165
+ balance: new BigNumber("2000000000000000000"), // 2 VET
166
+ operationsCount: 0,
167
+ subAccounts: [mockSubAccountWithBalance],
168
+ };
169
+
170
+ const result = isAccountEmpty(account);
171
+
172
+ expect(result).toBe(false);
173
+ });
174
+ });
175
+
176
+ describe("edge cases", () => {
177
+ it("should handle very small balances", () => {
178
+ const account = {
179
+ ...baseAccount,
180
+ balance: new BigNumber("1"), // 1 wei
181
+ operationsCount: 0,
182
+ subAccounts: undefined as any,
183
+ };
184
+
185
+ const result = isAccountEmpty(account);
186
+
187
+ expect(result).toBe(false);
188
+ });
189
+
190
+ it("should handle very large balances", () => {
191
+ const account = {
192
+ ...baseAccount,
193
+ balance: new BigNumber("1000000000000000000000000"), // 1M VET
194
+ operationsCount: 0,
195
+ subAccounts: undefined as any,
196
+ };
197
+
198
+ const result = isAccountEmpty(account);
199
+
200
+ expect(result).toBe(false);
201
+ });
202
+
203
+ it("should handle negative balance", () => {
204
+ const account = {
205
+ ...baseAccount,
206
+ balance: new BigNumber("-1000000000000000000"), // -1 VET (edge case)
207
+ operationsCount: 0,
208
+ subAccounts: undefined as any,
209
+ };
210
+
211
+ const result = isAccountEmpty(account);
212
+
213
+ expect(result).toBe(false);
214
+ });
215
+
216
+ it("should handle multiple subAccounts where first is empty", () => {
217
+ const emptySubAccount: TokenAccount = {
218
+ type: "TokenAccount",
219
+ id: "vechain:1:0x123:+empty",
220
+ parentId: "vechain:1:0x123:",
221
+ token: {} as any,
222
+ balance: new BigNumber("0"),
223
+ spendableBalance: new BigNumber("0"),
224
+ creationDate: new Date("2022-01-01"),
225
+ operationsCount: 0,
226
+ operations: [],
227
+ pendingOperations: [],
228
+ balanceHistoryCache: { HOUR: {}, DAY: {}, WEEK: {} } as any,
229
+ swapHistory: [],
230
+ };
231
+
232
+ const nonEmptySubAccount: TokenAccount = {
233
+ type: "TokenAccount",
234
+ id: "vechain:1:0x123:+vtho",
235
+ parentId: "vechain:1:0x123:",
236
+ token: {} as any,
237
+ balance: new BigNumber("1000000000000000000"),
238
+ spendableBalance: new BigNumber("1000000000000000000"),
239
+ creationDate: new Date("2022-01-01"),
240
+ operationsCount: 0,
241
+ operations: [],
242
+ pendingOperations: [],
243
+ balanceHistoryCache: { HOUR: {}, DAY: {}, WEEK: {} } as any,
244
+ swapHistory: [],
245
+ };
246
+
247
+ const account = {
248
+ ...baseAccount,
249
+ balance: new BigNumber("0"),
250
+ operationsCount: 0,
251
+ subAccounts: [emptySubAccount, nonEmptySubAccount],
252
+ };
253
+
254
+ const result = isAccountEmpty(account);
255
+
256
+ // Should check only the first subAccount according to the implementation
257
+ expect(result).toBe(true);
258
+ });
259
+
260
+ it("should handle account with operations but zero balance", () => {
261
+ const account = {
262
+ ...baseAccount,
263
+ balance: new BigNumber("0"),
264
+ operationsCount: 1,
265
+ subAccounts: undefined as any,
266
+ };
267
+
268
+ const result = isAccountEmpty(account);
269
+
270
+ expect(result).toBe(false);
271
+ });
272
+
273
+ it("should handle decimal balance", () => {
274
+ const account = {
275
+ ...baseAccount,
276
+ balance: new BigNumber("0.5"), // 0.5 VET (unlikely but possible)
277
+ operationsCount: 0,
278
+ subAccounts: undefined as any,
279
+ };
280
+
281
+ const result = isAccountEmpty(account);
282
+
283
+ expect(result).toBe(false);
284
+ });
285
+ });
286
+
287
+ describe("subAccount balance checking logic", () => {
288
+ it("should correctly identify when subAccount balance isZero() returns false", () => {
289
+ const mockSubAccountWithBalance: TokenAccount = {
290
+ type: "TokenAccount",
291
+ id: "vechain:1:0x123:+vtho",
292
+ parentId: "vechain:1:0x123:",
293
+ token: {} as any,
294
+ balance: new BigNumber("0.000000000000000001"), // Very small but non-zero
295
+ spendableBalance: new BigNumber("0.000000000000000001"),
296
+ creationDate: new Date("2022-01-01"),
297
+ operationsCount: 0,
298
+ operations: [],
299
+ pendingOperations: [],
300
+ balanceHistoryCache: { HOUR: {}, DAY: {}, WEEK: {} } as any,
301
+ swapHistory: [],
302
+ };
303
+
304
+ const account = {
305
+ ...baseAccount,
306
+ balance: new BigNumber("0"),
307
+ operationsCount: 0,
308
+ subAccounts: [mockSubAccountWithBalance],
309
+ };
310
+
311
+ const result = isAccountEmpty(account);
312
+
313
+ expect(result).toBe(false);
314
+ });
315
+
316
+ it("should correctly handle when subAccounts is null", () => {
317
+ const account = {
318
+ ...baseAccount,
319
+ balance: new BigNumber("0"),
320
+ operationsCount: 0,
321
+ subAccounts: null as any,
322
+ };
323
+
324
+ const result = isAccountEmpty(account);
325
+
326
+ expect(result).toBe(true);
327
+ });
328
+ });
329
+
330
+ describe("BigNumber behavior", () => {
331
+ it("should correctly use BigNumber.isZero() method", () => {
332
+ const zeroBalance = new BigNumber("0");
333
+ const nonZeroBalance = new BigNumber("1");
334
+
335
+ expect(zeroBalance.isZero()).toBe(true);
336
+ expect(nonZeroBalance.isZero()).toBe(false);
337
+
338
+ const accountWithZero = {
339
+ ...baseAccount,
340
+ balance: zeroBalance,
341
+ operationsCount: 0,
342
+ subAccounts: undefined as any,
343
+ };
344
+
345
+ const accountWithNonZero = {
346
+ ...baseAccount,
347
+ balance: nonZeroBalance,
348
+ operationsCount: 0,
349
+ subAccounts: undefined as any,
350
+ };
351
+
352
+ expect(isAccountEmpty(accountWithZero)).toBe(true);
353
+ expect(isAccountEmpty(accountWithNonZero)).toBe(false);
354
+ });
355
+ });
356
+ });
@@ -0,0 +1,345 @@
1
+ import BigNumber from "bignumber.js";
2
+ import { prepareTransaction } from "./prepareTransaction";
3
+ import {
4
+ calculateTransactionInfo,
5
+ calculateClausesVet,
6
+ calculateClausesVtho,
7
+ parseAddress,
8
+ } from "../common-logic";
9
+ import { getBlockRef } from "../network";
10
+ import { Transaction } from "../types";
11
+ import { Account, TokenAccount } from "@ledgerhq/types-live";
12
+
13
+ // Mock dependencies
14
+ jest.mock("../common-logic");
15
+ jest.mock("../network");
16
+
17
+ const mockedCalculateTransactionInfo = jest.mocked(calculateTransactionInfo);
18
+ const mockedCalculateClausesVet = jest.mocked(calculateClausesVet);
19
+ const mockedCalculateClausesVtho = jest.mocked(calculateClausesVtho);
20
+ const mockedParseAddress = jest.mocked(parseAddress);
21
+ const mockedGetBlockRef = jest.mocked(getBlockRef);
22
+
23
+ describe("prepareTransaction", () => {
24
+ const mockAccount: Account = {
25
+ type: "Account",
26
+ id: "vechain:1:0x123:",
27
+ seedIdentifier: "seed123",
28
+ derivationMode: "" as any,
29
+ index: 0,
30
+ freshAddress: "0x742d35Cc6634C0532925a3b8D0B251d8c1743eC4",
31
+ freshAddressPath: "44'/818'/0'/0/0",
32
+ used: true,
33
+ balance: new BigNumber("5000000000000000000"), // 5 VET
34
+ spendableBalance: new BigNumber("5000000000000000000"),
35
+ creationDate: new Date("2022-01-01"),
36
+ blockHeight: 12345,
37
+ currency: { name: "VeChain" } as any,
38
+ operationsCount: 10,
39
+ operations: [],
40
+ pendingOperations: [],
41
+ lastSyncDate: new Date("2022-01-01"),
42
+ balanceHistoryCache: { HOUR: {}, DAY: {}, WEEK: {} } as any,
43
+ swapHistory: [],
44
+ subAccounts: [],
45
+ };
46
+
47
+ const mockTransaction: Transaction = {
48
+ family: "vechain",
49
+ recipient: "0x456789012345678901234567890123456789abcd",
50
+ amount: new BigNumber("1000000000000000000"), // 1 VET
51
+ estimatedFees: "0",
52
+ body: {
53
+ chainTag: 74,
54
+ blockRef: "0x0000000000000000",
55
+ expiration: 18,
56
+ clauses: [],
57
+ maxFeePerGas: 0,
58
+ maxPriorityFeePerGas: 0,
59
+ gas: "0",
60
+ dependsOn: null,
61
+ nonce: "0x12345678",
62
+ },
63
+ } as Transaction;
64
+
65
+ const mockTransactionInfo = {
66
+ amount: new BigNumber("1000000000000000000"),
67
+ isTokenAccount: false,
68
+ estimatedFees: "210000000000000000",
69
+ estimatedGas: 21000,
70
+ maxFeePerGas: 10000000000000,
71
+ maxPriorityFeePerGas: 1000000000000,
72
+ spendableBalance: new BigNumber("4790000000000000000"),
73
+ balance: new BigNumber("5000000000000000000"),
74
+ tokenAccount: undefined,
75
+ };
76
+
77
+ const mockVetClauses = [
78
+ {
79
+ to: "0x456789012345678901234567890123456789abcd",
80
+ value: "1000000000000000000",
81
+ data: "0x",
82
+ },
83
+ ];
84
+
85
+ const mockVthoClauses = [
86
+ {
87
+ to: "0x0000000000000000000000000000456e65726779",
88
+ value: "0",
89
+ data: "0xa9059cbb000000000000000000000000456789012345678901234567890123456789abcd0000000000000000000000000000000000000000000000000de0b6b3a7640000",
90
+ },
91
+ ];
92
+
93
+ beforeEach(() => {
94
+ jest.clearAllMocks();
95
+ mockedCalculateTransactionInfo.mockResolvedValue(mockTransactionInfo);
96
+ mockedParseAddress.mockReturnValue(true);
97
+ mockedGetBlockRef.mockResolvedValue("0x00000000000b2bce");
98
+ mockedCalculateClausesVet.mockResolvedValue(mockVetClauses);
99
+ mockedCalculateClausesVtho.mockResolvedValue(mockVthoClauses);
100
+ });
101
+
102
+ describe("VET transactions", () => {
103
+ it("should prepare a VET transaction with valid recipient", async () => {
104
+ const result = await prepareTransaction(mockAccount, mockTransaction);
105
+
106
+ expect(result).toEqual({
107
+ ...mockTransaction,
108
+ body: {
109
+ ...mockTransaction.body,
110
+ gas: 21000,
111
+ blockRef: "0x00000000000b2bce",
112
+ clauses: mockVetClauses,
113
+ maxFeePerGas: 10000000000000,
114
+ maxPriorityFeePerGas: 1000000000000,
115
+ },
116
+ amount: new BigNumber("1000000000000000000"),
117
+ estimatedFees: "210000000000000000",
118
+ });
119
+
120
+ expect(mockedCalculateClausesVet).toHaveBeenCalledWith(
121
+ mockTransaction.recipient,
122
+ new BigNumber("1000000000000000000"),
123
+ );
124
+ expect(mockedCalculateClausesVtho).not.toHaveBeenCalled();
125
+ });
126
+
127
+ it("should handle VET transaction without recipient", async () => {
128
+ const transactionWithoutRecipient = {
129
+ ...mockTransaction,
130
+ recipient: "",
131
+ };
132
+
133
+ const result = await prepareTransaction(mockAccount, transactionWithoutRecipient);
134
+
135
+ expect(result.body.clauses).toEqual([]);
136
+ expect(result.body.blockRef).toBe("");
137
+ expect(mockedGetBlockRef).not.toHaveBeenCalled();
138
+ expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
139
+ });
140
+
141
+ it("should handle VET transaction with invalid recipient", async () => {
142
+ mockedParseAddress.mockReturnValue(false);
143
+
144
+ const result = await prepareTransaction(mockAccount, mockTransaction);
145
+
146
+ expect(result.body.clauses).toEqual([]);
147
+ expect(result.body.blockRef).toBe("");
148
+ expect(mockedGetBlockRef).not.toHaveBeenCalled();
149
+ expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
150
+ });
151
+ });
152
+
153
+ describe("Token transactions", () => {
154
+ it("should prepare a token transaction with valid recipient", async () => {
155
+ const tokenTransactionInfo = {
156
+ ...mockTransactionInfo,
157
+ isTokenAccount: true,
158
+ tokenAccount: {} as TokenAccount,
159
+ };
160
+
161
+ mockedCalculateTransactionInfo.mockResolvedValue(tokenTransactionInfo);
162
+
163
+ const result = await prepareTransaction(mockAccount, mockTransaction);
164
+
165
+ expect(result).toEqual({
166
+ ...mockTransaction,
167
+ body: {
168
+ ...mockTransaction.body,
169
+ gas: 21000,
170
+ blockRef: "0x00000000000b2bce",
171
+ clauses: mockVthoClauses,
172
+ maxFeePerGas: 10000000000000,
173
+ maxPriorityFeePerGas: 1000000000000,
174
+ },
175
+ amount: new BigNumber("1000000000000000000"),
176
+ estimatedFees: "210000000000000000",
177
+ });
178
+
179
+ expect(mockedCalculateClausesVtho).toHaveBeenCalledWith(
180
+ mockTransaction.recipient,
181
+ new BigNumber("1000000000000000000"),
182
+ );
183
+ expect(mockedCalculateClausesVet).not.toHaveBeenCalled();
184
+ });
185
+ });
186
+
187
+ describe("calculateTransactionInfo integration", () => {
188
+ it("should call calculateTransactionInfo with correct parameters", async () => {
189
+ await prepareTransaction(mockAccount, mockTransaction);
190
+
191
+ expect(mockedCalculateTransactionInfo).toHaveBeenCalledWith(mockAccount, mockTransaction);
192
+ });
193
+
194
+ it("should use transaction info results in the prepared transaction", async () => {
195
+ const customTransactionInfo = {
196
+ amount: new BigNumber("2000000000000000000"),
197
+ isTokenAccount: false,
198
+ estimatedFees: "420000000000000000",
199
+ estimatedGas: 42000,
200
+ maxFeePerGas: 20000000000000,
201
+ maxPriorityFeePerGas: 2000000000000,
202
+ spendableBalance: new BigNumber("3000000000000000000"),
203
+ balance: new BigNumber("5000000000000000000"),
204
+ tokenAccount: undefined,
205
+ };
206
+
207
+ mockedCalculateTransactionInfo.mockResolvedValue(customTransactionInfo);
208
+
209
+ const result = await prepareTransaction(mockAccount, mockTransaction);
210
+
211
+ expect(result.amount).toEqual(new BigNumber("2000000000000000000"));
212
+ expect(result.estimatedFees).toBe("420000000000000000");
213
+ expect(result.body.gas).toBe(42000);
214
+ expect(result.body.maxFeePerGas).toBe(20000000000000);
215
+ expect(result.body.maxPriorityFeePerGas).toBe(2000000000000);
216
+ });
217
+ });
218
+
219
+ describe("blockRef handling", () => {
220
+ it("should get blockRef when recipient is valid", async () => {
221
+ await prepareTransaction(mockAccount, mockTransaction);
222
+
223
+ expect(mockedGetBlockRef).toHaveBeenCalledTimes(1);
224
+ });
225
+
226
+ it("should not get blockRef when recipient is empty", async () => {
227
+ const transactionWithoutRecipient = {
228
+ ...mockTransaction,
229
+ recipient: "",
230
+ };
231
+
232
+ await prepareTransaction(mockAccount, transactionWithoutRecipient);
233
+
234
+ expect(mockedGetBlockRef).not.toHaveBeenCalled();
235
+ });
236
+
237
+ it("should not get blockRef when recipient is invalid", async () => {
238
+ mockedParseAddress.mockReturnValue(false);
239
+
240
+ await prepareTransaction(mockAccount, mockTransaction);
241
+
242
+ expect(mockedGetBlockRef).not.toHaveBeenCalled();
243
+ });
244
+
245
+ it("should handle getBlockRef errors", async () => {
246
+ const error = new Error("Network error");
247
+ mockedGetBlockRef.mockRejectedValue(error);
248
+
249
+ await expect(prepareTransaction(mockAccount, mockTransaction)).rejects.toThrow(
250
+ "Network error",
251
+ );
252
+ });
253
+ });
254
+
255
+ describe("clause calculation", () => {
256
+ it("should handle calculateClausesVet errors", async () => {
257
+ const error = new Error("VET clause calculation failed");
258
+ mockedCalculateClausesVet.mockRejectedValue(error);
259
+
260
+ await expect(prepareTransaction(mockAccount, mockTransaction)).rejects.toThrow(
261
+ "VET clause calculation failed",
262
+ );
263
+ });
264
+
265
+ it("should handle calculateClausesVtho errors", async () => {
266
+ const tokenTransactionInfo = {
267
+ ...mockTransactionInfo,
268
+ isTokenAccount: true,
269
+ tokenAccount: {} as TokenAccount,
270
+ };
271
+
272
+ mockedCalculateTransactionInfo.mockResolvedValue(tokenTransactionInfo);
273
+
274
+ const error = new Error("VTHO clause calculation failed");
275
+ mockedCalculateClausesVtho.mockRejectedValue(error);
276
+
277
+ await expect(prepareTransaction(mockAccount, mockTransaction)).rejects.toThrow(
278
+ "VTHO clause calculation failed",
279
+ );
280
+ });
281
+ });
282
+
283
+ describe("body preservation", () => {
284
+ it("should preserve existing body properties", async () => {
285
+ const transactionWithBody = {
286
+ ...mockTransaction,
287
+ body: {
288
+ ...mockTransaction.body,
289
+ chainTag: 39, // testnet
290
+ expiration: 32,
291
+ dependsOn: "0xprevious123",
292
+ nonce: "0xabcdef123456",
293
+ },
294
+ };
295
+
296
+ const result = await prepareTransaction(mockAccount, transactionWithBody);
297
+
298
+ expect(result.body.chainTag).toBe(39);
299
+ expect(result.body.expiration).toBe(32);
300
+ expect(result.body.dependsOn).toBe("0xprevious123");
301
+ expect(result.body.nonce).toBe("0xabcdef123456");
302
+ });
303
+
304
+ it("should override gas-related properties", async () => {
305
+ const transactionWithOldGas = {
306
+ ...mockTransaction,
307
+ body: {
308
+ ...mockTransaction.body,
309
+ gas: 999,
310
+ maxFeePerGas: 999,
311
+ maxPriorityFeePerGas: 999,
312
+ },
313
+ };
314
+
315
+ const result = await prepareTransaction(mockAccount, transactionWithOldGas);
316
+
317
+ expect(result.body.gas).toBe(21000);
318
+ expect(result.body.maxFeePerGas).toBe(10000000000000);
319
+ expect(result.body.maxPriorityFeePerGas).toBe(1000000000000);
320
+ });
321
+ });
322
+
323
+ describe("address validation", () => {
324
+ it("should call parseAddress with recipient", async () => {
325
+ await prepareTransaction(mockAccount, mockTransaction);
326
+
327
+ expect(mockedParseAddress).toHaveBeenCalledWith(mockTransaction.recipient);
328
+ });
329
+
330
+ it("should handle different recipient formats", async () => {
331
+ const recipients = [
332
+ "0x456789012345678901234567890123456789abcd",
333
+ "0X456789012345678901234567890123456789ABCD",
334
+ "456789012345678901234567890123456789abcd",
335
+ ];
336
+
337
+ for (const recipient of recipients) {
338
+ const txWithRecipient = { ...mockTransaction, recipient };
339
+ await prepareTransaction(mockAccount, txWithRecipient);
340
+
341
+ expect(mockedParseAddress).toHaveBeenCalledWith(recipient);
342
+ }
343
+ });
344
+ });
345
+ });