movehat 0.1.9 → 0.2.1

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 (445) hide show
  1. package/README.md +132 -279
  2. package/dist/__tests__/deployContract.test.d.ts +2 -0
  3. package/dist/__tests__/deployContract.test.d.ts.map +1 -0
  4. package/dist/__tests__/deployContract.test.js +368 -0
  5. package/dist/__tests__/deployContract.test.js.map +1 -0
  6. package/dist/__tests__/errors.test.d.ts +2 -0
  7. package/dist/__tests__/errors.test.d.ts.map +1 -0
  8. package/dist/__tests__/errors.test.js +46 -0
  9. package/dist/__tests__/errors.test.js.map +1 -0
  10. package/dist/__tests__/fixtures/sigint-deploy-harness.d.ts +24 -0
  11. package/dist/__tests__/fixtures/sigint-deploy-harness.d.ts.map +1 -0
  12. package/dist/__tests__/fixtures/sigint-deploy-harness.js +82 -0
  13. package/dist/__tests__/fixtures/sigint-deploy-harness.js.map +1 -0
  14. package/dist/__tests__/fork/api.test.d.ts +2 -0
  15. package/dist/__tests__/fork/api.test.d.ts.map +1 -0
  16. package/dist/__tests__/fork/api.test.js +110 -0
  17. package/dist/__tests__/fork/api.test.js.map +1 -0
  18. package/dist/__tests__/harness/Harness.createLive.test.d.ts +2 -0
  19. package/dist/__tests__/harness/Harness.createLive.test.d.ts.map +1 -0
  20. package/dist/__tests__/harness/Harness.createLive.test.js +53 -0
  21. package/dist/__tests__/harness/Harness.createLive.test.js.map +1 -0
  22. package/dist/__tests__/harness/Harness.proxy.test.d.ts +2 -0
  23. package/dist/__tests__/harness/Harness.proxy.test.d.ts.map +1 -0
  24. package/dist/__tests__/harness/Harness.proxy.test.js +89 -0
  25. package/dist/__tests__/harness/Harness.proxy.test.js.map +1 -0
  26. package/dist/__tests__/harness/_fixture.d.ts +54 -0
  27. package/dist/__tests__/harness/_fixture.d.ts.map +1 -0
  28. package/dist/__tests__/harness/_fixture.js +69 -0
  29. package/dist/__tests__/harness/_fixture.js.map +1 -0
  30. package/dist/__tests__/harness/codeObject.deploy.test.d.ts +2 -0
  31. package/dist/__tests__/harness/codeObject.deploy.test.d.ts.map +1 -0
  32. package/dist/__tests__/harness/codeObject.deploy.test.js +288 -0
  33. package/dist/__tests__/harness/codeObject.deploy.test.js.map +1 -0
  34. package/dist/__tests__/harness/codeObject.upgrade.test.d.ts +2 -0
  35. package/dist/__tests__/harness/codeObject.upgrade.test.d.ts.map +1 -0
  36. package/dist/__tests__/harness/codeObject.upgrade.test.js +138 -0
  37. package/dist/__tests__/harness/codeObject.upgrade.test.js.map +1 -0
  38. package/dist/__tests__/harness/script.test.d.ts +2 -0
  39. package/dist/__tests__/harness/script.test.d.ts.map +1 -0
  40. package/dist/__tests__/harness/script.test.js +219 -0
  41. package/dist/__tests__/harness/script.test.js.map +1 -0
  42. package/dist/__tests__/harness/view.test.d.ts +2 -0
  43. package/dist/__tests__/harness/view.test.d.ts.map +1 -0
  44. package/dist/__tests__/harness/view.test.js +92 -0
  45. package/dist/__tests__/harness/view.test.js.map +1 -0
  46. package/dist/__tests__/runtime.test.d.ts +2 -0
  47. package/dist/__tests__/runtime.test.d.ts.map +1 -0
  48. package/dist/__tests__/runtime.test.js +141 -0
  49. package/dist/__tests__/runtime.test.js.map +1 -0
  50. package/dist/cli.js +2 -1
  51. package/dist/cli.js.map +1 -1
  52. package/dist/commands/__tests__/compile.test.d.ts +2 -0
  53. package/dist/commands/__tests__/compile.test.d.ts.map +1 -0
  54. package/dist/commands/__tests__/compile.test.js +351 -0
  55. package/dist/commands/__tests__/compile.test.js.map +1 -0
  56. package/dist/commands/__tests__/init.test.d.ts +2 -0
  57. package/dist/commands/__tests__/init.test.d.ts.map +1 -0
  58. package/dist/commands/__tests__/init.test.js +101 -0
  59. package/dist/commands/__tests__/init.test.js.map +1 -0
  60. package/dist/commands/__tests__/run.test.d.ts +2 -0
  61. package/dist/commands/__tests__/run.test.d.ts.map +1 -0
  62. package/dist/commands/__tests__/run.test.js +166 -0
  63. package/dist/commands/__tests__/run.test.js.map +1 -0
  64. package/dist/commands/__tests__/test-move.test.d.ts +2 -0
  65. package/dist/commands/__tests__/test-move.test.d.ts.map +1 -0
  66. package/dist/commands/__tests__/test-move.test.js +59 -0
  67. package/dist/commands/__tests__/test-move.test.js.map +1 -0
  68. package/dist/commands/__tests__/test.test.d.ts +2 -0
  69. package/dist/commands/__tests__/test.test.d.ts.map +1 -0
  70. package/dist/commands/__tests__/test.test.js +168 -0
  71. package/dist/commands/__tests__/test.test.js.map +1 -0
  72. package/dist/commands/__tests__/update.test.d.ts +2 -0
  73. package/dist/commands/__tests__/update.test.d.ts.map +1 -0
  74. package/dist/commands/__tests__/update.test.js +176 -0
  75. package/dist/commands/__tests__/update.test.js.map +1 -0
  76. package/dist/commands/compile.d.ts +7 -1
  77. package/dist/commands/compile.d.ts.map +1 -1
  78. package/dist/commands/compile.js +150 -33
  79. package/dist/commands/compile.js.map +1 -1
  80. package/dist/commands/fork/__tests__/create.test.d.ts +2 -0
  81. package/dist/commands/fork/__tests__/create.test.d.ts.map +1 -0
  82. package/dist/commands/fork/__tests__/create.test.js +108 -0
  83. package/dist/commands/fork/__tests__/create.test.js.map +1 -0
  84. package/dist/commands/fork/__tests__/fund.test.d.ts +2 -0
  85. package/dist/commands/fork/__tests__/fund.test.d.ts.map +1 -0
  86. package/dist/commands/fork/__tests__/fund.test.js +72 -0
  87. package/dist/commands/fork/__tests__/fund.test.js.map +1 -0
  88. package/dist/commands/fork/__tests__/list.test.d.ts +2 -0
  89. package/dist/commands/fork/__tests__/list.test.d.ts.map +1 -0
  90. package/dist/commands/fork/__tests__/list.test.js +119 -0
  91. package/dist/commands/fork/__tests__/list.test.js.map +1 -0
  92. package/dist/commands/fork/__tests__/serve.test.d.ts +2 -0
  93. package/dist/commands/fork/__tests__/serve.test.d.ts.map +1 -0
  94. package/dist/commands/fork/__tests__/serve.test.js +97 -0
  95. package/dist/commands/fork/__tests__/serve.test.js.map +1 -0
  96. package/dist/commands/fork/__tests__/view-resource.test.d.ts +2 -0
  97. package/dist/commands/fork/__tests__/view-resource.test.d.ts.map +1 -0
  98. package/dist/commands/fork/__tests__/view-resource.test.js +77 -0
  99. package/dist/commands/fork/__tests__/view-resource.test.js.map +1 -0
  100. package/dist/commands/fork/create.d.ts +1 -1
  101. package/dist/commands/fork/create.d.ts.map +1 -1
  102. package/dist/commands/fork/create.js +3 -2
  103. package/dist/commands/fork/create.js.map +1 -1
  104. package/dist/commands/fork/fund.d.ts.map +1 -1
  105. package/dist/commands/fork/fund.js +15 -8
  106. package/dist/commands/fork/fund.js.map +1 -1
  107. package/dist/commands/fork/list.d.ts.map +1 -1
  108. package/dist/commands/fork/list.js +2 -1
  109. package/dist/commands/fork/list.js.map +1 -1
  110. package/dist/commands/fork/serve.d.ts +1 -0
  111. package/dist/commands/fork/serve.d.ts.map +1 -1
  112. package/dist/commands/fork/serve.js +4 -2
  113. package/dist/commands/fork/serve.js.map +1 -1
  114. package/dist/commands/fork/view-resource.d.ts.map +1 -1
  115. package/dist/commands/fork/view-resource.js +10 -5
  116. package/dist/commands/fork/view-resource.js.map +1 -1
  117. package/dist/commands/run.d.ts +15 -0
  118. package/dist/commands/run.d.ts.map +1 -1
  119. package/dist/commands/run.js +50 -27
  120. package/dist/commands/run.js.map +1 -1
  121. package/dist/commands/test-move.d.ts.map +1 -1
  122. package/dist/commands/test-move.js +3 -2
  123. package/dist/commands/test-move.js.map +1 -1
  124. package/dist/commands/test.js +52 -46
  125. package/dist/commands/test.js.map +1 -1
  126. package/dist/commands/update.d.ts.map +1 -1
  127. package/dist/commands/update.js +15 -13
  128. package/dist/commands/update.js.map +1 -1
  129. package/dist/core/AccountManager.d.ts +1 -4
  130. package/dist/core/AccountManager.d.ts.map +1 -1
  131. package/dist/core/AccountManager.js +20 -12
  132. package/dist/core/AccountManager.js.map +1 -1
  133. package/dist/core/Publisher.d.ts +26 -0
  134. package/dist/core/Publisher.d.ts.map +1 -0
  135. package/dist/core/Publisher.js +240 -0
  136. package/dist/core/Publisher.js.map +1 -0
  137. package/dist/core/__tests__/AccountManager.test.d.ts +2 -0
  138. package/dist/core/__tests__/AccountManager.test.d.ts.map +1 -0
  139. package/dist/core/__tests__/AccountManager.test.js +239 -0
  140. package/dist/core/__tests__/AccountManager.test.js.map +1 -0
  141. package/dist/core/__tests__/config.test.d.ts +2 -0
  142. package/dist/core/__tests__/config.test.d.ts.map +1 -0
  143. package/dist/core/__tests__/config.test.js +311 -0
  144. package/dist/core/__tests__/config.test.js.map +1 -0
  145. package/dist/core/__tests__/deployments.test.d.ts +2 -0
  146. package/dist/core/__tests__/deployments.test.d.ts.map +1 -0
  147. package/dist/core/__tests__/deployments.test.js +201 -0
  148. package/dist/core/__tests__/deployments.test.js.map +1 -0
  149. package/dist/core/__tests__/shell.test.d.ts +2 -0
  150. package/dist/core/__tests__/shell.test.d.ts.map +1 -0
  151. package/dist/core/__tests__/shell.test.js +107 -0
  152. package/dist/core/__tests__/shell.test.js.map +1 -0
  153. package/dist/core/config.d.ts +13 -1
  154. package/dist/core/config.d.ts.map +1 -1
  155. package/dist/core/config.js +80 -11
  156. package/dist/core/config.js.map +1 -1
  157. package/dist/core/contract.d.ts +1 -4
  158. package/dist/core/contract.d.ts.map +1 -1
  159. package/dist/core/contract.js +15 -7
  160. package/dist/core/contract.js.map +1 -1
  161. package/dist/core/deployments.d.ts +2 -8
  162. package/dist/core/deployments.d.ts.map +1 -1
  163. package/dist/core/deployments.js +8 -18
  164. package/dist/core/deployments.js.map +1 -1
  165. package/dist/core/movementProfile.d.ts +34 -0
  166. package/dist/core/movementProfile.d.ts.map +1 -0
  167. package/dist/core/movementProfile.js +150 -0
  168. package/dist/core/movementProfile.js.map +1 -0
  169. package/dist/core/shell.d.ts +23 -7
  170. package/dist/core/shell.d.ts.map +1 -1
  171. package/dist/core/shell.js +32 -14
  172. package/dist/core/shell.js.map +1 -1
  173. package/dist/errors.d.ts +35 -0
  174. package/dist/errors.d.ts.map +1 -1
  175. package/dist/errors.js +54 -0
  176. package/dist/errors.js.map +1 -1
  177. package/dist/fork/__tests__/manager.test.d.ts +2 -0
  178. package/dist/fork/__tests__/manager.test.d.ts.map +1 -0
  179. package/dist/fork/__tests__/manager.test.js +309 -0
  180. package/dist/fork/__tests__/manager.test.js.map +1 -0
  181. package/dist/fork/__tests__/server.test.d.ts +2 -0
  182. package/dist/fork/__tests__/server.test.d.ts.map +1 -0
  183. package/dist/fork/__tests__/server.test.js +54 -0
  184. package/dist/fork/__tests__/server.test.js.map +1 -0
  185. package/dist/fork/__tests__/storage.test.d.ts +2 -0
  186. package/dist/fork/__tests__/storage.test.d.ts.map +1 -0
  187. package/dist/fork/__tests__/storage.test.js +222 -0
  188. package/dist/fork/__tests__/storage.test.js.map +1 -0
  189. package/dist/fork/__tests__/test.test.d.ts +2 -0
  190. package/dist/fork/__tests__/test.test.d.ts.map +1 -0
  191. package/dist/fork/__tests__/test.test.js +81 -0
  192. package/dist/fork/__tests__/test.test.js.map +1 -0
  193. package/dist/fork/api.d.ts +14 -3
  194. package/dist/fork/api.d.ts.map +1 -1
  195. package/dist/fork/api.js +25 -14
  196. package/dist/fork/api.js.map +1 -1
  197. package/dist/fork/manager.d.ts +23 -29
  198. package/dist/fork/manager.d.ts.map +1 -1
  199. package/dist/fork/manager.js +79 -76
  200. package/dist/fork/manager.js.map +1 -1
  201. package/dist/fork/server.d.ts +11 -3
  202. package/dist/fork/server.d.ts.map +1 -1
  203. package/dist/fork/server.js +45 -13
  204. package/dist/fork/server.js.map +1 -1
  205. package/dist/fork/storage.d.ts +4 -4
  206. package/dist/fork/storage.d.ts.map +1 -1
  207. package/dist/fork/storage.js +7 -9
  208. package/dist/fork/storage.js.map +1 -1
  209. package/dist/fork/test.d.ts +12 -4
  210. package/dist/fork/test.d.ts.map +1 -1
  211. package/dist/fork/test.js +36 -27
  212. package/dist/fork/test.js.map +1 -1
  213. package/dist/harness/Harness.d.ts +118 -0
  214. package/dist/harness/Harness.d.ts.map +1 -0
  215. package/dist/harness/Harness.js +187 -0
  216. package/dist/harness/Harness.js.map +1 -0
  217. package/dist/harness/codeObject.d.ts +31 -0
  218. package/dist/harness/codeObject.d.ts.map +1 -0
  219. package/dist/harness/codeObject.js +267 -0
  220. package/dist/harness/codeObject.js.map +1 -0
  221. package/dist/harness/errors.d.ts +14 -0
  222. package/dist/harness/errors.d.ts.map +1 -0
  223. package/dist/harness/errors.js +22 -0
  224. package/dist/harness/errors.js.map +1 -0
  225. package/dist/harness/index.d.ts +4 -0
  226. package/dist/harness/index.d.ts.map +1 -0
  227. package/dist/harness/index.js +3 -0
  228. package/dist/harness/index.js.map +1 -0
  229. package/dist/harness/proxy.d.ts +7 -0
  230. package/dist/harness/proxy.d.ts.map +1 -0
  231. package/dist/harness/proxy.js +36 -0
  232. package/dist/harness/proxy.js.map +1 -0
  233. package/dist/harness/script.d.ts +21 -0
  234. package/dist/harness/script.d.ts.map +1 -0
  235. package/dist/harness/script.js +155 -0
  236. package/dist/harness/script.js.map +1 -0
  237. package/dist/harness/view.d.ts +22 -0
  238. package/dist/harness/view.d.ts.map +1 -0
  239. package/dist/harness/view.js +28 -0
  240. package/dist/harness/view.js.map +1 -0
  241. package/dist/helpers/__tests__/semver-utils.test.d.ts +2 -0
  242. package/dist/helpers/__tests__/semver-utils.test.d.ts.map +1 -0
  243. package/dist/helpers/__tests__/semver-utils.test.js +103 -0
  244. package/dist/helpers/__tests__/semver-utils.test.js.map +1 -0
  245. package/dist/helpers/index.d.ts +3 -2
  246. package/dist/helpers/index.d.ts.map +1 -1
  247. package/dist/helpers/index.js +2 -2
  248. package/dist/helpers/index.js.map +1 -1
  249. package/dist/helpers/move-tests.d.ts +3 -3
  250. package/dist/helpers/move-tests.d.ts.map +1 -1
  251. package/dist/helpers/move-tests.js +21 -20
  252. package/dist/helpers/move-tests.js.map +1 -1
  253. package/dist/helpers/npm-registry.d.ts.map +1 -1
  254. package/dist/helpers/npm-registry.js +1 -3
  255. package/dist/helpers/npm-registry.js.map +1 -1
  256. package/dist/helpers/semver-utils.d.ts.map +1 -1
  257. package/dist/helpers/semver-utils.js +4 -3
  258. package/dist/helpers/semver-utils.js.map +1 -1
  259. package/dist/helpers/setup.d.ts.map +1 -1
  260. package/dist/helpers/setup.js +6 -4
  261. package/dist/helpers/setup.js.map +1 -1
  262. package/dist/helpers/setupLocalTesting.d.ts +31 -27
  263. package/dist/helpers/setupLocalTesting.d.ts.map +1 -1
  264. package/dist/helpers/setupLocalTesting.js +179 -180
  265. package/dist/helpers/setupLocalTesting.js.map +1 -1
  266. package/dist/helpers/testFixtures.d.ts +19 -53
  267. package/dist/helpers/testFixtures.d.ts.map +1 -1
  268. package/dist/helpers/testFixtures.js +89 -107
  269. package/dist/helpers/testFixtures.js.map +1 -1
  270. package/dist/index.d.ts +4 -2
  271. package/dist/index.d.ts.map +1 -1
  272. package/dist/index.js +6 -3
  273. package/dist/index.js.map +1 -1
  274. package/dist/node/LocalNodeManager.d.ts +9 -1
  275. package/dist/node/LocalNodeManager.d.ts.map +1 -1
  276. package/dist/node/LocalNodeManager.js +75 -58
  277. package/dist/node/LocalNodeManager.js.map +1 -1
  278. package/dist/node/__tests__/LocalNodeManager.test.d.ts +2 -0
  279. package/dist/node/__tests__/LocalNodeManager.test.d.ts.map +1 -0
  280. package/dist/node/__tests__/LocalNodeManager.test.js +349 -0
  281. package/dist/node/__tests__/LocalNodeManager.test.js.map +1 -0
  282. package/dist/runtime.d.ts +12 -15
  283. package/dist/runtime.d.ts.map +1 -1
  284. package/dist/runtime.js +26 -239
  285. package/dist/runtime.js.map +1 -1
  286. package/dist/templates/README.md +1 -1
  287. package/dist/templates/movehat.config.ts +10 -0
  288. package/dist/templates/package.json +2 -1
  289. package/dist/templates/scripts/deploy-counter.ts +46 -38
  290. package/dist/templates/tests/Counter.test.ts +39 -51
  291. package/dist/templates/types/movehat.d.ts +6 -9
  292. package/dist/types/config.d.ts +8 -0
  293. package/dist/types/config.d.ts.map +1 -1
  294. package/dist/types/fork.d.ts +7 -1
  295. package/dist/types/fork.d.ts.map +1 -1
  296. package/dist/types/harness.d.ts +166 -0
  297. package/dist/types/harness.d.ts.map +1 -0
  298. package/dist/types/harness.js +2 -0
  299. package/dist/types/harness.js.map +1 -0
  300. package/dist/types/runtime.d.ts +7 -1
  301. package/dist/types/runtime.d.ts.map +1 -1
  302. package/dist/ui/__tests__/colors.test.d.ts +2 -0
  303. package/dist/ui/__tests__/colors.test.d.ts.map +1 -0
  304. package/dist/ui/__tests__/colors.test.js +127 -0
  305. package/dist/ui/__tests__/colors.test.js.map +1 -0
  306. package/dist/ui/colors.d.ts.map +1 -1
  307. package/dist/ui/colors.js +6 -2
  308. package/dist/ui/colors.js.map +1 -1
  309. package/dist/ui/logger.d.ts +17 -0
  310. package/dist/ui/logger.d.ts.map +1 -1
  311. package/dist/ui/logger.js +22 -0
  312. package/dist/ui/logger.js.map +1 -1
  313. package/dist/ui/symbols.d.ts +1 -0
  314. package/dist/ui/symbols.d.ts.map +1 -1
  315. package/dist/ui/symbols.js +7 -1
  316. package/dist/ui/symbols.js.map +1 -1
  317. package/dist/utils/__tests__/address.test.d.ts +2 -0
  318. package/dist/utils/__tests__/address.test.d.ts.map +1 -0
  319. package/dist/utils/__tests__/address.test.js +70 -0
  320. package/dist/utils/__tests__/address.test.js.map +1 -0
  321. package/dist/utils/__tests__/childProcessAdapter.test.d.ts +2 -0
  322. package/dist/utils/__tests__/childProcessAdapter.test.d.ts.map +1 -0
  323. package/dist/utils/__tests__/childProcessAdapter.test.js +217 -0
  324. package/dist/utils/__tests__/childProcessAdapter.test.js.map +1 -0
  325. package/dist/utils/__tests__/runCli.test.d.ts +2 -0
  326. package/dist/utils/__tests__/runCli.test.d.ts.map +1 -0
  327. package/dist/utils/__tests__/runCli.test.js +187 -0
  328. package/dist/utils/__tests__/runCli.test.js.map +1 -0
  329. package/dist/utils/address.d.ts +29 -0
  330. package/dist/utils/address.d.ts.map +1 -0
  331. package/dist/utils/address.js +48 -0
  332. package/dist/utils/address.js.map +1 -0
  333. package/dist/utils/childProcessAdapter.d.ts +93 -0
  334. package/dist/utils/childProcessAdapter.d.ts.map +1 -0
  335. package/dist/utils/childProcessAdapter.js +108 -0
  336. package/dist/utils/childProcessAdapter.js.map +1 -0
  337. package/dist/utils/parseCliOutput.d.ts +20 -0
  338. package/dist/utils/parseCliOutput.d.ts.map +1 -0
  339. package/dist/utils/parseCliOutput.js +26 -0
  340. package/dist/utils/parseCliOutput.js.map +1 -0
  341. package/dist/utils/redact.d.ts +15 -0
  342. package/dist/utils/redact.d.ts.map +1 -0
  343. package/dist/utils/redact.js +24 -0
  344. package/dist/utils/redact.js.map +1 -0
  345. package/dist/utils/runCli.d.ts +24 -0
  346. package/dist/utils/runCli.d.ts.map +1 -0
  347. package/dist/utils/runCli.js +37 -0
  348. package/dist/utils/runCli.js.map +1 -0
  349. package/package.json +15 -4
  350. package/src/__tests__/deployContract.test.ts +429 -0
  351. package/src/__tests__/errors.test.ts +84 -0
  352. package/src/__tests__/fixtures/sigint-deploy-harness.ts +95 -0
  353. package/src/__tests__/fork/api.test.ts +143 -0
  354. package/src/__tests__/harness/Harness.createLive.test.ts +57 -0
  355. package/src/__tests__/harness/Harness.proxy.test.ts +111 -0
  356. package/src/__tests__/harness/_fixture.ts +131 -0
  357. package/src/__tests__/harness/codeObject.deploy.test.ts +319 -0
  358. package/src/__tests__/harness/codeObject.upgrade.test.ts +156 -0
  359. package/src/__tests__/harness/script.test.ts +245 -0
  360. package/src/__tests__/harness/view.test.ts +104 -0
  361. package/src/__tests__/runtime.test.ts +182 -0
  362. package/src/cli.ts +2 -1
  363. package/src/commands/__tests__/compile.test.ts +407 -0
  364. package/src/commands/__tests__/init.test.ts +125 -0
  365. package/src/commands/__tests__/run.test.ts +192 -0
  366. package/src/commands/__tests__/test-move.test.ts +81 -0
  367. package/src/commands/__tests__/test.test.ts +204 -0
  368. package/src/commands/__tests__/update.test.ts +223 -0
  369. package/src/commands/compile.ts +168 -32
  370. package/src/commands/fork/__tests__/create.test.ts +132 -0
  371. package/src/commands/fork/__tests__/fund.test.ts +104 -0
  372. package/src/commands/fork/__tests__/list.test.ts +139 -0
  373. package/src/commands/fork/__tests__/serve.test.ts +121 -0
  374. package/src/commands/fork/__tests__/view-resource.test.ts +101 -0
  375. package/src/commands/fork/create.ts +4 -3
  376. package/src/commands/fork/fund.ts +16 -9
  377. package/src/commands/fork/list.ts +3 -2
  378. package/src/commands/fork/serve.ts +6 -3
  379. package/src/commands/fork/view-resource.ts +11 -6
  380. package/src/commands/run.ts +54 -28
  381. package/src/commands/test-move.ts +4 -3
  382. package/src/commands/test.ts +56 -44
  383. package/src/commands/update.ts +19 -16
  384. package/src/core/AccountManager.ts +23 -22
  385. package/src/core/Publisher.ts +314 -0
  386. package/src/core/__tests__/AccountManager.test.ts +290 -0
  387. package/src/core/__tests__/config.test.ts +377 -0
  388. package/src/core/__tests__/deployments.test.ts +247 -0
  389. package/src/core/__tests__/shell.test.ts +138 -0
  390. package/src/core/config.ts +96 -12
  391. package/src/core/contract.ts +13 -7
  392. package/src/core/deployments.ts +13 -23
  393. package/src/core/movementProfile.ts +179 -0
  394. package/src/core/shell.ts +34 -14
  395. package/src/errors.ts +60 -0
  396. package/src/fork/__tests__/manager.test.ts +385 -0
  397. package/src/fork/__tests__/server.test.ts +65 -0
  398. package/src/fork/__tests__/storage.test.ts +281 -0
  399. package/src/fork/__tests__/test.test.ts +97 -0
  400. package/src/fork/api.ts +28 -14
  401. package/src/fork/manager.ts +88 -83
  402. package/src/fork/server.ts +53 -19
  403. package/src/fork/storage.ts +12 -15
  404. package/src/fork/test.ts +57 -32
  405. package/src/harness/Harness.ts +222 -0
  406. package/src/harness/codeObject.ts +384 -0
  407. package/src/harness/errors.ts +22 -0
  408. package/src/harness/index.ts +3 -0
  409. package/src/harness/proxy.ts +40 -0
  410. package/src/harness/script.ts +196 -0
  411. package/src/harness/view.ts +34 -0
  412. package/src/helpers/__tests__/semver-utils.test.ts +121 -0
  413. package/src/helpers/index.ts +2 -8
  414. package/src/helpers/move-tests.ts +27 -23
  415. package/src/helpers/npm-registry.ts +4 -3
  416. package/src/helpers/semver-utils.ts +4 -3
  417. package/src/helpers/setup.ts +6 -4
  418. package/src/helpers/setupLocalTesting.ts +218 -200
  419. package/src/helpers/testFixtures.ts +106 -118
  420. package/src/index.ts +8 -3
  421. package/src/node/LocalNodeManager.ts +87 -62
  422. package/src/node/__tests__/LocalNodeManager.test.ts +452 -0
  423. package/src/runtime.ts +28 -288
  424. package/src/templates/README.md +1 -1
  425. package/src/templates/movehat.config.ts +10 -0
  426. package/src/templates/package.json +2 -1
  427. package/src/templates/scripts/deploy-counter.ts +46 -38
  428. package/src/templates/tests/Counter.test.ts +39 -51
  429. package/src/templates/types/movehat.d.ts +6 -9
  430. package/src/types/config.ts +8 -0
  431. package/src/types/fork.ts +7 -1
  432. package/src/types/harness.ts +182 -0
  433. package/src/types/runtime.ts +11 -3
  434. package/src/ui/__tests__/colors.test.ts +156 -0
  435. package/src/ui/colors.ts +5 -2
  436. package/src/ui/logger.ts +22 -0
  437. package/src/ui/symbols.ts +7 -1
  438. package/src/utils/__tests__/address.test.ts +93 -0
  439. package/src/utils/__tests__/childProcessAdapter.test.ts +266 -0
  440. package/src/utils/__tests__/runCli.test.ts +240 -0
  441. package/src/utils/address.ts +52 -0
  442. package/src/utils/childProcessAdapter.ts +214 -0
  443. package/src/utils/parseCliOutput.ts +27 -0
  444. package/src/utils/redact.ts +24 -0
  445. package/src/utils/runCli.ts +64 -0
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=test.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.test.d.ts","sourceRoot":"","sources":["../../../src/fork/__tests__/test.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,81 @@
1
+ import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2
+ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { snapshot, viewForkResource } from '../test.js';
6
+ /**
7
+ * Guards the exitCode-failure path that CodeRabbit flagged on PR #100:
8
+ * before this hardening, an `aptos` command that exited non-zero with a
9
+ * stderr containing the word "Success" (or no stderr at all) could slip
10
+ * past the stderr-defense check in `snapshot`, and a non-JSON stderr from
11
+ * `view-resource` produced a cryptic JSON parse error instead of the
12
+ * actual aptos failure.
13
+ */
14
+ describe('fork/test — exitCode failure paths', () => {
15
+ let tmpCwd;
16
+ let origCwd;
17
+ beforeEach(() => {
18
+ tmpCwd = mkdtempSync(join(tmpdir(), 'movehat-fork-test-'));
19
+ origCwd = process.cwd();
20
+ process.chdir(tmpCwd);
21
+ });
22
+ afterEach(() => {
23
+ try {
24
+ process.chdir(origCwd);
25
+ }
26
+ finally {
27
+ rmSync(tmpCwd, { recursive: true, force: true });
28
+ }
29
+ });
30
+ function adapterReturning(result) {
31
+ return {
32
+ async run() {
33
+ return result;
34
+ },
35
+ spawn() {
36
+ throw new Error('spawn not used in fork/test failure-path tests');
37
+ },
38
+ };
39
+ }
40
+ it("snapshot throws on non-zero exit even when stderr contains 'Success'", async () => {
41
+ // The pre-fix edge case: aptos exits 1, stderr says
42
+ // "Failed: Success criteria not met" → the stderr.includes('Success')
43
+ // gate returned false-positive ok, and a stale directory from a prior
44
+ // run would mask the failure entirely.
45
+ const adapter = adapterReturning({
46
+ exitCode: 1,
47
+ stdout: '',
48
+ stderr: 'Failed: Success criteria not met for snapshot init',
49
+ });
50
+ await expect(snapshot({ name: 'edge', adapter })).rejects.toThrow(/Success criteria not met/);
51
+ });
52
+ it('snapshot still throws when a stale directory from a prior run exists (the full edge case)', async () => {
53
+ // The pre-fix combined edge case: aptos exits non-zero, stderr happens
54
+ // to contain "Success" (so the stderr.includes('Success') gate would
55
+ // false-positive), AND the snapshot directory already exists from a
56
+ // previous successful run (so the existsSync check would false-positive
57
+ // too). The new exitCode check fires first and throws regardless.
58
+ const stalePath = join(tmpCwd, '.movehat', 'snapshots', 'stale');
59
+ mkdirSync(stalePath, { recursive: true });
60
+ writeFileSync(join(stalePath, 'config.json'), '{}');
61
+ const adapter = adapterReturning({
62
+ exitCode: 1,
63
+ stdout: '',
64
+ stderr: 'Failed but Success was nearby',
65
+ });
66
+ await expect(snapshot({ name: 'stale', path: stalePath, adapter })).rejects.toThrow(/Failed but Success was nearby/);
67
+ });
68
+ it('viewForkResource throws on non-zero exit with non-JSON stderr (informative message)', async () => {
69
+ // Pre-fix the failure surfaced as "Unexpected token ..." from
70
+ // JSON.parse, which obscured the actual aptos error.
71
+ const adapter = adapterReturning({
72
+ exitCode: 1,
73
+ stdout: '',
74
+ stderr: 'Error: session not found',
75
+ });
76
+ await expect(viewForkResource('/nonexistent/session', '0x1', '0x1::coin::CoinStore', {
77
+ adapter,
78
+ })).rejects.toThrow(/session not found/);
79
+ });
80
+ });
81
+ //# sourceMappingURL=test.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"test.test.js","sourceRoot":"","sources":["../../../src/fork/__tests__/test.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACrE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAGxD;;;;;;;GAOG;AACH,QAAQ,CAAC,oCAAoC,EAAE,GAAG,EAAE;IAClD,IAAI,MAAc,CAAC;IACnB,IAAI,OAAe,CAAC;IAEpB,UAAU,CAAC,GAAG,EAAE;QACd,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,MAAM,EAAE,EAAE,oBAAoB,CAAC,CAAC,CAAC;QAC3D,OAAO,GAA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AE,CAAC,CAAC;QAC1C,aAAa,CAAC,IAAI,CAAC,SAAS,EAAE,aAAa,CAAC,EAAE,IAAI,CAAC,CAAC;QAEpD,MAAM,OAAO,GAAG,gBAAgB,CAAC;YAC/B,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,+BAA+B;SACxC,CAAC,CAAC;QAEH,MAAM,MAAM,CACV,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,CACtD,CAAC,OAAO,CAAC,OAAO,CAAC,+BAA+B,CAAC,CAAC;IACrD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,qFAAqF,EAAE,KAAK,IAAI,EAAE;QACnG,8DAA8D;QAC9D,qDAAqD;QACrD,MAAM,OAAO,GAAG,gBAAgB,CAAC;YAC/B,QAAQ,EAAE,CAAC;YACX,MAAM,EAAE,EAAE;YACV,MAAM,EAAE,0BAA0B;SACnC,CAAC,CAAC;QAEH,MAAM,MAAM,CACV,gBAAgB,CAAC,sBAAsB,EAAE,KAAK,EAAE,sBAAsB,EAAE;YACtE,OAAO;SACR,CAAC,CACH,CAAC,OAAO,CAAC,OAAO,CAAC,mBAAmB,CAAC,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,12 +1,23 @@
1
1
  import type { LedgerInfo, AccountData, AccountResource } from '../types/fork.js';
2
2
  /**
3
- * Client for interacting with Movement/Aptos-compatible JSON API
3
+ * Client for interacting with Movement L1 JSON API.
4
+ *
5
+ * When constructed with an `apiKey`, every outgoing request carries
6
+ * an `Authorization: Bearer <apiKey>` header. Use this for rate-
7
+ * limited public endpoints (e.g. Movement testnet under load) or
8
+ * auth-gated nodes.
4
9
  */
5
10
  export declare class MovementApiClient {
6
11
  private nodeUrl;
7
- constructor(nodeUrl: string);
12
+ private readonly apiKey?;
13
+ constructor(nodeUrl: string, apiKey?: string);
8
14
  /**
9
- * Make a GET request to the API
15
+ * Make a GET request to the API.
16
+ *
17
+ * Adds `Authorization: Bearer <apiKey>` when the client was
18
+ * constructed with an `apiKey`. The header is omitted otherwise
19
+ * to preserve backwards-compatible behavior for unauthenticated
20
+ * public endpoints.
10
21
  */
11
22
  private get;
12
23
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/fork/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEjF;;GAEG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAS;gBAEZ,OAAO,EAAE,MAAM;IAa3B;;OAEG;YACW,GAAG;IAqCjB;;OAEG;IACH,OAAO,CAAC,OAAO;IAMf;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC;IAI1C;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IASvD;;OAEG;IACG,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAW7E;;OAEG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;CAOvE"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/fork/api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAGjF;;;;;;;GAOG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAS;gBAErB,OAAO,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM;IAc5C;;;;;;;OAOG;YACW,GAAG;IA6CjB;;OAEG;IACH,OAAO,CAAC,OAAO;IAMf;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,UAAU,CAAC;IAI1C;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAMvD;;OAEG;IACG,kBAAkB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAS7E;;OAEG;IACG,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,eAAe,EAAE,CAAC;CAKvE"}
package/dist/fork/api.js CHANGED
@@ -1,12 +1,19 @@
1
1
  import https from 'https';
2
2
  import http from 'http';
3
3
  import { URL } from 'url';
4
+ import { normalizeAddressShort } from '../utils/address.js';
4
5
  /**
5
- * Client for interacting with Movement/Aptos-compatible JSON API
6
+ * Client for interacting with Movement L1 JSON API.
7
+ *
8
+ * When constructed with an `apiKey`, every outgoing request carries
9
+ * an `Authorization: Bearer <apiKey>` header. Use this for rate-
10
+ * limited public endpoints (e.g. Movement testnet under load) or
11
+ * auth-gated nodes.
6
12
  */
7
13
  export class MovementApiClient {
8
14
  nodeUrl;
9
- constructor(nodeUrl) {
15
+ apiKey;
16
+ constructor(nodeUrl, apiKey) {
10
17
  // Remove trailing slash
11
18
  let normalized = nodeUrl.replace(/\/$/, '');
12
19
  // If URL already ends with /v1, use as is
@@ -15,17 +22,28 @@ export class MovementApiClient {
15
22
  // Base URL without /v1, we'll add it in requests
16
23
  }
17
24
  this.nodeUrl = normalized;
25
+ if (apiKey !== undefined)
26
+ this.apiKey = apiKey;
18
27
  }
19
28
  /**
20
- * Make a GET request to the API
29
+ * Make a GET request to the API.
30
+ *
31
+ * Adds `Authorization: Bearer <apiKey>` when the client was
32
+ * constructed with an `apiKey`. The header is omitted otherwise
33
+ * to preserve backwards-compatible behavior for unauthenticated
34
+ * public endpoints.
21
35
  */
22
36
  async get(path) {
23
37
  const fullUrl = `${this.nodeUrl}${path}`;
24
38
  const parsedUrl = new URL(fullUrl);
25
39
  const isHttps = parsedUrl.protocol === 'https:';
26
40
  const client = isHttps ? https : http;
41
+ const requestOptions = { method: 'GET' };
42
+ if (this.apiKey !== undefined) {
43
+ requestOptions.headers = { Authorization: `Bearer ${this.apiKey}` };
44
+ }
27
45
  return new Promise((resolve, reject) => {
28
- const req = client.get(fullUrl, (res) => {
46
+ const req = client.get(fullUrl, requestOptions, (res) => {
29
47
  let data = '';
30
48
  res.on('data', (chunk) => {
31
49
  data += chunk;
@@ -68,19 +86,14 @@ export class MovementApiClient {
68
86
  * Get account information
69
87
  */
70
88
  async getAccount(address) {
71
- // Normalize address (ensure 0x prefix and lowercase)
72
- const normalizedAddress = address.toLowerCase().startsWith('0x')
73
- ? address.toLowerCase()
74
- : `0x${address.toLowerCase()}`;
89
+ const normalizedAddress = normalizeAddressShort(address);
75
90
  return this.get(this.apiPath(`/accounts/${normalizedAddress}`));
76
91
  }
77
92
  /**
78
93
  * Get a specific account resource
79
94
  */
80
95
  async getAccountResource(address, resourceType) {
81
- const normalizedAddress = address.toLowerCase().startsWith('0x')
82
- ? address.toLowerCase()
83
- : `0x${address.toLowerCase()}`;
96
+ const normalizedAddress = normalizeAddressShort(address);
84
97
  // URL encode the resource type
85
98
  const encodedType = encodeURIComponent(resourceType);
86
99
  return this.get(this.apiPath(`/accounts/${normalizedAddress}/resource/${encodedType}`));
@@ -89,9 +102,7 @@ export class MovementApiClient {
89
102
  * Get all resources for an account
90
103
  */
91
104
  async getAccountResources(address) {
92
- const normalizedAddress = address.toLowerCase().startsWith('0x')
93
- ? address.toLowerCase()
94
- : `0x${address.toLowerCase()}`;
105
+ const normalizedAddress = normalizeAddressShort(address);
95
106
  return this.get(this.apiPath(`/accounts/${normalizedAddress}/resources`));
96
107
  }
97
108
  }
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/fork/api.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,I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D,OAAO,IAAI,CAAC,GAAG,CAAc,IAAI,CAAC,OAAO,CAAC,aAAa,iBAAiB,EAAE,CAAC,CAAC,CAAC;IAC/E,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,kBAAkB,CAAC,OAAe,EAAE,YAAoB;QAC5D,MAAM,iBAAiB,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAEzD,+BAA+B;QAC/B,MAAM,WAAW,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;QAErD,OAAO,IAAI,CAAC,GAAG,CAAM,IAAI,CAAC,OAAO,CAAC,aAAa,iBAAiB,aAAa,WAAW,EAAE,CAAC,CAAC,CAAC;IAC/F,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,mBAAmB,CAAC,OAAe;QACvC,MAAM,iBAAiB,GAAG,qBAAqB,CAAC,OAAO,CAAC,CAAC;QAEzD,OAAO,IAAI,CAAC,GAAG,CAAoB,IAAI,CAAC,OAAO,CAAC,aAAa,iBAAiB,YAAY,CAAC,CAAC,CAAC;IAC/F,CAAC;CACF"}
@@ -7,53 +7,47 @@ export declare class ForkManager {
7
7
  private storage;
8
8
  private apiClient;
9
9
  private metadata;
10
- constructor(forkPath: string);
11
10
  /**
12
- * Initialize a new fork from a network
11
+ * Optional API key sent as `Authorization: Bearer <key>` on every
12
+ * outgoing Movement API request. Not persisted to disk via
13
+ * {@link ForkMetadata} (keys stay in process memory). For the
14
+ * load-then-set pattern, call {@link setApiKey} after `load()`.
13
15
  */
14
- initialize(nodeUrl: string, networkName?: string): Promise<void>;
16
+ private apiKey?;
17
+ constructor(forkPath: string);
15
18
  /**
16
- * Load an existing fork
19
+ * Set or update the API key used for upstream Movement API requests.
20
+ * Reconstructs the internal `MovementApiClient` if one exists.
17
21
  */
18
- load(): void;
22
+ setApiKey(apiKey: string | undefined): void;
19
23
  /**
20
- * Get fork metadata
24
+ * Initialize a new fork from a network.
25
+ *
26
+ * @param nodeUrl - Upstream JSON-RPC base URL.
27
+ * @param networkName - Logical network label (defaults to `'custom'`).
28
+ * @param apiKey - Optional API key for `Authorization: Bearer` header.
21
29
  */
22
- getMetadata(): ForkMetadata;
30
+ initialize(nodeUrl: string, networkName?: string, apiKey?: string): Promise<void>;
23
31
  /**
24
- * Get account state (with lazy loading)
32
+ * Load an existing fork. The API key is NOT persisted to disk —
33
+ * callers needing authenticated upstream reads after `load()` must
34
+ * call {@link setApiKey} explicitly.
25
35
  */
36
+ load(): void;
37
+ getMetadata(): ForkMetadata;
26
38
  getAccount(address: string): Promise<AccountState>;
27
- /**
28
- * Get a specific resource (with lazy loading)
29
- */
30
39
  getResource(address: string, resourceType: string): Promise<any>;
31
- /**
32
- * Get all resources for an account (with lazy loading)
33
- */
34
40
  getAllResources(address: string): Promise<Record<string, any>>;
35
- /**
36
- * Set a resource value (for testing/mocking)
37
- */
38
- setResource(address: string, resourceType: string, data: any): Promise<void>;
39
- /**
40
- * Fund an account with coins (adds to existing balance)
41
- */
41
+ setResource(address: string, resourceType: string, data: unknown): Promise<void>;
42
+ /** Adds to the existing balance rather than replacing it. */
42
43
  fundAccount(address: string, amount: number, coinType?: string): Promise<void>;
43
- /**
44
- * Normalize address format
45
- */
46
- private normalizeAddress;
47
- /**
48
- * List all accounts in the fork
49
- */
50
44
  listAccounts(): string[];
51
45
  /**
52
46
  * Fund multiple accounts at once (batch operation)
53
47
  *
54
48
  * @param addresses Array of addresses to fund
55
49
  * @param amount Amount of coins per account
56
- * @param coinType Coin type (defaults to AptosCoin)
50
+ * @param coinType Coin type (defaults to the chain's native coin)
57
51
  *
58
52
  * @example
59
53
  * await forkManager.fundMultipleAccounts(
@@ -1 +1 @@
1
- {"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/fork/manager.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAEnE;;;GAGG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,OAAO,CAAc;IAC7B,OA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,MAAM,EACd,QAAQ,GAAE,MAAqC,GAC9C,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;;OAMG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAYjC;;;;;;;;;OASG;IACG,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC;CAiBjE"}
@@ -1,5 +1,22 @@
1
+ import { createHash } from 'node:crypto';
1
2
  import { MovementApiClient } from './api.js';
2
3
  import { ForkStorage } from './storage.js';
4
+ import { normalizeAddress } from '../utils/address.js';
5
+ import { logger } from '../ui/index.js';
6
+ /**
7
+ * Derive a deterministic 32-byte hex placeholder for the `authentication_key`
8
+ * of a fork-funded account. The real auth_key is `sha3_256(public_key || 0x00)`
9
+ * for Ed25519; the fork has no public key material, so we hash the address
10
+ * itself. This is NOT a real auth key — downstream code must not treat it as
11
+ * trustworthy key material. Distinguishable from the address by construction
12
+ * (#63 — prior code used `address.padEnd(66, '0')` which was a no-op since
13
+ * normalized addresses are already 66 chars).
14
+ */
15
+ function forkAuthKeyPlaceholder(normalizedAddress) {
16
+ const stripped = normalizedAddress.startsWith('0x') ? normalizedAddress.slice(2) : normalizedAddress;
17
+ const digest = createHash('sha3-256').update(stripped, 'hex').digest('hex');
18
+ return `0x${digest}`;
19
+ }
3
20
  /**
4
21
  * Manager for fork operations
5
22
  * Orchestrates API client and storage
@@ -8,20 +25,44 @@ export class ForkManager {
8
25
  storage;
9
26
  apiClient = null;
10
27
  metadata = null;
28
+ /**
29
+ * Optional API key sent as `Authorization: Bearer <key>` on every
30
+ * outgoing Movement API request. Not persisted to disk via
31
+ * {@link ForkMetadata} (keys stay in process memory). For the
32
+ * load-then-set pattern, call {@link setApiKey} after `load()`.
33
+ */
34
+ apiKey;
11
35
  constructor(forkPath) {
12
36
  this.storage = new ForkStorage(forkPath);
13
37
  }
14
38
  /**
15
- * Initialize a new fork from a network
39
+ * Set or update the API key used for upstream Movement API requests.
40
+ * Reconstructs the internal `MovementApiClient` if one exists.
41
+ */
42
+ setApiKey(apiKey) {
43
+ if (apiKey === undefined) {
44
+ delete this.apiKey;
45
+ }
46
+ else {
47
+ this.apiKey = apiKey;
48
+ }
49
+ if (this.apiClient && this.metadata) {
50
+ this.apiClient = new MovementApiClient(this.metadata.nodeUrl, this.apiKey);
51
+ }
52
+ }
53
+ /**
54
+ * Initialize a new fork from a network.
55
+ *
56
+ * @param nodeUrl - Upstream JSON-RPC base URL.
57
+ * @param networkName - Logical network label (defaults to `'custom'`).
58
+ * @param apiKey - Optional API key for `Authorization: Bearer` header.
16
59
  */
17
- async initialize(nodeUrl, networkName = 'custom') {
18
- // Create API client
19
- this.apiClient = new MovementApiClient(nodeUrl);
20
- // Fetch network info
60
+ async initialize(nodeUrl, networkName = 'custom', apiKey) {
61
+ if (apiKey !== undefined)
62
+ this.apiKey = apiKey;
63
+ this.apiClient = new MovementApiClient(nodeUrl, this.apiKey);
21
64
  const ledgerInfo = await this.apiClient.getLedgerInfo();
22
- // Create fork structure
23
65
  this.storage.initialize();
24
- // Save metadata
25
66
  this.metadata = {
26
67
  network: networkName,
27
68
  nodeUrl,
@@ -36,34 +77,27 @@ export class ForkManager {
36
77
  console.log(`✓ Fork initialized at ledger version ${ledgerInfo.ledger_version}`);
37
78
  }
38
79
  /**
39
- * Load an existing fork
80
+ * Load an existing fork. The API key is NOT persisted to disk —
81
+ * callers needing authenticated upstream reads after `load()` must
82
+ * call {@link setApiKey} explicitly.
40
83
  */
41
84
  load() {
42
85
  if (!this.storage.exists()) {
43
86
  throw new Error('Fork does not exist. Run `initialize()` first.');
44
87
  }
45
88
  this.metadata = this.storage.loadMetadata();
46
- this.apiClient = new MovementApiClient(this.metadata.nodeUrl);
89
+ this.apiClient = new MovementApiClient(this.metadata.nodeUrl, this.apiKey);
47
90
  }
48
- /**
49
- * Get fork metadata
50
- */
51
91
  getMetadata() {
52
92
  if (!this.metadata) {
53
93
  this.metadata = this.storage.loadMetadata();
54
94
  }
55
95
  return this.metadata;
56
96
  }
57
- /**
58
- * Get account state (with lazy loading)
59
- */
60
97
  async getAccount(address) {
61
- // Normalize address
62
- const normalizedAddress = this.normalizeAddress(address);
63
- // Check cache first
98
+ const normalizedAddress = normalizeAddress(address);
64
99
  let accountState = this.storage.getAccount(normalizedAddress);
65
100
  if (!accountState) {
66
- // Fetch from network
67
101
  if (!this.apiClient) {
68
102
  throw new Error('Fork not initialized. Call initialize() or load() first.');
69
103
  }
@@ -73,21 +107,15 @@ export class ForkManager {
73
107
  sequenceNumber: accountData.sequence_number,
74
108
  authenticationKey: accountData.authentication_key,
75
109
  };
76
- // Cache it
77
110
  this.storage.saveAccount(normalizedAddress, accountState);
78
111
  console.log(` ✓ Cached account ${normalizedAddress}`);
79
112
  }
80
113
  return accountState;
81
114
  }
82
- /**
83
- * Get a specific resource (with lazy loading)
84
- */
85
115
  async getResource(address, resourceType) {
86
- const normalizedAddress = this.normalizeAddress(address);
87
- // Check cache first
116
+ const normalizedAddress = normalizeAddress(address);
88
117
  let resource = this.storage.getResource(normalizedAddress, resourceType);
89
118
  if (!resource) {
90
- // Fetch from network
91
119
  if (!this.apiClient) {
92
120
  throw new Error('Fork not initialized. Call initialize() or load() first.');
93
121
  }
@@ -95,12 +123,12 @@ export class ForkManager {
95
123
  try {
96
124
  const resourceData = await this.apiClient.getAccountResource(normalizedAddress, resourceType);
97
125
  resource = resourceData.data;
98
- // Cache it
99
126
  this.storage.saveResource(normalizedAddress, resourceType, resource);
100
127
  console.log(` ✓ Cached resource ${resourceType}`);
101
128
  }
102
129
  catch (error) {
103
- if (error.message.includes('404')) {
130
+ const msg = error instanceof Error ? error.message : String(error);
131
+ if (msg.includes('404')) {
104
132
  throw new Error(`Resource ${resourceType} not found for account ${normalizedAddress}`);
105
133
  }
106
134
  throw error;
@@ -108,14 +136,9 @@ export class ForkManager {
108
136
  }
109
137
  return resource;
110
138
  }
111
- /**
112
- * Get all resources for an account (with lazy loading)
113
- */
114
139
  async getAllResources(address) {
115
- const normalizedAddress = this.normalizeAddress(address);
116
- // Check if we have any cached resources
140
+ const normalizedAddress = normalizeAddress(address);
117
141
  let resources = this.storage.getAllResources(normalizedAddress);
118
- // If no cached resources, fetch all from network
119
142
  if (Object.keys(resources).length === 0) {
120
143
  if (!this.apiClient) {
121
144
  throw new Error('Fork not initialized. Call initialize() or load() first.');
@@ -126,37 +149,35 @@ export class ForkManager {
126
149
  for (const resource of resourcesList) {
127
150
  resources[resource.type] = resource.data;
128
151
  }
129
- // Cache them
130
152
  this.storage.saveAllResources(normalizedAddress, resources);
131
153
  console.log(` ✓ Cached ${Object.keys(resources).length} resources`);
132
154
  }
133
155
  return resources;
134
156
  }
135
- /**
136
- * Set a resource value (for testing/mocking)
137
- */
138
157
  async setResource(address, resourceType, data) {
139
- const normalizedAddress = this.normalizeAddress(address);
158
+ const normalizedAddress = normalizeAddress(address);
140
159
  this.storage.saveResource(normalizedAddress, resourceType, data);
141
160
  console.log(` ✓ Updated resource ${resourceType} for ${normalizedAddress}`);
142
161
  }
143
- /**
144
- * Fund an account with coins (adds to existing balance)
145
- */
162
+ /** Adds to the existing balance rather than replacing it. */
146
163
  async fundAccount(address, amount, coinType = '0x1::aptos_coin::AptosCoin') {
147
- const normalizedAddress = this.normalizeAddress(address);
164
+ const normalizedAddress = normalizeAddress(address);
148
165
  const resourceType = `0x1::coin::CoinStore<${coinType}>`;
149
- // Try to get existing coin store
166
+ // Try to get existing coin store. The coin store is a CoinStore<T>
167
+ // resource whose `data` is Movement-side untyped JSON; we shape it
168
+ // locally as a structural object with `coin.value: string`.
169
+ // any: full CoinStore schema lives at the Movement REST boundary —
170
+ // proper validation deferred to the boundary-validation follow-up of #57.
150
171
  let coinStore;
151
172
  try {
152
173
  coinStore = await this.getResource(normalizedAddress, resourceType);
153
174
  }
154
175
  catch (error) {
155
176
  // Only catch "not found" errors, rethrow others (network, API, etc.)
156
- if (!error.message || !error.message.includes('not found')) {
177
+ const msg = error instanceof Error ? error.message : String(error);
178
+ if (!msg.includes('not found')) {
157
179
  throw error;
158
180
  }
159
- // If doesn't exist, create new one
160
181
  coinStore = {
161
182
  coin: { value: '0' },
162
183
  deposit_events: {
@@ -180,40 +201,20 @@ export class ForkManager {
180
201
  frozen: false,
181
202
  };
182
203
  }
183
- // Add to existing balance (instead of replacing it)
184
204
  const currentBalance = BigInt(coinStore.coin.value ?? '0');
185
205
  const newBalance = currentBalance + BigInt(amount);
186
206
  coinStore.coin.value = newBalance.toString();
187
- // Save
188
207
  await this.setResource(normalizedAddress, resourceType, coinStore);
189
- // Also ensure account exists
190
208
  let account = this.storage.getAccount(normalizedAddress);
191
209
  if (!account) {
192
210
  account = {
193
211
  sequenceNumber: '0',
194
- authenticationKey: normalizedAddress.padEnd(66, '0'),
212
+ authenticationKey: forkAuthKeyPlaceholder(normalizedAddress),
195
213
  };
196
214
  this.storage.saveAccount(normalizedAddress, account);
197
215
  }
198
216
  console.log(` ✓ Funded ${normalizedAddress} with ${amount} coins`);
199
217
  }
200
- /**
201
- * Normalize address format
202
- */
203
- normalizeAddress(address) {
204
- let normalized = address.toLowerCase();
205
- if (!normalized.startsWith('0x')) {
206
- normalized = `0x${normalized}`;
207
- }
208
- // Pad to 66 characters (0x + 64 hex chars)
209
- if (normalized.length < 66) {
210
- normalized = '0x' + normalized.slice(2).padStart(64, '0');
211
- }
212
- return normalized;
213
- }
214
- /**
215
- * List all accounts in the fork
216
- */
217
218
  listAccounts() {
218
219
  return this.storage.listAccounts();
219
220
  }
@@ -222,7 +223,7 @@ export class ForkManager {
222
223
  *
223
224
  * @param addresses Array of addresses to fund
224
225
  * @param amount Amount of coins per account
225
- * @param coinType Coin type (defaults to AptosCoin)
226
+ * @param coinType Coin type (defaults to the chain's native coin)
226
227
  *
227
228
  * @example
228
229
  * await forkManager.fundMultipleAccounts(
@@ -231,11 +232,13 @@ export class ForkManager {
231
232
  * );
232
233
  */
233
234
  async fundMultipleAccounts(addresses, amount, coinType = '0x1::aptos_coin::AptosCoin') {
234
- console.log(`\n💰 Funding ${addresses.length} accounts with ${amount} coins each...`);
235
+ logger.newline();
236
+ logger.step(`Funding ${addresses.length} accounts with ${amount} coins each...`);
235
237
  for (const address of addresses) {
236
238
  await this.fundAccount(address, amount, coinType);
237
239
  }
238
- console.log(`✓ All accounts funded successfully\n`);
240
+ logger.success("All accounts funded successfully");
241
+ logger.newline();
239
242
  }
240
243
  /**
241
244
  * Reset fork state to initial snapshot
@@ -245,11 +248,13 @@ export class ForkManager {
245
248
  * await forkManager.resetState();
246
249
  */
247
250
  async resetState() {
248
- console.log(`\n🔄 Resetting fork state...`);
251
+ logger.newline();
252
+ logger.step("Resetting fork state...");
249
253
  // Clear all accounts and resources from storage
250
254
  this.storage.clearAccounts();
251
255
  this.storage.clearResources();
252
- console.log(`✓ Fork state reset to initial snapshot\n`);
256
+ logger.success("Fork state reset to initial snapshot");
257
+ logger.newline();
253
258
  }
254
259
  /**
255
260
  * Get or create an account, ensuring it exists in the fork
@@ -262,16 +267,14 @@ export class ForkManager {
262
267
  * const account = await forkManager.getOrCreateAccount("0x123...");
263
268
  */
264
269
  async getOrCreateAccount(address) {
265
- const normalizedAddress = this.normalizeAddress(address);
266
- // Try to get existing account
270
+ const normalizedAddress = normalizeAddress(address);
267
271
  try {
268
272
  return await this.getAccount(normalizedAddress);
269
273
  }
270
274
  catch (error) {
271
- // If account doesn't exist, create a minimal one
272
275
  const newAccount = {
273
276
  sequenceNumber: '0',
274
- authenticationKey: normalizedAddress.padEnd(66, '0'),
277
+ authenticationKey: forkAuthKeyPlaceholder(normalizedAddress),
275
278
  };
276
279
  this.storage.saveAccount(normalizedAddress, newAccount);
277
280
  console.log(` ✓ Created new account ${normalizedAddress}`);