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,384 @@
1
+ import { homedir } from "os";
2
+ import { join } from "path";
3
+ import { randomUUID } from "crypto";
4
+ import type { MovehatRuntime } from "../types/runtime.js";
5
+ import type {
6
+ DeployCodeObjectOptions,
7
+ UpgradeCodeObjectOptions,
8
+ CodeObjectInfo,
9
+ } from "../types/harness.js";
10
+ import { extractNamedAddresses } from "../commands/compile.js";
11
+ import {
12
+ saveDeployment,
13
+ loadDeployment,
14
+ validateSafeName,
15
+ type DeploymentInfo,
16
+ } from "../core/deployments.js";
17
+ import { validatePathSafety, validateProfileSafety } from "../core/shell.js";
18
+ import {
19
+ CliExecutionError,
20
+ ModuleAlreadyDeployedError,
21
+ PostPublishError,
22
+ } from "../errors.js";
23
+ import { runCli } from "../utils/runCli.js";
24
+ import { parseTxHash } from "../utils/parseCliOutput.js";
25
+ import { logger } from "../ui/index.js";
26
+ import {
27
+ withYamlLock,
28
+ addProfile,
29
+ removeProfile,
30
+ removeProfileSync,
31
+ ensureSignalHandler,
32
+ cleanupCallbacks,
33
+ } from "../core/movementProfile.js";
34
+
35
+ /**
36
+ * Deploy a Move package as a code object via `movement move deploy-object`.
37
+ *
38
+ * Mirrors `core/Publisher.deploy` exactly for the security-critical parts
39
+ * (per-deploy unique profile, atomic ~/.aptos/config.yaml mutation under
40
+ * the shared mutex, SIGINT-safe sync cleanup, stderr redaction via
41
+ * `runCli`). The only differences are:
42
+ *
43
+ * 1. CLI subcommand: `deploy-object` instead of `publish` + a required
44
+ * `--address-name <moduleName>` flag that binds the derived object
45
+ * address to the package's named-address slot.
46
+ * 2. `DeploymentInfo.address` is the derived **object address** parsed
47
+ * from CLI output, not the deployer's account address.
48
+ *
49
+ * @internal — called from `Harness.deployCodeObject`.
50
+ */
51
+ export async function deployCodeObject(
52
+ runtime: MovehatRuntime,
53
+ options: DeployCodeObjectOptions
54
+ ): Promise<CodeObjectInfo> {
55
+ return executeMovementMoveObject({
56
+ runtime,
57
+ moduleName: options.moduleName,
58
+ addressName: options.addressName,
59
+ packageDir: options.packageDir,
60
+ namedAddresses: options.namedAddresses,
61
+ includedArtifacts: options.includedArtifacts,
62
+ adapter: options.adapter,
63
+ subcommand: "deploy-object",
64
+ extraArgs: [],
65
+ checkIdempotency: true,
66
+ });
67
+ }
68
+
69
+ /**
70
+ * Upgrade an existing code object via `movement move upgrade-object`.
71
+ *
72
+ * Requires {@link UpgradeCodeObjectOptions.objectAddress} — the address
73
+ * of the existing on-chain object. The local `DeploymentInfo` record
74
+ * for `moduleName` is overwritten with a new timestamp + txHash; the
75
+ * address stays the same.
76
+ *
77
+ * @internal — called from `Harness.upgradeCodeObject`.
78
+ */
79
+ export async function upgradeCodeObject(
80
+ runtime: MovehatRuntime,
81
+ options: UpgradeCodeObjectOptions
82
+ ): Promise<CodeObjectInfo> {
83
+ if (!options.objectAddress) {
84
+ throw new Error(
85
+ "Harness.upgradeCodeObject requires options.objectAddress (the existing object's address)."
86
+ );
87
+ }
88
+ return executeMovementMoveObject({
89
+ runtime,
90
+ moduleName: options.moduleName,
91
+ addressName: options.addressName,
92
+ packageDir: options.packageDir,
93
+ namedAddresses: options.namedAddresses,
94
+ includedArtifacts: options.includedArtifacts,
95
+ adapter: options.adapter,
96
+ subcommand: "upgrade-object",
97
+ extraArgs: ["--object-address", options.objectAddress],
98
+ checkIdempotency: false,
99
+ fixedAddress: options.objectAddress,
100
+ });
101
+ }
102
+
103
+ interface ExecuteOptions {
104
+ runtime: MovehatRuntime;
105
+ moduleName: string;
106
+ /**
107
+ * Move.toml named address for the `--address-name` CLI flag.
108
+ * Defaults to `moduleName` when undefined.
109
+ */
110
+ addressName?: string | undefined;
111
+ packageDir?: string | undefined;
112
+ namedAddresses?: Record<string, string> | undefined;
113
+ includedArtifacts?: "none" | "sparse" | "all" | undefined;
114
+ adapter?: import("../utils/childProcessAdapter.js").ChildProcessAdapter | undefined;
115
+ subcommand: "deploy-object" | "upgrade-object";
116
+ extraArgs: readonly string[];
117
+ /** Whether to throw `ModuleAlreadyDeployedError` if a record exists. */
118
+ checkIdempotency: boolean;
119
+ /**
120
+ * For upgrade-object: the object's existing address. Skips the parse-
121
+ * from-stdout step (the address is known up front).
122
+ */
123
+ fixedAddress?: string;
124
+ }
125
+
126
+ async function executeMovementMoveObject(
127
+ opts: ExecuteOptions
128
+ ): Promise<CodeObjectInfo> {
129
+ const { runtime, moduleName, subcommand } = opts;
130
+ const config = runtime.config;
131
+ const account = runtime.account;
132
+
133
+ validateSafeName(moduleName, "module");
134
+
135
+ // Idempotency: deploy-object refuses re-deploy unless MH_CLI_REDEPLOY=true.
136
+ // Upgrade does not check this (the whole point is to overwrite).
137
+ const forceRedeploy = process.env.MH_CLI_REDEPLOY === "true";
138
+ if (opts.checkIdempotency) {
139
+ const existing = loadDeployment(config.network, moduleName);
140
+ if (existing && !forceRedeploy) {
141
+ const errorDetails = [
142
+ `Module "${moduleName}" is already deployed on ${config.network}`,
143
+ `Address: ${existing.address}`,
144
+ `Deployed at: ${new Date(existing.timestamp).toLocaleString()}`,
145
+ existing.txHash ? `Transaction: ${existing.txHash}` : null,
146
+ `\nTo redeploy, set MH_CLI_REDEPLOY=true or call harness.upgradeCodeObject({ objectAddress: "${existing.address}", ... }).`,
147
+ ]
148
+ .filter(Boolean)
149
+ .join("\n");
150
+
151
+ logger.error(
152
+ `Module "${moduleName}" is already deployed on ${config.network}`
153
+ );
154
+ logger.plain(` Address: ${existing.address}`);
155
+ logger.plain(
156
+ ` Deployed at: ${new Date(existing.timestamp).toLocaleString()}`
157
+ );
158
+ if (existing.txHash) logger.plain(` Transaction: ${existing.txHash}`);
159
+ logger.newline();
160
+
161
+ throw new ModuleAlreadyDeployedError(
162
+ errorDetails,
163
+ moduleName,
164
+ config.network,
165
+ existing.address,
166
+ existing.timestamp,
167
+ existing.txHash
168
+ );
169
+ }
170
+ }
171
+
172
+ const dir = opts.packageDir || config.moveDir;
173
+ const profile = `movehat-deploy-${randomUUID().slice(0, 8)}`;
174
+ const safeDir = validatePathSafety(dir, "package directory");
175
+ const safeProfile = validateProfileSafety(profile);
176
+
177
+ logger.step(
178
+ `${subcommand === "deploy-object" ? "Deploying" : "Upgrading"} module "${moduleName}" from ${dir}...`
179
+ );
180
+
181
+ try {
182
+ const deployerAddress = account.accountAddress.toString();
183
+
184
+ // Build named-addresses arg: auto-detected names from Move sources
185
+ // are bound to the deployer's address (Publisher convention).
186
+ // Caller-supplied `namedAddresses` overlay on top.
187
+ const detectedAddresses = extractNamedAddresses(dir);
188
+ const addrMap = new Map<string, string>();
189
+ for (const name of detectedAddresses) addrMap.set(name, deployerAddress);
190
+ if (opts.namedAddresses) {
191
+ for (const [k, v] of Object.entries(opts.namedAddresses)) addrMap.set(k, v);
192
+ }
193
+ const namedAddrArgs: string[] =
194
+ addrMap.size > 0
195
+ ? [
196
+ "--named-addresses",
197
+ Array.from(addrMap.entries())
198
+ .map(([k, v]) => `${k}=${v}`)
199
+ .join(","),
200
+ ]
201
+ : [];
202
+
203
+ // Build step (same as Publisher — produces the bytecode the
204
+ // subcommand will publish/upgrade).
205
+ logger.step("Building package...");
206
+ const buildResult = await runCli(
207
+ {
208
+ command: "movement",
209
+ args: ["move", "build", "--package-dir", safeDir, ...namedAddrArgs],
210
+ timeoutMs: 120000,
211
+ },
212
+ { adapter: opts.adapter }
213
+ );
214
+ if (buildResult.stdout) console.log(buildResult.stdout.trim());
215
+
216
+ // Strip `ed25519-priv-` prefix if present — Movement CLI expects the
217
+ // raw hex.
218
+ let cleanPrivateKey = config.privateKey;
219
+ if (cleanPrivateKey.startsWith("ed25519-priv-")) {
220
+ cleanPrivateKey = cleanPrivateKey.replace("ed25519-priv-", "");
221
+ }
222
+
223
+ const movementConfigPath = join(homedir(), ".aptos", "config.yaml");
224
+
225
+ // Register SIGINT-safe sync cleanup BEFORE writing the key (same
226
+ // pattern as Publisher — closes bug #36).
227
+ ensureSignalHandler();
228
+ const syncCleanup = () => removeProfileSync(movementConfigPath, profile);
229
+ cleanupCallbacks.add(syncCleanup);
230
+
231
+ await withYamlLock(() =>
232
+ addProfile(movementConfigPath, profile, {
233
+ private_key: cleanPrivateKey,
234
+ public_key: account.publicKey.toString(),
235
+ account: deployerAddress,
236
+ rest_url: config.rpc,
237
+ })
238
+ );
239
+
240
+ let deployOut = "";
241
+ try {
242
+ logger.step(
243
+ `Running 'movement move ${subcommand}'${subcommand === "upgrade-object" ? "" : " (this may take a moment)"}...`
244
+ );
245
+ const includedArtifacts: ("--included-artifacts" | string)[] =
246
+ opts.includedArtifacts
247
+ ? ["--included-artifacts", opts.includedArtifacts]
248
+ : [];
249
+ const result = await runCli(
250
+ {
251
+ command: "movement",
252
+ args: [
253
+ "move",
254
+ subcommand,
255
+ "--address-name",
256
+ opts.addressName ?? moduleName,
257
+ "--package-dir",
258
+ safeDir,
259
+ "--url",
260
+ config.rpc,
261
+ "--profile",
262
+ safeProfile,
263
+ "--assume-yes",
264
+ ...includedArtifacts,
265
+ ...namedAddrArgs,
266
+ ...opts.extraArgs,
267
+ ],
268
+ timeoutMs: 180000, // 3 min — deploy-object can be slow with chunked publishing.
269
+ },
270
+ { adapter: opts.adapter }
271
+ );
272
+ deployOut = result.stdout;
273
+ if (result.stdout) console.log(result.stdout.trim());
274
+ if (result.stderr) console.error(result.stderr.trim());
275
+ } finally {
276
+ // Best-effort profile removal. CRITICAL: catch + log instead of
277
+ // re-throwing — an await-in-finally that throws would clobber the
278
+ // try block's success/error (the bug-#37 lesson from Publisher).
279
+ await withYamlLock(() => removeProfile(movementConfigPath, profile)).catch(
280
+ (err) => {
281
+ const cleanupMsg = err instanceof Error ? err.message : String(err);
282
+ logger.warning(
283
+ `Failed to remove deploy profile "${profile}" from ${movementConfigPath}: ${cleanupMsg}. ` +
284
+ `Run 'movement config delete-profile --profile ${profile}' to clean up manually.`
285
+ );
286
+ }
287
+ );
288
+ cleanupCallbacks.delete(syncCleanup);
289
+ }
290
+
291
+ // Parse object address (for deploy-object) and txHash (both flows).
292
+ const objectAddress = opts.fixedAddress ?? parseObjectAddress(deployOut);
293
+ const txHash = parseTxHash(deployOut);
294
+
295
+ if (!objectAddress) {
296
+ throw new Error(
297
+ `Could not parse object address from '${subcommand}' output. ` +
298
+ `Expected a line containing 'object address 0x...' or a JSON ` +
299
+ `'Result' block with an 'object_address' field. Captured stdout:\n${deployOut.slice(0, 1000)}`
300
+ );
301
+ }
302
+
303
+ logger.success(
304
+ `${subcommand === "deploy-object" ? "Module deployed" : "Module upgraded"} successfully!`
305
+ );
306
+
307
+ // Publish/upgrade succeeded. Everything below this point that throws
308
+ // is a local-side bookkeeping failure, not an on-chain failure.
309
+
310
+ const deployment: DeploymentInfo = {
311
+ address: objectAddress,
312
+ moduleName,
313
+ network: config.network,
314
+ deployer: deployerAddress,
315
+ timestamp: Date.now(),
316
+ ...(txHash !== undefined ? { txHash } : {}),
317
+ };
318
+
319
+ try {
320
+ saveDeployment(deployment);
321
+ } catch (error) {
322
+ const err = error instanceof Error ? error : new Error(String(error));
323
+ throw new PostPublishError(
324
+ `Module "${moduleName}" ${subcommand === "deploy-object" ? "deployed" : "upgraded"} to ${deployment.address} ` +
325
+ `but local deployment record could not be written: ${err.message}`,
326
+ deployment,
327
+ err
328
+ );
329
+ }
330
+
331
+ return deployment;
332
+ } catch (error) {
333
+ if (error instanceof PostPublishError) {
334
+ logger.warning(
335
+ `Module ${subcommand === "deploy-object" ? "deployed" : "upgraded"} successfully to ${error.deployment.address} ` +
336
+ `(tx=${error.deployment.txHash ?? "unknown"}) but local deployment record could not be written.`
337
+ );
338
+ logger.warning(` Cause: ${error.cause.message}`);
339
+ logger.warning(
340
+ ` To recover, manually write the deployment to deployments/${error.deployment.network}/${error.deployment.moduleName}.json.`
341
+ );
342
+ throw error;
343
+ }
344
+ if (error instanceof CliExecutionError) {
345
+ if (error.stdoutPreview) console.log(error.stdoutPreview);
346
+ logger.error(
347
+ `Failed to ${subcommand === "deploy-object" ? "deploy" : "upgrade"} module: ${error.message}\n${error.stderr}`
348
+ );
349
+ } else {
350
+ const err = error instanceof Error ? error : new Error(String(error));
351
+ logger.error(
352
+ `Failed to ${subcommand === "deploy-object" ? "deploy" : "upgrade"} module: ${err.message}`
353
+ );
354
+ }
355
+ throw error;
356
+ }
357
+ }
358
+
359
+ /**
360
+ * Extract a code-object address from `movement move deploy-object` stdout.
361
+ *
362
+ * Movement CLI typically emits the address in one of these shapes:
363
+ *
364
+ * - Free text: `Code was successfully deployed to object address 0x…`
365
+ * - Free text: `Object address: 0x…`
366
+ * - JSON `Result` block with `"object_address": "0x…"`
367
+ *
368
+ * Falls through the patterns in order. Returns `undefined` on no match.
369
+ */
370
+ function parseObjectAddress(stdout: string): string | undefined {
371
+ // Pattern 1: phrase-context match.
372
+ const phraseMatch = stdout.match(
373
+ /object\s+address[:\s]+\b(0x[a-fA-F0-9]{1,64})\b/i
374
+ );
375
+ if (phraseMatch?.[1]) return phraseMatch[1];
376
+
377
+ // Pattern 2: JSON-shaped key.
378
+ const jsonMatch = stdout.match(
379
+ /"object_address"\s*:\s*"(0x[a-fA-F0-9]{1,64})"/
380
+ );
381
+ if (jsonMatch?.[1]) return jsonMatch[1];
382
+
383
+ return undefined;
384
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Thrown synchronously when any method other than `cleanup` is invoked
3
+ * on a Harness instance whose `cleanup()` has already run.
4
+ *
5
+ * The throw happens on property access (Proxy `get` trap), not after the
6
+ * async method body. That means `await harness.deployCodeObject(...)`
7
+ * throws *before* the call site awaits — callers can use a plain
8
+ * `try`/`catch` or rely on the rejected promise; either form will fire.
9
+ */
10
+ export class HarnessDisposedError extends Error {
11
+ constructor(public readonly methodName: string) {
12
+ super(
13
+ `Harness is disposed; call to '${methodName}' is not allowed. ` +
14
+ `Create a new Harness via Harness.createLocal/createFork/createLive instead.`
15
+ );
16
+ this.name = "HarnessDisposedError";
17
+
18
+ if (Error.captureStackTrace) {
19
+ Error.captureStackTrace(this, HarnessDisposedError);
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,3 @@
1
+ export { Harness } from "./Harness.js";
2
+ export type { HarnessMode } from "./Harness.js";
3
+ export { HarnessDisposedError } from "./errors.js";
@@ -0,0 +1,40 @@
1
+ import { HarnessDisposedError } from "./errors.js";
2
+
3
+ /**
4
+ * Names of Harness methods that must throw `HarnessDisposedError`
5
+ * synchronously once the harness has been disposed (via `cleanup()`).
6
+ *
7
+ * Properties NOT in this set — `cleanup`, `mode`, `poisoned`, the runtime
8
+ * accessors, well-known Symbols, and the promise-protocol hooks
9
+ * (`then`/`catch`/`finally`) — always pass through. That keeps:
10
+ * - `await harness` from breaking on `.then` access
11
+ * - debug tools (`console.log`, `util.inspect`) from throwing
12
+ * - idempotent `cleanup()` callable post-poisoning
13
+ *
14
+ * New Harness methods that should fail post-cleanup MUST be added here.
15
+ */
16
+ const POISONED_METHODS: ReadonlySet<string> = new Set([
17
+ "deployCodeObject",
18
+ "upgradeCodeObject",
19
+ "runViewFunction",
20
+ "runMoveScript",
21
+ ]);
22
+
23
+ /**
24
+ * Wrap a Harness instance in a Proxy that throws `HarnessDisposedError`
25
+ * synchronously on access to any method in {@link POISONED_METHODS} once
26
+ * `isPoisoned()` returns true.
27
+ */
28
+ export function createHarnessProxy<T extends object>(
29
+ target: T,
30
+ isPoisoned: () => boolean
31
+ ): T {
32
+ return new Proxy(target, {
33
+ get(obj, prop, receiver) {
34
+ if (typeof prop === "string" && POISONED_METHODS.has(prop) && isPoisoned()) {
35
+ throw new HarnessDisposedError(prop);
36
+ }
37
+ return Reflect.get(obj, prop, receiver);
38
+ },
39
+ });
40
+ }
@@ -0,0 +1,196 @@
1
+ import { existsSync } from "fs";
2
+ import { homedir } from "os";
3
+ import { extname, join } from "path";
4
+ import { randomUUID } from "crypto";
5
+ import type { MovehatRuntime } from "../types/runtime.js";
6
+ import type {
7
+ RunMoveScriptOptions,
8
+ MoveScriptResult,
9
+ } from "../types/harness.js";
10
+ import { validatePathSafety, validateProfileSafety } from "../core/shell.js";
11
+ import { CliExecutionError } from "../errors.js";
12
+ import { runCli } from "../utils/runCli.js";
13
+ import { parseTxHash } from "../utils/parseCliOutput.js";
14
+ import { logger } from "../ui/index.js";
15
+ import {
16
+ withYamlLock,
17
+ addProfile,
18
+ removeProfile,
19
+ removeProfileSync,
20
+ ensureSignalHandler,
21
+ cleanupCallbacks,
22
+ } from "../core/movementProfile.js";
23
+
24
+ /**
25
+ * Execute a Move script via `movement move run-script`.
26
+ *
27
+ * Auto-detects the script kind from the extension:
28
+ * - `.move` source → `--script-path` (CLI compiles inline)
29
+ * - `.mv` compiled bytecode → `--compiled-script-path`
30
+ *
31
+ * Reuses Publisher's security model via the shared `movementProfile`
32
+ * helpers: per-deploy unique profile, atomic 0o600 yaml writes under
33
+ * the mutex, SIGINT-safe sync cleanup, `--profile` auth (key never
34
+ * appears in `ps` output).
35
+ *
36
+ * Returns {@link MoveScriptResult}. `txHash` is guaranteed; `success`
37
+ * and `vmStatus` are best-effort parsed from the CLI's Result JSON.
38
+ *
39
+ * @internal — called from `Harness.runMoveScript`.
40
+ */
41
+ export async function runMoveScript(
42
+ runtime: MovehatRuntime,
43
+ options: RunMoveScriptOptions
44
+ ): Promise<MoveScriptResult> {
45
+ const config = runtime.config;
46
+ const account = runtime.account;
47
+
48
+ // Synchronous validation before any CLI call.
49
+ if (!options.scriptPath || typeof options.scriptPath !== "string") {
50
+ throw new Error(
51
+ "Harness.runMoveScript requires options.scriptPath (string path to .move or .mv)."
52
+ );
53
+ }
54
+ const ext = extname(options.scriptPath).toLowerCase();
55
+ let scriptFlag: "--script-path" | "--compiled-script-path";
56
+ if (ext === ".move") {
57
+ scriptFlag = "--script-path";
58
+ } else if (ext === ".mv") {
59
+ scriptFlag = "--compiled-script-path";
60
+ } else {
61
+ throw new Error(
62
+ `Harness.runMoveScript: unsupported script extension '${ext || "<none>"}'. ` +
63
+ `Expected '.move' (source — CLI auto-compiles) or '.mv' (pre-compiled bytecode).`
64
+ );
65
+ }
66
+ if (!existsSync(options.scriptPath)) {
67
+ throw new Error(
68
+ `Harness.runMoveScript: script not found at '${options.scriptPath}'.`
69
+ );
70
+ }
71
+
72
+ const safeScriptPath = validatePathSafety(options.scriptPath, "script path");
73
+ const profile = `movehat-script-${randomUUID().slice(0, 8)}`;
74
+ const safeProfile = validateProfileSafety(profile);
75
+
76
+ logger.step(
77
+ `Running Move script '${options.scriptPath}' on ${config.network}...`
78
+ );
79
+
80
+ try {
81
+ const deployerAddress = account.accountAddress.toString();
82
+
83
+ let cleanPrivateKey = config.privateKey;
84
+ if (cleanPrivateKey.startsWith("ed25519-priv-")) {
85
+ cleanPrivateKey = cleanPrivateKey.replace("ed25519-priv-", "");
86
+ }
87
+
88
+ const movementConfigPath = join(homedir(), ".aptos", "config.yaml");
89
+
90
+ ensureSignalHandler();
91
+ const syncCleanup = () => removeProfileSync(movementConfigPath, profile);
92
+ cleanupCallbacks.add(syncCleanup);
93
+
94
+ await withYamlLock(() =>
95
+ addProfile(movementConfigPath, profile, {
96
+ private_key: cleanPrivateKey,
97
+ public_key: account.publicKey.toString(),
98
+ account: deployerAddress,
99
+ rest_url: config.rpc,
100
+ })
101
+ );
102
+
103
+ let scriptOut = "";
104
+ try {
105
+ const typeArgsFragment: string[] =
106
+ options.typeArgs && options.typeArgs.length > 0
107
+ ? ["--type-args", ...options.typeArgs]
108
+ : [];
109
+ const argsFragment: string[] =
110
+ options.args && options.args.length > 0
111
+ ? ["--args", ...options.args]
112
+ : [];
113
+
114
+ const result = await runCli(
115
+ {
116
+ command: "movement",
117
+ args: [
118
+ "move",
119
+ "run-script",
120
+ "--profile",
121
+ safeProfile,
122
+ "--url",
123
+ config.rpc,
124
+ "--assume-yes",
125
+ scriptFlag,
126
+ safeScriptPath,
127
+ ...typeArgsFragment,
128
+ ...argsFragment,
129
+ ],
130
+ timeoutMs: 120000,
131
+ },
132
+ { adapter: options.adapter }
133
+ );
134
+ scriptOut = result.stdout;
135
+ if (result.stdout) console.log(result.stdout.trim());
136
+ if (result.stderr) console.error(result.stderr.trim());
137
+ } finally {
138
+ await withYamlLock(() => removeProfile(movementConfigPath, profile)).catch(
139
+ (err) => {
140
+ const cleanupMsg = err instanceof Error ? err.message : String(err);
141
+ logger.warning(
142
+ `Failed to remove script profile "${profile}" from ${movementConfigPath}: ${cleanupMsg}. ` +
143
+ `Run 'movement config delete-profile --profile ${profile}' to clean up manually.`
144
+ );
145
+ }
146
+ );
147
+ cleanupCallbacks.delete(syncCleanup);
148
+ }
149
+
150
+ const txHash = parseTxHash(scriptOut);
151
+ if (!txHash) {
152
+ throw new Error(
153
+ `Could not parse transaction hash from 'move run-script' output. ` +
154
+ `Captured stdout:\n${scriptOut.slice(0, 1000)}`
155
+ );
156
+ }
157
+
158
+ const success = parseSuccess(scriptOut);
159
+ const vmStatus = parseVmStatus(scriptOut);
160
+
161
+ logger.success(`Move script executed (tx ${txHash}).`);
162
+
163
+ const out: MoveScriptResult = { txHash };
164
+ if (success !== undefined) out.success = success;
165
+ if (vmStatus !== undefined) out.vmStatus = vmStatus;
166
+ return out;
167
+ } catch (error) {
168
+ if (error instanceof CliExecutionError) {
169
+ if (error.stdoutPreview) console.log(error.stdoutPreview);
170
+ logger.error(`Failed to run Move script: ${error.message}\n${error.stderr}`);
171
+ } else {
172
+ const err = error instanceof Error ? error : new Error(String(error));
173
+ logger.error(`Failed to run Move script: ${err.message}`);
174
+ }
175
+ throw error;
176
+ }
177
+ }
178
+
179
+ /**
180
+ * Best-effort parse of the `"success": true|false` field from
181
+ * Movement CLI's Result JSON block. Returns `undefined` on no match.
182
+ */
183
+ function parseSuccess(stdout: string): boolean | undefined {
184
+ const m = stdout.match(/"success"\s*:\s*(true|false)/);
185
+ if (!m) return undefined;
186
+ return m[1] === "true";
187
+ }
188
+
189
+ /**
190
+ * Best-effort parse of the `"vm_status"` string. Returns `undefined`
191
+ * on no match.
192
+ */
193
+ function parseVmStatus(stdout: string): string | undefined {
194
+ const m = stdout.match(/"vm_status"\s*:\s*"([^"]*)"/);
195
+ return m?.[1];
196
+ }
@@ -0,0 +1,34 @@
1
+ import type { MoveFunctionId } from "@aptos-labs/ts-sdk";
2
+ import type { MovehatRuntime } from "../types/runtime.js";
3
+ import type { RunViewFunctionOptions } from "../types/harness.js";
4
+
5
+ /**
6
+ * Execute a Move view function via the Aptos SDK (no CLI invocation).
7
+ *
8
+ * Returns the SDK's raw `unknown[]` — the Move boundary may return a
9
+ * tuple of any arity. Callers destructure:
10
+ *
11
+ * ```ts
12
+ * const [count] = await harness.runViewFunction({
13
+ * function: "0xCAFE::counter::get",
14
+ * functionArguments: ["0xdeployer"],
15
+ * });
16
+ * ```
17
+ *
18
+ * Works on all 3 harness modes (createLocal, createFork, createLive) —
19
+ * view functions read on-chain state without writing.
20
+ *
21
+ * @internal — called from `Harness.runViewFunction`.
22
+ */
23
+ export async function runViewFunction(
24
+ runtime: MovehatRuntime,
25
+ options: RunViewFunctionOptions
26
+ ): Promise<unknown[]> {
27
+ return runtime.aptos.view({
28
+ payload: {
29
+ function: options.function as MoveFunctionId,
30
+ typeArguments: options.typeArguments ?? [],
31
+ functionArguments: (options.functionArguments ?? []) as never[],
32
+ },
33
+ });
34
+ }