@ledgerhq/coin-aptos 3.4.0-nightly.7 → 3.4.0

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 (299) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/CHANGELOG.md +25 -66
  3. package/lib/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  4. package/lib/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  5. package/lib/__tests__/api/craftTransaction.unit.test.js +177 -0
  6. package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  7. package/lib/__tests__/api/getBalance.unit.test.d.ts +2 -0
  8. package/lib/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  9. package/lib/__tests__/api/getBalance.unit.test.js +80 -0
  10. package/lib/__tests__/api/getBalance.unit.test.js.map +1 -0
  11. package/lib/__tests__/api/index.integ.test.d.ts +2 -0
  12. package/lib/__tests__/api/index.integ.test.d.ts.map +1 -0
  13. package/lib/__tests__/api/index.integ.test.js +340 -0
  14. package/lib/__tests__/api/index.integ.test.js.map +1 -0
  15. package/lib/__tests__/api/index.test.d.ts +2 -0
  16. package/lib/__tests__/api/index.test.d.ts.map +1 -0
  17. package/lib/__tests__/api/index.test.js +66 -0
  18. package/lib/__tests__/api/index.test.js.map +1 -0
  19. package/lib/__tests__/bridge/broadcast.test.d.ts +2 -0
  20. package/lib/__tests__/bridge/broadcast.test.d.ts.map +1 -0
  21. package/lib/__tests__/bridge/broadcast.test.js +92 -0
  22. package/lib/__tests__/bridge/broadcast.test.js.map +1 -0
  23. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
  24. package/lib/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  25. package/lib/__tests__/bridge/deviceTransactionConfig.test.js +128 -0
  26. package/lib/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
  27. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
  28. package/lib/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  29. package/lib/__tests__/bridge/estimateMaxSpendable.test.js +75 -0
  30. package/lib/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
  31. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
  32. package/lib/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  33. package/lib/__tests__/bridge/getFeesForTransaction.test.js +280 -0
  34. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
  35. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
  36. package/lib/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
  37. package/lib/__tests__/bridge/getTransactionStatus.test.js +453 -0
  38. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
  39. package/lib/__tests__/bridge/index.test.d.ts +2 -0
  40. package/lib/__tests__/bridge/index.test.d.ts.map +1 -0
  41. package/lib/__tests__/bridge/index.test.js +110 -0
  42. package/lib/__tests__/bridge/index.test.js.map +1 -0
  43. package/lib/__tests__/bridge/logic.test.d.ts +2 -0
  44. package/lib/__tests__/bridge/logic.test.d.ts.map +1 -0
  45. package/lib/__tests__/bridge/logic.test.js +997 -0
  46. package/lib/__tests__/bridge/logic.test.js.map +1 -0
  47. package/lib/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
  48. package/lib/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
  49. package/lib/__tests__/bridge/prepareTransaction.test.js +109 -0
  50. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -0
  51. package/lib/__tests__/bridge/serialization.d.ts +2 -0
  52. package/lib/__tests__/bridge/serialization.d.ts.map +1 -0
  53. package/lib/__tests__/bridge/serialization.js +91 -0
  54. package/lib/__tests__/bridge/serialization.js.map +1 -0
  55. package/lib/__tests__/bridge/signOperation.test.d.ts +2 -0
  56. package/lib/__tests__/bridge/signOperation.test.d.ts.map +1 -0
  57. package/lib/__tests__/bridge/signOperation.test.js +299 -0
  58. package/lib/__tests__/bridge/signOperation.test.js.map +1 -0
  59. package/lib/__tests__/bridge/synchronisation.test.d.ts +2 -0
  60. package/lib/__tests__/bridge/synchronisation.test.d.ts.map +1 -0
  61. package/lib/__tests__/bridge/synchronisation.test.js +2226 -0
  62. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -0
  63. package/lib/__tests__/bridge/transaction.test.d.ts +2 -0
  64. package/lib/__tests__/bridge/transaction.test.d.ts.map +1 -0
  65. package/lib/__tests__/bridge/transaction.test.js +221 -0
  66. package/lib/__tests__/bridge/transaction.test.js.map +1 -0
  67. package/lib/__tests__/errors.test.d.ts +2 -0
  68. package/lib/__tests__/errors.test.d.ts.map +1 -0
  69. package/lib/__tests__/errors.test.js +18 -0
  70. package/lib/__tests__/errors.test.js.map +1 -0
  71. package/lib/__tests__/index.test.d.ts +2 -0
  72. package/lib/__tests__/index.test.d.ts.map +1 -0
  73. package/lib/__tests__/index.test.js +27 -0
  74. package/lib/__tests__/index.test.js.map +1 -0
  75. package/lib/__tests__/logic/buildTransaction.test.d.ts +2 -0
  76. package/lib/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  77. package/lib/__tests__/logic/buildTransaction.test.js +114 -0
  78. package/lib/__tests__/logic/buildTransaction.test.js.map +1 -0
  79. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  80. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  81. package/lib/__tests__/logic/calculateAmount.unit.test.js +45 -0
  82. package/lib/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  83. package/lib/__tests__/logic/combine.unit.test.d.ts +2 -0
  84. package/lib/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  85. package/lib/__tests__/logic/combine.unit.test.js +47 -0
  86. package/lib/__tests__/logic/combine.unit.test.js.map +1 -0
  87. package/lib/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  88. package/lib/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  89. package/lib/__tests__/logic/compareAddress.unit.test.js +26 -0
  90. package/lib/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  91. package/lib/__tests__/logic/createTransaction.test.d.ts +2 -0
  92. package/lib/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  93. package/lib/__tests__/logic/createTransaction.test.js +29 -0
  94. package/lib/__tests__/logic/createTransaction.test.js.map +1 -0
  95. package/lib/__tests__/logic/getBalances.test.d.ts +2 -0
  96. package/lib/__tests__/logic/getBalances.test.d.ts.map +1 -0
  97. package/lib/__tests__/logic/getBalances.test.js +62 -0
  98. package/lib/__tests__/logic/getBalances.test.js.map +1 -0
  99. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  100. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  101. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js +186 -0
  102. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  103. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  104. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  105. package/lib/__tests__/logic/getFunctionAddress.unit.test.js +29 -0
  106. package/lib/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  107. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  108. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  109. package/lib/__tests__/logic/getResourceAddress.unit.test.js +218 -0
  110. package/lib/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  111. package/lib/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  112. package/lib/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  113. package/lib/__tests__/logic/isTestnet.unit.test.js +12 -0
  114. package/lib/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  115. package/lib/__tests__/logic/normalizeAddress.unit.test.d.ts +2 -0
  116. package/lib/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
  117. package/lib/__tests__/logic/normalizeAddress.unit.test.js +12 -0
  118. package/lib/__tests__/logic/normalizeAddress.unit.test.js.map +1 -0
  119. package/lib/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  120. package/lib/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  121. package/lib/__tests__/logic/processRecipients.unit.test.js +79 -0
  122. package/lib/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  123. package/lib/__tests__/logic/staking.test.d.ts +2 -0
  124. package/lib/__tests__/logic/staking.test.d.ts.map +1 -0
  125. package/lib/__tests__/logic/staking.test.js +202 -0
  126. package/lib/__tests__/logic/staking.test.js.map +1 -0
  127. package/lib/__tests__/network/client.test.d.ts +2 -0
  128. package/lib/__tests__/network/client.test.d.ts.map +1 -0
  129. package/lib/__tests__/network/client.test.js +1179 -0
  130. package/lib/__tests__/network/client.test.js.map +1 -0
  131. package/lib/__tests__/network/index.test.d.ts +2 -0
  132. package/lib/__tests__/network/index.test.d.ts.map +1 -0
  133. package/lib/__tests__/network/index.test.js +51 -0
  134. package/lib/__tests__/network/index.test.js.map +1 -0
  135. package/lib/__tests__/network/validators.test.d.ts +2 -0
  136. package/lib/__tests__/network/validators.test.d.ts.map +1 -0
  137. package/lib/__tests__/network/validators.test.js +102 -0
  138. package/lib/__tests__/network/validators.test.js.map +1 -0
  139. package/lib/__tests__/signer/index.test.d.ts +2 -0
  140. package/lib/__tests__/signer/index.test.d.ts.map +1 -0
  141. package/lib/__tests__/signer/index.test.js +26 -0
  142. package/lib/__tests__/signer/index.test.js.map +1 -0
  143. package/lib/__tests__/utils/IconGenerator.test.d.ts +2 -0
  144. package/lib/__tests__/utils/IconGenerator.test.d.ts.map +1 -0
  145. package/lib/__tests__/utils/IconGenerator.test.js +14 -0
  146. package/lib/__tests__/utils/IconGenerator.test.js.map +1 -0
  147. package/lib/__tests__/utils/index.test.d.ts +2 -0
  148. package/lib/__tests__/utils/index.test.d.ts.map +1 -0
  149. package/lib/__tests__/utils/index.test.js +11 -0
  150. package/lib/__tests__/utils/index.test.js.map +1 -0
  151. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  152. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  153. package/lib-es/__tests__/api/craftTransaction.unit.test.js +175 -0
  154. package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  155. package/lib-es/__tests__/api/getBalance.unit.test.d.ts +2 -0
  156. package/lib-es/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  157. package/lib-es/__tests__/api/getBalance.unit.test.js +78 -0
  158. package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -0
  159. package/lib-es/__tests__/api/index.integ.test.d.ts +2 -0
  160. package/lib-es/__tests__/api/index.integ.test.d.ts.map +1 -0
  161. package/lib-es/__tests__/api/index.integ.test.js +338 -0
  162. package/lib-es/__tests__/api/index.integ.test.js.map +1 -0
  163. package/lib-es/__tests__/api/index.test.d.ts +2 -0
  164. package/lib-es/__tests__/api/index.test.d.ts.map +1 -0
  165. package/lib-es/__tests__/api/index.test.js +61 -0
  166. package/lib-es/__tests__/api/index.test.js.map +1 -0
  167. package/lib-es/__tests__/bridge/broadcast.test.d.ts +2 -0
  168. package/lib-es/__tests__/bridge/broadcast.test.d.ts.map +1 -0
  169. package/lib-es/__tests__/bridge/broadcast.test.js +87 -0
  170. package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -0
  171. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts +2 -0
  172. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.d.ts.map +1 -0
  173. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js +123 -0
  174. package/lib-es/__tests__/bridge/deviceTransactionConfig.test.js.map +1 -0
  175. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts +2 -0
  176. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.d.ts.map +1 -0
  177. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js +70 -0
  178. package/lib-es/__tests__/bridge/estimateMaxSpendable.test.js.map +1 -0
  179. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts +2 -0
  180. package/lib-es/__tests__/bridge/getFeesForTransaction.test.d.ts.map +1 -0
  181. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +252 -0
  182. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -0
  183. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts +2 -0
  184. package/lib-es/__tests__/bridge/getTransactionStatus.test.d.ts.map +1 -0
  185. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +448 -0
  186. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -0
  187. package/lib-es/__tests__/bridge/index.test.d.ts +2 -0
  188. package/lib-es/__tests__/bridge/index.test.d.ts.map +1 -0
  189. package/lib-es/__tests__/bridge/index.test.js +105 -0
  190. package/lib-es/__tests__/bridge/index.test.js.map +1 -0
  191. package/lib-es/__tests__/bridge/logic.test.d.ts +2 -0
  192. package/lib-es/__tests__/bridge/logic.test.d.ts.map +1 -0
  193. package/lib-es/__tests__/bridge/logic.test.js +992 -0
  194. package/lib-es/__tests__/bridge/logic.test.js.map +1 -0
  195. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts +2 -0
  196. package/lib-es/__tests__/bridge/prepareTransaction.test.d.ts.map +1 -0
  197. package/lib-es/__tests__/bridge/prepareTransaction.test.js +104 -0
  198. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -0
  199. package/lib-es/__tests__/bridge/serialization.d.ts +2 -0
  200. package/lib-es/__tests__/bridge/serialization.d.ts.map +1 -0
  201. package/lib-es/__tests__/bridge/serialization.js +86 -0
  202. package/lib-es/__tests__/bridge/serialization.js.map +1 -0
  203. package/lib-es/__tests__/bridge/signOperation.test.d.ts +2 -0
  204. package/lib-es/__tests__/bridge/signOperation.test.d.ts.map +1 -0
  205. package/lib-es/__tests__/bridge/signOperation.test.js +271 -0
  206. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -0
  207. package/lib-es/__tests__/bridge/synchronisation.test.d.ts +2 -0
  208. package/lib-es/__tests__/bridge/synchronisation.test.d.ts.map +1 -0
  209. package/lib-es/__tests__/bridge/synchronisation.test.js +2221 -0
  210. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -0
  211. package/lib-es/__tests__/bridge/transaction.test.d.ts +2 -0
  212. package/lib-es/__tests__/bridge/transaction.test.d.ts.map +1 -0
  213. package/lib-es/__tests__/bridge/transaction.test.js +216 -0
  214. package/lib-es/__tests__/bridge/transaction.test.js.map +1 -0
  215. package/lib-es/__tests__/errors.test.d.ts +2 -0
  216. package/lib-es/__tests__/errors.test.d.ts.map +1 -0
  217. package/lib-es/__tests__/errors.test.js +16 -0
  218. package/lib-es/__tests__/errors.test.js.map +1 -0
  219. package/lib-es/__tests__/index.test.d.ts +2 -0
  220. package/lib-es/__tests__/index.test.d.ts.map +1 -0
  221. package/lib-es/__tests__/index.test.js +25 -0
  222. package/lib-es/__tests__/index.test.js.map +1 -0
  223. package/lib-es/__tests__/logic/buildTransaction.test.d.ts +2 -0
  224. package/lib-es/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  225. package/lib-es/__tests__/logic/buildTransaction.test.js +109 -0
  226. package/lib-es/__tests__/logic/buildTransaction.test.js.map +1 -0
  227. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  228. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  229. package/lib-es/__tests__/logic/calculateAmount.unit.test.js +40 -0
  230. package/lib-es/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  231. package/lib-es/__tests__/logic/combine.unit.test.d.ts +2 -0
  232. package/lib-es/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  233. package/lib-es/__tests__/logic/combine.unit.test.js +45 -0
  234. package/lib-es/__tests__/logic/combine.unit.test.js.map +1 -0
  235. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  236. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  237. package/lib-es/__tests__/logic/compareAddress.unit.test.js +24 -0
  238. package/lib-es/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  239. package/lib-es/__tests__/logic/createTransaction.test.d.ts +2 -0
  240. package/lib-es/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  241. package/lib-es/__tests__/logic/createTransaction.test.js +24 -0
  242. package/lib-es/__tests__/logic/createTransaction.test.js.map +1 -0
  243. package/lib-es/__tests__/logic/getBalances.test.d.ts +2 -0
  244. package/lib-es/__tests__/logic/getBalances.test.d.ts.map +1 -0
  245. package/lib-es/__tests__/logic/getBalances.test.js +60 -0
  246. package/lib-es/__tests__/logic/getBalances.test.js.map +1 -0
  247. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  248. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  249. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js +181 -0
  250. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  251. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  252. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  253. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js +27 -0
  254. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  255. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  256. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  257. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js +216 -0
  258. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  259. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  260. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  261. package/lib-es/__tests__/logic/isTestnet.unit.test.js +10 -0
  262. package/lib-es/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  263. package/lib-es/__tests__/logic/normalizeAddress.unit.test.d.ts +2 -0
  264. package/lib-es/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
  265. package/lib-es/__tests__/logic/normalizeAddress.unit.test.js +10 -0
  266. package/lib-es/__tests__/logic/normalizeAddress.unit.test.js.map +1 -0
  267. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  268. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  269. package/lib-es/__tests__/logic/processRecipients.unit.test.js +74 -0
  270. package/lib-es/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  271. package/lib-es/__tests__/logic/staking.test.d.ts +2 -0
  272. package/lib-es/__tests__/logic/staking.test.d.ts.map +1 -0
  273. package/lib-es/__tests__/logic/staking.test.js +197 -0
  274. package/lib-es/__tests__/logic/staking.test.js.map +1 -0
  275. package/lib-es/__tests__/network/client.test.d.ts +2 -0
  276. package/lib-es/__tests__/network/client.test.d.ts.map +1 -0
  277. package/lib-es/__tests__/network/client.test.js +1174 -0
  278. package/lib-es/__tests__/network/client.test.js.map +1 -0
  279. package/lib-es/__tests__/network/index.test.d.ts +2 -0
  280. package/lib-es/__tests__/network/index.test.d.ts.map +1 -0
  281. package/lib-es/__tests__/network/index.test.js +49 -0
  282. package/lib-es/__tests__/network/index.test.js.map +1 -0
  283. package/lib-es/__tests__/network/validators.test.d.ts +2 -0
  284. package/lib-es/__tests__/network/validators.test.d.ts.map +1 -0
  285. package/lib-es/__tests__/network/validators.test.js +97 -0
  286. package/lib-es/__tests__/network/validators.test.js.map +1 -0
  287. package/lib-es/__tests__/signer/index.test.d.ts +2 -0
  288. package/lib-es/__tests__/signer/index.test.d.ts.map +1 -0
  289. package/lib-es/__tests__/signer/index.test.js +21 -0
  290. package/lib-es/__tests__/signer/index.test.js.map +1 -0
  291. package/lib-es/__tests__/utils/IconGenerator.test.d.ts +2 -0
  292. package/lib-es/__tests__/utils/IconGenerator.test.d.ts.map +1 -0
  293. package/lib-es/__tests__/utils/IconGenerator.test.js +12 -0
  294. package/lib-es/__tests__/utils/IconGenerator.test.js.map +1 -0
  295. package/lib-es/__tests__/utils/index.test.d.ts +2 -0
  296. package/lib-es/__tests__/utils/index.test.d.ts.map +1 -0
  297. package/lib-es/__tests__/utils/index.test.js +9 -0
  298. package/lib-es/__tests__/utils/index.test.js.map +1 -0
  299. package/package.json +10 -10
@@ -0,0 +1,1174 @@
1
+ import { ApolloClient } from "@apollo/client";
2
+ import { AccountAddress, Aptos, Ed25519PublicKey, Hex, RawTransaction, postAptosFullNode, TransactionResponseType, } from "@aptos-labs/ts-sdk";
3
+ import network from "@ledgerhq/live-network";
4
+ import BigNumber from "bignumber.js";
5
+ import { AptosAPI } from "../../network";
6
+ import { APTOS_ASSET_ID } from "../../constants";
7
+ jest.mock("@aptos-labs/ts-sdk");
8
+ jest.mock("@apollo/client");
9
+ let mockedAptos;
10
+ let mockedApolloClient;
11
+ let mockedPost = jest.fn();
12
+ let mockedHex;
13
+ jest.mock("@ledgerhq/live-network/network");
14
+ const mockedNetwork = jest.mocked(network);
15
+ jest.mock("@ledgerhq/cryptoassets/tokens", () => ({
16
+ findTokenByAddressInCurrency: jest.fn().mockReturnValue("token-name"),
17
+ }));
18
+ describe("Aptos API", () => {
19
+ beforeEach(() => {
20
+ mockedAptos = jest.mocked(Aptos);
21
+ mockedHex = jest.mocked(Hex);
22
+ mockedApolloClient = jest.mocked(ApolloClient);
23
+ mockedPost = jest.mocked(postAptosFullNode);
24
+ });
25
+ afterEach(() => jest.clearAllMocks());
26
+ it("builds the client properly for mainnet", () => {
27
+ const api = new AptosAPI("aptos");
28
+ expect(api.broadcast).toBeDefined();
29
+ expect(typeof api.broadcast).toBe("function");
30
+ expect(api.estimateGasPrice).toBeDefined();
31
+ expect(typeof api.estimateGasPrice).toBe("function");
32
+ expect(api.generateTransaction).toBeDefined();
33
+ expect(typeof api.generateTransaction).toBe("function");
34
+ expect(api.getAccount).toBeDefined();
35
+ expect(typeof api.getAccount).toBe("function");
36
+ expect(api.getAccountInfo).toBeDefined();
37
+ expect(typeof api.getAccountInfo).toBe("function");
38
+ expect(api.simulateTransaction).toBeDefined();
39
+ expect(typeof api.simulateTransaction).toBe("function");
40
+ });
41
+ it("builds the client properly for testnet", () => {
42
+ const api = new AptosAPI("aptos_testnet");
43
+ expect(api.broadcast).toBeDefined();
44
+ expect(typeof api.broadcast).toBe("function");
45
+ expect(api.estimateGasPrice).toBeDefined();
46
+ expect(typeof api.estimateGasPrice).toBe("function");
47
+ expect(api.generateTransaction).toBeDefined();
48
+ expect(typeof api.generateTransaction).toBe("function");
49
+ expect(api.getAccount).toBeDefined();
50
+ expect(typeof api.getAccount).toBe("function");
51
+ expect(api.getAccountInfo).toBeDefined();
52
+ expect(typeof api.getAccountInfo).toBe("function");
53
+ expect(api.simulateTransaction).toBeDefined();
54
+ expect(typeof api.simulateTransaction).toBe("function");
55
+ });
56
+ describe("getAccount", () => {
57
+ it("calls getAccountInfo", async () => {
58
+ const mockGetAccountInfo = jest.fn();
59
+ mockedAptos.mockImplementation(() => ({
60
+ getAccountInfo: mockGetAccountInfo,
61
+ }));
62
+ const mockGetAccountSpy = jest.spyOn({ getAccount: mockGetAccountInfo }, "getAccount");
63
+ const api = new AptosAPI("aptos");
64
+ await api.getAccount("address");
65
+ expect(mockGetAccountSpy).toHaveBeenCalledWith({
66
+ accountAddress: "address",
67
+ });
68
+ });
69
+ });
70
+ describe("getAccountInfo", () => {
71
+ it("calls getCoinBalance, fetchTransactions and getHeight", async () => {
72
+ mockedAptos.mockImplementation(() => ({
73
+ view: jest.fn().mockReturnValue(["123"]),
74
+ getTransactionByVersion: jest.fn().mockReturnValue({
75
+ type: "user_transaction",
76
+ version: "v1",
77
+ }),
78
+ getBlockByVersion: jest.fn().mockReturnValue({
79
+ block_height: "1",
80
+ block_hash: "83ca6d",
81
+ }),
82
+ getCurrentFungibleAssetBalances: jest.fn().mockResolvedValue([
83
+ {
84
+ asset_type: APTOS_ASSET_ID,
85
+ amount: new BigNumber(123),
86
+ },
87
+ ]),
88
+ }));
89
+ mockedNetwork.mockResolvedValue(Promise.resolve({
90
+ data: {
91
+ account: {
92
+ account_number: 1,
93
+ sequence: 0,
94
+ pub_key: { key: "k", "@type": "type" },
95
+ base_account: {
96
+ account_number: 2,
97
+ sequence: 42,
98
+ pub_key: { key: "k2", "@type": "type2" },
99
+ },
100
+ },
101
+ block_height: "999",
102
+ },
103
+ status: 200,
104
+ headers: {},
105
+ statusText: "",
106
+ config: {
107
+ headers: {},
108
+ },
109
+ }));
110
+ mockedApolloClient.mockImplementation(() => ({
111
+ query: async () => ({
112
+ data: {
113
+ account_transactions: [{ transaction_version: 1 }],
114
+ },
115
+ loading: false,
116
+ networkStatus: 7,
117
+ }),
118
+ }));
119
+ const api = new AptosAPI("aptos");
120
+ const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
121
+ expect(accountInfo.balance).toEqual(new BigNumber(123));
122
+ expect(accountInfo.transactions).toEqual([
123
+ {
124
+ type: "user_transaction",
125
+ version: "v1",
126
+ block: {
127
+ height: 1,
128
+ hash: "83ca6d",
129
+ },
130
+ },
131
+ ]);
132
+ expect(accountInfo.blockHeight).toEqual(999);
133
+ });
134
+ it("return balance = 0 if it fails to fetch balance", async () => {
135
+ mockedAptos.mockImplementation(() => ({
136
+ view: jest.fn().mockImplementation(() => {
137
+ throw new Error("error");
138
+ }),
139
+ getTransactionByVersion: jest.fn().mockReturnValue({
140
+ type: "user_transaction",
141
+ version: "v1",
142
+ }),
143
+ getBlockByVersion: jest.fn().mockReturnValue({
144
+ block_height: "1",
145
+ block_hash: "83ca6d",
146
+ }),
147
+ }));
148
+ mockedNetwork.mockResolvedValue(Promise.resolve({
149
+ data: {
150
+ account: {
151
+ account_number: 1,
152
+ sequence: 0,
153
+ pub_key: { key: "k", "@type": "type" },
154
+ base_account: {
155
+ account_number: 2,
156
+ sequence: 42,
157
+ pub_key: { key: "k2", "@type": "type2" },
158
+ },
159
+ },
160
+ block_height: "999",
161
+ },
162
+ status: 200,
163
+ headers: {},
164
+ statusText: "",
165
+ config: {
166
+ headers: {},
167
+ },
168
+ }));
169
+ mockedApolloClient.mockImplementation(() => ({
170
+ query: async () => ({
171
+ data: {
172
+ account_transactions: [{ transaction_version: 1 }],
173
+ },
174
+ loading: false,
175
+ networkStatus: 7,
176
+ }),
177
+ }));
178
+ const api = new AptosAPI("aptos");
179
+ const accountInfo = await api.getAccountInfo("APTOS_1_ADDRESS", "1");
180
+ expect(accountInfo.balance).toEqual(new BigNumber(0));
181
+ expect(accountInfo.transactions).toEqual([
182
+ {
183
+ type: "user_transaction",
184
+ version: "v1",
185
+ block: {
186
+ height: 1,
187
+ hash: "83ca6d",
188
+ },
189
+ },
190
+ ]);
191
+ expect(accountInfo.blockHeight).toEqual(999);
192
+ });
193
+ it("returns no transactions if it the address is empty", async () => {
194
+ mockedAptos.mockImplementation(() => ({
195
+ view: jest.fn().mockReturnValue(["123"]),
196
+ getTransactionByVersion: jest.fn().mockReturnValue({
197
+ type: "user_transaction",
198
+ version: "v1",
199
+ }),
200
+ getBlockByVersion: jest.fn().mockReturnValue({
201
+ block_height: "1",
202
+ block_hash: "83ca6d",
203
+ }),
204
+ getCurrentFungibleAssetBalances: jest.fn().mockResolvedValue([
205
+ {
206
+ asset_type: APTOS_ASSET_ID,
207
+ amount: new BigNumber(123),
208
+ },
209
+ ]),
210
+ }));
211
+ mockedNetwork.mockResolvedValue(Promise.resolve({
212
+ data: {
213
+ account: {
214
+ account_number: 1,
215
+ sequence: 0,
216
+ pub_key: { key: "k", "@type": "type" },
217
+ base_account: {
218
+ account_number: 2,
219
+ sequence: 42,
220
+ pub_key: { key: "k2", "@type": "type2" },
221
+ },
222
+ },
223
+ block_height: "999",
224
+ },
225
+ status: 200,
226
+ headers: {},
227
+ statusText: "",
228
+ config: {
229
+ headers: {},
230
+ },
231
+ }));
232
+ mockedApolloClient.mockImplementation(() => ({
233
+ query: async () => ({
234
+ data: {
235
+ account_transactions: [{ transaction_version: 1 }],
236
+ },
237
+ loading: false,
238
+ networkStatus: 7,
239
+ }),
240
+ }));
241
+ const api = new AptosAPI("aptos");
242
+ const accountInfo = await api.getAccountInfo("", "1");
243
+ expect(accountInfo.balance).toEqual(new BigNumber(123));
244
+ expect(accountInfo.transactions).toEqual([]);
245
+ expect(accountInfo.blockHeight).toEqual(999);
246
+ });
247
+ it("returns transaction with amount equals to zero when no account found", async () => {
248
+ mockedAptos.mockImplementation(() => ({
249
+ view: jest.fn().mockReturnValue(["123"]),
250
+ getTransactionByVersion: jest.fn().mockReturnValue({
251
+ type: "user_transaction",
252
+ version: "v1",
253
+ }),
254
+ getBlockByVersion: jest.fn().mockReturnValue({
255
+ block_height: "1",
256
+ block_hash: "83ca6d",
257
+ }),
258
+ getCurrentFungibleAssetBalances: jest.fn().mockResolvedValue([]),
259
+ }));
260
+ mockedNetwork.mockResolvedValue(Promise.resolve({
261
+ data: {
262
+ account: {
263
+ account_number: 1,
264
+ sequence: 0,
265
+ pub_key: { key: "k", "@type": "type" },
266
+ base_account: {
267
+ account_number: 2,
268
+ sequence: 42,
269
+ pub_key: { key: "k2", "@type": "type2" },
270
+ },
271
+ },
272
+ block_height: "999",
273
+ },
274
+ status: 200,
275
+ headers: {},
276
+ statusText: "",
277
+ config: {
278
+ headers: {},
279
+ },
280
+ }));
281
+ mockedApolloClient.mockImplementation(() => ({
282
+ query: async () => ({
283
+ data: {
284
+ account_transactions: [{ transaction_version: 1 }],
285
+ },
286
+ loading: false,
287
+ networkStatus: 7,
288
+ }),
289
+ }));
290
+ const api = new AptosAPI("aptos");
291
+ const accountInfo = await api.getAccountInfo("", "1");
292
+ expect(accountInfo.balance).toEqual(new BigNumber(0));
293
+ expect(accountInfo.transactions).toEqual([]);
294
+ expect(accountInfo.blockHeight).toEqual(999);
295
+ });
296
+ it("returns a null transaction if it fails to getTransactionByVersion", async () => {
297
+ mockedAptos.mockImplementation(() => ({
298
+ view: jest.fn().mockReturnValue(["123"]),
299
+ getTransactionByVersion: jest.fn().mockImplementation(() => {
300
+ throw new Error("error");
301
+ }),
302
+ getBlockByVersion: jest.fn().mockReturnValue({
303
+ block_height: "1",
304
+ block_hash: "83ca6d",
305
+ }),
306
+ getCurrentFungibleAssetBalances: jest.fn().mockResolvedValue([
307
+ {
308
+ asset_type: APTOS_ASSET_ID,
309
+ amount: new BigNumber(123),
310
+ },
311
+ ]),
312
+ }));
313
+ mockedNetwork.mockResolvedValue(Promise.resolve({
314
+ data: {
315
+ account: {
316
+ account_number: 1,
317
+ sequence: 0,
318
+ pub_key: { key: "k", "@type": "type" },
319
+ base_account: {
320
+ account_number: 2,
321
+ sequence: 42,
322
+ pub_key: { key: "k2", "@type": "type2" },
323
+ },
324
+ },
325
+ block_height: "999",
326
+ },
327
+ status: 200,
328
+ headers: {},
329
+ statusText: "",
330
+ config: {
331
+ headers: {},
332
+ },
333
+ }));
334
+ mockedApolloClient.mockImplementation(() => ({
335
+ query: async () => ({
336
+ data: {
337
+ account_transactions: [{ transaction_version: 1 }],
338
+ },
339
+ loading: false,
340
+ networkStatus: 7,
341
+ }),
342
+ }));
343
+ const api = new AptosAPI("aptos");
344
+ const accountInfo = await api.getAccountInfo(APTOS_ASSET_ID, "1");
345
+ expect(accountInfo.balance).toEqual(new BigNumber(123));
346
+ expect(accountInfo.transactions).toEqual([null]);
347
+ expect(accountInfo.blockHeight).toEqual(999);
348
+ });
349
+ });
350
+ describe("estimateGasPrice", () => {
351
+ it("estimates the gas price", async () => {
352
+ const gasEstimation = { gas_estimate: 100 };
353
+ mockedAptos.mockImplementation(() => ({
354
+ getGasPriceEstimation: jest.fn().mockReturnValue(gasEstimation),
355
+ }));
356
+ const api = new AptosAPI("aptos");
357
+ const gasPrice = await api.estimateGasPrice();
358
+ expect(gasPrice.gas_estimate).toEqual(100);
359
+ });
360
+ });
361
+ describe("generateTransaction", () => {
362
+ const payload = {
363
+ function: "0x1::coin::transfer",
364
+ functionArguments: ["0x13", 1],
365
+ };
366
+ it("generates a transaction without expireTimestamp", async () => {
367
+ const options = {
368
+ maxGasAmount: "100",
369
+ gasUnitPrice: "50",
370
+ };
371
+ const mockSimple = jest.fn().mockImplementation(async () => ({
372
+ rawTransaction: null,
373
+ }));
374
+ mockedAptos.mockImplementation(() => ({
375
+ transaction: {
376
+ build: {
377
+ simple: mockSimple,
378
+ },
379
+ },
380
+ }));
381
+ const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
382
+ const api = new AptosAPI("aptos");
383
+ await api.generateTransaction("APTOS_1_ADDRESS", payload, options);
384
+ expect(mockSimpleSpy).toHaveBeenCalledWith({
385
+ data: payload,
386
+ options: {
387
+ maxGasAmount: Number(options.maxGasAmount),
388
+ gasUnitPrice: Number(options.gasUnitPrice),
389
+ },
390
+ sender: "APTOS_1_ADDRESS",
391
+ });
392
+ });
393
+ it("generates a transaction with default expireTimestamp", async () => {
394
+ const options = {
395
+ maxGasAmount: "100",
396
+ gasUnitPrice: "50",
397
+ };
398
+ const mockSimple = jest.fn().mockImplementation(async () => ({
399
+ rawTransaction: null,
400
+ }));
401
+ const mockGetLedgerInfo = jest.fn().mockImplementation(async () => ({
402
+ ledger_timestamp: "0",
403
+ }));
404
+ mockedAptos.mockImplementation(() => ({
405
+ transaction: {
406
+ build: {
407
+ simple: mockSimple,
408
+ },
409
+ },
410
+ getLedgerInfo: mockGetLedgerInfo,
411
+ }));
412
+ const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
413
+ const api = new AptosAPI("aptos");
414
+ await api.generateTransaction("APTOS_1_ADDRESS", payload, options);
415
+ expect(mockSimpleSpy).toHaveBeenCalledWith({
416
+ data: payload,
417
+ options: {
418
+ maxGasAmount: Number(options.maxGasAmount),
419
+ gasUnitPrice: Number(options.gasUnitPrice),
420
+ expireTimestamp: 120,
421
+ },
422
+ sender: "APTOS_1_ADDRESS",
423
+ });
424
+ });
425
+ it("throws an error when failing to build a transaction", async () => {
426
+ const options = {
427
+ maxGasAmount: "100",
428
+ gasUnitPrice: "50",
429
+ };
430
+ const mockSimple = jest.fn().mockImplementation(async () => null);
431
+ mockedAptos.mockImplementation(() => ({
432
+ transaction: {
433
+ build: {
434
+ simple: mockSimple,
435
+ },
436
+ },
437
+ }));
438
+ const api = new AptosAPI("aptos");
439
+ expect(async () => await api.generateTransaction("APTOS_1_ADDRESS", payload, options)).rejects.toThrow();
440
+ });
441
+ });
442
+ describe("simulateTransaction", () => {
443
+ it("simulates a transaction with the correct options", async () => {
444
+ const mockSimple = jest.fn().mockImplementation(async () => ({
445
+ rawTransaction: null,
446
+ }));
447
+ mockedAptos.mockImplementation(() => ({
448
+ transaction: {
449
+ simulate: {
450
+ simple: mockSimple,
451
+ },
452
+ },
453
+ }));
454
+ const mockSimpleSpy = jest.spyOn({ simple: mockSimple }, "simple");
455
+ const api = new AptosAPI("aptos");
456
+ const address = new Ed25519PublicKey("APTOS_1_ADDRESS");
457
+ const tx = new RawTransaction(new AccountAddress(Uint8Array.from(Buffer.from("APTOS_2_ADDRESS"))), BigInt(1), "", BigInt(100), BigInt(50), BigInt(1), { chainId: 1 });
458
+ await api.simulateTransaction(address, tx);
459
+ expect(mockSimpleSpy).toHaveBeenCalledWith({
460
+ signerPublicKey: address,
461
+ transaction: { rawTransaction: tx },
462
+ options: {
463
+ estimateGasUnitPrice: true,
464
+ estimateMaxGasAmount: true,
465
+ estimatePrioritizedGasUnitPrice: false,
466
+ },
467
+ });
468
+ });
469
+ });
470
+ describe("broadcast", () => {
471
+ it("broadcasts the transaction", async () => {
472
+ mockedPost.mockImplementation(async () => ({ data: { hash: "ok" } }));
473
+ const mockedPostSpy = jest.spyOn({ postAptosFullNode: mockedPost }, "postAptosFullNode");
474
+ // const txBytes = Hex.fromHexString(tx).toUint8Array();
475
+ mockedAptos.mockImplementation(() => ({
476
+ config: "config",
477
+ }));
478
+ mockedHex.fromHexString = jest.fn().mockReturnValue({ toUint8Array: () => "123" });
479
+ const api = new AptosAPI("aptos");
480
+ await api.broadcast("signed transaction");
481
+ expect(mockedPostSpy).toHaveBeenCalledWith({
482
+ aptosConfig: "config",
483
+ body: "123",
484
+ path: "transactions",
485
+ originMethod: "",
486
+ contentType: "application/x.aptos.signed_transaction+bcs",
487
+ });
488
+ });
489
+ });
490
+ describe("estimateFees", () => {
491
+ it("estimates the fees for native asset", async () => {
492
+ const gasEstimation = { gas_estimate: 100 };
493
+ const buildSimple = jest.fn().mockResolvedValue({ rawTransaction: {} });
494
+ const time = new Date("2025-05-29");
495
+ jest.useFakeTimers().setSystemTime(time);
496
+ mockedAptos.mockImplementation(() => ({
497
+ getLedgerInfo: jest.fn().mockResolvedValue({
498
+ ledger_timestamp: time,
499
+ }),
500
+ transaction: {
501
+ build: {
502
+ simple: buildSimple,
503
+ },
504
+ simulate: {
505
+ simple: jest.fn().mockResolvedValue([
506
+ {
507
+ gas_used: 10,
508
+ gas_unit_price: 4,
509
+ },
510
+ ]),
511
+ },
512
+ },
513
+ getGasPriceEstimation: jest.fn().mockReturnValue(gasEstimation),
514
+ }));
515
+ const amount = BigInt(100);
516
+ const sender = {
517
+ xpub: "xpub",
518
+ freshAddress: "address1",
519
+ };
520
+ const recipient = "address2";
521
+ const api = new AptosAPI("aptos");
522
+ const transactionIntent = {
523
+ intentType: "transaction",
524
+ asset: {
525
+ type: "native",
526
+ },
527
+ type: "send",
528
+ sender: sender.freshAddress,
529
+ senderPublicKey: sender.xpub,
530
+ amount,
531
+ recipient,
532
+ };
533
+ const fees = await api.estimateFees(transactionIntent);
534
+ expect(buildSimple.mock.calls[0][0]).toEqual({
535
+ sender: "address1",
536
+ data: {
537
+ function: "0x1::aptos_account::transfer_coins",
538
+ typeArguments: ["0x1::aptos_coin::AptosCoin"],
539
+ functionArguments: ["address2", 100n],
540
+ },
541
+ options: {
542
+ maxGasAmount: 200,
543
+ gasUnitPrice: 100,
544
+ expireTimestamp: Number(Math.ceil(+time / 1_000_000 + 2 * 60)),
545
+ },
546
+ });
547
+ expect(fees.value.toString()).toEqual("44");
548
+ });
549
+ it("estimates the fees for token coin", async () => {
550
+ const gasEstimation = { gas_estimate: 100 };
551
+ const buildSimple = jest.fn().mockResolvedValue({ rawTransaction: {} });
552
+ const time = new Date("2025-05-29");
553
+ jest.useFakeTimers().setSystemTime(time);
554
+ mockedAptos.mockImplementation(() => ({
555
+ getLedgerInfo: jest.fn().mockResolvedValue({
556
+ ledger_timestamp: time,
557
+ }),
558
+ transaction: {
559
+ build: {
560
+ simple: buildSimple,
561
+ },
562
+ simulate: {
563
+ simple: jest.fn().mockResolvedValue([
564
+ {
565
+ gas_used: 10,
566
+ gas_unit_price: 2,
567
+ },
568
+ ]),
569
+ },
570
+ },
571
+ getGasPriceEstimation: jest.fn().mockReturnValue(gasEstimation),
572
+ }));
573
+ const amount = BigInt(100);
574
+ const sender = {
575
+ xpub: "xpub",
576
+ freshAddress: "address1",
577
+ };
578
+ const recipient = "address2";
579
+ const api = new AptosAPI("aptos");
580
+ const transactionIntent = {
581
+ intentType: "transaction",
582
+ asset: {
583
+ type: "coin",
584
+ assetReference: "0x111",
585
+ },
586
+ type: "send",
587
+ sender: sender.freshAddress,
588
+ senderPublicKey: sender.xpub,
589
+ amount,
590
+ recipient,
591
+ };
592
+ const fees = await api.estimateFees(transactionIntent);
593
+ expect(buildSimple.mock.calls[0][0]).toEqual({
594
+ sender: "address1",
595
+ data: {
596
+ function: "0x1::aptos_account::transfer_coins",
597
+ typeArguments: ["0x111"],
598
+ functionArguments: ["address2", 100n],
599
+ },
600
+ options: {
601
+ maxGasAmount: 200,
602
+ gasUnitPrice: 100,
603
+ expireTimestamp: Number(Math.ceil(+time / 1_000_000 + 2 * 60)),
604
+ },
605
+ });
606
+ expect(fees.value.toString()).toEqual("22");
607
+ });
608
+ it("estimates the fees for token FA", async () => {
609
+ const gasEstimation = { gas_estimate: 100 };
610
+ const buildSimple = jest.fn().mockResolvedValue({ rawTransaction: {} });
611
+ const time = new Date("2025-05-29");
612
+ jest.useFakeTimers().setSystemTime(time);
613
+ mockedAptos.mockImplementation(() => ({
614
+ getLedgerInfo: jest.fn().mockResolvedValue({
615
+ ledger_timestamp: time,
616
+ }),
617
+ transaction: {
618
+ build: {
619
+ simple: buildSimple,
620
+ },
621
+ simulate: {
622
+ simple: jest.fn().mockResolvedValue([
623
+ {
624
+ gas_used: 10,
625
+ gas_unit_price: 3,
626
+ },
627
+ ]),
628
+ },
629
+ },
630
+ getGasPriceEstimation: jest.fn().mockReturnValue(gasEstimation),
631
+ }));
632
+ const amount = BigInt(100);
633
+ const sender = {
634
+ xpub: "xpub",
635
+ freshAddress: "address1",
636
+ };
637
+ const recipient = "address2";
638
+ const api = new AptosAPI("aptos");
639
+ const transactionIntent = {
640
+ intentType: "transaction",
641
+ asset: {
642
+ type: "fungible_asset",
643
+ assetReference: "0x111",
644
+ },
645
+ type: "send",
646
+ sender: sender.freshAddress,
647
+ senderPublicKey: sender.xpub,
648
+ amount,
649
+ recipient,
650
+ };
651
+ const fees = await api.estimateFees(transactionIntent);
652
+ expect(buildSimple.mock.calls[0][0]).toEqual({
653
+ sender: "address1",
654
+ data: {
655
+ function: "0x1::primary_fungible_store::transfer",
656
+ typeArguments: ["0x1::fungible_asset::Metadata"],
657
+ functionArguments: ["0x111", "address2", 100n],
658
+ },
659
+ options: {
660
+ maxGasAmount: 200,
661
+ gasUnitPrice: 100,
662
+ expireTimestamp: Number(Math.ceil(+time / 1_000_000 + 2 * 60)),
663
+ },
664
+ });
665
+ expect(fees.value.toString()).toEqual("33");
666
+ });
667
+ });
668
+ describe("getBalances", () => {
669
+ it("returns an array of AptosBalances objects", async () => {
670
+ const expectedAptosBalace = {
671
+ contractAddress: APTOS_ASSET_ID,
672
+ amount: BigNumber(200),
673
+ };
674
+ const assets = [{ asset_type: APTOS_ASSET_ID, amount: 200 }];
675
+ const mockGetCurrentFungibleAssetBalances = jest.fn().mockResolvedValue(assets);
676
+ mockedAptos.mockImplementation(() => ({
677
+ getCurrentFungibleAssetBalances: mockGetCurrentFungibleAssetBalances,
678
+ }));
679
+ const address = "0x42";
680
+ const api = new AptosAPI("aptos");
681
+ const balances = await api.getBalances(address, APTOS_ASSET_ID);
682
+ expect(mockGetCurrentFungibleAssetBalances).toHaveBeenCalledWith({
683
+ options: {
684
+ where: {
685
+ asset_type: { _eq: APTOS_ASSET_ID },
686
+ owner_address: { _eq: address },
687
+ },
688
+ },
689
+ });
690
+ expect(balances).toEqual([expectedAptosBalace]);
691
+ });
692
+ it("returns an array of AptosBalances when just address ispassed", async () => {
693
+ const expectedAptosBalace = {
694
+ contractAddress: APTOS_ASSET_ID,
695
+ amount: BigNumber(200),
696
+ };
697
+ const assets = [{ asset_type: APTOS_ASSET_ID, amount: 200n }];
698
+ const mockGetCurrentFungibleAssetBalances = jest.fn().mockResolvedValue(assets);
699
+ mockedAptos.mockImplementation(() => ({
700
+ getCurrentFungibleAssetBalances: mockGetCurrentFungibleAssetBalances,
701
+ }));
702
+ const address = "0x42";
703
+ const api = new AptosAPI("aptos");
704
+ const balance = await api.getBalances(address);
705
+ expect(mockGetCurrentFungibleAssetBalances).toHaveBeenCalledWith({
706
+ options: {
707
+ where: {
708
+ owner_address: { _eq: address },
709
+ },
710
+ },
711
+ });
712
+ expect(balance).toEqual([expectedAptosBalace]);
713
+ });
714
+ it("return 0 balace if could not retrieve proper balance of fungible assets", async () => {
715
+ const expectedBalance = new BigNumber(0);
716
+ mockedAptos.mockImplementation(() => ({
717
+ getCurrentFungibleAssetBalances: jest.fn().mockImplementation(() => {
718
+ throw new Error("error");
719
+ }),
720
+ }));
721
+ const api = new AptosAPI("aptos");
722
+ const balance = await api.getBalances("address", "0x42");
723
+ expect(balance).toEqual([
724
+ {
725
+ contractAddress: "",
726
+ amount: expectedBalance,
727
+ },
728
+ ]);
729
+ });
730
+ });
731
+ describe("listOperations", () => {
732
+ it("list of operations", async () => {
733
+ const api = new AptosAPI("aptos");
734
+ const address = "0x12345";
735
+ const pagination = { minHeight: 0, order: "asc" };
736
+ const txs = [
737
+ {
738
+ version: "2532591427",
739
+ replay_protection_nonce: "replay_protection_nonce",
740
+ hash: "0x3f35",
741
+ state_change_hash: "0xb480",
742
+ event_root_hash: "0x3fa1",
743
+ state_checkpoint_hash: null,
744
+ gas_used: "12",
745
+ success: true,
746
+ vm_status: "Executed successfully",
747
+ accumulator_root_hash: "0x319f",
748
+ changes: [
749
+ {
750
+ address: "0x4e5e",
751
+ state_key_hash: "0x3c0c",
752
+ data: {
753
+ type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
754
+ data: {
755
+ coin: {
756
+ value: "4000000",
757
+ },
758
+ deposit_events: {
759
+ counter: "9",
760
+ guid: {
761
+ id: {
762
+ addr: "0x4e5e",
763
+ creation_num: "4",
764
+ },
765
+ },
766
+ },
767
+ frozen: false,
768
+ withdraw_events: {
769
+ counter: "6",
770
+ guid: {
771
+ id: {
772
+ addr: "0x4e5e",
773
+ creation_num: "5",
774
+ },
775
+ },
776
+ },
777
+ },
778
+ },
779
+ type: "write_resource",
780
+ },
781
+ {
782
+ address: address,
783
+ state_key_hash: "0x1709",
784
+ data: {
785
+ type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
786
+ data: {
787
+ coin: {
788
+ value: "68254118",
789
+ },
790
+ deposit_events: {
791
+ counter: "46",
792
+ guid: {
793
+ id: {
794
+ addr: address,
795
+ creation_num: "2",
796
+ },
797
+ },
798
+ },
799
+ frozen: false,
800
+ withdraw_events: {
801
+ counter: "89",
802
+ guid: {
803
+ id: {
804
+ addr: address,
805
+ creation_num: "3",
806
+ },
807
+ },
808
+ },
809
+ },
810
+ },
811
+ type: "write_resource",
812
+ },
813
+ {
814
+ address: address,
815
+ state_key_hash: "0x5520",
816
+ data: {
817
+ type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
818
+ data: {
819
+ coin: {
820
+ value: "1000000",
821
+ },
822
+ deposit_events: {
823
+ counter: "7",
824
+ guid: {
825
+ id: {
826
+ addr: address,
827
+ creation_num: "10",
828
+ },
829
+ },
830
+ },
831
+ frozen: false,
832
+ withdraw_events: {
833
+ counter: "13",
834
+ guid: {
835
+ id: {
836
+ addr: address,
837
+ creation_num: "11",
838
+ },
839
+ },
840
+ },
841
+ },
842
+ },
843
+ type: "write_resource",
844
+ },
845
+ {
846
+ address: address,
847
+ state_key_hash: "0x6f1e",
848
+ data: {
849
+ type: "0x1::account::Account",
850
+ data: {
851
+ authentication_key: address,
852
+ coin_register_events: {
853
+ counter: "5",
854
+ guid: {
855
+ id: {
856
+ addr: address,
857
+ creation_num: "0",
858
+ },
859
+ },
860
+ },
861
+ guid_creation_num: "12",
862
+ key_rotation_events: {
863
+ counter: "0",
864
+ guid: {
865
+ id: {
866
+ addr: address,
867
+ creation_num: "1",
868
+ },
869
+ },
870
+ },
871
+ rotation_capability_offer: {
872
+ for: {
873
+ vec: [],
874
+ },
875
+ },
876
+ sequence_number: "122",
877
+ signer_capability_offer: {
878
+ for: {
879
+ vec: [],
880
+ },
881
+ },
882
+ },
883
+ },
884
+ type: "write_resource",
885
+ },
886
+ {
887
+ state_key_hash: "0x6e4b",
888
+ handle: "0x1b85",
889
+ key: "0x0619",
890
+ value: "0x1ddaf8da3b1497010000000000000000",
891
+ type: "write_table_item",
892
+ },
893
+ ],
894
+ sender: address,
895
+ sequence_number: "121",
896
+ max_gas_amount: "12",
897
+ gas_unit_price: "100",
898
+ expiration_timestamp_secs: "1743177404",
899
+ payload: {
900
+ function: "0x1::aptos_account::transfer_coins",
901
+ type_arguments: ["0xd111::staked_coin::StakedAptos"],
902
+ arguments: ["0x4e5e", "1500000"],
903
+ type: "entry_function_payload",
904
+ },
905
+ events: [
906
+ {
907
+ guid: {
908
+ creation_number: "11",
909
+ account_address: address,
910
+ },
911
+ sequence_number: "12",
912
+ type: "0x1::coin::WithdrawEvent",
913
+ data: {
914
+ amount: "1500000",
915
+ },
916
+ },
917
+ {
918
+ guid: {
919
+ creation_number: "4",
920
+ account_address: "0x4e5e",
921
+ },
922
+ sequence_number: "8",
923
+ type: "0x1::coin::DepositEvent",
924
+ data: {
925
+ amount: "1500000",
926
+ },
927
+ },
928
+ {
929
+ guid: {
930
+ creation_number: "0",
931
+ account_address: "0x0",
932
+ },
933
+ sequence_number: "0",
934
+ type: "0x1::transaction_fee::FeeStatement",
935
+ data: {
936
+ execution_gas_units: "6",
937
+ io_gas_units: "6",
938
+ storage_fee_octas: "0",
939
+ storage_fee_refund_octas: "0",
940
+ total_charge_gas_units: "12",
941
+ },
942
+ },
943
+ ],
944
+ timestamp: "1743177360481259",
945
+ type: TransactionResponseType.User,
946
+ block: {
947
+ height: 311948147,
948
+ hash: "0x6d02",
949
+ },
950
+ },
951
+ {
952
+ version: "2532549325",
953
+ replay_protection_nonce: "replay_protection_nonce",
954
+ hash: "0x9a6b",
955
+ state_change_hash: "0xa424",
956
+ event_root_hash: "0x0321",
957
+ state_checkpoint_hash: null,
958
+ gas_used: "12",
959
+ success: true,
960
+ vm_status: "Executed successfully",
961
+ accumulator_root_hash: "0xede9",
962
+ changes: [
963
+ {
964
+ address: "0x4e5e",
965
+ state_key_hash: "0x3c0c",
966
+ data: {
967
+ type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
968
+ data: {
969
+ coin: {
970
+ value: "2500000",
971
+ },
972
+ deposit_events: {
973
+ counter: "8",
974
+ guid: {
975
+ id: {
976
+ addr: "0x4e5e",
977
+ creation_num: "4",
978
+ },
979
+ },
980
+ },
981
+ frozen: false,
982
+ withdraw_events: {
983
+ counter: "6",
984
+ guid: {
985
+ id: {
986
+ addr: "0x4e5e",
987
+ creation_num: "5",
988
+ },
989
+ },
990
+ },
991
+ },
992
+ },
993
+ type: "write_resource",
994
+ },
995
+ {
996
+ address: address,
997
+ state_key_hash: "0x1709",
998
+ data: {
999
+ type: "0x1::coin::CoinStore<0x1::aptos_coin::AptosCoin>",
1000
+ data: {
1001
+ coin: {
1002
+ value: "68255318",
1003
+ },
1004
+ deposit_events: {
1005
+ counter: "46",
1006
+ guid: {
1007
+ id: {
1008
+ addr: address,
1009
+ creation_num: "2",
1010
+ },
1011
+ },
1012
+ },
1013
+ frozen: false,
1014
+ withdraw_events: {
1015
+ counter: "89",
1016
+ guid: {
1017
+ id: {
1018
+ addr: address,
1019
+ creation_num: "3",
1020
+ },
1021
+ },
1022
+ },
1023
+ },
1024
+ },
1025
+ type: "write_resource",
1026
+ },
1027
+ {
1028
+ address: address,
1029
+ state_key_hash: "0x5520",
1030
+ data: {
1031
+ type: "0x1::coin::CoinStore<0xd111::staked_coin::StakedAptos>",
1032
+ data: {
1033
+ coin: {
1034
+ value: "2500000",
1035
+ },
1036
+ deposit_events: {
1037
+ counter: "7",
1038
+ guid: {
1039
+ id: {
1040
+ addr: address,
1041
+ creation_num: "10",
1042
+ },
1043
+ },
1044
+ },
1045
+ frozen: false,
1046
+ withdraw_events: {
1047
+ counter: "12",
1048
+ guid: {
1049
+ id: {
1050
+ addr: address,
1051
+ creation_num: "11",
1052
+ },
1053
+ },
1054
+ },
1055
+ },
1056
+ },
1057
+ type: "write_resource",
1058
+ },
1059
+ {
1060
+ address: address,
1061
+ state_key_hash: "0x6f1e",
1062
+ data: {
1063
+ type: "0x1::account::Account",
1064
+ data: {
1065
+ authentication_key: address,
1066
+ coin_register_events: {
1067
+ counter: "5",
1068
+ guid: {
1069
+ id: {
1070
+ addr: address,
1071
+ creation_num: "0",
1072
+ },
1073
+ },
1074
+ },
1075
+ guid_creation_num: "12",
1076
+ key_rotation_events: {
1077
+ counter: "0",
1078
+ guid: {
1079
+ id: {
1080
+ addr: address,
1081
+ creation_num: "1",
1082
+ },
1083
+ },
1084
+ },
1085
+ rotation_capability_offer: {
1086
+ for: {
1087
+ vec: [],
1088
+ },
1089
+ },
1090
+ sequence_number: "121",
1091
+ signer_capability_offer: {
1092
+ for: {
1093
+ vec: [],
1094
+ },
1095
+ },
1096
+ },
1097
+ },
1098
+ type: "write_resource",
1099
+ },
1100
+ {
1101
+ state_key_hash: "0x6e4b",
1102
+ handle: "0x1b85",
1103
+ key: "0x0619",
1104
+ value: "0xe86e0039581497010000000000000000",
1105
+ type: "write_table_item",
1106
+ },
1107
+ ],
1108
+ sender: address,
1109
+ sequence_number: "120",
1110
+ max_gas_amount: "12",
1111
+ gas_unit_price: "100",
1112
+ expiration_timestamp_secs: "1743176706",
1113
+ payload: {
1114
+ function: "0x1::aptos_account::transfer_coins",
1115
+ type_arguments: ["0xd111::staked_coin::StakedAptos"],
1116
+ arguments: ["0x4e5e", "2500000"],
1117
+ type: "entry_function_payload",
1118
+ },
1119
+ events: [
1120
+ {
1121
+ guid: {
1122
+ creation_number: "11",
1123
+ account_address: address,
1124
+ },
1125
+ sequence_number: "11",
1126
+ type: "0x1::coin::WithdrawEvent",
1127
+ data: {
1128
+ amount: "2500000",
1129
+ },
1130
+ },
1131
+ {
1132
+ guid: {
1133
+ creation_number: "4",
1134
+ account_address: "0x4e5e",
1135
+ },
1136
+ sequence_number: "7",
1137
+ type: "0x1::coin::DepositEvent",
1138
+ data: {
1139
+ amount: "2500000",
1140
+ },
1141
+ },
1142
+ {
1143
+ guid: {
1144
+ creation_number: "0",
1145
+ account_address: "0x0",
1146
+ },
1147
+ sequence_number: "0",
1148
+ type: "0x1::transaction_fee::FeeStatement",
1149
+ data: {
1150
+ execution_gas_units: "6",
1151
+ io_gas_units: "6",
1152
+ storage_fee_octas: "0",
1153
+ storage_fee_refund_octas: "0",
1154
+ total_charge_gas_units: "12",
1155
+ },
1156
+ },
1157
+ ],
1158
+ timestamp: "1743176594693251",
1159
+ type: TransactionResponseType.User,
1160
+ block: {
1161
+ height: 311942427,
1162
+ hash: "0x8655",
1163
+ },
1164
+ },
1165
+ ];
1166
+ const transactions = txs;
1167
+ api.getAccountInfo = jest.fn().mockResolvedValue({ transactions });
1168
+ const ops = await api.listOperations(address, pagination.minHeight);
1169
+ expect(ops[0]).toHaveLength(2);
1170
+ expect(ops[1]).toBe("");
1171
+ });
1172
+ });
1173
+ });
1174
+ //# sourceMappingURL=client.test.js.map