@ledgerhq/coin-aptos 2.0.0-nightly.5 → 2.1.0-next.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 (533) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/.unimportedrc.json +18 -6
  3. package/CHANGELOG.md +178 -34
  4. package/jest.config.js +2 -1
  5. package/jest.integ.config.js +8 -0
  6. package/lib/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  7. package/lib/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  8. package/lib/__tests__/api/craftTransaction.unit.test.js +187 -0
  9. package/lib/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  10. package/lib/__tests__/api/getBalance.unit.test.d.ts +2 -0
  11. package/lib/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  12. package/lib/__tests__/api/getBalance.unit.test.js +41 -0
  13. package/lib/__tests__/api/getBalance.unit.test.js.map +1 -0
  14. package/lib/__tests__/api/index.integ.test.d.ts +2 -0
  15. package/lib/__tests__/api/index.integ.test.d.ts.map +1 -0
  16. package/lib/__tests__/api/index.integ.test.js +319 -0
  17. package/lib/__tests__/api/index.integ.test.js.map +1 -0
  18. package/lib/__tests__/api/index.test.js +48 -404
  19. package/lib/__tests__/api/index.test.js.map +1 -1
  20. package/lib/__tests__/bridge/broadcast.test.js +5 -5
  21. package/lib/__tests__/bridge/broadcast.test.js.map +1 -1
  22. package/lib/__tests__/bridge/getFeesForTransaction.test.js +115 -14
  23. package/lib/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  24. package/lib/__tests__/bridge/getTransactionStatus.test.js +175 -37
  25. package/lib/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  26. package/lib/__tests__/bridge/logic.test.js +703 -479
  27. package/lib/__tests__/bridge/logic.test.js.map +1 -1
  28. package/lib/__tests__/bridge/prepareTransaction.test.js +3 -3
  29. package/lib/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  30. package/lib/__tests__/bridge/signOperation.test.js +137 -14
  31. package/lib/__tests__/bridge/signOperation.test.js.map +1 -1
  32. package/lib/__tests__/bridge/synchronisation.test.js +1215 -68
  33. package/lib/__tests__/bridge/synchronisation.test.js.map +1 -1
  34. package/lib/__tests__/index.test.js +1 -1
  35. package/lib/__tests__/index.test.js.map +1 -1
  36. package/lib/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  37. package/lib/__tests__/logic/buildTransaction.test.js +114 -0
  38. package/lib/__tests__/logic/buildTransaction.test.js.map +1 -0
  39. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  40. package/lib/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  41. package/lib/__tests__/logic/calculateAmount.unit.test.js +45 -0
  42. package/lib/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  43. package/lib/__tests__/logic/combine.unit.test.d.ts +2 -0
  44. package/lib/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  45. package/lib/__tests__/logic/combine.unit.test.js +47 -0
  46. package/lib/__tests__/logic/combine.unit.test.js.map +1 -0
  47. package/lib/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  48. package/lib/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  49. package/lib/__tests__/logic/compareAddress.unit.test.js +26 -0
  50. package/lib/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  51. package/lib/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  52. package/lib/__tests__/{bridge → logic}/createTransaction.test.js +2 -2
  53. package/lib/__tests__/logic/createTransaction.test.js.map +1 -0
  54. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  55. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  56. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js +186 -0
  57. package/lib/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  58. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  59. package/lib/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  60. package/lib/__tests__/logic/getFunctionAddress.unit.test.js +29 -0
  61. package/lib/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  62. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  63. package/lib/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  64. package/lib/__tests__/logic/getResourceAddress.unit.test.js +218 -0
  65. package/lib/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  66. package/lib/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  67. package/lib/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  68. package/lib/__tests__/logic/isTestnet.unit.test.js +12 -0
  69. package/lib/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  70. package/lib/__tests__/logic/normalizeAddress.unit.test.d.ts +2 -0
  71. package/lib/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
  72. package/lib/__tests__/logic/normalizeAddress.unit.test.js +12 -0
  73. package/lib/__tests__/logic/normalizeAddress.unit.test.js.map +1 -0
  74. package/lib/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  75. package/lib/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  76. package/lib/__tests__/logic/processRecipients.unit.test.js +79 -0
  77. package/lib/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  78. package/lib/__tests__/network/client.test.d.ts +2 -0
  79. package/lib/__tests__/network/client.test.d.ts.map +1 -0
  80. package/lib/__tests__/network/client.test.js +1124 -0
  81. package/lib/__tests__/network/client.test.js.map +1 -0
  82. package/lib/api/index.d.ts +4 -30
  83. package/lib/api/index.d.ts.map +1 -1
  84. package/lib/api/index.js +19 -170
  85. package/lib/api/index.js.map +1 -1
  86. package/lib/bridge/bridge.fixture.d.ts +2 -0
  87. package/lib/bridge/bridge.fixture.d.ts.map +1 -1
  88. package/lib/bridge/bridge.fixture.js +85 -13
  89. package/lib/bridge/bridge.fixture.js.map +1 -1
  90. package/lib/bridge/broadcast.d.ts +3 -2
  91. package/lib/bridge/broadcast.d.ts.map +1 -1
  92. package/lib/bridge/broadcast.js +4 -3
  93. package/lib/bridge/broadcast.js.map +1 -1
  94. package/lib/bridge/estimateMaxSpendable.d.ts.map +1 -1
  95. package/lib/bridge/estimateMaxSpendable.js +6 -5
  96. package/lib/bridge/estimateMaxSpendable.js.map +1 -1
  97. package/lib/bridge/getFeesForTransaction.d.ts +1 -1
  98. package/lib/bridge/getFeesForTransaction.d.ts.map +1 -1
  99. package/lib/bridge/getFeesForTransaction.js +20 -14
  100. package/lib/bridge/getFeesForTransaction.js.map +1 -1
  101. package/lib/bridge/getTransactionStatus.d.ts.map +1 -1
  102. package/lib/bridge/getTransactionStatus.js +28 -14
  103. package/lib/bridge/getTransactionStatus.js.map +1 -1
  104. package/lib/bridge/index.d.ts +1 -1
  105. package/lib/bridge/index.d.ts.map +1 -1
  106. package/lib/bridge/index.js +1 -1
  107. package/lib/bridge/index.js.map +1 -1
  108. package/lib/bridge/logic.d.ts +5 -19
  109. package/lib/bridge/logic.d.ts.map +1 -1
  110. package/lib/bridge/logic.js +50 -147
  111. package/lib/bridge/logic.js.map +1 -1
  112. package/lib/bridge/prepareTransaction.d.ts.map +1 -1
  113. package/lib/bridge/prepareTransaction.js +5 -4
  114. package/lib/bridge/prepareTransaction.js.map +1 -1
  115. package/lib/bridge/signOperation.d.ts.map +1 -1
  116. package/lib/bridge/signOperation.js +21 -7
  117. package/lib/bridge/signOperation.js.map +1 -1
  118. package/lib/bridge/synchronisation.d.ts +15 -0
  119. package/lib/bridge/synchronisation.d.ts.map +1 -1
  120. package/lib/bridge/synchronisation.js +129 -6
  121. package/lib/bridge/synchronisation.js.map +1 -1
  122. package/lib/config.d.ts +13 -0
  123. package/lib/config.d.ts.map +1 -0
  124. package/lib/config.js +9 -0
  125. package/lib/config.js.map +1 -0
  126. package/lib/constants.d.ts +13 -2
  127. package/lib/constants.d.ts.map +1 -1
  128. package/lib/constants.js +17 -2
  129. package/lib/constants.js.map +1 -1
  130. package/lib/logic/buildTransaction.d.ts +9 -0
  131. package/lib/logic/buildTransaction.d.ts.map +1 -0
  132. package/lib/logic/buildTransaction.js +47 -0
  133. package/lib/logic/buildTransaction.js.map +1 -0
  134. package/lib/logic/calculateAmount.d.ts +3 -0
  135. package/lib/logic/calculateAmount.d.ts.map +1 -0
  136. package/lib/logic/calculateAmount.js +13 -0
  137. package/lib/logic/calculateAmount.js.map +1 -0
  138. package/lib/logic/combine.d.ts +4 -0
  139. package/lib/logic/combine.d.ts.map +1 -0
  140. package/lib/logic/combine.js +34 -0
  141. package/lib/logic/combine.js.map +1 -0
  142. package/lib/logic/craftTransaction.d.ts +5 -0
  143. package/lib/logic/craftTransaction.d.ts.map +1 -0
  144. package/lib/logic/craftTransaction.js +68 -0
  145. package/lib/logic/craftTransaction.js.map +1 -0
  146. package/lib/logic/createTransaction.d.ts.map +1 -0
  147. package/lib/{bridge → logic}/createTransaction.js +3 -3
  148. package/lib/logic/createTransaction.js.map +1 -0
  149. package/lib/logic/getBalance.d.ts +5 -0
  150. package/lib/logic/getBalance.d.ts.map +1 -0
  151. package/lib/logic/getBalance.js +12 -0
  152. package/lib/logic/getBalance.js.map +1 -0
  153. package/lib/logic/getCoinAndAmounts.d.ts +13 -0
  154. package/lib/logic/getCoinAndAmounts.d.ts.map +1 -0
  155. package/lib/logic/getCoinAndAmounts.js +112 -0
  156. package/lib/logic/getCoinAndAmounts.js.map +1 -0
  157. package/lib/logic/getFunctionAddress.d.ts +3 -0
  158. package/lib/logic/getFunctionAddress.d.ts.map +1 -0
  159. package/lib/logic/getFunctionAddress.js +12 -0
  160. package/lib/logic/getFunctionAddress.js.map +1 -0
  161. package/lib/logic/getResourceAddress.d.ts +4 -0
  162. package/lib/logic/getResourceAddress.d.ts.map +1 -0
  163. package/lib/logic/getResourceAddress.js +17 -0
  164. package/lib/logic/getResourceAddress.js.map +1 -0
  165. package/lib/logic/isTestnet.d.ts +2 -0
  166. package/lib/logic/isTestnet.d.ts.map +1 -0
  167. package/lib/logic/isTestnet.js +9 -0
  168. package/lib/logic/isTestnet.js.map +1 -0
  169. package/lib/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  170. package/lib/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  171. package/lib/logic/isWriteSetChangeWriteResource.js +8 -0
  172. package/lib/logic/isWriteSetChangeWriteResource.js.map +1 -0
  173. package/lib/logic/normalizeAddress.d.ts +2 -0
  174. package/lib/logic/normalizeAddress.d.ts.map +1 -0
  175. package/lib/logic/normalizeAddress.js +12 -0
  176. package/lib/logic/normalizeAddress.js.map +1 -0
  177. package/lib/logic/normalizeTransactionOptions.d.ts +3 -0
  178. package/lib/logic/normalizeTransactionOptions.d.ts.map +1 -0
  179. package/lib/logic/normalizeTransactionOptions.js +21 -0
  180. package/lib/logic/normalizeTransactionOptions.js.map +1 -0
  181. package/lib/logic/processRecipients.d.ts +6 -0
  182. package/lib/logic/processRecipients.d.ts.map +1 -0
  183. package/lib/logic/processRecipients.js +58 -0
  184. package/lib/logic/processRecipients.js.map +1 -0
  185. package/lib/logic/transactionsToOperations.d.ts +7 -0
  186. package/lib/logic/transactionsToOperations.d.ts.map +1 -0
  187. package/lib/logic/transactionsToOperations.js +89 -0
  188. package/lib/logic/transactionsToOperations.js.map +1 -0
  189. package/lib/network/client.d.ts +38 -0
  190. package/lib/network/client.d.ts.map +1 -0
  191. package/lib/network/client.js +283 -0
  192. package/lib/network/client.js.map +1 -0
  193. package/lib/network/graphql/queries.d.ts.map +1 -0
  194. package/lib/{api → network}/graphql/queries.js +6 -6
  195. package/lib/network/graphql/queries.js.map +1 -0
  196. package/lib/{api → network}/graphql/types.d.ts +9 -9
  197. package/lib/network/graphql/types.d.ts.map +1 -0
  198. package/lib/{api → network}/graphql/types.js.map +1 -1
  199. package/lib/network/index.d.ts +2 -1
  200. package/lib/network/index.d.ts.map +1 -1
  201. package/lib/network/index.js +19 -7
  202. package/lib/network/index.js.map +1 -1
  203. package/lib/test/bot-specs.d.ts.map +1 -1
  204. package/lib/test/bot-specs.js +40 -1
  205. package/lib/test/bot-specs.js.map +1 -1
  206. package/lib/test/bridgeDatasetTest.d.ts.map +1 -1
  207. package/lib/test/bridgeDatasetTest.js +44 -62
  208. package/lib/test/bridgeDatasetTest.js.map +1 -1
  209. package/lib/test/speculos-deviceActions.d.ts +1 -0
  210. package/lib/test/speculos-deviceActions.d.ts.map +1 -1
  211. package/lib/test/speculos-deviceActions.js +37 -5
  212. package/lib/test/speculos-deviceActions.js.map +1 -1
  213. package/lib/types/assets.d.ts +16 -0
  214. package/lib/types/assets.d.ts.map +1 -0
  215. package/lib/types/assets.js +3 -0
  216. package/lib/types/assets.js.map +1 -0
  217. package/lib/types/index.d.ts +22 -7
  218. package/lib/types/index.d.ts.map +1 -1
  219. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts +2 -0
  220. package/lib-es/__tests__/api/craftTransaction.unit.test.d.ts.map +1 -0
  221. package/lib-es/__tests__/api/craftTransaction.unit.test.js +185 -0
  222. package/lib-es/__tests__/api/craftTransaction.unit.test.js.map +1 -0
  223. package/lib-es/__tests__/api/getBalance.unit.test.d.ts +2 -0
  224. package/lib-es/__tests__/api/getBalance.unit.test.d.ts.map +1 -0
  225. package/lib-es/__tests__/api/getBalance.unit.test.js +36 -0
  226. package/lib-es/__tests__/api/getBalance.unit.test.js.map +1 -0
  227. package/lib-es/__tests__/api/index.integ.test.d.ts +2 -0
  228. package/lib-es/__tests__/api/index.integ.test.d.ts.map +1 -0
  229. package/lib-es/__tests__/api/index.integ.test.js +317 -0
  230. package/lib-es/__tests__/api/index.integ.test.js.map +1 -0
  231. package/lib-es/__tests__/api/index.test.js +52 -408
  232. package/lib-es/__tests__/api/index.test.js.map +1 -1
  233. package/lib-es/__tests__/bridge/broadcast.test.js +2 -2
  234. package/lib-es/__tests__/bridge/broadcast.test.js.map +1 -1
  235. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js +112 -11
  236. package/lib-es/__tests__/bridge/getFeesForTransaction.test.js.map +1 -1
  237. package/lib-es/__tests__/bridge/getTransactionStatus.test.js +177 -39
  238. package/lib-es/__tests__/bridge/getTransactionStatus.test.js.map +1 -1
  239. package/lib-es/__tests__/bridge/logic.test.js +703 -479
  240. package/lib-es/__tests__/bridge/logic.test.js.map +1 -1
  241. package/lib-es/__tests__/bridge/prepareTransaction.test.js +2 -2
  242. package/lib-es/__tests__/bridge/prepareTransaction.test.js.map +1 -1
  243. package/lib-es/__tests__/bridge/signOperation.test.js +137 -14
  244. package/lib-es/__tests__/bridge/signOperation.test.js.map +1 -1
  245. package/lib-es/__tests__/bridge/synchronisation.test.js +1213 -69
  246. package/lib-es/__tests__/bridge/synchronisation.test.js.map +1 -1
  247. package/lib-es/__tests__/index.test.js +1 -1
  248. package/lib-es/__tests__/index.test.js.map +1 -1
  249. package/lib-es/__tests__/logic/buildTransaction.test.d.ts.map +1 -0
  250. package/lib-es/__tests__/logic/buildTransaction.test.js +109 -0
  251. package/lib-es/__tests__/logic/buildTransaction.test.js.map +1 -0
  252. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts +2 -0
  253. package/lib-es/__tests__/logic/calculateAmount.unit.test.d.ts.map +1 -0
  254. package/lib-es/__tests__/logic/calculateAmount.unit.test.js +40 -0
  255. package/lib-es/__tests__/logic/calculateAmount.unit.test.js.map +1 -0
  256. package/lib-es/__tests__/logic/combine.unit.test.d.ts +2 -0
  257. package/lib-es/__tests__/logic/combine.unit.test.d.ts.map +1 -0
  258. package/lib-es/__tests__/logic/combine.unit.test.js +45 -0
  259. package/lib-es/__tests__/logic/combine.unit.test.js.map +1 -0
  260. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts +2 -0
  261. package/lib-es/__tests__/logic/compareAddress.unit.test.d.ts.map +1 -0
  262. package/lib-es/__tests__/logic/compareAddress.unit.test.js +24 -0
  263. package/lib-es/__tests__/logic/compareAddress.unit.test.js.map +1 -0
  264. package/lib-es/__tests__/logic/createTransaction.test.d.ts.map +1 -0
  265. package/lib-es/__tests__/{bridge → logic}/createTransaction.test.js +2 -2
  266. package/lib-es/__tests__/logic/createTransaction.test.js.map +1 -0
  267. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts +2 -0
  268. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.d.ts.map +1 -0
  269. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js +181 -0
  270. package/lib-es/__tests__/logic/getCoinAndAmounts.unit.test.js.map +1 -0
  271. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts +2 -0
  272. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.d.ts.map +1 -0
  273. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js +27 -0
  274. package/lib-es/__tests__/logic/getFunctionAddress.unit.test.js.map +1 -0
  275. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts +2 -0
  276. package/lib-es/__tests__/logic/getResourceAddress.unit.test.d.ts.map +1 -0
  277. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js +216 -0
  278. package/lib-es/__tests__/logic/getResourceAddress.unit.test.js.map +1 -0
  279. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts +2 -0
  280. package/lib-es/__tests__/logic/isTestnet.unit.test.d.ts.map +1 -0
  281. package/lib-es/__tests__/logic/isTestnet.unit.test.js +10 -0
  282. package/lib-es/__tests__/logic/isTestnet.unit.test.js.map +1 -0
  283. package/lib-es/__tests__/logic/normalizeAddress.unit.test.d.ts +2 -0
  284. package/lib-es/__tests__/logic/normalizeAddress.unit.test.d.ts.map +1 -0
  285. package/lib-es/__tests__/logic/normalizeAddress.unit.test.js +10 -0
  286. package/lib-es/__tests__/logic/normalizeAddress.unit.test.js.map +1 -0
  287. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts +2 -0
  288. package/lib-es/__tests__/logic/processRecipients.unit.test.d.ts.map +1 -0
  289. package/lib-es/__tests__/logic/processRecipients.unit.test.js +74 -0
  290. package/lib-es/__tests__/logic/processRecipients.unit.test.js.map +1 -0
  291. package/lib-es/__tests__/network/client.test.d.ts +2 -0
  292. package/lib-es/__tests__/network/client.test.d.ts.map +1 -0
  293. package/lib-es/__tests__/network/client.test.js +1119 -0
  294. package/lib-es/__tests__/network/client.test.js.map +1 -0
  295. package/lib-es/api/index.d.ts +4 -30
  296. package/lib-es/api/index.d.ts.map +1 -1
  297. package/lib-es/api/index.js +17 -168
  298. package/lib-es/api/index.js.map +1 -1
  299. package/lib-es/bridge/bridge.fixture.d.ts +2 -0
  300. package/lib-es/bridge/bridge.fixture.d.ts.map +1 -1
  301. package/lib-es/bridge/bridge.fixture.js +82 -12
  302. package/lib-es/bridge/bridge.fixture.js.map +1 -1
  303. package/lib-es/bridge/broadcast.d.ts +3 -2
  304. package/lib-es/bridge/broadcast.d.ts.map +1 -1
  305. package/lib-es/bridge/broadcast.js +4 -3
  306. package/lib-es/bridge/broadcast.js.map +1 -1
  307. package/lib-es/bridge/estimateMaxSpendable.d.ts.map +1 -1
  308. package/lib-es/bridge/estimateMaxSpendable.js +4 -3
  309. package/lib-es/bridge/estimateMaxSpendable.js.map +1 -1
  310. package/lib-es/bridge/getFeesForTransaction.d.ts +1 -1
  311. package/lib-es/bridge/getFeesForTransaction.d.ts.map +1 -1
  312. package/lib-es/bridge/getFeesForTransaction.js +15 -9
  313. package/lib-es/bridge/getFeesForTransaction.js.map +1 -1
  314. package/lib-es/bridge/getTransactionStatus.d.ts.map +1 -1
  315. package/lib-es/bridge/getTransactionStatus.js +28 -14
  316. package/lib-es/bridge/getTransactionStatus.js.map +1 -1
  317. package/lib-es/bridge/index.d.ts +1 -1
  318. package/lib-es/bridge/index.d.ts.map +1 -1
  319. package/lib-es/bridge/index.js +1 -1
  320. package/lib-es/bridge/index.js.map +1 -1
  321. package/lib-es/bridge/logic.d.ts +5 -19
  322. package/lib-es/bridge/logic.d.ts.map +1 -1
  323. package/lib-es/bridge/logic.js +44 -134
  324. package/lib-es/bridge/logic.js.map +1 -1
  325. package/lib-es/bridge/prepareTransaction.d.ts.map +1 -1
  326. package/lib-es/bridge/prepareTransaction.js +5 -4
  327. package/lib-es/bridge/prepareTransaction.js.map +1 -1
  328. package/lib-es/bridge/signOperation.d.ts.map +1 -1
  329. package/lib-es/bridge/signOperation.js +19 -5
  330. package/lib-es/bridge/signOperation.js.map +1 -1
  331. package/lib-es/bridge/synchronisation.d.ts +15 -0
  332. package/lib-es/bridge/synchronisation.d.ts.map +1 -1
  333. package/lib-es/bridge/synchronisation.js +124 -4
  334. package/lib-es/bridge/synchronisation.js.map +1 -1
  335. package/lib-es/config.d.ts +13 -0
  336. package/lib-es/config.d.ts.map +1 -0
  337. package/lib-es/config.js +4 -0
  338. package/lib-es/config.js.map +1 -0
  339. package/lib-es/constants.d.ts +13 -2
  340. package/lib-es/constants.d.ts.map +1 -1
  341. package/lib-es/constants.js +13 -1
  342. package/lib-es/constants.js.map +1 -1
  343. package/lib-es/logic/buildTransaction.d.ts +9 -0
  344. package/lib-es/logic/buildTransaction.d.ts.map +1 -0
  345. package/lib-es/logic/buildTransaction.js +43 -0
  346. package/lib-es/logic/buildTransaction.js.map +1 -0
  347. package/lib-es/logic/calculateAmount.d.ts +3 -0
  348. package/lib-es/logic/calculateAmount.d.ts.map +1 -0
  349. package/lib-es/logic/calculateAmount.js +9 -0
  350. package/lib-es/logic/calculateAmount.js.map +1 -0
  351. package/lib-es/logic/combine.d.ts +4 -0
  352. package/lib-es/logic/combine.d.ts.map +1 -0
  353. package/lib-es/logic/combine.js +29 -0
  354. package/lib-es/logic/combine.js.map +1 -0
  355. package/lib-es/logic/craftTransaction.d.ts +5 -0
  356. package/lib-es/logic/craftTransaction.d.ts.map +1 -0
  357. package/lib-es/logic/craftTransaction.js +38 -0
  358. package/lib-es/logic/craftTransaction.js.map +1 -0
  359. package/lib-es/logic/createTransaction.d.ts.map +1 -0
  360. package/lib-es/{bridge → logic}/createTransaction.js +1 -1
  361. package/lib-es/logic/createTransaction.js.map +1 -0
  362. package/lib-es/logic/getBalance.d.ts +5 -0
  363. package/lib-es/logic/getBalance.d.ts.map +1 -0
  364. package/lib-es/logic/getBalance.js +8 -0
  365. package/lib-es/logic/getBalance.js.map +1 -0
  366. package/lib-es/logic/getCoinAndAmounts.d.ts +13 -0
  367. package/lib-es/logic/getCoinAndAmounts.d.ts.map +1 -0
  368. package/lib-es/logic/getCoinAndAmounts.js +101 -0
  369. package/lib-es/logic/getCoinAndAmounts.js.map +1 -0
  370. package/lib-es/logic/getFunctionAddress.d.ts +3 -0
  371. package/lib-es/logic/getFunctionAddress.d.ts.map +1 -0
  372. package/lib-es/logic/getFunctionAddress.js +8 -0
  373. package/lib-es/logic/getFunctionAddress.js.map +1 -0
  374. package/lib-es/logic/getResourceAddress.d.ts +4 -0
  375. package/lib-es/logic/getResourceAddress.d.ts.map +1 -0
  376. package/lib-es/logic/getResourceAddress.js +13 -0
  377. package/lib-es/logic/getResourceAddress.js.map +1 -0
  378. package/lib-es/logic/isTestnet.d.ts +2 -0
  379. package/lib-es/logic/isTestnet.d.ts.map +1 -0
  380. package/lib-es/logic/isTestnet.js +5 -0
  381. package/lib-es/logic/isTestnet.js.map +1 -0
  382. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts +3 -0
  383. package/lib-es/logic/isWriteSetChangeWriteResource.d.ts.map +1 -0
  384. package/lib-es/logic/isWriteSetChangeWriteResource.js +4 -0
  385. package/lib-es/logic/isWriteSetChangeWriteResource.js.map +1 -0
  386. package/lib-es/logic/normalizeAddress.d.ts +2 -0
  387. package/lib-es/logic/normalizeAddress.d.ts.map +1 -0
  388. package/lib-es/logic/normalizeAddress.js +8 -0
  389. package/lib-es/logic/normalizeAddress.js.map +1 -0
  390. package/lib-es/logic/normalizeTransactionOptions.d.ts +3 -0
  391. package/lib-es/logic/normalizeTransactionOptions.d.ts.map +1 -0
  392. package/lib-es/logic/normalizeTransactionOptions.js +17 -0
  393. package/lib-es/logic/normalizeTransactionOptions.js.map +1 -0
  394. package/lib-es/logic/processRecipients.d.ts +6 -0
  395. package/lib-es/logic/processRecipients.d.ts.map +1 -0
  396. package/lib-es/logic/processRecipients.js +54 -0
  397. package/lib-es/logic/processRecipients.js.map +1 -0
  398. package/lib-es/logic/transactionsToOperations.d.ts +7 -0
  399. package/lib-es/logic/transactionsToOperations.d.ts.map +1 -0
  400. package/lib-es/logic/transactionsToOperations.js +81 -0
  401. package/lib-es/logic/transactionsToOperations.js.map +1 -0
  402. package/lib-es/network/client.d.ts +38 -0
  403. package/lib-es/network/client.d.ts.map +1 -0
  404. package/lib-es/network/client.js +276 -0
  405. package/lib-es/network/client.js.map +1 -0
  406. package/lib-es/network/graphql/queries.d.ts.map +1 -0
  407. package/lib-es/{api → network}/graphql/queries.js +6 -6
  408. package/lib-es/network/graphql/queries.js.map +1 -0
  409. package/lib-es/{api → network}/graphql/types.d.ts +9 -9
  410. package/lib-es/network/graphql/types.d.ts.map +1 -0
  411. package/lib-es/{api → network}/graphql/types.js.map +1 -1
  412. package/lib-es/network/index.d.ts +2 -1
  413. package/lib-es/network/index.d.ts.map +1 -1
  414. package/lib-es/network/index.js +6 -8
  415. package/lib-es/network/index.js.map +1 -1
  416. package/lib-es/test/bot-specs.d.ts.map +1 -1
  417. package/lib-es/test/bot-specs.js +41 -2
  418. package/lib-es/test/bot-specs.js.map +1 -1
  419. package/lib-es/test/bridgeDatasetTest.d.ts.map +1 -1
  420. package/lib-es/test/bridgeDatasetTest.js +44 -59
  421. package/lib-es/test/bridgeDatasetTest.js.map +1 -1
  422. package/lib-es/test/speculos-deviceActions.d.ts +1 -0
  423. package/lib-es/test/speculos-deviceActions.d.ts.map +1 -1
  424. package/lib-es/test/speculos-deviceActions.js +36 -4
  425. package/lib-es/test/speculos-deviceActions.js.map +1 -1
  426. package/lib-es/types/assets.d.ts +16 -0
  427. package/lib-es/types/assets.d.ts.map +1 -0
  428. package/lib-es/types/assets.js +2 -0
  429. package/lib-es/types/assets.js.map +1 -0
  430. package/lib-es/types/index.d.ts +22 -7
  431. package/lib-es/types/index.d.ts.map +1 -1
  432. package/package.json +16 -13
  433. package/src/__tests__/api/craftTransaction.unit.test.ts +243 -0
  434. package/src/__tests__/api/getBalance.unit.test.ts +44 -0
  435. package/src/__tests__/api/index.integ.test.ts +401 -0
  436. package/src/__tests__/api/index.test.ts +60 -477
  437. package/src/__tests__/bridge/broadcast.test.ts +2 -2
  438. package/src/__tests__/bridge/getFeesForTransaction.test.ts +146 -11
  439. package/src/__tests__/bridge/getTransactionStatus.test.ts +217 -38
  440. package/src/__tests__/bridge/logic.test.ts +728 -569
  441. package/src/__tests__/bridge/prepareTransaction.test.ts +2 -2
  442. package/src/__tests__/bridge/signOperation.test.ts +153 -15
  443. package/src/__tests__/bridge/synchronisation.test.ts +1265 -71
  444. package/src/__tests__/index.test.ts +1 -1
  445. package/src/__tests__/logic/buildTransaction.test.ts +150 -0
  446. package/src/__tests__/logic/calculateAmount.unit.test.ts +51 -0
  447. package/src/__tests__/logic/combine.unit.test.ts +65 -0
  448. package/src/__tests__/logic/compareAddress.unit.test.ts +27 -0
  449. package/src/__tests__/{bridge → logic}/createTransaction.test.ts +2 -2
  450. package/src/__tests__/logic/getCoinAndAmounts.unit.test.ts +195 -0
  451. package/src/__tests__/logic/getFunctionAddress.unit.test.ts +33 -0
  452. package/src/__tests__/logic/getResourceAddress.unit.test.ts +241 -0
  453. package/src/__tests__/logic/isTestnet.unit.test.ts +11 -0
  454. package/src/__tests__/logic/normalizeAddress.unit.test.ts +15 -0
  455. package/src/__tests__/logic/processRecipients.unit.test.ts +95 -0
  456. package/src/__tests__/network/client.test.ts +1257 -0
  457. package/src/api/index.ts +29 -224
  458. package/src/bridge/bridge.fixture.ts +91 -12
  459. package/src/bridge/broadcast.ts +7 -7
  460. package/src/bridge/estimateMaxSpendable.ts +4 -3
  461. package/src/bridge/getFeesForTransaction.ts +17 -11
  462. package/src/bridge/getTransactionStatus.ts +35 -13
  463. package/src/bridge/index.ts +2 -2
  464. package/src/bridge/logic.ts +58 -194
  465. package/src/bridge/prepareTransaction.ts +7 -4
  466. package/src/bridge/signOperation.ts +21 -5
  467. package/src/bridge/synchronisation.ts +171 -4
  468. package/src/config.ts +19 -0
  469. package/src/constants.ts +22 -2
  470. package/src/logic/buildTransaction.ts +70 -0
  471. package/src/logic/calculateAmount.ts +15 -0
  472. package/src/logic/combine.ts +51 -0
  473. package/src/logic/craftTransaction.ts +65 -0
  474. package/src/{bridge → logic}/createTransaction.ts +1 -1
  475. package/src/logic/getBalance.ts +15 -0
  476. package/src/logic/getCoinAndAmounts.ts +141 -0
  477. package/src/logic/getFunctionAddress.ts +9 -0
  478. package/src/logic/getResourceAddress.ts +24 -0
  479. package/src/logic/isTestnet.ts +5 -0
  480. package/src/logic/isWriteSetChangeWriteResource.ts +7 -0
  481. package/src/logic/normalizeAddress.ts +8 -0
  482. package/src/logic/normalizeTransactionOptions.ts +18 -0
  483. package/src/logic/processRecipients.ts +88 -0
  484. package/src/logic/transactionsToOperations.ts +106 -0
  485. package/src/network/client.ts +374 -0
  486. package/src/{api → network}/graphql/queries.ts +6 -6
  487. package/src/{api → network}/graphql/types.ts +9 -9
  488. package/src/network/index.ts +6 -14
  489. package/src/test/bot-specs.ts +63 -3
  490. package/src/test/bridgeDatasetTest.ts +46 -59
  491. package/src/test/speculos-deviceActions.ts +40 -4
  492. package/src/types/assets.ts +20 -0
  493. package/src/types/index.ts +20 -1
  494. package/lib/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  495. package/lib/__tests__/bridge/buildTransaction.test.js +0 -53
  496. package/lib/__tests__/bridge/buildTransaction.test.js.map +0 -1
  497. package/lib/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  498. package/lib/__tests__/bridge/createTransaction.test.js.map +0 -1
  499. package/lib/api/graphql/queries.d.ts.map +0 -1
  500. package/lib/api/graphql/queries.js.map +0 -1
  501. package/lib/api/graphql/types.d.ts.map +0 -1
  502. package/lib/bridge/buildTransaction.d.ts +0 -7
  503. package/lib/bridge/buildTransaction.d.ts.map +0 -1
  504. package/lib/bridge/buildTransaction.js +0 -19
  505. package/lib/bridge/buildTransaction.js.map +0 -1
  506. package/lib/bridge/createTransaction.d.ts.map +0 -1
  507. package/lib/bridge/createTransaction.js.map +0 -1
  508. package/lib-es/__tests__/bridge/buildTransaction.test.d.ts.map +0 -1
  509. package/lib-es/__tests__/bridge/buildTransaction.test.js +0 -48
  510. package/lib-es/__tests__/bridge/buildTransaction.test.js.map +0 -1
  511. package/lib-es/__tests__/bridge/createTransaction.test.d.ts.map +0 -1
  512. package/lib-es/__tests__/bridge/createTransaction.test.js.map +0 -1
  513. package/lib-es/api/graphql/queries.d.ts.map +0 -1
  514. package/lib-es/api/graphql/queries.js.map +0 -1
  515. package/lib-es/api/graphql/types.d.ts.map +0 -1
  516. package/lib-es/bridge/buildTransaction.d.ts +0 -7
  517. package/lib-es/bridge/buildTransaction.d.ts.map +0 -1
  518. package/lib-es/bridge/buildTransaction.js +0 -17
  519. package/lib-es/bridge/buildTransaction.js.map +0 -1
  520. package/lib-es/bridge/createTransaction.d.ts.map +0 -1
  521. package/lib-es/bridge/createTransaction.js.map +0 -1
  522. package/src/__tests__/bridge/buildTransaction.test.ts +0 -61
  523. package/src/bridge/buildTransaction.ts +0 -29
  524. /package/lib/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  525. /package/lib/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  526. /package/lib/{bridge → logic}/createTransaction.d.ts +0 -0
  527. /package/lib/{api → network}/graphql/queries.d.ts +0 -0
  528. /package/lib/{api → network}/graphql/types.js +0 -0
  529. /package/lib-es/__tests__/{bridge → logic}/buildTransaction.test.d.ts +0 -0
  530. /package/lib-es/__tests__/{bridge → logic}/createTransaction.test.d.ts +0 -0
  531. /package/lib-es/{bridge → logic}/createTransaction.d.ts +0 -0
  532. /package/lib-es/{api → network}/graphql/queries.d.ts +0 -0
  533. /package/lib-es/{api → network}/graphql/types.js +0 -0
@@ -1,11 +1,16 @@
1
1
  import BigNumber from "bignumber.js";
2
- import { createFixtureAccount, createFixtureTransaction } from "../../bridge/bridge.fixture";
2
+ import {
3
+ createFixtureAccount,
4
+ createFixtureAccountWithSubAccount,
5
+ createFixtureTransaction,
6
+ createFixtureTransactionWithSubAccount,
7
+ } from "../../bridge/bridge.fixture";
3
8
  import * as getFeesForTransaction from "../../bridge/getFeesForTransaction";
4
- import { AptosAPI } from "../../api";
9
+ import { AptosAPI } from "../../network";
5
10
 
6
11
  let simulateTransaction = jest.fn();
7
12
 
8
- jest.mock("../../api", () => {
13
+ jest.mock("../../network", () => {
9
14
  return {
10
15
  AptosAPI: function () {
11
16
  return {
@@ -24,16 +29,18 @@ jest.mock("@aptos-labs/ts-sdk", () => {
24
29
  };
25
30
  });
26
31
 
27
- jest.mock("../../bridge/logic", () => {
28
- return {
29
- DEFAULT_GAS: 201,
30
- DEFAULT_GAS_PRICE: 101,
31
- ESTIMATE_GAS_MUL: 1,
32
- normalizeTransactionOptions: jest.fn(),
33
- };
34
- });
32
+ const mockedGetTokenAccount = jest.fn();
35
33
 
36
34
  describe("getFeesForTransaction Test", () => {
35
+ beforeEach(() => {
36
+ jest.mock("../../bridge/logic", () => ({
37
+ DEFAULT_GAS: 201,
38
+ DEFAULT_GAS_PRICE: 101,
39
+ ESTIMATE_GAS_MUL: 1,
40
+ normalizeTransactionOptions: jest.fn(),
41
+ getTokenAccount: mockedGetTokenAccount,
42
+ }));
43
+ });
37
44
  describe("when using getFee", () => {
38
45
  describe("with vm_status as INSUFFICIENT_BALANCE", () => {
39
46
  it("should return a fee estimation object", async () => {
@@ -46,6 +53,7 @@ describe("getFeesForTransaction Test", () => {
46
53
  gas_unit_price: "102",
47
54
  },
48
55
  ]);
56
+ mockedGetTokenAccount.mockReturnValue(undefined);
49
57
 
50
58
  const account = createFixtureAccount();
51
59
  const transaction = createFixtureTransaction();
@@ -68,6 +76,40 @@ describe("getFeesForTransaction Test", () => {
68
76
 
69
77
  expect(result).toEqual(expected);
70
78
  });
79
+
80
+ it("should return a fee estimation object for the token transaction", async () => {
81
+ simulateTransaction = jest.fn(() => [
82
+ {
83
+ success: true,
84
+ vm_status: [],
85
+ expiration_timestamp_secs: 5,
86
+ gas_used: "202",
87
+ gas_unit_price: "102",
88
+ },
89
+ ]);
90
+ mockedGetTokenAccount.mockReturnValue(undefined);
91
+
92
+ const account = createFixtureAccountWithSubAccount("coin");
93
+ const transaction = createFixtureTransactionWithSubAccount();
94
+ const aptosClient = new AptosAPI(account.currency.id);
95
+
96
+ transaction.amount = new BigNumber(1);
97
+ account.xpub = "xpub";
98
+ account.spendableBalance = new BigNumber(100000000);
99
+
100
+ const result = await getFeesForTransaction.getFee(account, transaction, aptosClient);
101
+
102
+ const expected = {
103
+ fees: new BigNumber(20604),
104
+ estimate: {
105
+ maxGasAmount: "202",
106
+ gasUnitPrice: "102",
107
+ },
108
+ errors: {},
109
+ };
110
+
111
+ expect(result).toEqual(expected);
112
+ });
71
113
  });
72
114
 
73
115
  describe("with vm_status as DUMMY_STATE", () => {
@@ -81,6 +123,7 @@ describe("getFeesForTransaction Test", () => {
81
123
  gas_unit_price: "100",
82
124
  },
83
125
  ]);
126
+ mockedGetTokenAccount.mockReturnValue(undefined);
84
127
 
85
128
  const account = createFixtureAccount();
86
129
  const transaction = createFixtureTransaction();
@@ -95,6 +138,44 @@ describe("getFeesForTransaction Test", () => {
95
138
  }).rejects.toThrow("Simulation failed with following error: DUMMY_STATE");
96
139
  });
97
140
  });
141
+
142
+ describe("with vm_status as MAX_GAS_UNITS_BELOW_MIN_TRANSACTION_GAS_UNITS", () => {
143
+ it("should return a fee estimation object with GasInsuficeinetBalance error", async () => {
144
+ simulateTransaction = jest.fn(() => [
145
+ {
146
+ success: false,
147
+ vm_status: ["MAX_GAS_UNITS_BELOW_MIN_TRANSACTION_GAS_UNITS"],
148
+ expiration_timestamp_secs: 5,
149
+ gas_used: "0",
150
+ gas_unit_price: "100",
151
+ },
152
+ ]);
153
+ mockedGetTokenAccount.mockReturnValue(undefined);
154
+
155
+ const account = createFixtureAccountWithSubAccount("coin");
156
+ const transaction = createFixtureTransactionWithSubAccount();
157
+ const aptosClient = new AptosAPI(account.currency.id);
158
+
159
+ transaction.amount = new BigNumber(1);
160
+ account.xpub = "xpub";
161
+ account.spendableBalance = new BigNumber(100000000);
162
+
163
+ const result = await getFeesForTransaction.getFee(account, transaction, aptosClient);
164
+
165
+ const expected = {
166
+ fees: new BigNumber(0),
167
+ estimate: {
168
+ maxGasAmount: "0",
169
+ gasUnitPrice: "100",
170
+ },
171
+ errors: {
172
+ maxGasAmount: "GasInsufficientBalance",
173
+ },
174
+ };
175
+
176
+ expect(result).toEqual(expected);
177
+ });
178
+ });
98
179
  });
99
180
 
100
181
  describe("when using getEstimatedGas", () => {
@@ -109,6 +190,7 @@ describe("getFeesForTransaction Test", () => {
109
190
  gas_unit_price: "102",
110
191
  },
111
192
  ]);
193
+ mockedGetTokenAccount.mockReturnValue(undefined);
112
194
 
113
195
  const account = createFixtureAccount();
114
196
  const transaction = createFixtureTransaction();
@@ -152,6 +234,8 @@ describe("getFeesForTransaction Test", () => {
152
234
  gas_unit_price: "102",
153
235
  },
154
236
  ]);
237
+ mockedGetTokenAccount.mockReturnValue(undefined);
238
+
155
239
  const account = createFixtureAccount();
156
240
  account.xpub = "xpub";
157
241
  const transaction = createFixtureTransaction();
@@ -186,4 +270,55 @@ describe("getFeesForTransaction Test", () => {
186
270
  });
187
271
  });
188
272
  });
273
+
274
+ describe("when key is in cache from a token account", () => {
275
+ beforeEach(() => {
276
+ jest.clearAllMocks();
277
+ });
278
+
279
+ it("should return cached fee", async () => {
280
+ simulateTransaction = jest.fn(() => [
281
+ {
282
+ success: true,
283
+ vm_status: [],
284
+ expiration_timestamp_secs: 5,
285
+ gas_used: "202",
286
+ gas_unit_price: "102",
287
+ },
288
+ ]);
289
+ mockedGetTokenAccount.mockReturnValue(undefined);
290
+
291
+ const account = createFixtureAccountWithSubAccount("coin");
292
+ account.xpub = "xpub";
293
+ const transaction = createFixtureTransactionWithSubAccount();
294
+ const aptosClient = new AptosAPI(account.currency.id);
295
+
296
+ transaction.amount = new BigNumber(10);
297
+
298
+ const result1 = await getFeesForTransaction.getEstimatedGas(
299
+ account,
300
+ transaction,
301
+ aptosClient,
302
+ );
303
+ const result2 = await getFeesForTransaction.getEstimatedGas(
304
+ account,
305
+ transaction,
306
+ aptosClient,
307
+ );
308
+
309
+ expect(simulateTransaction.mock.calls).toHaveLength(1);
310
+
311
+ const expected = {
312
+ errors: {},
313
+ estimate: {
314
+ gasUnitPrice: "102",
315
+ maxGasAmount: "202",
316
+ },
317
+ fees: new BigNumber("20604"),
318
+ };
319
+
320
+ expect(result1).toEqual(expected);
321
+ expect(result2).toEqual(expected);
322
+ });
323
+ });
189
324
  });
@@ -1,5 +1,10 @@
1
1
  import BigNumber from "bignumber.js";
2
- import { createFixtureAccount, createFixtureTransaction } from "../../bridge/bridge.fixture";
2
+ import {
3
+ createFixtureAccount,
4
+ createFixtureAccountWithSubAccount,
5
+ createFixtureTransaction,
6
+ createFixtureTransactionWithSubAccount,
7
+ } from "../../bridge/bridge.fixture";
3
8
  import getTransactionStatus from "../../bridge/getTransactionStatus";
4
9
  import {
5
10
  AmountRequired,
@@ -7,15 +12,16 @@ import {
7
12
  InvalidAddress,
8
13
  InvalidAddressBecauseDestinationIsAlsoSource,
9
14
  NotEnoughBalance,
15
+ NotEnoughBalanceFees,
10
16
  RecipientRequired,
11
17
  } from "@ledgerhq/errors";
12
18
 
13
19
  describe("getTransactionStatus Test", () => {
14
- it("should return errors for AmountRequired", async () => {
20
+ it("should return error for AmountRequired", async () => {
15
21
  const account = createFixtureAccount();
16
22
  const transaction = createFixtureTransaction();
17
23
 
18
- transaction.fees = new BigNumber(2);
24
+ transaction.fees = BigNumber(2);
19
25
  transaction.recipient = "0x" + "0".repeat(64);
20
26
 
21
27
  const result = await getTransactionStatus(account, transaction);
@@ -25,21 +31,21 @@ describe("getTransactionStatus Test", () => {
25
31
  amount: new AmountRequired(),
26
32
  },
27
33
  warnings: {},
28
- estimatedFees: new BigNumber(2),
29
- amount: new BigNumber(0),
30
- totalSpent: new BigNumber(2),
34
+ estimatedFees: BigNumber(2),
35
+ amount: BigNumber(0),
36
+ totalSpent: BigNumber(2),
31
37
  };
32
38
 
33
39
  expect(result).toEqual(expected);
34
40
  });
35
41
 
36
- it("should return errors for FeeNotLoaded", async () => {
42
+ it("should return error for FeeNotLoaded", async () => {
37
43
  const account = createFixtureAccount();
38
- account.balance = new BigNumber(10);
44
+ account.spendableBalance = BigNumber(10);
39
45
 
40
46
  const transaction = createFixtureTransaction();
41
47
  transaction.fees = null;
42
- transaction.amount = new BigNumber(2);
48
+ transaction.amount = BigNumber(2);
43
49
  transaction.recipient = "0x" + "0".repeat(64);
44
50
 
45
51
  const result = await getTransactionStatus(account, transaction);
@@ -49,22 +55,71 @@ describe("getTransactionStatus Test", () => {
49
55
  fees: new FeeNotLoaded(),
50
56
  },
51
57
  warnings: {},
52
- estimatedFees: new BigNumber(0),
53
- amount: new BigNumber(2),
54
- totalSpent: new BigNumber(2),
58
+ estimatedFees: BigNumber(0),
59
+ amount: BigNumber(2),
60
+ totalSpent: BigNumber(2),
61
+ };
62
+
63
+ expect(result).toEqual(expected);
64
+ });
65
+
66
+ it("should return error for NotEnoughBalance", async () => {
67
+ const account = createFixtureAccount();
68
+ account.spendableBalance = BigNumber(1);
69
+
70
+ const transaction = createFixtureTransaction();
71
+ transaction.recipient = "0x" + "0".repeat(64);
72
+ transaction.amount = BigNumber(2);
73
+ transaction.fees = BigNumber(2);
74
+
75
+ const result = await getTransactionStatus(account, transaction);
76
+
77
+ const expected = {
78
+ errors: {
79
+ amount: new NotEnoughBalance(),
80
+ },
81
+ warnings: {},
82
+ estimatedFees: BigNumber(2),
83
+ amount: BigNumber(2),
84
+ totalSpent: BigNumber(4),
55
85
  };
56
86
 
57
87
  expect(result).toEqual(expected);
58
88
  });
59
89
 
60
- it("should return errors for NotEnoughBalance", async () => {
90
+ it("should return error for NotEnoughBalance and amount equal to zero with use all amount option", async () => {
61
91
  const account = createFixtureAccount();
62
- account.balance = new BigNumber(1);
92
+ account.spendableBalance = BigNumber(1);
63
93
 
64
94
  const transaction = createFixtureTransaction();
65
95
  transaction.recipient = "0x" + "0".repeat(64);
66
- transaction.amount = new BigNumber(2);
67
- transaction.fees = new BigNumber(2);
96
+ transaction.amount = BigNumber(2);
97
+ transaction.fees = BigNumber(2);
98
+ transaction.useAllAmount = true;
99
+
100
+ const result = await getTransactionStatus(account, transaction);
101
+
102
+ const expected = {
103
+ errors: {
104
+ amount: new NotEnoughBalance(),
105
+ },
106
+ warnings: {},
107
+ estimatedFees: BigNumber(2),
108
+ amount: BigNumber(0),
109
+ totalSpent: BigNumber(2),
110
+ };
111
+
112
+ expect(result).toEqual(expected);
113
+ });
114
+
115
+ it("should return error for NotEnoughBalance for token account when not enough tokens", async () => {
116
+ const account = createFixtureAccountWithSubAccount("coin");
117
+ account.spendableBalance = BigNumber(300);
118
+
119
+ const transaction = createFixtureTransactionWithSubAccount();
120
+ transaction.recipient = "0x" + "0".repeat(64);
121
+ transaction.amount = BigNumber(2000);
122
+ transaction.fees = BigNumber(200);
68
123
 
69
124
  const result = await getTransactionStatus(account, transaction);
70
125
 
@@ -73,21 +128,97 @@ describe("getTransactionStatus Test", () => {
73
128
  amount: new NotEnoughBalance(),
74
129
  },
75
130
  warnings: {},
76
- estimatedFees: new BigNumber(2),
77
- amount: new BigNumber(2),
78
- totalSpent: new BigNumber(4),
131
+ estimatedFees: BigNumber(200),
132
+ amount: BigNumber(2000),
133
+ totalSpent: BigNumber(2000),
79
134
  };
80
135
 
81
136
  expect(result).toEqual(expected);
82
137
  });
83
138
 
84
- it("should return errors for RecipientRequired", async () => {
139
+ it("should return error for NotEnoughBalance with use all amount option", async () => {
85
140
  const account = createFixtureAccount();
86
- account.balance = new BigNumber(10);
141
+ account.spendableBalance = BigNumber(1);
87
142
 
88
143
  const transaction = createFixtureTransaction();
89
- transaction.amount = new BigNumber(2);
90
- transaction.fees = new BigNumber(2);
144
+ transaction.recipient = "0x" + "0".repeat(64);
145
+ transaction.amount = BigNumber(2);
146
+ transaction.fees = BigNumber(2);
147
+ transaction.useAllAmount = true;
148
+
149
+ const result = await getTransactionStatus(account, transaction);
150
+
151
+ const expected = {
152
+ errors: {
153
+ amount: new NotEnoughBalance(),
154
+ },
155
+ warnings: {},
156
+ estimatedFees: BigNumber(2),
157
+ amount: BigNumber(0),
158
+ totalSpent: BigNumber(2),
159
+ };
160
+
161
+ expect(result).toEqual(expected);
162
+ });
163
+
164
+ it("should return error for NotEnoughBalance for token account with use all amount option when not enough fees", async () => {
165
+ const account = createFixtureAccountWithSubAccount("coin");
166
+ account.spendableBalance = BigNumber(10);
167
+
168
+ const transaction = createFixtureTransactionWithSubAccount();
169
+ transaction.recipient = "0x" + "0".repeat(64);
170
+ transaction.amount = BigNumber(2000);
171
+ transaction.fees = BigNumber(200);
172
+ transaction.useAllAmount = true;
173
+
174
+ const result = await getTransactionStatus(account, transaction);
175
+
176
+ const expected = {
177
+ errors: {
178
+ amount: new NotEnoughBalance(),
179
+ },
180
+ warnings: {},
181
+ estimatedFees: BigNumber(200),
182
+ amount: BigNumber(1000),
183
+ totalSpent: BigNumber(1000),
184
+ };
185
+
186
+ expect(result).toEqual(expected);
187
+ });
188
+
189
+ it("should return error for NotEnoughBalanceFees", async () => {
190
+ const account = createFixtureAccountWithSubAccount("coin");
191
+ account.spendableBalance = BigNumber(1);
192
+
193
+ const transaction = createFixtureTransactionWithSubAccount();
194
+ transaction.recipient = "0x" + "0".repeat(64);
195
+ transaction.amount = BigNumber(2);
196
+ transaction.fees = BigNumber(0);
197
+ transaction.errors = { maxGasAmount: "GasInsufficientBalance" };
198
+
199
+ const result = await getTransactionStatus(account, transaction);
200
+
201
+ const expected = {
202
+ errors: {
203
+ amount: new NotEnoughBalanceFees(),
204
+ },
205
+ warnings: {},
206
+ estimatedFees: BigNumber(0),
207
+ amount: BigNumber(2),
208
+ totalSpent: BigNumber(2),
209
+ };
210
+
211
+ expect(result).toEqual(expected);
212
+ });
213
+
214
+ it("should return error for RecipientRequired", async () => {
215
+ const account = createFixtureAccount();
216
+ account.spendableBalance = BigNumber(10);
217
+
218
+ const transaction = createFixtureTransaction();
219
+ transaction.amount = BigNumber(2);
220
+ transaction.fees = BigNumber(2);
221
+ transaction.recipient = "";
91
222
 
92
223
  const result = await getTransactionStatus(account, transaction);
93
224
 
@@ -96,20 +227,20 @@ describe("getTransactionStatus Test", () => {
96
227
  recipient: new RecipientRequired(),
97
228
  },
98
229
  warnings: {},
99
- estimatedFees: new BigNumber(2),
100
- amount: new BigNumber(2),
101
- totalSpent: new BigNumber(4),
230
+ estimatedFees: BigNumber(2),
231
+ amount: BigNumber(2),
232
+ totalSpent: BigNumber(4),
102
233
  };
103
234
 
104
235
  expect(result).toEqual(expected);
105
236
  });
106
237
 
107
- it("should return errors for InvalidAddress", async () => {
238
+ it("should return error for InvalidAddress", async () => {
108
239
  const account = createFixtureAccount();
109
240
  const transaction = createFixtureTransaction();
110
241
 
111
- transaction.amount = new BigNumber(2);
112
- transaction.fees = new BigNumber(2);
242
+ transaction.amount = BigNumber(2);
243
+ transaction.fees = BigNumber(2);
113
244
  transaction.recipient = "0x";
114
245
 
115
246
  const result = await getTransactionStatus(account, transaction);
@@ -120,20 +251,20 @@ describe("getTransactionStatus Test", () => {
120
251
  amount: new NotEnoughBalance(),
121
252
  },
122
253
  warnings: {},
123
- estimatedFees: new BigNumber(2),
124
- amount: new BigNumber(2),
125
- totalSpent: new BigNumber(4),
254
+ estimatedFees: BigNumber(2),
255
+ amount: BigNumber(2),
256
+ totalSpent: BigNumber(4),
126
257
  };
127
258
 
128
259
  expect(result).toEqual(expected);
129
260
  });
130
261
 
131
- it("should return errors for InvalidAddressBecauseDestinationIsAlsoSource", async () => {
262
+ it("should return error for InvalidAddressBecauseDestinationIsAlsoSource", async () => {
132
263
  const account = createFixtureAccount();
133
264
  const transaction = createFixtureTransaction();
134
265
 
135
- transaction.amount = new BigNumber(2);
136
- transaction.fees = new BigNumber(2);
266
+ transaction.amount = BigNumber(2);
267
+ transaction.fees = BigNumber(2);
137
268
  transaction.recipient = "0x" + "0".repeat(64);
138
269
  account.freshAddress = transaction.recipient;
139
270
 
@@ -145,9 +276,57 @@ describe("getTransactionStatus Test", () => {
145
276
  amount: new NotEnoughBalance(),
146
277
  },
147
278
  warnings: {},
148
- estimatedFees: new BigNumber(2),
149
- amount: new BigNumber(2),
150
- totalSpent: new BigNumber(4),
279
+ estimatedFees: BigNumber(2),
280
+ amount: BigNumber(2),
281
+ totalSpent: BigNumber(4),
282
+ };
283
+
284
+ expect(result).toEqual(expected);
285
+ });
286
+
287
+ it("should return error for RecipientRequired", async () => {
288
+ const account = createFixtureAccount();
289
+ const transaction = createFixtureTransaction();
290
+
291
+ transaction.amount = BigNumber(2);
292
+ transaction.fees = BigNumber(2);
293
+ transaction.recipient = "";
294
+ account.freshAddress = transaction.recipient;
295
+
296
+ const result = await getTransactionStatus(account, transaction);
297
+
298
+ const expected = {
299
+ errors: {
300
+ recipient: new RecipientRequired(),
301
+ amount: new NotEnoughBalance(),
302
+ },
303
+ warnings: {},
304
+ estimatedFees: BigNumber(2),
305
+ amount: BigNumber(2),
306
+ totalSpent: BigNumber(4),
307
+ };
308
+
309
+ expect(result).toEqual(expected);
310
+ });
311
+
312
+ it("should return right amount and total spent with use all amount option", async () => {
313
+ const account = createFixtureAccount();
314
+ account.spendableBalance = BigNumber(10);
315
+
316
+ const transaction = createFixtureTransaction();
317
+ transaction.recipient = "0x" + "0".repeat(64);
318
+ transaction.amount = BigNumber(2);
319
+ transaction.fees = BigNumber(2);
320
+ transaction.useAllAmount = true;
321
+
322
+ const result = await getTransactionStatus(account, transaction);
323
+
324
+ const expected = {
325
+ errors: {},
326
+ warnings: {},
327
+ estimatedFees: BigNumber(2),
328
+ amount: BigNumber(8),
329
+ totalSpent: BigNumber(10),
151
330
  };
152
331
 
153
332
  expect(result).toEqual(expected);