@ledgerhq/live-common 27.0.0 → 27.0.1-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 (405) hide show
  1. package/lib/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.js +2 -2
  2. package/lib/__tests__/test-helpers/environment.d.ts +2 -0
  3. package/lib/__tests__/test-helpers/environment.d.ts.map +1 -0
  4. package/lib/__tests__/test-helpers/environment.js +107 -0
  5. package/lib/__tests__/test-helpers/environment.js.map +1 -0
  6. package/lib/__tests__/test-helpers/setup.d.ts +1 -1
  7. package/lib/__tests__/test-helpers/setup.d.ts.map +1 -1
  8. package/lib/__tests__/test-helpers/setup.js +1 -101
  9. package/lib/__tests__/test-helpers/setup.js.map +1 -1
  10. package/lib/account/serialization.d.ts.map +1 -1
  11. package/lib/account/serialization.js +83 -40
  12. package/lib/account/serialization.js.map +1 -1
  13. package/lib/bot/bot-test-context.d.ts +3 -0
  14. package/lib/bot/bot-test-context.d.ts.map +1 -0
  15. package/lib/bot/bot-test-context.js +26 -0
  16. package/lib/bot/bot-test-context.js.map +1 -0
  17. package/lib/bot/bot-test-context.test.d.ts +2 -0
  18. package/lib/bot/bot-test-context.test.d.ts.map +1 -0
  19. package/lib/bot/bot-test-context.test.js +41 -0
  20. package/lib/bot/bot-test-context.test.js.map +1 -0
  21. package/lib/bot/cli.d.ts +2 -0
  22. package/lib/bot/cli.d.ts.map +1 -0
  23. package/lib/bot/cli.js +14 -0
  24. package/lib/bot/cli.js.map +1 -0
  25. package/lib/bot/engine.d.ts +5 -5
  26. package/lib/bot/engine.d.ts.map +1 -1
  27. package/lib/bot/engine.js +161 -112
  28. package/lib/bot/engine.js.map +1 -1
  29. package/lib/bot/formatters.d.ts +2 -2
  30. package/lib/bot/formatters.d.ts.map +1 -1
  31. package/lib/bot/formatters.js +41 -15
  32. package/lib/bot/formatters.js.map +1 -1
  33. package/lib/bot/index.d.ts +1 -1
  34. package/lib/bot/index.d.ts.map +1 -1
  35. package/lib/bot/index.js +90 -15
  36. package/lib/bot/index.js.map +1 -1
  37. package/lib/bot/specs.d.ts +2 -1
  38. package/lib/bot/specs.d.ts.map +1 -1
  39. package/lib/bot/specs.js +13 -9
  40. package/lib/bot/specs.js.map +1 -1
  41. package/lib/bot/types.d.ts +5 -2
  42. package/lib/bot/types.d.ts.map +1 -1
  43. package/lib/countervalues/logic.integration.test.js +65 -0
  44. package/lib/countervalues/logic.integration.test.js.map +1 -1
  45. package/lib/countervalues/modules/weth.d.ts.map +1 -1
  46. package/lib/countervalues/modules/weth.js +5 -10
  47. package/lib/countervalues/modules/weth.js.map +1 -1
  48. package/lib/currencies/sortByMarketcap.d.ts +0 -2
  49. package/lib/currencies/sortByMarketcap.d.ts.map +1 -1
  50. package/lib/currencies/sortByMarketcap.js +3 -17
  51. package/lib/currencies/sortByMarketcap.js.map +1 -1
  52. package/lib/currencies/sortByMarketcap.test.js +0 -5
  53. package/lib/currencies/sortByMarketcap.test.js.map +1 -1
  54. package/lib/env.js +1 -1
  55. package/lib/families/algorand/specs.d.ts.map +1 -1
  56. package/lib/families/algorand/specs.js +18 -10
  57. package/lib/families/algorand/specs.js.map +1 -1
  58. package/lib/families/algorand/speculos-deviceActions.d.ts +1 -4
  59. package/lib/families/algorand/speculos-deviceActions.d.ts.map +1 -1
  60. package/lib/families/algorand/speculos-deviceActions.js +25 -8
  61. package/lib/families/algorand/speculos-deviceActions.js.map +1 -1
  62. package/lib/families/bitcoin/bridge/mock.d.ts.map +1 -1
  63. package/lib/families/bitcoin/bridge/mock.js +6 -1
  64. package/lib/families/bitcoin/bridge/mock.js.map +1 -1
  65. package/lib/families/bitcoin/datasets/bitcoin_cash.d.ts.map +1 -1
  66. package/lib/families/bitcoin/datasets/bitcoin_cash.js +1 -1
  67. package/lib/families/bitcoin/datasets/bitcoin_cash.js.map +1 -1
  68. package/lib/families/bitcoin/datasets/dash.d.ts.map +1 -1
  69. package/lib/families/bitcoin/datasets/dash.js +1 -1
  70. package/lib/families/bitcoin/datasets/dash.js.map +1 -1
  71. package/lib/families/bitcoin/datasets/decred.d.ts.map +1 -1
  72. package/lib/families/bitcoin/datasets/decred.js +1 -1
  73. package/lib/families/bitcoin/datasets/decred.js.map +1 -1
  74. package/lib/families/bitcoin/datasets/digibyte.d.ts.map +1 -1
  75. package/lib/families/bitcoin/datasets/digibyte.js +8 -2
  76. package/lib/families/bitcoin/datasets/digibyte.js.map +1 -1
  77. package/lib/families/bitcoin/datasets/dogecoin.d.ts.map +1 -1
  78. package/lib/families/bitcoin/datasets/dogecoin.js +1 -1
  79. package/lib/families/bitcoin/datasets/dogecoin.js.map +1 -1
  80. package/lib/families/bitcoin/datasets/komodo.js +1 -1
  81. package/lib/families/bitcoin/datasets/komodo.js.map +1 -1
  82. package/lib/families/bitcoin/datasets/litecoin.d.ts.map +1 -1
  83. package/lib/families/bitcoin/datasets/litecoin.js +8 -2
  84. package/lib/families/bitcoin/datasets/litecoin.js.map +1 -1
  85. package/lib/families/bitcoin/datasets/peercoin.js +1 -1
  86. package/lib/families/bitcoin/datasets/peercoin.js.map +1 -1
  87. package/lib/families/bitcoin/datasets/pivx.js +1 -1
  88. package/lib/families/bitcoin/datasets/pivx.js.map +1 -1
  89. package/lib/families/bitcoin/datasets/qtum.js +1 -1
  90. package/lib/families/bitcoin/datasets/qtum.js.map +1 -1
  91. package/lib/families/bitcoin/datasets/stakenet.d.ts.map +1 -1
  92. package/lib/families/bitcoin/datasets/stakenet.js +1 -1
  93. package/lib/families/bitcoin/datasets/stakenet.js.map +1 -1
  94. package/lib/families/bitcoin/datasets/vertcoin.d.ts.map +1 -1
  95. package/lib/families/bitcoin/datasets/vertcoin.js +1 -1
  96. package/lib/families/bitcoin/datasets/vertcoin.js.map +1 -1
  97. package/lib/families/bitcoin/datasets/viacoin.d.ts.map +1 -1
  98. package/lib/families/bitcoin/datasets/viacoin.js +1 -1
  99. package/lib/families/bitcoin/datasets/viacoin.js.map +1 -1
  100. package/lib/families/bitcoin/datasets/zcash.d.ts.map +1 -1
  101. package/lib/families/bitcoin/datasets/zcash.js +1 -1
  102. package/lib/families/bitcoin/datasets/zcash.js.map +1 -1
  103. package/lib/families/bitcoin/datasets/zencash.d.ts.map +1 -1
  104. package/lib/families/bitcoin/datasets/zencash.js +1 -1
  105. package/lib/families/bitcoin/datasets/zencash.js.map +1 -1
  106. package/lib/families/bitcoin/platformAdapter.test.d.ts +2 -0
  107. package/lib/families/bitcoin/platformAdapter.test.d.ts.map +1 -0
  108. package/lib/families/bitcoin/platformAdapter.test.js +48 -0
  109. package/lib/families/bitcoin/platformAdapter.test.js.map +1 -0
  110. package/lib/families/bitcoin/specs.d.ts.map +1 -1
  111. package/lib/families/bitcoin/specs.js +62 -24
  112. package/lib/families/bitcoin/specs.js.map +1 -1
  113. package/lib/families/bitcoin/speculos-deviceActions.d.ts +1 -4
  114. package/lib/families/bitcoin/speculos-deviceActions.d.ts.map +1 -1
  115. package/lib/families/bitcoin/speculos-deviceActions.js +2 -4
  116. package/lib/families/bitcoin/speculos-deviceActions.js.map +1 -1
  117. package/lib/families/cardano/js-estimateMaxSpendable.js +1 -1
  118. package/lib/families/cardano/js-estimateMaxSpendable.js.map +1 -1
  119. package/lib/families/cardano/specs.d.ts.map +1 -1
  120. package/lib/families/cardano/specs.js +19 -8
  121. package/lib/families/cardano/specs.js.map +1 -1
  122. package/lib/families/cardano/speculos-deviceActions.d.ts +1 -4
  123. package/lib/families/cardano/speculos-deviceActions.d.ts.map +1 -1
  124. package/lib/families/cardano/speculos-deviceActions.js +2 -2
  125. package/lib/families/cardano/speculos-deviceActions.js.map +1 -1
  126. package/lib/families/celo/specs.d.ts.map +1 -1
  127. package/lib/families/celo/specs.js +2 -0
  128. package/lib/families/celo/specs.js.map +1 -1
  129. package/lib/families/celo/speculos-deviceActions.d.ts +1 -4
  130. package/lib/families/celo/speculos-deviceActions.d.ts.map +1 -1
  131. package/lib/families/celo/speculos-deviceActions.js +2 -4
  132. package/lib/families/celo/speculos-deviceActions.js.map +1 -1
  133. package/lib/families/cosmos/specs.d.ts.map +1 -1
  134. package/lib/families/cosmos/specs.js +41 -25
  135. package/lib/families/cosmos/specs.js.map +1 -1
  136. package/lib/families/cosmos/speculos-deviceActions.d.ts +1 -4
  137. package/lib/families/cosmos/speculos-deviceActions.d.ts.map +1 -1
  138. package/lib/families/cosmos/speculos-deviceActions.js +2 -4
  139. package/lib/families/cosmos/speculos-deviceActions.js.map +1 -1
  140. package/lib/families/crypto_org/specs.d.ts.map +1 -1
  141. package/lib/families/crypto_org/specs.js +3 -0
  142. package/lib/families/crypto_org/specs.js.map +1 -1
  143. package/lib/families/crypto_org/speculos-deviceActions.d.ts +1 -4
  144. package/lib/families/crypto_org/speculos-deviceActions.d.ts.map +1 -1
  145. package/lib/families/crypto_org/speculos-deviceActions.js +2 -2
  146. package/lib/families/crypto_org/speculos-deviceActions.js.map +1 -1
  147. package/lib/families/elrond/specs.d.ts.map +1 -1
  148. package/lib/families/elrond/specs.js +15 -2
  149. package/lib/families/elrond/specs.js.map +1 -1
  150. package/lib/families/elrond/speculos-deviceActions.d.ts +1 -4
  151. package/lib/families/elrond/speculos-deviceActions.d.ts.map +1 -1
  152. package/lib/families/elrond/speculos-deviceActions.js +2 -4
  153. package/lib/families/elrond/speculos-deviceActions.js.map +1 -1
  154. package/lib/families/ethereum/platformAdapter.test.d.ts +2 -0
  155. package/lib/families/ethereum/platformAdapter.test.d.ts.map +1 -0
  156. package/lib/families/ethereum/platformAdapter.test.js +88 -0
  157. package/lib/families/ethereum/platformAdapter.test.js.map +1 -0
  158. package/lib/families/ethereum/specs.d.ts.map +1 -1
  159. package/lib/families/ethereum/specs.js +36 -12
  160. package/lib/families/ethereum/specs.js.map +1 -1
  161. package/lib/families/ethereum/speculos-deviceActions.d.ts +1 -4
  162. package/lib/families/ethereum/speculos-deviceActions.d.ts.map +1 -1
  163. package/lib/families/ethereum/speculos-deviceActions.js +2 -4
  164. package/lib/families/ethereum/speculos-deviceActions.js.map +1 -1
  165. package/lib/families/filecoin/specs.d.ts.map +1 -1
  166. package/lib/families/filecoin/specs.js +2 -0
  167. package/lib/families/filecoin/specs.js.map +1 -1
  168. package/lib/families/filecoin/speculos-deviceActions.d.ts +1 -4
  169. package/lib/families/filecoin/speculos-deviceActions.d.ts.map +1 -1
  170. package/lib/families/filecoin/speculos-deviceActions.js +2 -2
  171. package/lib/families/filecoin/speculos-deviceActions.js.map +1 -1
  172. package/lib/families/hedera/specs.d.ts.map +1 -1
  173. package/lib/families/hedera/specs.js +11 -3
  174. package/lib/families/hedera/specs.js.map +1 -1
  175. package/lib/families/hedera/speculos-deviceActions.d.ts +1 -4
  176. package/lib/families/hedera/speculos-deviceActions.d.ts.map +1 -1
  177. package/lib/families/hedera/speculos-deviceActions.js +4 -4
  178. package/lib/families/hedera/speculos-deviceActions.js.map +1 -1
  179. package/lib/families/osmosis/specs.d.ts.map +1 -1
  180. package/lib/families/osmosis/specs.js +13 -5
  181. package/lib/families/osmosis/specs.js.map +1 -1
  182. package/lib/families/osmosis/speculos-deviceActions.d.ts +1 -4
  183. package/lib/families/osmosis/speculos-deviceActions.d.ts.map +1 -1
  184. package/lib/families/osmosis/speculos-deviceActions.js +2 -4
  185. package/lib/families/osmosis/speculos-deviceActions.js.map +1 -1
  186. package/lib/families/polkadot/platformAdapter.test.d.ts +2 -0
  187. package/lib/families/polkadot/platformAdapter.test.d.ts.map +1 -0
  188. package/lib/families/polkadot/platformAdapter.test.js +51 -0
  189. package/lib/families/polkadot/platformAdapter.test.js.map +1 -0
  190. package/lib/families/polkadot/specs.d.ts.map +1 -1
  191. package/lib/families/polkadot/specs.js +12 -1
  192. package/lib/families/polkadot/specs.js.map +1 -1
  193. package/lib/families/polkadot/speculos-deviceActions.d.ts +1 -4
  194. package/lib/families/polkadot/speculos-deviceActions.d.ts.map +1 -1
  195. package/lib/families/polkadot/speculos-deviceActions.js +2 -4
  196. package/lib/families/polkadot/speculos-deviceActions.js.map +1 -1
  197. package/lib/families/ripple/platformAdapter.test.d.ts +2 -0
  198. package/lib/families/ripple/platformAdapter.test.d.ts.map +1 -0
  199. package/lib/families/ripple/platformAdapter.test.js +51 -0
  200. package/lib/families/ripple/platformAdapter.test.js.map +1 -0
  201. package/lib/families/ripple/specs.d.ts.map +1 -1
  202. package/lib/families/ripple/specs.js +9 -4
  203. package/lib/families/ripple/specs.js.map +1 -1
  204. package/lib/families/ripple/speculos-deviceActions.d.ts +1 -4
  205. package/lib/families/ripple/speculos-deviceActions.d.ts.map +1 -1
  206. package/lib/families/ripple/speculos-deviceActions.js +2 -4
  207. package/lib/families/ripple/speculos-deviceActions.js.map +1 -1
  208. package/lib/families/solana/specs.d.ts.map +1 -1
  209. package/lib/families/solana/specs.js +29 -11
  210. package/lib/families/solana/specs.js.map +1 -1
  211. package/lib/families/solana/speculos-deviceActions.d.ts +0 -5
  212. package/lib/families/solana/speculos-deviceActions.d.ts.map +1 -1
  213. package/lib/families/solana/speculos-deviceActions.js +0 -4
  214. package/lib/families/solana/speculos-deviceActions.js.map +1 -1
  215. package/lib/families/stellar/api/horizon.d.ts.map +1 -1
  216. package/lib/families/stellar/api/horizon.js +15 -10
  217. package/lib/families/stellar/api/horizon.js.map +1 -1
  218. package/lib/families/stellar/specs.d.ts.map +1 -1
  219. package/lib/families/stellar/specs.js +30 -12
  220. package/lib/families/stellar/specs.js.map +1 -1
  221. package/lib/families/stellar/speculos-deviceActions.d.ts +1 -4
  222. package/lib/families/stellar/speculos-deviceActions.d.ts.map +1 -1
  223. package/lib/families/stellar/speculos-deviceActions.js +2 -4
  224. package/lib/families/stellar/speculos-deviceActions.js.map +1 -1
  225. package/lib/families/tezos/bakers.whitelist-default.d.ts.map +1 -1
  226. package/lib/families/tezos/bakers.whitelist-default.js +1 -1
  227. package/lib/families/tezos/bakers.whitelist-default.js.map +1 -1
  228. package/lib/families/tezos/specs.d.ts.map +1 -1
  229. package/lib/families/tezos/specs.js +2 -0
  230. package/lib/families/tezos/specs.js.map +1 -1
  231. package/lib/families/tezos/speculos-deviceActions.d.ts +1 -4
  232. package/lib/families/tezos/speculos-deviceActions.d.ts.map +1 -1
  233. package/lib/families/tezos/speculos-deviceActions.js +2 -2
  234. package/lib/families/tezos/speculos-deviceActions.js.map +1 -1
  235. package/lib/families/tron/specs.d.ts.map +1 -1
  236. package/lib/families/tron/specs.js +49 -17
  237. package/lib/families/tron/specs.js.map +1 -1
  238. package/lib/families/tron/speculos-deviceActions.d.ts +1 -4
  239. package/lib/families/tron/speculos-deviceActions.d.ts.map +1 -1
  240. package/lib/families/tron/speculos-deviceActions.js +2 -4
  241. package/lib/families/tron/speculos-deviceActions.js.map +1 -1
  242. package/lib/hw/getGenuineCheckFromDeviceId.d.ts +22 -0
  243. package/lib/hw/getGenuineCheckFromDeviceId.d.ts.map +1 -0
  244. package/lib/hw/getGenuineCheckFromDeviceId.js +49 -0
  245. package/lib/hw/getGenuineCheckFromDeviceId.js.map +1 -0
  246. package/lib/hw/getGenuineCheckFromDeviceId.test.d.ts +2 -0
  247. package/lib/hw/getGenuineCheckFromDeviceId.test.d.ts.map +1 -0
  248. package/lib/hw/getGenuineCheckFromDeviceId.test.js +84 -0
  249. package/lib/hw/getGenuineCheckFromDeviceId.test.js.map +1 -0
  250. package/lib/hw/getLatestAvailableFirmwareFromDeviceId.d.ts +17 -0
  251. package/lib/hw/getLatestAvailableFirmwareFromDeviceId.d.ts.map +1 -0
  252. package/lib/hw/getLatestAvailableFirmwareFromDeviceId.js +27 -0
  253. package/lib/hw/getLatestAvailableFirmwareFromDeviceId.js.map +1 -0
  254. package/lib/hw/hooks/useGenuineCheck.d.ts +34 -0
  255. package/lib/hw/hooks/useGenuineCheck.d.ts.map +1 -0
  256. package/lib/hw/hooks/useGenuineCheck.js +115 -0
  257. package/lib/hw/hooks/useGenuineCheck.js.map +1 -0
  258. package/lib/hw/hooks/useGenuineCheck.test.d.ts +2 -0
  259. package/lib/hw/hooks/useGenuineCheck.test.d.ts.map +1 -0
  260. package/lib/hw/hooks/useGenuineCheck.test.js +316 -0
  261. package/lib/hw/hooks/useGenuineCheck.test.js.map +1 -0
  262. package/lib/hw/hooks/useGetLatestAvailableFirmware.d.ts +29 -0
  263. package/lib/hw/hooks/useGetLatestAvailableFirmware.d.ts.map +1 -0
  264. package/lib/hw/hooks/useGetLatestAvailableFirmware.js +72 -0
  265. package/lib/hw/hooks/useGetLatestAvailableFirmware.js.map +1 -0
  266. package/lib/hw/hooks/useGetLatestAvailableFirmware.test.d.ts +2 -0
  267. package/lib/hw/hooks/useGetLatestAvailableFirmware.test.d.ts.map +1 -0
  268. package/lib/hw/hooks/useGetLatestAvailableFirmware.test.js +155 -0
  269. package/lib/hw/hooks/useGetLatestAvailableFirmware.test.js.map +1 -0
  270. package/lib/load/speculos.d.ts +1 -0
  271. package/lib/load/speculos.d.ts.map +1 -1
  272. package/lib/load/speculos.js +2 -1
  273. package/lib/load/speculos.js.map +1 -1
  274. package/lib/mock/fixtures/cryptoCurrencies.d.ts +5 -0
  275. package/lib/mock/fixtures/cryptoCurrencies.d.ts.map +1 -0
  276. package/lib/mock/fixtures/cryptoCurrencies.js +91 -0
  277. package/lib/mock/fixtures/cryptoCurrencies.js.map +1 -0
  278. package/lib/platform/converters.test.js +44 -218
  279. package/lib/platform/converters.test.js.map +1 -1
  280. package/lib/platform/logic.d.ts +44 -0
  281. package/lib/platform/logic.d.ts.map +1 -1
  282. package/lib/platform/logic.js +147 -1
  283. package/lib/platform/logic.js.map +1 -1
  284. package/lib/platform/logic.test.d.ts +2 -0
  285. package/lib/platform/logic.test.d.ts.map +1 -0
  286. package/lib/platform/logic.test.js +903 -0
  287. package/lib/platform/logic.test.js.map +1 -0
  288. package/lib/platform/react.d.ts +6 -0
  289. package/lib/platform/react.d.ts.map +1 -1
  290. package/lib/platform/react.js +6 -0
  291. package/lib/platform/react.js.map +1 -1
  292. package/lib/platform/tracking.d.ts +1 -1
  293. package/lib/platform/tracking.d.ts.map +1 -1
  294. package/lib/platform/tracking.test.js +14 -41
  295. package/lib/platform/tracking.test.js.map +1 -1
  296. package/lib/reconciliation.d.ts.map +1 -1
  297. package/lib/reconciliation.js +28 -10
  298. package/lib/reconciliation.js.map +1 -1
  299. package/package.json +5 -6
  300. package/src/__tests__/families/bitcoin/wallet-btc/xpub.syncing.integration.test.ts +2 -2
  301. package/src/__tests__/test-helpers/environment.ts +91 -0
  302. package/src/__tests__/test-helpers/setup.ts +2 -91
  303. package/src/account/serialization.ts +103 -64
  304. package/src/bot/bot-test-context.test.ts +37 -0
  305. package/src/bot/bot-test-context.ts +24 -0
  306. package/src/bot/cli.ts +18 -0
  307. package/src/bot/engine.ts +109 -73
  308. package/src/bot/formatters.ts +40 -14
  309. package/src/bot/index.ts +124 -18
  310. package/src/bot/specs.ts +10 -5
  311. package/src/bot/types.ts +7 -3
  312. package/src/countervalues/logic.integration.test.ts +50 -0
  313. package/src/countervalues/modules/weth.ts +9 -12
  314. package/src/currencies/__snapshots__/sortByMarketcap.test.ts.snap +59 -1
  315. package/src/currencies/sortByMarketcap.test.ts +1 -12
  316. package/src/currencies/sortByMarketcap.ts +2 -22
  317. package/src/env.ts +1 -1
  318. package/src/families/algorand/__snapshots__/bridge.integration.test.ts.snap +733 -8
  319. package/src/families/algorand/specs.ts +26 -16
  320. package/src/families/algorand/speculos-deviceActions.ts +31 -10
  321. package/src/families/bitcoin/__snapshots__/bridge.integration.test.ts.snap +43309 -7957
  322. package/src/families/bitcoin/bridge/mock.ts +7 -1
  323. package/src/families/bitcoin/datasets/bitcoin_cash.ts +73 -13
  324. package/src/families/bitcoin/datasets/dash.ts +29 -17
  325. package/src/families/bitcoin/datasets/decred.ts +42 -12
  326. package/src/families/bitcoin/datasets/digibyte.ts +9 -3
  327. package/src/families/bitcoin/datasets/dogecoin.ts +29 -17
  328. package/src/families/bitcoin/datasets/komodo.ts +22 -22
  329. package/src/families/bitcoin/datasets/litecoin.ts +9 -3
  330. package/src/families/bitcoin/datasets/peercoin.ts +17 -17
  331. package/src/families/bitcoin/datasets/pivx.ts +17 -17
  332. package/src/families/bitcoin/datasets/qtum.ts +40 -40
  333. package/src/families/bitcoin/datasets/stakenet.ts +56 -26
  334. package/src/families/bitcoin/datasets/vertcoin.ts +43 -55
  335. package/src/families/bitcoin/datasets/viacoin.ts +35 -23
  336. package/src/families/bitcoin/datasets/zcash.ts +78 -12
  337. package/src/families/bitcoin/datasets/zencash.ts +56 -10
  338. package/src/families/bitcoin/platformAdapter.test.ts +58 -0
  339. package/src/families/bitcoin/specs.ts +81 -41
  340. package/src/families/bitcoin/speculos-deviceActions.ts +68 -69
  341. package/src/families/cardano/js-estimateMaxSpendable.ts +1 -1
  342. package/src/families/cardano/specs.ts +28 -11
  343. package/src/families/cardano/speculos-deviceActions.ts +65 -66
  344. package/src/families/celo/specs.ts +2 -0
  345. package/src/families/celo/speculos-deviceActions.ts +42 -43
  346. package/src/families/cosmos/__snapshots__/bridge.integration.test.ts.snap +246 -5
  347. package/src/families/cosmos/specs.ts +44 -28
  348. package/src/families/cosmos/speculos-deviceActions.ts +82 -83
  349. package/src/families/crypto_org/specs.ts +3 -0
  350. package/src/families/crypto_org/speculos-deviceActions.ts +58 -59
  351. package/src/families/elrond/specs.ts +21 -4
  352. package/src/families/elrond/speculos-deviceActions.ts +41 -42
  353. package/src/families/ethereum/__snapshots__/bridge.integration.test.ts.snap +90 -90
  354. package/src/families/ethereum/platformAdapter.test.ts +112 -0
  355. package/src/families/ethereum/specs.ts +47 -23
  356. package/src/families/ethereum/speculos-deviceActions.ts +93 -95
  357. package/src/families/filecoin/specs.ts +2 -1
  358. package/src/families/filecoin/speculos-deviceActions.ts +61 -62
  359. package/src/families/hedera/__snapshots__/bridge.integration.test.ts.snap +57 -2
  360. package/src/families/hedera/specs.ts +13 -5
  361. package/src/families/hedera/speculos-deviceActions.ts +59 -60
  362. package/src/families/osmosis/specs.ts +15 -7
  363. package/src/families/osmosis/speculos-deviceActions.ts +82 -83
  364. package/src/families/polkadot/platformAdapter.test.ts +61 -0
  365. package/src/families/polkadot/specs.ts +20 -2
  366. package/src/families/polkadot/speculos-deviceActions.ts +83 -82
  367. package/src/families/ripple/platformAdapter.test.ts +54 -0
  368. package/src/families/ripple/specs.ts +14 -7
  369. package/src/families/ripple/speculos-deviceActions.ts +72 -73
  370. package/src/families/solana/specs.ts +33 -14
  371. package/src/families/solana/speculos-deviceActions.ts +0 -5
  372. package/src/families/stellar/api/horizon.ts +10 -6
  373. package/src/families/stellar/specs.ts +37 -19
  374. package/src/families/stellar/speculos-deviceActions.ts +85 -87
  375. package/src/families/tezos/bakers.whitelist-default.ts +0 -1
  376. package/src/families/tezos/specs.ts +2 -0
  377. package/src/families/tezos/speculos-deviceActions.ts +76 -77
  378. package/src/families/tron/specs.ts +67 -30
  379. package/src/families/tron/speculos-deviceActions.ts +81 -84
  380. package/src/hw/getGenuineCheckFromDeviceId.test.ts +98 -0
  381. package/src/hw/getGenuineCheckFromDeviceId.ts +61 -0
  382. package/src/hw/getLatestAvailableFirmwareFromDeviceId.ts +37 -0
  383. package/src/hw/hooks/useGenuineCheck.test.ts +232 -0
  384. package/src/hw/hooks/useGenuineCheck.ts +138 -0
  385. package/src/hw/hooks/useGetLatestAvailableFirmware.test.ts +111 -0
  386. package/src/hw/hooks/useGetLatestAvailableFirmware.ts +90 -0
  387. package/src/load/speculos.ts +2 -0
  388. package/src/mock/fixtures/cryptoCurrencies.ts +88 -0
  389. package/src/platform/converters.test.ts +49 -282
  390. package/src/platform/logic.test.ts +756 -0
  391. package/src/platform/logic.ts +285 -0
  392. package/src/platform/react.ts +6 -0
  393. package/src/platform/tracking.test.ts +6 -7
  394. package/src/platform/tracking.ts +1 -1
  395. package/src/reconciliation.ts +66 -43
  396. package/lib/bot/test.bot.d.ts +0 -2
  397. package/lib/bot/test.bot.d.ts.map +0 -1
  398. package/lib/bot/test.bot.js +0 -62
  399. package/lib/bot/test.bot.js.map +0 -1
  400. package/lib/generated/speculos-deviceActions.d.ts +0 -56
  401. package/lib/generated/speculos-deviceActions.d.ts.map +0 -1
  402. package/lib/generated/speculos-deviceActions.js +0 -42
  403. package/lib/generated/speculos-deviceActions.js.map +0 -1
  404. package/src/bot/test.bot.ts +0 -21
  405. package/src/generated/speculos-deviceActions.ts +0 -37
@@ -794,20 +794,19 @@ export function fromAccountRaw(rawAccount: AccountRaw): Account {
794
794
  fromCosmosResourcesRaw(cosmosResourcesRaw);
795
795
  break;
796
796
  }
797
- case "tezos":
798
- {
799
- const tezosResourcesRaw = (rawAccount as TezosAccountRaw)
800
- .tezosResources;
801
- if (tezosResourcesRaw)
802
- (res as TezosAccount).tezosResources =
803
- fromTezosResourcesRaw(tezosResourcesRaw);
804
- }
797
+ case "tezos": {
798
+ const tezosResourcesRaw = (rawAccount as TezosAccountRaw).tezosResources;
799
+ if (tezosResourcesRaw)
800
+ (res as TezosAccount).tezosResources =
801
+ fromTezosResourcesRaw(tezosResourcesRaw);
805
802
  break;
803
+ }
806
804
  case "bitcoin": {
807
805
  const bitcoinResourcesRaw = (rawAccount as BitcoinAccountRaw)
808
806
  .bitcoinResources;
809
- (res as BitcoinAccount).bitcoinResources =
810
- fromBitcoinResourcesRaw(bitcoinResourcesRaw);
807
+ if (bitcoinResourcesRaw)
808
+ (res as BitcoinAccount).bitcoinResources =
809
+ fromBitcoinResourcesRaw(bitcoinResourcesRaw);
811
810
  break;
812
811
  }
813
812
  case "algorand": {
@@ -818,20 +817,17 @@ export function fromAccountRaw(rawAccount: AccountRaw): Account {
818
817
  fromAlgorandResourcesRaw(algoResourcesRaw);
819
818
  break;
820
819
  }
821
- case "polkadot":
822
- {
823
- const polkadotResourcesRaw = (rawAccount as PolkadotAccountRaw)
824
- .polkadotResources;
825
-
826
- if (polkadotResourcesRaw)
827
- (res as PolkadotAccount).polkadotResources =
828
- fromPolkadotResourcesRaw(polkadotResourcesRaw);
829
- }
820
+ case "polkadot": {
821
+ const polkadotResourcesRaw = (rawAccount as PolkadotAccountRaw)
822
+ .polkadotResources;
823
+ if (polkadotResourcesRaw)
824
+ (res as PolkadotAccount).polkadotResources =
825
+ fromPolkadotResourcesRaw(polkadotResourcesRaw);
830
826
  break;
827
+ }
831
828
  case "elrond": {
832
829
  const elrondResourcesRaw = (rawAccount as ElrondAccountRaw)
833
830
  .elrondResources;
834
-
835
831
  if (elrondResourcesRaw)
836
832
  (res as ElrondAccount).elrondResources =
837
833
  fromElrondResourcesRaw(elrondResourcesRaw);
@@ -942,61 +938,104 @@ export function toAccountRaw(account: Account): AccountRaw {
942
938
  }
943
939
 
944
940
  switch (account.currency.family) {
945
- case "tron":
946
- (res as TronAccountRaw).tronResources = toTronResourcesRaw(
947
- (account as TronAccount).tronResources
948
- );
941
+ case "tron": {
942
+ const tronAccount = account as TronAccount;
943
+ if (tronAccount.tronResources) {
944
+ (res as TronAccountRaw).tronResources = toTronResourcesRaw(
945
+ tronAccount.tronResources
946
+ );
947
+ }
949
948
  break;
950
- case "cosmos":
951
- (res as CosmosAccountRaw).cosmosResources = toCosmosResourcesRaw(
952
- (account as CosmosAccount).cosmosResources
953
- );
949
+ }
950
+ case "osmosis": {
951
+ const cosmosAccount = account as CosmosAccount;
952
+ if (cosmosAccount.cosmosResources) {
953
+ (res as CosmosAccountRaw).cosmosResources = toCosmosResourcesRaw(
954
+ cosmosAccount.cosmosResources
955
+ );
956
+ }
954
957
  break;
955
- case "osmosis":
956
- (res as CosmosAccountRaw).cosmosResources = toCosmosResourcesRaw(
957
- (account as CosmosAccount).cosmosResources
958
- );
958
+ }
959
+ case "cosmos": {
960
+ const cosmosAccount = account as CosmosAccount;
961
+ if (cosmosAccount.cosmosResources) {
962
+ (res as CosmosAccountRaw).cosmosResources = toCosmosResourcesRaw(
963
+ cosmosAccount.cosmosResources
964
+ );
965
+ }
959
966
  break;
960
- case "tezos":
961
- (res as TezosAccountRaw).tezosResources = toTezosResourcesRaw(
962
- (account as TezosAccount).tezosResources
963
- );
967
+ }
968
+ case "tezos": {
969
+ const tezosAccount = account as TezosAccount;
970
+ if (tezosAccount.tezosResources) {
971
+ (res as TezosAccountRaw).tezosResources = toTezosResourcesRaw(
972
+ tezosAccount.tezosResources
973
+ );
974
+ }
964
975
  break;
965
- case "bitcoin":
966
- (res as BitcoinAccountRaw).bitcoinResources = toBitcoinResourcesRaw(
967
- (account as BitcoinAccount).bitcoinResources
968
- );
976
+ }
977
+ case "bitcoin": {
978
+ const bitcoinAccount = account as BitcoinAccount;
979
+ if (bitcoinAccount.bitcoinResources) {
980
+ (res as BitcoinAccountRaw).bitcoinResources = toBitcoinResourcesRaw(
981
+ bitcoinAccount.bitcoinResources
982
+ );
983
+ }
969
984
  break;
970
- case "algorand":
971
- (res as AlgorandAccountRaw).algorandResources = toAlgorandResourcesRaw(
972
- (account as AlgorandAccount).algorandResources
973
- );
985
+ }
986
+ case "algorand": {
987
+ const algorandAccount = account as AlgorandAccount;
988
+ if (algorandAccount.algorandResources) {
989
+ (res as AlgorandAccountRaw).algorandResources = toAlgorandResourcesRaw(
990
+ algorandAccount.algorandResources
991
+ );
992
+ }
974
993
  break;
975
- case "polkadot":
976
- (res as PolkadotAccountRaw).polkadotResources = toPolkadotResourcesRaw(
977
- (account as PolkadotAccount).polkadotResources
978
- );
994
+ }
995
+ case "polkadot": {
996
+ const polkadotAccount = account as PolkadotAccount;
997
+ if (polkadotAccount.polkadotResources) {
998
+ (res as PolkadotAccountRaw).polkadotResources = toPolkadotResourcesRaw(
999
+ polkadotAccount.polkadotResources
1000
+ );
1001
+ }
979
1002
  break;
980
- case "elrond":
981
- (res as ElrondAccountRaw).elrondResources = toElrondResourcesRaw(
982
- (account as ElrondAccount).elrondResources
983
- );
1003
+ }
1004
+ case "elrond": {
1005
+ const elrondAccount = account as ElrondAccount;
1006
+ if (elrondAccount.elrondResources) {
1007
+ (res as ElrondAccountRaw).elrondResources = toElrondResourcesRaw(
1008
+ elrondAccount.elrondResources
1009
+ );
1010
+ }
984
1011
  break;
985
- case "cardano":
986
- (res as CardanoAccountRaw).cardanoResources = toCardanoResourceRaw(
987
- (account as CardanoAccount).cardanoResources
988
- );
1012
+ }
1013
+ case "cardano": {
1014
+ const cardanoAccount = account as CardanoAccount;
1015
+ if (cardanoAccount.cardanoResources) {
1016
+ (res as CardanoAccountRaw).cardanoResources = toCardanoResourceRaw(
1017
+ cardanoAccount.cardanoResources
1018
+ );
1019
+ }
989
1020
  break;
990
- case "solana":
991
- (res as SolanaAccountRaw).solanaResources = toSolanaResourcesRaw(
992
- (account as SolanaAccount).solanaResources
993
- );
1021
+ }
1022
+ case "solana": {
1023
+ const solanaAccount = account as SolanaAccount;
1024
+ if (solanaAccount.solanaResources) {
1025
+ (res as SolanaAccountRaw).solanaResources = toSolanaResourcesRaw(
1026
+ solanaAccount.solanaResources
1027
+ );
1028
+ }
994
1029
  break;
995
- case "crypto_org":
996
- (res as CryptoOrgAccountRaw).cryptoOrgResources = toCryptoOrgResourcesRaw(
997
- (account as CryptoOrgAccount).cryptoOrgResources
998
- );
1030
+ }
1031
+ case "crypto_org": {
1032
+ const crytpoOrgAccount = account as CryptoOrgAccount;
1033
+ if (crytpoOrgAccount.cryptoOrgResources) {
1034
+ (res as CryptoOrgAccountRaw).cryptoOrgResources =
1035
+ toCryptoOrgResourcesRaw(crytpoOrgAccount.cryptoOrgResources);
1036
+ }
999
1037
  break;
1038
+ }
1000
1039
  }
1001
1040
 
1002
1041
  if (swapHistory) {
@@ -0,0 +1,37 @@
1
+ import { botTest, getContext } from "./bot-test-context";
2
+ import { formatError } from "./formatters";
3
+
4
+ describe("test the botTest context itself", () => {
5
+ test("botTest", () => {
6
+ const f = () => {
7
+ try {
8
+ botTest("CTX", () => expect(true).toEqual(false));
9
+ } catch (e) {
10
+ return getContext(e);
11
+ }
12
+ };
13
+ expect(f()).toEqual("CTX");
14
+ });
15
+
16
+ test("double botTest", () => {
17
+ const f = () => {
18
+ try {
19
+ botTest("1", () => botTest("2", () => expect(true).toEqual(false)));
20
+ } catch (e) {
21
+ return getContext(e);
22
+ }
23
+ };
24
+ expect(f()).toEqual("1 > 2");
25
+ });
26
+
27
+ test("formatError", () => {
28
+ const f = () => {
29
+ try {
30
+ botTest("CTX", () => expect(true).toEqual(false));
31
+ } catch (e) {
32
+ return formatError(e);
33
+ }
34
+ };
35
+ expect(f()?.slice(0, 8)).toEqual("TEST CTX");
36
+ });
37
+ });
@@ -0,0 +1,24 @@
1
+ type EnhancedError = Error & {
2
+ _bot_context?: string[];
3
+ };
4
+
5
+ // This provides a botTest("description", () => {}) helper in order to give context in bot expect tests
6
+ export function botTest(description: string, f: () => void): void {
7
+ try {
8
+ f();
9
+ } catch (e) {
10
+ if (e instanceof Error) {
11
+ const err = e as EnhancedError;
12
+ err._bot_context = [description].concat(err._bot_context || []);
13
+ throw err;
14
+ }
15
+ throw e;
16
+ }
17
+ }
18
+
19
+ // retrieve the text context of a given error that was thrown from inside a botTest(...)
20
+ export function getContext(error: any): string | undefined {
21
+ if (error instanceof Error) {
22
+ return ((error as EnhancedError)._bot_context || []).join(" > ");
23
+ }
24
+ }
package/src/bot/cli.ts ADDED
@@ -0,0 +1,18 @@
1
+ import "../__tests__/test-helpers/environment";
2
+ import { bot } from ".";
3
+
4
+ const { BOT_FILTER_CURRENCY, BOT_FILTER_FAMILY } = process.env;
5
+ const arg: {
6
+ currency?: string;
7
+ family?: string;
8
+ } = {};
9
+
10
+ if (BOT_FILTER_CURRENCY) {
11
+ arg.currency = BOT_FILTER_CURRENCY;
12
+ }
13
+
14
+ if (BOT_FILTER_FAMILY) {
15
+ arg.family = BOT_FILTER_FAMILY;
16
+ }
17
+
18
+ bot(arg);
package/src/bot/engine.ts CHANGED
@@ -2,7 +2,7 @@ import expect from "expect";
2
2
  import invariant from "invariant";
3
3
  import now from "performance-now";
4
4
  import sample from "lodash/sample";
5
- import { throwError, of, Observable } from "rxjs";
5
+ import { throwError, of, Observable, OperatorFunction } from "rxjs";
6
6
  import {
7
7
  first,
8
8
  filter,
@@ -25,7 +25,6 @@ import {
25
25
  releaseSpeculosDevice,
26
26
  findAppCandidate,
27
27
  } from "../load/speculos";
28
- import deviceActions from "../generated/speculos-deviceActions";
29
28
  import type { AppCandidate } from "../load/speculos";
30
29
  import {
31
30
  formatReportForConsole,
@@ -50,8 +49,8 @@ import type {
50
49
  Operation,
51
50
  SignOperationEvent,
52
51
  } from "@ledgerhq/types-live";
53
- import type { CryptoCurrency } from "@ledgerhq/types-cryptoassets";
54
52
  import type { Transaction, TransactionStatus } from "../generated/types";
53
+ import { botTest } from "./bot-test-context";
55
54
 
56
55
  let appCandidates;
57
56
  const localCache = {};
@@ -120,17 +119,18 @@ export async function runWithAppSpec<T extends Transaction>(
120
119
 
121
120
  try {
122
121
  device = await createSpeculosDevice(deviceParams);
122
+ appReport.appPath = device.appPath;
123
123
  const bridge = getCurrencyBridge(currency);
124
124
  const syncConfig = {
125
125
  paginationConfig: {},
126
126
  };
127
127
  let t = now();
128
128
  const preloadedData = await cache.prepareCurrency(currency);
129
- const preloadTime = now() - t;
129
+ const preloadDuration = now() - t;
130
+ appReport.preloadDuration = preloadDuration;
130
131
  // Scan all existing accounts
132
+ const beforeScanTime = now();
131
133
  t = now();
132
- let scanTime = 0;
133
- const firstSyncDurations = {};
134
134
  let accounts = await bridge
135
135
  .scanAccounts({
136
136
  currency,
@@ -140,12 +140,6 @@ export async function runWithAppSpec<T extends Transaction>(
140
140
  .pipe(
141
141
  filter((e) => e.type === "discovered"),
142
142
  map((e) => e.account),
143
- tap((account) => {
144
- const dt = now() - t;
145
- firstSyncDurations[account.id] = dt;
146
- t = now();
147
- scanTime += dt;
148
- }),
149
143
  reduce<Account, Account[]>((all, a) => all.concat(a), []),
150
144
  timeoutWith(
151
145
  getEnv("BOT_TIMEOUT_SCAN_ACCOUNTS"),
@@ -155,7 +149,7 @@ export async function runWithAppSpec<T extends Transaction>(
155
149
  )
156
150
  )
157
151
  .toPromise();
158
- appReport.scanTime = scanTime;
152
+ appReport.scanDuration = now() - beforeScanTime;
159
153
  // "Migrate" the FIRST and every {crossAccountFrequency} account to simulate an export/import (same logic as export to mobile) – default to every 10
160
154
  // this is made a subset of the accounts to help identify problem that would be specific to the "cross" or not.
161
155
  for (
@@ -171,21 +165,13 @@ export async function runWithAppSpec<T extends Transaction>(
171
165
  "unexpected empty accounts for " + currency.name
172
166
  );
173
167
  const preloadStats =
174
- preloadTime > 10 ? ` (preload: ${formatTime(preloadTime)})` : "";
168
+ preloadDuration > 10 ? ` (preload: ${formatTime(preloadDuration)})` : "";
175
169
  reportLog(
176
170
  `Spec ${spec.name} found ${accounts.length} ${
177
171
  currency.name
178
172
  } accounts${preloadStats}. Will use ${formatAppCandidate(
179
173
  appCandidate as AppCandidate
180
- )}\n${accounts
181
- .map(
182
- (a) =>
183
- "(" +
184
- formatTime(firstSyncDurations[a.id] || 0) +
185
- ") " +
186
- formatAccount(a, "head")
187
- )
188
- .join("\n")}\n`
174
+ )}\n${accounts.map((a) => formatAccount(a, "head")).join("\n")}\n`
189
175
  );
190
176
 
191
177
  if (accounts.every(isAccountEmpty)) {
@@ -204,6 +190,8 @@ export async function runWithAppSpec<T extends Transaction>(
204
190
  // we sequentially iterate on the initial account set to perform mutations
205
191
  const length = accounts.length;
206
192
  const totalTries = spec.multipleRuns || 1;
193
+ // dynamic buffer with ids of accounts that need a resync (between runs)
194
+ let accountIdsNeedResync: string[] = [];
207
195
 
208
196
  for (let j = 0; j < totalTries; j++) {
209
197
  for (let i = 0; i < length; i++) {
@@ -211,15 +199,24 @@ export async function runWithAppSpec<T extends Transaction>(
211
199
  "engine",
212
200
  `spec ${spec.name} sync all accounts (try ${j} run ${i})`
213
201
  );
214
- // resync all accounts (necessary between mutations)
202
+ // resync all accounts that needs to be resynced
215
203
  t = now();
216
- accounts = await promiseAllBatched(
204
+
205
+ const resynced = await promiseAllBatched(
217
206
  getEnv("SYNC_MAX_CONCURRENT"),
218
- accounts,
207
+ accounts.filter((a) => accountIdsNeedResync.includes(a.id)),
219
208
  syncAccount
220
209
  );
210
+
211
+ accounts = accounts.map((a: Account) => {
212
+ const i = accountIdsNeedResync.indexOf(a.id);
213
+ return i !== -1 ? resynced[i] : a;
214
+ });
215
+
216
+ accountIdsNeedResync = [];
217
+
221
218
  appReport.accountsAfter = accounts;
222
- const syncAllAccountsTime = now() - t;
219
+ const resyncAccountsDuration = now() - t;
223
220
  const account = accounts[i];
224
221
  const report = await runOnAccount({
225
222
  appCandidate,
@@ -228,9 +225,20 @@ export async function runWithAppSpec<T extends Transaction>(
228
225
  account,
229
226
  accounts,
230
227
  mutationsCount,
231
- syncAllAccountsTime,
228
+ resyncAccountsDuration,
229
+ accountIdsNeedResync,
232
230
  preloadedData,
233
231
  });
232
+ if (report.finalAccount) {
233
+ // optim: no need to resync if all went well with finalAccount
234
+ const finalAccount: Account = report.finalAccount;
235
+ accountIdsNeedResync = accountIdsNeedResync.filter(
236
+ (id) => id !== finalAccount.id
237
+ );
238
+ accounts = accounts.map((a: Account) =>
239
+ a.id === finalAccount.id ? finalAccount : a
240
+ );
241
+ }
234
242
  // eslint-disable-next-line no-console
235
243
  console.log(formatReportForConsole(report));
236
244
  mutationReports.push(report);
@@ -261,7 +269,7 @@ export async function runWithAppSpec<T extends Transaction>(
261
269
  appReport.mutations = mutationReports;
262
270
  appReport.accountsAfter = accounts;
263
271
  } catch (e: any) {
264
- console.error(e);
272
+ if (process.env.CI) console.error(e);
265
273
  appReport.fatalError = e;
266
274
  log("engine", `spec ${spec.name} failed with ${String(e)}`);
267
275
  } finally {
@@ -277,8 +285,9 @@ export async function runOnAccount<T extends Transaction>({
277
285
  device,
278
286
  account,
279
287
  accounts,
288
+ accountIdsNeedResync,
280
289
  mutationsCount,
281
- syncAllAccountsTime,
290
+ resyncAccountsDuration,
282
291
  preloadedData,
283
292
  }: {
284
293
  appCandidate: any;
@@ -286,8 +295,9 @@ export async function runOnAccount<T extends Transaction>({
286
295
  device: any;
287
296
  account: any;
288
297
  accounts: any;
298
+ accountIdsNeedResync: string[];
289
299
  mutationsCount: Record<string, number>;
290
- syncAllAccountsTime: number;
300
+ resyncAccountsDuration: number;
291
301
  preloadedData: any;
292
302
  }): Promise<MutationReport<T>> {
293
303
  const { mutations } = spec;
@@ -295,7 +305,7 @@ export async function runOnAccount<T extends Transaction>({
295
305
  const report: MutationReport<T> = {
296
306
  spec,
297
307
  appCandidate,
298
- syncAllAccountsTime,
308
+ resyncAccountsDuration,
299
309
  };
300
310
 
301
311
  try {
@@ -348,7 +358,7 @@ export async function runOnAccount<T extends Transaction>({
348
358
  updates: r.updates,
349
359
  });
350
360
  } catch (error: any) {
351
- console.error(error);
361
+ if (process.env.CI) console.error(error);
352
362
  unavailableMutationReasons.push({
353
363
  mutation,
354
364
  error,
@@ -425,7 +435,11 @@ export async function runOnAccount<T extends Transaction>({
425
435
 
426
436
  // without recovering mechanism, we simply assume an error is a failure
427
437
  if (errors.length) {
428
- throw errors[0];
438
+ botTest("mutation must not have tx status errors", () => {
439
+ // all mutation must express transaction that are POSSIBLE
440
+ // recoveredFromTransactionStatus can also be used to solve this for tricky cases
441
+ throw errors[0];
442
+ });
429
443
  }
430
444
 
431
445
  mutationsCount[mutation.name] = (mutationsCount[mutation.name] || 0) + 1;
@@ -444,8 +458,7 @@ export async function runOnAccount<T extends Transaction>({
444
458
  }),
445
459
  autoSignTransaction({
446
460
  transport: device.transport,
447
- deviceAction:
448
- mutation.deviceAction || getImplicitDeviceAction(account.currency),
461
+ deviceAction: mutation.deviceAction || spec.genericDeviceAction,
449
462
  appCandidate,
450
463
  account,
451
464
  transaction,
@@ -462,19 +475,34 @@ export async function runOnAccount<T extends Transaction>({
462
475
  .toPromise();
463
476
  report.signedOperation = signedOperation;
464
477
  report.signedTime = now();
478
+
479
+ // at this stage, we are about to broadcast we assume we will need to resync receiver account
480
+ if (report.destination) {
481
+ accountIdsNeedResync.push(report.destination.id);
482
+ }
483
+ accountIdsNeedResync.push(account.id);
484
+
465
485
  // broadcast the transaction
466
486
  const optimisticOperation = getEnv("DISABLE_TRANSACTION_BROADCAST")
467
487
  ? signedOperation.operation
468
- : await accountBridge.broadcast({
469
- account,
470
- signedOperation,
471
- });
488
+ : await accountBridge
489
+ .broadcast({
490
+ account,
491
+ signedOperation,
492
+ })
493
+ .catch((e) => {
494
+ // wrap the error into some bot test context
495
+ botTest("during broadcast", () => {
496
+ throw e;
497
+ });
498
+ });
472
499
  report.optimisticOperation = optimisticOperation;
473
500
  report.broadcastedTime = now();
474
501
  log(
475
502
  "engine",
476
503
  `spec ${spec.name}/${account.name}/${optimisticOperation.hash} broadcasted`
477
504
  );
505
+
478
506
  // wait the condition are good (operation confirmed)
479
507
  const testBefore = now();
480
508
 
@@ -487,9 +515,11 @@ export async function runOnAccount<T extends Transaction>({
487
515
  );
488
516
 
489
517
  if (timedOut && !operation) {
490
- throw new Error(
491
- "could not find optimisticOperation " + optimisticOperation.id
492
- );
518
+ botTest("waiting operation id to appear after broadcast", () => {
519
+ throw new Error(
520
+ "could not find optimisticOperation " + optimisticOperation.id
521
+ );
522
+ });
493
523
  }
494
524
 
495
525
  if (operation) {
@@ -533,8 +563,8 @@ export async function runOnAccount<T extends Transaction>({
533
563
  `spec ${spec.name}/${account.name}/${optimisticOperation.hash} confirmed`
534
564
  );
535
565
  } catch (error: any) {
536
- console.error(error);
537
- log("mutation-error", spec.name + ": " + formatError(error));
566
+ if (process.env.CI) console.error(error);
567
+ log("mutation-error", spec.name + ": " + formatError(error, true));
538
568
  report.error = error;
539
569
  }
540
570
 
@@ -572,7 +602,7 @@ export function autoSignTransaction<T extends Transaction>({
572
602
  account: Account;
573
603
  transaction: T;
574
604
  status: TransactionStatus;
575
- }) {
605
+ }): OperatorFunction<SignOperationEvent, SignOperationEvent> {
576
606
  let sub;
577
607
  let observer;
578
608
  let state;
@@ -643,16 +673,6 @@ export function autoSignTransaction<T extends Transaction>({
643
673
  return of<SignOperationEvent>(e);
644
674
  });
645
675
  }
646
- export function getImplicitDeviceAction(currency: CryptoCurrency) {
647
- const actions = deviceActions[currency.family];
648
- const accept = actions && actions.acceptTransaction;
649
- invariant(
650
- accept,
651
- "a acceptTransaction is missing for family %s",
652
- currency.family
653
- );
654
- return accept;
655
- }
656
676
 
657
677
  function awaitAccountOperation({
658
678
  account,
@@ -667,6 +687,9 @@ function awaitAccountOperation({
667
687
  log("engine", "awaitAccountOperation on " + account.name);
668
688
  let syncCounter = 0;
669
689
  let acc = account;
690
+ let lastSync = now();
691
+ const loopDebounce = 1000;
692
+ const targetInterval = getEnv("SYNC_PENDING_INTERVAL");
670
693
 
671
694
  async function loop() {
672
695
  const operation = step(acc);
@@ -678,8 +701,10 @@ function awaitAccountOperation({
678
701
  operation,
679
702
  };
680
703
  }
704
+ const spent = now() - lastSync;
705
+ await delay(Math.max(loopDebounce, targetInterval - spent));
681
706
 
682
- await delay(5000);
707
+ lastSync = now();
683
708
  log("engine", "sync #" + syncCounter++ + " on " + account.name);
684
709
  acc = await syncAccount(acc);
685
710
  const r = await loop();
@@ -698,30 +723,41 @@ function transactionTest<T>({
698
723
  const timingThreshold = 30 * 60 * 1000;
699
724
  // FIXME: .valueOf to do arithmetic operations on date with typescript
700
725
  const dt = Date.now().valueOf() - operation.date.valueOf();
701
- invariant(dt > 0, "operation.date must not be in in future");
702
- expect(dt).toBeLessThan(timingThreshold);
703
- invariant(!operation.hasFailed, "operation has failed");
726
+ botTest("operation.date must not be in future", () =>
727
+ expect(dt).toBeGreaterThanOrEqual(0)
728
+ );
729
+ botTest("operation.date less than 30mn ago", () =>
730
+ expect(dt).toBeLessThan(timingThreshold)
731
+ );
732
+ botTest("operation must not failed", () => {
733
+ expect(!operation.hasFailed).toBe(true);
734
+ });
735
+
704
736
  const { blockAvgTime } = account.currency;
705
737
 
706
738
  if (blockAvgTime && account.blockHeight) {
707
739
  const expected = getOperationConfirmationNumber(operation, account);
708
740
  const expectedMax = Math.ceil(timingThreshold / blockAvgTime);
709
- invariant(
710
- expected <= expectedMax,
711
- "There are way too much operation confirmation for a small amount of time. %s < %s",
712
- expected,
713
- expectedMax
741
+ botTest("low amount of confirmations", () =>
742
+ invariant(
743
+ expected <= expectedMax,
744
+ "There are way too much operation confirmation for a small amount of time. %s < %s",
745
+ expected,
746
+ expectedMax
747
+ )
714
748
  );
715
749
  }
716
750
 
717
- invariant(
718
- !optimisticOperation.value.isNaN(),
719
- "optimisticOperation.value must not be NaN"
751
+ botTest("optimisticOperation.value must not be NaN", () =>
752
+ expect(!optimisticOperation.value.isNaN()).toBe(true)
720
753
  );
721
- invariant(
722
- !optimisticOperation.fee.isNaN(),
723
- "optimisticOperation.fee must not be NaN"
754
+ botTest("optimisticOperation.fee must not be NaN", () =>
755
+ expect(!optimisticOperation.fee.isNaN()).toBe(true)
756
+ );
757
+ botTest("operation.value must not be NaN", () =>
758
+ expect(!operation.value.isNaN()).toBe(true)
759
+ );
760
+ botTest("operation.fee must not be NaN", () =>
761
+ expect(!operation.fee.isNaN()).toBe(true)
724
762
  );
725
- invariant(!operation.value.isNaN(), "operation.value must not be NaN");
726
- invariant(!operation.fee.isNaN(), "operation.fee must not be NaN");
727
763
  }