@typeberry/lib 0.5.10 → 0.5.11-1fbacf3

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 (502) hide show
  1. package/README.md +2 -2
  2. package/bin/lib/examples/pvm-usage.test.js +2 -2
  3. package/package.json +1 -1
  4. package/packages/core/codec/descriptor.js +1 -1
  5. package/packages/core/codec/descriptors.js +7 -4
  6. package/packages/core/codec/encoder.d.ts +1 -1
  7. package/packages/core/codec/encoder.d.ts.map +1 -1
  8. package/packages/core/codec/encoder.js +3 -2
  9. package/packages/core/codec/index.test.js +1 -1
  10. package/packages/core/codec/skip.d.ts +2 -1
  11. package/packages/core/codec/skip.d.ts.map +1 -1
  12. package/packages/core/codec/skip.js +3 -0
  13. package/packages/core/codec/view.js +2 -2
  14. package/packages/core/collections/multi-map.d.ts +2 -1
  15. package/packages/core/collections/multi-map.d.ts.map +1 -1
  16. package/packages/core/collections/multi-map.js +3 -0
  17. package/packages/core/collections/multi-map.test.js +2 -2
  18. package/packages/core/concurrent/parent.js +4 -1
  19. package/packages/core/crypto/ed25519.d.ts +2 -5
  20. package/packages/core/crypto/ed25519.d.ts.map +1 -1
  21. package/packages/core/crypto/ed25519.js +4 -1
  22. package/packages/core/hash/hash.d.ts +4 -2
  23. package/packages/core/hash/hash.d.ts.map +1 -1
  24. package/packages/core/hash/hash.js +6 -1
  25. package/packages/core/networking/quic-network.d.ts +3 -2
  26. package/packages/core/networking/quic-network.d.ts.map +1 -1
  27. package/packages/core/networking/quic-network.js +3 -0
  28. package/packages/core/networking/quic-peer.d.ts +2 -1
  29. package/packages/core/networking/quic-peer.d.ts.map +1 -1
  30. package/packages/core/networking/quic-peer.js +5 -2
  31. package/packages/core/networking/quic-stream.d.ts +2 -1
  32. package/packages/core/networking/quic-stream.d.ts.map +1 -1
  33. package/packages/core/networking/quic-stream.js +3 -0
  34. package/packages/core/networking/setup.js +2 -2
  35. package/packages/core/pvm-host-calls/bin.js +2 -2
  36. package/packages/core/pvm-host-calls/ecalli-trace-logger.d.ts +5 -0
  37. package/packages/core/pvm-host-calls/ecalli-trace-logger.d.ts.map +1 -1
  38. package/packages/core/pvm-host-calls/ecalli-trace-logger.js +8 -1
  39. package/packages/core/pvm-host-calls/ecalli-trace-logger.test.js +1 -1
  40. package/packages/core/pvm-host-calls/host-call-memory.d.ts +2 -1
  41. package/packages/core/pvm-host-calls/host-call-memory.d.ts.map +1 -1
  42. package/packages/core/pvm-host-calls/host-call-memory.js +3 -0
  43. package/packages/core/pvm-host-calls/host-call-memory.test.js +1 -1
  44. package/packages/core/pvm-host-calls/host-call-registers.d.ts +5 -1
  45. package/packages/core/pvm-host-calls/host-call-registers.d.ts.map +1 -1
  46. package/packages/core/pvm-host-calls/host-call-registers.js +11 -1
  47. package/packages/core/pvm-host-calls/host-call-registers.test.js +2 -2
  48. package/packages/core/pvm-host-calls/host-calls-executor.d.ts +2 -1
  49. package/packages/core/pvm-host-calls/host-calls-executor.d.ts.map +1 -1
  50. package/packages/core/pvm-host-calls/host-calls-executor.js +5 -2
  51. package/packages/core/pvm-host-calls/host-calls.d.ts +4 -2
  52. package/packages/core/pvm-host-calls/host-calls.d.ts.map +1 -1
  53. package/packages/core/pvm-host-calls/host-calls.js +9 -4
  54. package/packages/core/pvm-host-calls/pvm-instance-manager.js +1 -1
  55. package/packages/core/pvm-interface/pvm.d.ts +2 -0
  56. package/packages/core/pvm-interface/pvm.d.ts.map +1 -1
  57. package/packages/core/pvm-interpreter/args-decoder/args-decoder.js +1 -1
  58. package/packages/core/pvm-interpreter/args-decoder/args-decoder.test.js +3 -3
  59. package/packages/core/pvm-interpreter/args-decoder/args-decoding-results.js +11 -11
  60. package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.d.ts +2 -1
  61. package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.d.ts.map +1 -1
  62. package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.js +3 -0
  63. package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.test.js +2 -2
  64. package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.d.ts +2 -1
  65. package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.d.ts.map +1 -1
  66. package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.js +3 -0
  67. package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.test.js +26 -26
  68. package/packages/core/pvm-interpreter/basic-blocks/basic-blocks.test.js +8 -8
  69. package/packages/core/pvm-interpreter/bin.js +1 -1
  70. package/packages/core/pvm-interpreter/debugger-adapter.d.ts +2 -1
  71. package/packages/core/pvm-interpreter/debugger-adapter.d.ts.map +1 -1
  72. package/packages/core/pvm-interpreter/debugger-adapter.js +6 -3
  73. package/packages/core/pvm-interpreter/gas.js +4 -1
  74. package/packages/core/pvm-interpreter/interpreter.d.ts +2 -1
  75. package/packages/core/pvm-interpreter/interpreter.d.ts.map +1 -1
  76. package/packages/core/pvm-interpreter/interpreter.js +19 -16
  77. package/packages/core/pvm-interpreter/memory/memory-builder.js +2 -2
  78. package/packages/core/pvm-interpreter/memory/memory-builder.test.js +7 -7
  79. package/packages/core/pvm-interpreter/memory/memory.d.ts +2 -1
  80. package/packages/core/pvm-interpreter/memory/memory.d.ts.map +1 -1
  81. package/packages/core/pvm-interpreter/memory/memory.js +4 -1
  82. package/packages/core/pvm-interpreter/memory/memory.test.js +31 -31
  83. package/packages/core/pvm-interpreter/memory/pages/readable-page.d.ts +2 -1
  84. package/packages/core/pvm-interpreter/memory/pages/readable-page.d.ts.map +1 -1
  85. package/packages/core/pvm-interpreter/memory/pages/readable-page.js +3 -0
  86. package/packages/core/pvm-interpreter/memory/pages/readable-page.test.js +3 -3
  87. package/packages/core/pvm-interpreter/memory/pages/writeable-page.d.ts +2 -1
  88. package/packages/core/pvm-interpreter/memory/pages/writeable-page.d.ts.map +1 -1
  89. package/packages/core/pvm-interpreter/memory/pages/writeable-page.js +3 -0
  90. package/packages/core/pvm-interpreter/memory/pages/writeable-page.test.js +4 -4
  91. package/packages/core/pvm-interpreter/ops/bit-ops.d.ts +2 -1
  92. package/packages/core/pvm-interpreter/ops/bit-ops.d.ts.map +1 -1
  93. package/packages/core/pvm-interpreter/ops/bit-ops.js +3 -0
  94. package/packages/core/pvm-interpreter/ops/bit-ops.test.js +3 -3
  95. package/packages/core/pvm-interpreter/ops/bit-rotation-ops.d.ts +2 -1
  96. package/packages/core/pvm-interpreter/ops/bit-rotation-ops.d.ts.map +1 -1
  97. package/packages/core/pvm-interpreter/ops/bit-rotation-ops.js +3 -0
  98. package/packages/core/pvm-interpreter/ops/bit-rotation-ops.test.js +5 -5
  99. package/packages/core/pvm-interpreter/ops/boolean-ops.d.ts +2 -1
  100. package/packages/core/pvm-interpreter/ops/boolean-ops.d.ts.map +1 -1
  101. package/packages/core/pvm-interpreter/ops/boolean-ops.js +3 -0
  102. package/packages/core/pvm-interpreter/ops/boolean-ops.test.js +3 -3
  103. package/packages/core/pvm-interpreter/ops/branch-ops.d.ts +2 -1
  104. package/packages/core/pvm-interpreter/ops/branch-ops.d.ts.map +1 -1
  105. package/packages/core/pvm-interpreter/ops/branch-ops.js +3 -0
  106. package/packages/core/pvm-interpreter/ops/branch-ops.test.js +4 -4
  107. package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.d.ts +2 -1
  108. package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.d.ts.map +1 -1
  109. package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.js +3 -0
  110. package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.test.js +5 -5
  111. package/packages/core/pvm-interpreter/ops/host-call-ops.d.ts +2 -1
  112. package/packages/core/pvm-interpreter/ops/host-call-ops.d.ts.map +1 -1
  113. package/packages/core/pvm-interpreter/ops/host-call-ops.js +3 -0
  114. package/packages/core/pvm-interpreter/ops/host-call-ops.test.js +2 -2
  115. package/packages/core/pvm-interpreter/ops/load-ops.d.ts +2 -1
  116. package/packages/core/pvm-interpreter/ops/load-ops.d.ts.map +1 -1
  117. package/packages/core/pvm-interpreter/ops/load-ops.js +3 -0
  118. package/packages/core/pvm-interpreter/ops/load-ops.test.js +10 -10
  119. package/packages/core/pvm-interpreter/ops/math-ops.d.ts +2 -1
  120. package/packages/core/pvm-interpreter/ops/math-ops.d.ts.map +1 -1
  121. package/packages/core/pvm-interpreter/ops/math-ops.js +3 -0
  122. package/packages/core/pvm-interpreter/ops/math-ops.test.js +3 -3
  123. package/packages/core/pvm-interpreter/ops/memory-ops.d.ts +2 -1
  124. package/packages/core/pvm-interpreter/ops/memory-ops.d.ts.map +1 -1
  125. package/packages/core/pvm-interpreter/ops/memory-ops.js +3 -0
  126. package/packages/core/pvm-interpreter/ops/memory-ops.test.js +3 -3
  127. package/packages/core/pvm-interpreter/ops/move-ops.d.ts +2 -1
  128. package/packages/core/pvm-interpreter/ops/move-ops.d.ts.map +1 -1
  129. package/packages/core/pvm-interpreter/ops/move-ops.js +3 -0
  130. package/packages/core/pvm-interpreter/ops/move-ops.test.js +3 -3
  131. package/packages/core/pvm-interpreter/ops/no-args-ops.d.ts +2 -1
  132. package/packages/core/pvm-interpreter/ops/no-args-ops.d.ts.map +1 -1
  133. package/packages/core/pvm-interpreter/ops/no-args-ops.js +3 -0
  134. package/packages/core/pvm-interpreter/ops/no-args-ops.test.js +2 -2
  135. package/packages/core/pvm-interpreter/ops/shift-ops.d.ts +2 -1
  136. package/packages/core/pvm-interpreter/ops/shift-ops.d.ts.map +1 -1
  137. package/packages/core/pvm-interpreter/ops/shift-ops.js +3 -0
  138. package/packages/core/pvm-interpreter/ops/shift-ops.test.js +3 -3
  139. package/packages/core/pvm-interpreter/ops/store-ops.d.ts +2 -1
  140. package/packages/core/pvm-interpreter/ops/store-ops.d.ts.map +1 -1
  141. package/packages/core/pvm-interpreter/ops/store-ops.js +3 -0
  142. package/packages/core/pvm-interpreter/ops/store-ops.test.js +7 -7
  143. package/packages/core/pvm-interpreter/ops-dispatchers/no-args-dispatcher.test.js +1 -1
  144. package/packages/core/pvm-interpreter/ops-dispatchers/one-imm-dispatcher.test.js +4 -4
  145. package/packages/core/pvm-interpreter/ops-dispatchers/one-offset-dispatcher.test.js +2 -2
  146. package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-one-ext-imm-dispatcher.test.js +4 -4
  147. package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-one-imm-dispatcher.test.js +7 -7
  148. package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-one-imm-one-offset-dispatcher.test.js +10 -10
  149. package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-two-imms-dispatcher.test.js +5 -5
  150. package/packages/core/pvm-interpreter/ops-dispatchers/three-regs-dispatcher.test.js +7 -7
  151. package/packages/core/pvm-interpreter/ops-dispatchers/two-imms-dispatcher.test.js +5 -5
  152. package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-dispatcher.test.js +6 -6
  153. package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-one-imm-dispatcher.test.js +11 -11
  154. package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-one-offset-dispatcher.test.js +2 -2
  155. package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-two-imms-dispatcher.test.js +14 -14
  156. package/packages/core/pvm-interpreter/program-decoder/jump-table.d.ts +5 -2
  157. package/packages/core/pvm-interpreter/program-decoder/jump-table.d.ts.map +1 -1
  158. package/packages/core/pvm-interpreter/program-decoder/jump-table.js +9 -4
  159. package/packages/core/pvm-interpreter/program-decoder/jump-table.test.js +6 -6
  160. package/packages/core/pvm-interpreter/program-decoder/mask.d.ts +2 -1
  161. package/packages/core/pvm-interpreter/program-decoder/mask.d.ts.map +1 -1
  162. package/packages/core/pvm-interpreter/program-decoder/mask.js +3 -0
  163. package/packages/core/pvm-interpreter/program-decoder/mask.test.js +10 -10
  164. package/packages/core/pvm-interpreter/program-decoder/program-decoder.d.ts +2 -1
  165. package/packages/core/pvm-interpreter/program-decoder/program-decoder.d.ts.map +1 -1
  166. package/packages/core/pvm-interpreter/program-decoder/program-decoder.js +6 -3
  167. package/packages/core/pvm-interpreter/program-decoder/program-decoder.test.js +5 -5
  168. package/packages/core/pvm-interpreter/program.js +3 -3
  169. package/packages/core/pvm-interpreter/registers.d.ts +5 -2
  170. package/packages/core/pvm-interpreter/registers.d.ts.map +1 -1
  171. package/packages/core/pvm-interpreter/registers.js +10 -6
  172. package/packages/core/pvm-interpreter/registers.test.js +10 -10
  173. package/packages/core/pvm-interpreter/spi-decoder/decode-standard-program.d.ts +6 -3
  174. package/packages/core/pvm-interpreter/spi-decoder/decode-standard-program.d.ts.map +1 -1
  175. package/packages/core/pvm-interpreter/spi-decoder/decode-standard-program.js +11 -2
  176. package/packages/core/pvm-interpreter-ananas/index.d.ts +6 -3
  177. package/packages/core/pvm-interpreter-ananas/index.d.ts.map +1 -1
  178. package/packages/core/pvm-interpreter-ananas/index.js +12 -3
  179. package/packages/core/trie/nodes.d.ts +7 -2
  180. package/packages/core/trie/nodes.d.ts.map +1 -1
  181. package/packages/core/trie/nodes.js +20 -11
  182. package/packages/core/trie/nodesDb.d.ts +3 -1
  183. package/packages/core/trie/nodesDb.d.ts.map +1 -1
  184. package/packages/core/trie/nodesDb.js +6 -0
  185. package/packages/core/trie/trie.js +2 -2
  186. package/packages/extensions/ipc/index.js +5 -2
  187. package/packages/extensions/ipc/jamnp/handler.d.ts +4 -2
  188. package/packages/extensions/ipc/jamnp/handler.d.ts.map +1 -1
  189. package/packages/extensions/ipc/jamnp/handler.js +9 -3
  190. package/packages/extensions/ipc/jamnp/server.js +3 -3
  191. package/packages/extensions/ipc/server.d.ts +2 -1
  192. package/packages/extensions/ipc/server.d.ts.map +1 -1
  193. package/packages/extensions/ipc/server.js +4 -1
  194. package/packages/jam/block/header.js +1 -1
  195. package/packages/jam/block/work-package.d.ts +7 -7
  196. package/packages/jam/block/work-package.d.ts.map +1 -1
  197. package/packages/jam/block/work-package.js +12 -12
  198. package/packages/jam/config/chain-spec.d.ts +2 -1
  199. package/packages/jam/config/chain-spec.d.ts.map +1 -1
  200. package/packages/jam/config/chain-spec.js +5 -2
  201. package/packages/jam/config/network.d.ts +2 -7
  202. package/packages/jam/config/network.d.ts.map +1 -1
  203. package/packages/jam/config/network.js +3 -0
  204. package/packages/jam/config-node/jip-chain-spec.js +1 -1
  205. package/packages/jam/database/blocks.test.js +1 -1
  206. package/packages/jam/database/states.d.ts +2 -1
  207. package/packages/jam/database/states.d.ts.map +1 -1
  208. package/packages/jam/database/states.js +3 -0
  209. package/packages/jam/database/states.test.js +1 -1
  210. package/packages/jam/database-lmdb/blocks.d.ts +2 -1
  211. package/packages/jam/database-lmdb/blocks.d.ts.map +1 -1
  212. package/packages/jam/database-lmdb/blocks.js +3 -0
  213. package/packages/jam/database-lmdb/root.d.ts +2 -1
  214. package/packages/jam/database-lmdb/root.d.ts.map +1 -1
  215. package/packages/jam/database-lmdb/root.js +3 -0
  216. package/packages/jam/database-lmdb/states.d.ts +2 -1
  217. package/packages/jam/database-lmdb/states.d.ts.map +1 -1
  218. package/packages/jam/database-lmdb/states.js +3 -0
  219. package/packages/jam/database-lmdb/states.test.js +9 -9
  220. package/packages/jam/executor/index.d.ts +1 -1
  221. package/packages/jam/executor/index.d.ts.map +1 -1
  222. package/packages/jam/executor/index.js +1 -1
  223. package/packages/jam/executor/pvm-executor.d.ts +9 -2
  224. package/packages/jam/executor/pvm-executor.d.ts.map +1 -1
  225. package/packages/jam/executor/pvm-executor.js +36 -21
  226. package/packages/jam/fuzz-proto/v1/handler.d.ts +2 -1
  227. package/packages/jam/fuzz-proto/v1/handler.d.ts.map +1 -1
  228. package/packages/jam/fuzz-proto/v1/handler.js +3 -0
  229. package/packages/jam/fuzz-proto/v1/handler.test.js +10 -10
  230. package/packages/jam/in-core/externalities/index.d.ts +4 -0
  231. package/packages/jam/in-core/externalities/index.d.ts.map +1 -0
  232. package/packages/jam/in-core/externalities/index.js +3 -0
  233. package/packages/jam/in-core/externalities/is-authorized-fetch.d.ts +20 -0
  234. package/packages/jam/in-core/externalities/is-authorized-fetch.d.ts.map +1 -0
  235. package/packages/jam/in-core/externalities/is-authorized-fetch.js +41 -0
  236. package/packages/jam/in-core/externalities/is-authorized-fetch.test.d.ts +2 -0
  237. package/packages/jam/in-core/externalities/is-authorized-fetch.test.d.ts.map +1 -0
  238. package/packages/jam/in-core/externalities/is-authorized-fetch.test.js +101 -0
  239. package/packages/jam/in-core/externalities/refine-fetch.d.ts +51 -0
  240. package/packages/jam/in-core/externalities/refine-fetch.d.ts.map +1 -0
  241. package/packages/jam/in-core/externalities/refine-fetch.js +80 -0
  242. package/packages/jam/in-core/externalities/refine-fetch.test.d.ts +2 -0
  243. package/packages/jam/in-core/externalities/refine-fetch.test.d.ts.map +1 -0
  244. package/packages/jam/in-core/externalities/refine-fetch.test.js +219 -0
  245. package/packages/jam/in-core/externalities/refine.d.ts +18 -8
  246. package/packages/jam/in-core/externalities/refine.d.ts.map +1 -1
  247. package/packages/jam/in-core/externalities/refine.js +86 -7
  248. package/packages/jam/in-core/externalities/refine.test.js +168 -3
  249. package/packages/jam/in-core/in-core.d.ts +9 -23
  250. package/packages/jam/in-core/in-core.d.ts.map +1 -1
  251. package/packages/jam/in-core/in-core.js +22 -187
  252. package/packages/jam/in-core/in-core.test.js +52 -20
  253. package/packages/jam/in-core/is-authorized.d.ts +34 -0
  254. package/packages/jam/in-core/is-authorized.d.ts.map +1 -0
  255. package/packages/jam/in-core/is-authorized.js +73 -0
  256. package/packages/jam/in-core/is-authorized.test.d.ts +2 -0
  257. package/packages/jam/in-core/is-authorized.test.d.ts.map +1 -0
  258. package/packages/jam/in-core/is-authorized.test.js +167 -0
  259. package/packages/jam/in-core/refine.d.ts +31 -0
  260. package/packages/jam/in-core/refine.d.ts.map +1 -0
  261. package/packages/jam/in-core/refine.js +182 -0
  262. package/packages/jam/in-core/refine.test.d.ts +2 -0
  263. package/packages/jam/in-core/refine.test.d.ts.map +1 -0
  264. package/packages/jam/in-core/refine.test.js +6 -0
  265. package/packages/jam/jam-host-calls/accumulate/assign.d.ts +2 -1
  266. package/packages/jam/jam-host-calls/accumulate/assign.d.ts.map +1 -1
  267. package/packages/jam/jam-host-calls/accumulate/assign.js +3 -0
  268. package/packages/jam/jam-host-calls/accumulate/assign.test.js +8 -9
  269. package/packages/jam/jam-host-calls/accumulate/bless.d.ts +2 -1
  270. package/packages/jam/jam-host-calls/accumulate/bless.d.ts.map +1 -1
  271. package/packages/jam/jam-host-calls/accumulate/bless.js +12 -9
  272. package/packages/jam/jam-host-calls/accumulate/bless.test.js +11 -12
  273. package/packages/jam/jam-host-calls/accumulate/checkpoint.d.ts +2 -1
  274. package/packages/jam/jam-host-calls/accumulate/checkpoint.d.ts.map +1 -1
  275. package/packages/jam/jam-host-calls/accumulate/checkpoint.js +4 -1
  276. package/packages/jam/jam-host-calls/accumulate/checkpoint.test.js +2 -3
  277. package/packages/jam/jam-host-calls/accumulate/designate.d.ts +2 -1
  278. package/packages/jam/jam-host-calls/accumulate/designate.d.ts.map +1 -1
  279. package/packages/jam/jam-host-calls/accumulate/designate.js +3 -0
  280. package/packages/jam/jam-host-calls/accumulate/designate.test.js +5 -6
  281. package/packages/jam/jam-host-calls/accumulate/eject.d.ts +2 -1
  282. package/packages/jam/jam-host-calls/accumulate/eject.d.ts.map +1 -1
  283. package/packages/jam/jam-host-calls/accumulate/eject.js +3 -0
  284. package/packages/jam/jam-host-calls/accumulate/eject.test.js +8 -9
  285. package/packages/jam/jam-host-calls/accumulate/forget.d.ts +2 -1
  286. package/packages/jam/jam-host-calls/accumulate/forget.d.ts.map +1 -1
  287. package/packages/jam/jam-host-calls/accumulate/forget.js +3 -0
  288. package/packages/jam/jam-host-calls/accumulate/forget.test.js +5 -6
  289. package/packages/jam/jam-host-calls/accumulate/new.d.ts +2 -1
  290. package/packages/jam/jam-host-calls/accumulate/new.d.ts.map +1 -1
  291. package/packages/jam/jam-host-calls/accumulate/new.js +3 -0
  292. package/packages/jam/jam-host-calls/accumulate/new.test.js +9 -10
  293. package/packages/jam/jam-host-calls/accumulate/provide.d.ts +2 -1
  294. package/packages/jam/jam-host-calls/accumulate/provide.d.ts.map +1 -1
  295. package/packages/jam/jam-host-calls/accumulate/provide.js +3 -0
  296. package/packages/jam/jam-host-calls/accumulate/provide.test.js +8 -9
  297. package/packages/jam/jam-host-calls/accumulate/query.d.ts +2 -1
  298. package/packages/jam/jam-host-calls/accumulate/query.d.ts.map +1 -1
  299. package/packages/jam/jam-host-calls/accumulate/query.js +3 -0
  300. package/packages/jam/jam-host-calls/accumulate/query.test.js +8 -9
  301. package/packages/jam/jam-host-calls/accumulate/solicit.d.ts +2 -1
  302. package/packages/jam/jam-host-calls/accumulate/solicit.d.ts.map +1 -1
  303. package/packages/jam/jam-host-calls/accumulate/solicit.js +3 -0
  304. package/packages/jam/jam-host-calls/accumulate/solicit.test.js +7 -8
  305. package/packages/jam/jam-host-calls/accumulate/transfer.d.ts +2 -1
  306. package/packages/jam/jam-host-calls/accumulate/transfer.d.ts.map +1 -1
  307. package/packages/jam/jam-host-calls/accumulate/transfer.js +3 -0
  308. package/packages/jam/jam-host-calls/accumulate/transfer.test.js +9 -10
  309. package/packages/jam/jam-host-calls/accumulate/upgrade.d.ts +2 -1
  310. package/packages/jam/jam-host-calls/accumulate/upgrade.d.ts.map +1 -1
  311. package/packages/jam/jam-host-calls/accumulate/upgrade.js +3 -0
  312. package/packages/jam/jam-host-calls/accumulate/upgrade.test.js +4 -5
  313. package/packages/jam/jam-host-calls/accumulate/yield.d.ts +2 -1
  314. package/packages/jam/jam-host-calls/accumulate/yield.d.ts.map +1 -1
  315. package/packages/jam/jam-host-calls/accumulate/yield.js +3 -0
  316. package/packages/jam/jam-host-calls/accumulate/yield.test.js +4 -5
  317. package/packages/jam/jam-host-calls/externalities/partial-state.d.ts +1 -1
  318. package/packages/jam/jam-host-calls/externalities/refine-externalities.d.ts +1 -1
  319. package/packages/jam/jam-host-calls/externalities/refine-externalities.d.ts.map +1 -1
  320. package/packages/jam/jam-host-calls/externalities/refine-externalities.test.js +9 -9
  321. package/packages/jam/jam-host-calls/externalities/state-update.d.ts +2 -3
  322. package/packages/jam/jam-host-calls/externalities/state-update.d.ts.map +1 -1
  323. package/packages/jam/jam-host-calls/externalities/state-update.js +5 -2
  324. package/packages/jam/jam-host-calls/externalities/test-accounts.js +2 -2
  325. package/packages/jam/jam-host-calls/general/fetch.d.ts +166 -104
  326. package/packages/jam/jam-host-calls/general/fetch.d.ts.map +1 -1
  327. package/packages/jam/jam-host-calls/general/fetch.js +120 -23
  328. package/packages/jam/jam-host-calls/general/fetch.test.js +125 -92
  329. package/packages/jam/jam-host-calls/general/gas.d.ts +2 -1
  330. package/packages/jam/jam-host-calls/general/gas.d.ts.map +1 -1
  331. package/packages/jam/jam-host-calls/general/gas.js +3 -0
  332. package/packages/jam/jam-host-calls/general/gas.test.js +4 -5
  333. package/packages/jam/jam-host-calls/general/info.d.ts +2 -1
  334. package/packages/jam/jam-host-calls/general/info.d.ts.map +1 -1
  335. package/packages/jam/jam-host-calls/general/info.js +3 -0
  336. package/packages/jam/jam-host-calls/general/info.test.js +6 -7
  337. package/packages/jam/jam-host-calls/general/log.d.ts +2 -1
  338. package/packages/jam/jam-host-calls/general/log.d.ts.map +1 -1
  339. package/packages/jam/jam-host-calls/general/log.js +3 -0
  340. package/packages/jam/jam-host-calls/general/lookup.d.ts +2 -1
  341. package/packages/jam/jam-host-calls/general/lookup.d.ts.map +1 -1
  342. package/packages/jam/jam-host-calls/general/lookup.js +3 -0
  343. package/packages/jam/jam-host-calls/general/lookup.test.js +8 -9
  344. package/packages/jam/jam-host-calls/general/read.d.ts +2 -1
  345. package/packages/jam/jam-host-calls/general/read.d.ts.map +1 -1
  346. package/packages/jam/jam-host-calls/general/read.js +3 -0
  347. package/packages/jam/jam-host-calls/general/read.test.js +11 -12
  348. package/packages/jam/jam-host-calls/general/write.d.ts +2 -1
  349. package/packages/jam/jam-host-calls/general/write.d.ts.map +1 -1
  350. package/packages/jam/jam-host-calls/general/write.js +3 -0
  351. package/packages/jam/jam-host-calls/general/write.test.js +10 -11
  352. package/packages/jam/jam-host-calls/refine/export.d.ts +2 -1
  353. package/packages/jam/jam-host-calls/refine/export.d.ts.map +1 -1
  354. package/packages/jam/jam-host-calls/refine/export.js +3 -0
  355. package/packages/jam/jam-host-calls/refine/export.test.js +6 -7
  356. package/packages/jam/jam-host-calls/refine/expunge.d.ts +2 -1
  357. package/packages/jam/jam-host-calls/refine/expunge.d.ts.map +1 -1
  358. package/packages/jam/jam-host-calls/refine/expunge.js +3 -0
  359. package/packages/jam/jam-host-calls/refine/expunge.test.js +3 -4
  360. package/packages/jam/jam-host-calls/refine/historical-lookup.d.ts +2 -1
  361. package/packages/jam/jam-host-calls/refine/historical-lookup.d.ts.map +1 -1
  362. package/packages/jam/jam-host-calls/refine/historical-lookup.js +3 -0
  363. package/packages/jam/jam-host-calls/refine/historical-lookup.test.js +11 -12
  364. package/packages/jam/jam-host-calls/refine/invoke.d.ts +2 -1
  365. package/packages/jam/jam-host-calls/refine/invoke.d.ts.map +1 -1
  366. package/packages/jam/jam-host-calls/refine/invoke.js +4 -1
  367. package/packages/jam/jam-host-calls/refine/invoke.test.js +10 -11
  368. package/packages/jam/jam-host-calls/refine/machine.d.ts +2 -1
  369. package/packages/jam/jam-host-calls/refine/machine.d.ts.map +1 -1
  370. package/packages/jam/jam-host-calls/refine/machine.js +3 -0
  371. package/packages/jam/jam-host-calls/refine/machine.test.js +6 -7
  372. package/packages/jam/jam-host-calls/refine/pages.d.ts +2 -1
  373. package/packages/jam/jam-host-calls/refine/pages.d.ts.map +1 -1
  374. package/packages/jam/jam-host-calls/refine/pages.js +3 -0
  375. package/packages/jam/jam-host-calls/refine/pages.test.js +3 -4
  376. package/packages/jam/jam-host-calls/refine/peek.d.ts +2 -1
  377. package/packages/jam/jam-host-calls/refine/peek.d.ts.map +1 -1
  378. package/packages/jam/jam-host-calls/refine/peek.js +3 -0
  379. package/packages/jam/jam-host-calls/refine/peek.test.js +3 -4
  380. package/packages/jam/jam-host-calls/refine/poke.d.ts +2 -1
  381. package/packages/jam/jam-host-calls/refine/poke.d.ts.map +1 -1
  382. package/packages/jam/jam-host-calls/refine/poke.js +3 -0
  383. package/packages/jam/jam-host-calls/refine/poke.test.js +3 -4
  384. package/packages/jam/jamnp-s/network.js +1 -1
  385. package/packages/jam/jamnp-s/peers.d.ts +2 -1
  386. package/packages/jam/jamnp-s/peers.d.ts.map +1 -1
  387. package/packages/jam/jamnp-s/peers.js +3 -0
  388. package/packages/jam/jamnp-s/protocol/ce-128-block-request.d.ts +4 -2
  389. package/packages/jam/jamnp-s/protocol/ce-128-block-request.d.ts.map +1 -1
  390. package/packages/jam/jamnp-s/protocol/ce-128-block-request.js +6 -0
  391. package/packages/jam/jamnp-s/protocol/ce-128-block-request.test.js +2 -2
  392. package/packages/jam/jamnp-s/protocol/ce-129-state-request.d.ts +4 -2
  393. package/packages/jam/jamnp-s/protocol/ce-129-state-request.d.ts.map +1 -1
  394. package/packages/jam/jamnp-s/protocol/ce-129-state-request.js +6 -0
  395. package/packages/jam/jamnp-s/protocol/ce-129-state-request.test.js +4 -4
  396. package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.d.ts +4 -2
  397. package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.d.ts.map +1 -1
  398. package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.js +6 -0
  399. package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.test.js +2 -2
  400. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts +6 -3
  401. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts.map +1 -1
  402. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.js +7 -0
  403. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.test.js +2 -2
  404. package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.d.ts +5 -2
  405. package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.d.ts.map +1 -1
  406. package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.js +7 -0
  407. package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.test.js +2 -2
  408. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.d.ts +4 -2
  409. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.d.ts.map +1 -1
  410. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.js +6 -0
  411. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.test.js +2 -2
  412. package/packages/jam/jamnp-s/protocol/up-0-block-announcement.d.ts +2 -1
  413. package/packages/jam/jamnp-s/protocol/up-0-block-announcement.d.ts.map +1 -1
  414. package/packages/jam/jamnp-s/protocol/up-0-block-announcement.js +3 -0
  415. package/packages/jam/jamnp-s/stream-manager.d.ts +2 -1
  416. package/packages/jam/jamnp-s/stream-manager.d.ts.map +1 -1
  417. package/packages/jam/jamnp-s/stream-manager.js +4 -1
  418. package/packages/jam/jamnp-s/tasks/sync.js +4 -4
  419. package/packages/jam/jamnp-s/tasks/sync.test.js +4 -4
  420. package/packages/jam/jamnp-s/tasks/ticket-distribution.js +2 -2
  421. package/packages/jam/jamnp-s/tasks/ticket-distribution.test.js +1 -1
  422. package/packages/jam/node/common.d.ts.map +1 -1
  423. package/packages/jam/node/common.js +3 -3
  424. package/packages/jam/rpc-client/index.d.ts +4 -2
  425. package/packages/jam/rpc-client/index.d.ts.map +1 -1
  426. package/packages/jam/rpc-client/index.js +7 -1
  427. package/packages/jam/state/in-memory-state-view.d.ts +2 -1
  428. package/packages/jam/state/in-memory-state-view.d.ts.map +1 -1
  429. package/packages/jam/state/in-memory-state-view.js +3 -0
  430. package/packages/jam/state/in-memory-state.d.ts +16 -21
  431. package/packages/jam/state/in-memory-state.d.ts.map +1 -1
  432. package/packages/jam/state/in-memory-state.js +10 -6
  433. package/packages/jam/state/in-memory-state.test.js +2 -2
  434. package/packages/jam/state/service.d.ts +2 -6
  435. package/packages/jam/state/service.d.ts.map +1 -1
  436. package/packages/jam/state/service.js +3 -0
  437. package/packages/jam/state/test.utils.js +3 -3
  438. package/packages/jam/state-json/accounts.js +5 -5
  439. package/packages/jam/state-merkleization/in-memory-state-codec.d.ts +3 -34
  440. package/packages/jam/state-merkleization/in-memory-state-codec.d.ts.map +1 -1
  441. package/packages/jam/state-merkleization/in-memory-state-codec.js +1 -1
  442. package/packages/jam/state-merkleization/serialized-state-view.d.ts +8 -3
  443. package/packages/jam/state-merkleization/serialized-state-view.d.ts.map +1 -1
  444. package/packages/jam/state-merkleization/serialized-state-view.js +6 -3
  445. package/packages/jam/state-merkleization/serialized-state.d.ts +2 -3
  446. package/packages/jam/state-merkleization/serialized-state.d.ts.map +1 -1
  447. package/packages/jam/state-merkleization/serialized-state.js +10 -2
  448. package/packages/jam/state-merkleization/serialized-state.test.js +1 -1
  449. package/packages/jam/transition/accumulate/accumulate.d.ts.map +1 -1
  450. package/packages/jam/transition/accumulate/accumulate.js +20 -8
  451. package/packages/jam/transition/accumulate/accumulate.test.js +1 -1
  452. package/packages/jam/transition/accumulate/accumulation-result-merge-utils.js +48 -39
  453. package/packages/jam/transition/block-verifier.d.ts +2 -1
  454. package/packages/jam/transition/block-verifier.d.ts.map +1 -1
  455. package/packages/jam/transition/block-verifier.js +3 -0
  456. package/packages/jam/transition/block-verifier.test.js +8 -8
  457. package/packages/jam/transition/chain-stf.d.ts +12 -4
  458. package/packages/jam/transition/chain-stf.d.ts.map +1 -1
  459. package/packages/jam/transition/chain-stf.js +7 -3
  460. package/packages/jam/transition/externalities/accumulate-externalities.d.ts +22 -8
  461. package/packages/jam/transition/externalities/accumulate-externalities.d.ts.map +1 -1
  462. package/packages/jam/transition/externalities/accumulate-externalities.js +49 -29
  463. package/packages/jam/transition/externalities/accumulate-externalities.test.js +661 -101
  464. package/packages/jam/transition/externalities/accumulate-fetch-externalities.d.ts +19 -0
  465. package/packages/jam/transition/externalities/accumulate-fetch-externalities.d.ts.map +1 -0
  466. package/packages/jam/transition/externalities/accumulate-fetch-externalities.js +45 -0
  467. package/packages/jam/transition/externalities/accumulate-fetch-externalities.test.d.ts +2 -0
  468. package/packages/jam/transition/externalities/accumulate-fetch-externalities.test.d.ts.map +1 -0
  469. package/packages/jam/transition/externalities/accumulate-fetch-externalities.test.js +192 -0
  470. package/packages/jam/transition/externalities/fetch-externalities.d.ts +54 -37
  471. package/packages/jam/transition/externalities/fetch-externalities.d.ts.map +1 -1
  472. package/packages/jam/transition/externalities/fetch-externalities.js +45 -89
  473. package/packages/jam/transition/externalities/index.d.ts +1 -0
  474. package/packages/jam/transition/externalities/index.d.ts.map +1 -1
  475. package/packages/jam/transition/externalities/index.js +1 -0
  476. package/packages/jam/transition/hasher.d.ts +2 -1
  477. package/packages/jam/transition/hasher.d.ts.map +1 -1
  478. package/packages/jam/transition/hasher.js +5 -2
  479. package/packages/jam/transition/hasher.test.js +1 -1
  480. package/packages/jam/transition/preimages.test.js +4 -4
  481. package/packages/jam/transition/reports/test.utils.js +1 -1
  482. package/packages/workers/api-node/config.js +4 -4
  483. package/packages/workers/api-node/port.d.ts +2 -1
  484. package/packages/workers/api-node/port.d.ts.map +1 -1
  485. package/packages/workers/api-node/port.js +4 -1
  486. package/packages/workers/api-node/port.test.js +2 -2
  487. package/packages/workers/api-node/protocol.js +2 -2
  488. package/packages/workers/block-authorship/generator.d.ts +13 -2
  489. package/packages/workers/block-authorship/generator.d.ts.map +1 -1
  490. package/packages/workers/block-authorship/generator.js +13 -9
  491. package/packages/workers/block-authorship/generator.test.js +16 -2
  492. package/packages/workers/block-authorship/main.d.ts.map +1 -1
  493. package/packages/workers/block-authorship/main.js +8 -1
  494. package/packages/workers/importer/finality.test.js +1 -1
  495. package/packages/workers/importer/importer.d.ts +23 -6
  496. package/packages/workers/importer/importer.d.ts.map +1 -1
  497. package/packages/workers/importer/importer.js +34 -19
  498. package/packages/workers/importer/main.d.ts.map +1 -1
  499. package/packages/workers/importer/main.js +13 -5
  500. package/packages/jam/transition/externalities/fetch-externalities.test.d.ts +0 -2
  501. package/packages/jam/transition/externalities/fetch-externalities.test.d.ts.map +0 -1
  502. package/packages/jam/transition/externalities/fetch-externalities.test.js +0 -254
@@ -6,7 +6,7 @@ import { asKnownSize, FixedSizeArray, HashDictionary } from "#@typeberry/collect
6
6
  import { tinyChainSpec } from "#@typeberry/config";
7
7
  import { BANDERSNATCH_KEY_BYTES, BLS_KEY_BYTES, ED25519_KEY_BYTES } from "#@typeberry/crypto";
8
8
  import { Blake2b, HASH_SIZE } from "#@typeberry/hash";
9
- import { EjectError, ForgetPreimageError, NewServiceError, PartiallyUpdatedState, PendingTransfer, PreimageStatusKind, ProvidePreimageError, RequestPreimageError, TRANSFER_MEMO_BYTES, TransferError, UnprivilegedError, UpdatePrivilegesError, writeServiceIdAsLeBytes, } from "#@typeberry/jam-host-calls";
9
+ import { CURRENT_SERVICE_ID, EjectError, ForgetPreimageError, NewServiceError, PartiallyUpdatedState, PendingTransfer, PreimageStatusKind, ProvidePreimageError, RequestPreimageError, TRANSFER_MEMO_BYTES, TransferError, UnprivilegedError, UpdatePrivilegesError, writeServiceIdAsLeBytes, } from "#@typeberry/jam-host-calls";
10
10
  import { tryAsU32, tryAsU64 } from "#@typeberry/numbers";
11
11
  import { AUTHORIZATION_QUEUE_SIZE, InMemoryService, InMemoryState, LookupHistoryItem, PreimageItem, PrivilegedServices, ServiceAccountInfo, StorageItem, tryAsLookupHistorySlots, tryAsPerCore, UpdatePreimage, UpdateService, VALIDATOR_META_BYTES, ValidatorData, } from "#@typeberry/state";
12
12
  import { testState } from "#@typeberry/state/test.utils.js";
@@ -17,13 +17,20 @@ before(async () => {
17
17
  blake2b = await Blake2b.createHasher();
18
18
  });
19
19
  function partiallyUpdatedState() {
20
- return new PartiallyUpdatedState(testState());
20
+ return PartiallyUpdatedState.new(testState());
21
21
  }
22
22
  const INVALID_SERVICE_ID_ERROR = "Either manager or delegator or registrar is not a valid service id.";
23
23
  describe("PartialState.checkPreimageStatus", () => {
24
24
  it("should check preimage status from state", () => {
25
25
  const state = partiallyUpdatedState();
26
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
26
+ const partialState = AccumulateExternalities.forService({
27
+ chainSpec: tinyChainSpec,
28
+ blake2b: blake2b,
29
+ updatedState: state,
30
+ currentServiceId: tryAsServiceId(0),
31
+ nextNewServiceIdCandidate: tryAsServiceId(10),
32
+ currentTimeslot: tryAsTimeSlot(16),
33
+ });
27
34
  const preimageHash = Bytes.parseBytes("0xc16326432b5b3213dfd1609495e13c6b276cb474d679645337e5c2c09f19b53c", HASH_SIZE).asOpaque();
28
35
  const status = partialState.checkPreimageStatus(preimageHash, tryAsU64(35));
29
36
  assert.deepStrictEqual(status, {
@@ -34,12 +41,19 @@ describe("PartialState.checkPreimageStatus", () => {
34
41
  it("should return preimage status when its in updated state", () => {
35
42
  const state = partiallyUpdatedState();
36
43
  const serviceId = tryAsServiceId(0);
37
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, serviceId, tryAsServiceId(10), tryAsTimeSlot(16));
44
+ const partialState = AccumulateExternalities.forService({
45
+ chainSpec: tinyChainSpec,
46
+ blake2b: blake2b,
47
+ updatedState: state,
48
+ currentServiceId: serviceId,
49
+ nextNewServiceIdCandidate: tryAsServiceId(10),
50
+ currentTimeslot: tryAsTimeSlot(16),
51
+ });
38
52
  const preimageHash = Bytes.parseBytes("0xc16326432b5b3213dfd1609495e13c6b276cb474d679645337e5c2c09f19b53c", HASH_SIZE).asOpaque();
39
53
  const length = tryAsU64(35);
40
54
  const updates = state.stateUpdate.services.preimages.get(serviceId) ?? [];
41
55
  updates.push(UpdatePreimage.updateOrAdd({
42
- lookupHistory: new LookupHistoryItem(preimageHash, tryAsU32(Number(length)), tryAsLookupHistorySlots([])),
56
+ lookupHistory: LookupHistoryItem.new(preimageHash, tryAsU32(Number(length)), tryAsLookupHistorySlots([])),
43
57
  }));
44
58
  state.stateUpdate.services.preimages.set(serviceId, updates);
45
59
  const status = partialState.checkPreimageStatus(preimageHash, length);
@@ -57,7 +71,14 @@ describe("PartialState.requestPreimage", () => {
57
71
  throw new Error("Invalid service!");
58
72
  }
59
73
  const service = maybeService;
60
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, serviceId, tryAsServiceId(10), tryAsTimeSlot(16));
74
+ const partialState = AccumulateExternalities.forService({
75
+ chainSpec: tinyChainSpec,
76
+ blake2b: blake2b,
77
+ updatedState: state,
78
+ currentServiceId: serviceId,
79
+ nextNewServiceIdCandidate: tryAsServiceId(10),
80
+ currentTimeslot: tryAsTimeSlot(16),
81
+ });
61
82
  const preimageHash = Bytes.fill(HASH_SIZE, 0xa).asOpaque();
62
83
  const status = partialState.requestPreimage(preimageHash, tryAsU64(5));
63
84
  assert.deepStrictEqual(status, Result.ok(OK));
@@ -66,7 +87,7 @@ describe("PartialState.requestPreimage", () => {
66
87
  serviceId,
67
88
  [
68
89
  UpdatePreimage.updateOrAdd({
69
- lookupHistory: new LookupHistoryItem(preimageHash, tryAsU32(5), tryAsLookupHistorySlots([])),
90
+ lookupHistory: LookupHistoryItem.new(preimageHash, tryAsU32(5), tryAsLookupHistorySlots([])),
70
91
  }),
71
92
  ],
72
93
  ],
@@ -92,7 +113,14 @@ describe("PartialState.requestPreimage", () => {
92
113
  throw new Error("Invalid service!");
93
114
  }
94
115
  const service = maybeService;
95
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
116
+ const partialState = AccumulateExternalities.forService({
117
+ chainSpec: tinyChainSpec,
118
+ blake2b: blake2b,
119
+ updatedState: state,
120
+ currentServiceId: tryAsServiceId(0),
121
+ nextNewServiceIdCandidate: tryAsServiceId(10),
122
+ currentTimeslot: tryAsTimeSlot(16),
123
+ });
96
124
  const preimageHash = Bytes.fill(HASH_SIZE, 0xa).asOpaque();
97
125
  const status = partialState.requestPreimage(preimageHash, tryAsU64(5));
98
126
  assert.deepStrictEqual(status, Result.ok(OK));
@@ -101,7 +129,7 @@ describe("PartialState.requestPreimage", () => {
101
129
  serviceId,
102
130
  [
103
131
  UpdatePreimage.updateOrAdd({
104
- lookupHistory: new LookupHistoryItem(preimageHash, tryAsU32(5), tryAsLookupHistorySlots([])),
132
+ lookupHistory: LookupHistoryItem.new(preimageHash, tryAsU32(5), tryAsLookupHistorySlots([])),
105
133
  }),
106
134
  ],
107
135
  ],
@@ -121,7 +149,14 @@ describe("PartialState.requestPreimage", () => {
121
149
  });
122
150
  it("should fail if preimage is already requested", () => {
123
151
  const state = partiallyUpdatedState();
124
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
152
+ const partialState = AccumulateExternalities.forService({
153
+ chainSpec: tinyChainSpec,
154
+ blake2b: blake2b,
155
+ updatedState: state,
156
+ currentServiceId: tryAsServiceId(0),
157
+ nextNewServiceIdCandidate: tryAsServiceId(10),
158
+ currentTimeslot: tryAsTimeSlot(16),
159
+ });
125
160
  const preimageHash = Bytes.fill(HASH_SIZE, 0xa).asOpaque();
126
161
  const status = partialState.requestPreimage(preimageHash, tryAsU64(5));
127
162
  assert.deepStrictEqual(status, Result.ok(OK));
@@ -130,14 +165,28 @@ describe("PartialState.requestPreimage", () => {
130
165
  });
131
166
  it("should fail if preimage is already available", () => {
132
167
  const state = partiallyUpdatedState();
133
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
168
+ const partialState = AccumulateExternalities.forService({
169
+ chainSpec: tinyChainSpec,
170
+ blake2b: blake2b,
171
+ updatedState: state,
172
+ currentServiceId: tryAsServiceId(0),
173
+ nextNewServiceIdCandidate: tryAsServiceId(10),
174
+ currentTimeslot: tryAsTimeSlot(16),
175
+ });
134
176
  const preimageHash = Bytes.parseBytes("0xc16326432b5b3213dfd1609495e13c6b276cb474d679645337e5c2c09f19b53c", HASH_SIZE).asOpaque();
135
177
  const status = partialState.requestPreimage(preimageHash, tryAsU64(35));
136
178
  deepEqual(status, Result.error(RequestPreimageError.AlreadyAvailable, () => "Preimage already available: hash=0xc16326432b5b3213dfd1609495e13c6b276cb474d679645337e5c2c09f19b53c"));
137
179
  });
138
180
  it("should fail if balance is insufficient", () => {
139
181
  const state = partiallyUpdatedState();
140
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
182
+ const partialState = AccumulateExternalities.forService({
183
+ chainSpec: tinyChainSpec,
184
+ blake2b: blake2b,
185
+ updatedState: state,
186
+ currentServiceId: tryAsServiceId(0),
187
+ nextNewServiceIdCandidate: tryAsServiceId(10),
188
+ currentTimeslot: tryAsTimeSlot(16),
189
+ });
141
190
  const preimageHash = Bytes.fill(HASH_SIZE, 0xa).asOpaque();
142
191
  const status = partialState.requestPreimage(preimageHash, tryAsU64(2n ** 34n - 1n));
143
192
  deepEqual(status, Result.error(RequestPreimageError.InsufficientFunds, () => "Service balance (10000000000) below threshold (17179869696)"));
@@ -146,7 +195,14 @@ describe("PartialState.requestPreimage", () => {
146
195
  describe("PartialState.forgetPreimage", () => {
147
196
  it("should error if preimage does not exist", () => {
148
197
  const state = partiallyUpdatedState();
149
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
198
+ const partialState = AccumulateExternalities.forService({
199
+ chainSpec: tinyChainSpec,
200
+ blake2b: blake2b,
201
+ updatedState: state,
202
+ currentServiceId: tryAsServiceId(0),
203
+ nextNewServiceIdCandidate: tryAsServiceId(10),
204
+ currentTimeslot: tryAsTimeSlot(16),
205
+ });
150
206
  const hash = Bytes.fill(HASH_SIZE, 0x01).asOpaque();
151
207
  const result = partialState.forgetPreimage(hash, tryAsU64(42));
152
208
  deepEqual(result, Result.error(ForgetPreimageError.NotFound, () => "Preimage not found: hash=0x0101010101010101010101010101010101010101010101010101010101010101, length=42"));
@@ -156,10 +212,17 @@ describe("PartialState.forgetPreimage", () => {
156
212
  const serviceId = tryAsServiceId(0);
157
213
  const hash = Bytes.parseBytes("0xc16326432b5b3213dfd1609495e13c6b276cb474d679645337e5c2c09f19b53c", HASH_SIZE).asOpaque();
158
214
  const length = tryAsU64(35);
159
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, serviceId, tryAsServiceId(10), tryAsTimeSlot(50));
215
+ const partialState = AccumulateExternalities.forService({
216
+ chainSpec: tinyChainSpec,
217
+ blake2b: blake2b,
218
+ updatedState: state,
219
+ currentServiceId: serviceId,
220
+ nextNewServiceIdCandidate: tryAsServiceId(10),
221
+ currentTimeslot: tryAsTimeSlot(50),
222
+ });
160
223
  const updates = state.stateUpdate.services.preimages.get(serviceId) ?? [];
161
224
  updates.push(UpdatePreimage.updateOrAdd({
162
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([tryAsTimeSlot(0), tryAsTimeSlot(1)])),
225
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([tryAsTimeSlot(0), tryAsTimeSlot(1)])),
163
226
  }));
164
227
  state.stateUpdate.services.preimages.set(serviceId, updates);
165
228
  const result1 = partialState.forgetPreimage(hash, length);
@@ -173,7 +236,14 @@ describe("PartialState.forgetPreimage", () => {
173
236
  const serviceId = tryAsServiceId(0);
174
237
  const hash = Bytes.fill(HASH_SIZE, 0x03).asOpaque();
175
238
  const length = tryAsU64(42);
176
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, serviceId, tryAsServiceId(10), tryAsTimeSlot(16));
239
+ const partialState = AccumulateExternalities.forService({
240
+ chainSpec: tinyChainSpec,
241
+ blake2b: blake2b,
242
+ updatedState: state,
243
+ currentServiceId: serviceId,
244
+ nextNewServiceIdCandidate: tryAsServiceId(10),
245
+ currentTimeslot: tryAsTimeSlot(16),
246
+ });
177
247
  partialState.requestPreimage(hash, length);
178
248
  const result = partialState.forgetPreimage(hash, length);
179
249
  assert.deepStrictEqual(result, Result.ok(OK));
@@ -182,7 +252,7 @@ describe("PartialState.forgetPreimage", () => {
182
252
  serviceId,
183
253
  [
184
254
  UpdatePreimage.updateOrAdd({
185
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([])),
255
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([])),
186
256
  }),
187
257
  UpdatePreimage.remove({
188
258
  hash,
@@ -201,10 +271,17 @@ describe("PartialState.forgetPreimage", () => {
201
271
  const length = tryAsU64(42);
202
272
  const oldSlot = tryAsTimeSlot(0); // very old
203
273
  const serviceId = tryAsServiceId(0);
204
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, serviceId, tryAsServiceId(10), tryAsTimeSlot(50));
274
+ const partialState = AccumulateExternalities.forService({
275
+ chainSpec: tinyChainSpec,
276
+ blake2b: blake2b,
277
+ updatedState: state,
278
+ currentServiceId: serviceId,
279
+ nextNewServiceIdCandidate: tryAsServiceId(10),
280
+ currentTimeslot: tryAsTimeSlot(50),
281
+ });
205
282
  const updates = state.stateUpdate.services.preimages.get(serviceId) ?? [];
206
283
  updates.push(UpdatePreimage.updateOrAdd({
207
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([oldSlot, oldSlot])),
284
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([oldSlot, oldSlot])),
208
285
  }));
209
286
  state.stateUpdate.services.preimages.set(serviceId, updates);
210
287
  const result = partialState.forgetPreimage(hash, length);
@@ -214,7 +291,7 @@ describe("PartialState.forgetPreimage", () => {
214
291
  serviceId,
215
292
  [
216
293
  UpdatePreimage.updateOrAdd({
217
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([oldSlot, oldSlot])),
294
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([oldSlot, oldSlot])),
218
295
  }),
219
296
  UpdatePreimage.remove({
220
297
  hash,
@@ -233,10 +310,17 @@ describe("PartialState.forgetPreimage", () => {
233
310
  const length = tryAsU64(42);
234
311
  const recentSlot = tryAsTimeSlot(90); // within expunge period
235
312
  const serviceId = tryAsServiceId(0);
236
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, serviceId, tryAsServiceId(10), tryAsTimeSlot(16));
313
+ const partialState = AccumulateExternalities.forService({
314
+ chainSpec: tinyChainSpec,
315
+ blake2b: blake2b,
316
+ updatedState: state,
317
+ currentServiceId: serviceId,
318
+ nextNewServiceIdCandidate: tryAsServiceId(10),
319
+ currentTimeslot: tryAsTimeSlot(16),
320
+ });
237
321
  const updates = state.stateUpdate.services.preimages.get(serviceId) ?? [];
238
322
  updates.push(UpdatePreimage.updateOrAdd({
239
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([recentSlot])),
323
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([recentSlot])),
240
324
  }));
241
325
  state.stateUpdate.services.preimages.set(serviceId, updates);
242
326
  const result = partialState.forgetPreimage(hash, length);
@@ -251,10 +335,17 @@ describe("PartialState.forgetPreimage", () => {
251
335
  const length = tryAsU64(42);
252
336
  const availableSlot = tryAsTimeSlot(80);
253
337
  const serviceId = tryAsServiceId(0);
254
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, serviceId, tryAsServiceId(10), tryAsTimeSlot(100));
338
+ const partialState = AccumulateExternalities.forService({
339
+ chainSpec: tinyChainSpec,
340
+ blake2b: blake2b,
341
+ updatedState: state,
342
+ currentServiceId: serviceId,
343
+ nextNewServiceIdCandidate: tryAsServiceId(10),
344
+ currentTimeslot: tryAsTimeSlot(100),
345
+ });
255
346
  const updates = state.stateUpdate.services.preimages.get(serviceId) ?? [];
256
347
  updates.push(UpdatePreimage.updateOrAdd({
257
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([availableSlot])),
348
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([availableSlot])),
258
349
  }));
259
350
  state.stateUpdate.services.preimages.set(serviceId, updates);
260
351
  const result = partialState.forgetPreimage(hash, length);
@@ -264,10 +355,10 @@ describe("PartialState.forgetPreimage", () => {
264
355
  serviceId,
265
356
  [
266
357
  UpdatePreimage.updateOrAdd({
267
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([availableSlot])),
358
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([availableSlot])),
268
359
  }),
269
360
  UpdatePreimage.updateOrAdd({
270
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([availableSlot, state.state.timeslot])),
361
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([availableSlot, state.state.timeslot])),
271
362
  }),
272
363
  ],
273
364
  ],
@@ -283,10 +374,17 @@ describe("PartialState.forgetPreimage", () => {
283
374
  const y = tryAsTimeSlot(0);
284
375
  const z = tryAsTimeSlot(70);
285
376
  const serviceId = tryAsServiceId(0);
286
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, serviceId, tryAsServiceId(10), tryAsTimeSlot(100000));
377
+ const partialState = AccumulateExternalities.forService({
378
+ chainSpec: tinyChainSpec,
379
+ blake2b: blake2b,
380
+ updatedState: state,
381
+ currentServiceId: serviceId,
382
+ nextNewServiceIdCandidate: tryAsServiceId(10),
383
+ currentTimeslot: tryAsTimeSlot(100000),
384
+ });
287
385
  const updates = state.stateUpdate.services.preimages.get(serviceId) ?? [];
288
386
  updates.push(UpdatePreimage.updateOrAdd({
289
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([tryAsTimeSlot(0), y, z])),
387
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([tryAsTimeSlot(0), y, z])),
290
388
  }));
291
389
  state.stateUpdate.services.preimages.set(serviceId, updates);
292
390
  const result = partialState.forgetPreimage(hash, length);
@@ -296,10 +394,10 @@ describe("PartialState.forgetPreimage", () => {
296
394
  serviceId,
297
395
  [
298
396
  UpdatePreimage.updateOrAdd({
299
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([tryAsTimeSlot(0), y, z])),
397
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([tryAsTimeSlot(0), y, z])),
300
398
  }),
301
399
  UpdatePreimage.updateOrAdd({
302
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([z, state.state.timeslot])),
400
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([z, state.state.timeslot])),
303
401
  }),
304
402
  ],
305
403
  ],
@@ -315,10 +413,17 @@ describe("PartialState.forgetPreimage", () => {
315
413
  const y = tryAsTimeSlot(95); // too recent
316
414
  const z = tryAsTimeSlot(70);
317
415
  const serviceId = tryAsServiceId(0);
318
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, serviceId, tryAsServiceId(10), tryAsTimeSlot(100));
416
+ const partialState = AccumulateExternalities.forService({
417
+ chainSpec: tinyChainSpec,
418
+ blake2b: blake2b,
419
+ updatedState: state,
420
+ currentServiceId: serviceId,
421
+ nextNewServiceIdCandidate: tryAsServiceId(10),
422
+ currentTimeslot: tryAsTimeSlot(100),
423
+ });
319
424
  const updates = state.stateUpdate.services.preimages.get(serviceId) ?? [];
320
425
  updates.push(UpdatePreimage.updateOrAdd({
321
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([tryAsTimeSlot(0), y, z])),
426
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([tryAsTimeSlot(0), y, z])),
322
427
  }));
323
428
  state.stateUpdate.services.preimages.set(serviceId, updates);
324
429
  const result = partialState.forgetPreimage(hash, length);
@@ -329,10 +434,17 @@ describe("PartialState.forgetPreimage", () => {
329
434
  const hash = Bytes.fill(HASH_SIZE, 0x08).asOpaque();
330
435
  const length = tryAsU64(42);
331
436
  const serviceId = tryAsServiceId(0);
332
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, serviceId, tryAsServiceId(10), tryAsTimeSlot(2));
437
+ const partialState = AccumulateExternalities.forService({
438
+ chainSpec: tinyChainSpec,
439
+ blake2b: blake2b,
440
+ updatedState: state,
441
+ currentServiceId: serviceId,
442
+ nextNewServiceIdCandidate: tryAsServiceId(10),
443
+ currentTimeslot: tryAsTimeSlot(2),
444
+ });
333
445
  const updates = state.stateUpdate.services.preimages.get(serviceId) ?? [];
334
446
  updates.push(UpdatePreimage.updateOrAdd({
335
- lookupHistory: new LookupHistoryItem(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([tryAsTimeSlot(0), tryAsTimeSlot(1)])),
447
+ lookupHistory: LookupHistoryItem.new(hash, tryAsU32(Number(length)), tryAsLookupHistorySlots([tryAsTimeSlot(0), tryAsTimeSlot(1)])),
336
448
  }));
337
449
  state.stateUpdate.services.preimages.set(serviceId, updates);
338
450
  const result = partialState.forgetPreimage(hash, length);
@@ -347,7 +459,14 @@ describe("PartialState.newService", () => {
347
459
  throw new Error("Invalid service!");
348
460
  }
349
461
  const service = maybeService;
350
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
462
+ const partialState = AccumulateExternalities.forService({
463
+ chainSpec: tinyChainSpec,
464
+ blake2b: blake2b,
465
+ updatedState: state,
466
+ currentServiceId: tryAsServiceId(0),
467
+ nextNewServiceIdCandidate: tryAsServiceId(10),
468
+ currentTimeslot: tryAsTimeSlot(16),
469
+ });
351
470
  const codeHash = Bytes.fill(HASH_SIZE, 0x11).asOpaque();
352
471
  const codeLength = tryAsU32(100);
353
472
  const codeLengthU64 = tryAsU64(codeLength);
@@ -389,7 +508,7 @@ describe("PartialState.newService", () => {
389
508
  lastAccumulation: tryAsTimeSlot(0),
390
509
  parentService: service.serviceId,
391
510
  }),
392
- lookupHistory: new LookupHistoryItem(codeHash, codeLength, tryAsLookupHistorySlots([])),
511
+ lookupHistory: LookupHistoryItem.new(codeHash, codeLength, tryAsLookupHistorySlots([])),
393
512
  }),
394
513
  ],
395
514
  ]));
@@ -410,7 +529,14 @@ describe("PartialState.newService", () => {
410
529
  throw new Error("Invalid service!");
411
530
  }
412
531
  const service = maybeService;
413
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(serviceId), tryAsServiceId(10), tryAsTimeSlot(16));
532
+ const partialState = AccumulateExternalities.forService({
533
+ chainSpec: tinyChainSpec,
534
+ blake2b: blake2b,
535
+ updatedState: state,
536
+ currentServiceId: tryAsServiceId(serviceId),
537
+ nextNewServiceIdCandidate: tryAsServiceId(10),
538
+ currentTimeslot: tryAsTimeSlot(16),
539
+ });
414
540
  const codeHash = Bytes.fill(HASH_SIZE, 0x11).asOpaque();
415
541
  const codeLength = tryAsU32(100);
416
542
  const codeLengthU64 = tryAsU64(codeLength);
@@ -454,7 +580,7 @@ describe("PartialState.newService", () => {
454
580
  lastAccumulation: tryAsTimeSlot(0),
455
581
  parentService: service.serviceId,
456
582
  }),
457
- lookupHistory: new LookupHistoryItem(codeHash, codeLength, tryAsLookupHistorySlots([])),
583
+ lookupHistory: LookupHistoryItem.new(codeHash, codeLength, tryAsLookupHistorySlots([])),
458
584
  }),
459
585
  ],
460
586
  ]));
@@ -469,7 +595,7 @@ describe("PartialState.newService", () => {
469
595
  throw new Error("Invalid service!");
470
596
  }
471
597
  const service = maybeService;
472
- const updatedService = new InMemoryService(service.serviceId, {
598
+ const updatedService = InMemoryService.new(service.serviceId, {
473
599
  ...service.data,
474
600
  info: ServiceAccountInfo.create({
475
601
  ...service.data.info,
@@ -478,7 +604,14 @@ describe("PartialState.newService", () => {
478
604
  }),
479
605
  });
480
606
  state.state.services.set(tryAsServiceId(0), updatedService);
481
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
607
+ const partialState = AccumulateExternalities.forService({
608
+ chainSpec: tinyChainSpec,
609
+ blake2b: blake2b,
610
+ updatedState: state,
611
+ currentServiceId: tryAsServiceId(0),
612
+ nextNewServiceIdCandidate: tryAsServiceId(10),
613
+ currentTimeslot: tryAsTimeSlot(16),
614
+ });
482
615
  const codeHash = Bytes.fill(HASH_SIZE, 0x12).asOpaque();
483
616
  // artificially large to exceed balance
484
617
  const codeLength = tryAsU64(2 ** 32 + 1);
@@ -504,7 +637,7 @@ describe("PartialState.newService", () => {
504
637
  throw new Error("Invalid service!");
505
638
  }
506
639
  const service = maybeService;
507
- const updatedService = new InMemoryService(service.serviceId, {
640
+ const updatedService = InMemoryService.new(service.serviceId, {
508
641
  ...service.data,
509
642
  info: ServiceAccountInfo.create({
510
643
  ...service.data.info,
@@ -512,7 +645,14 @@ describe("PartialState.newService", () => {
512
645
  }),
513
646
  });
514
647
  state.state.services.set(tryAsServiceId(0), updatedService);
515
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
648
+ const partialState = AccumulateExternalities.forService({
649
+ chainSpec: tinyChainSpec,
650
+ blake2b: blake2b,
651
+ updatedState: state,
652
+ currentServiceId: tryAsServiceId(0),
653
+ nextNewServiceIdCandidate: tryAsServiceId(10),
654
+ currentTimeslot: tryAsTimeSlot(16),
655
+ });
516
656
  const codeHash = Bytes.fill(HASH_SIZE, 0x12).asOpaque();
517
657
  const codeLength = tryAsU64(1024);
518
658
  const accumulateMinGas = tryAsServiceGas(10n);
@@ -538,7 +678,14 @@ describe("PartialState.newService", () => {
538
678
  if (maybeService === undefined) {
539
679
  throw new Error("Invalid service!");
540
680
  }
541
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
681
+ const partialState = AccumulateExternalities.forService({
682
+ chainSpec: tinyChainSpec,
683
+ blake2b: blake2b,
684
+ updatedState: state,
685
+ currentServiceId: tryAsServiceId(0),
686
+ nextNewServiceIdCandidate: tryAsServiceId(10),
687
+ currentTimeslot: tryAsTimeSlot(16),
688
+ });
542
689
  const codeHash = Bytes.fill(HASH_SIZE, 0x11).asOpaque();
543
690
  const codeLength = tryAsU32(100);
544
691
  const codeLengthU64 = tryAsU64(codeLength);
@@ -565,7 +712,14 @@ describe("PartialState.newService", () => {
565
712
  if (maybeService === undefined) {
566
713
  throw new Error("Invalid service!");
567
714
  }
568
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
715
+ const partialState = AccumulateExternalities.forService({
716
+ chainSpec: tinyChainSpec,
717
+ blake2b: blake2b,
718
+ updatedState: state,
719
+ currentServiceId: tryAsServiceId(0),
720
+ nextNewServiceIdCandidate: tryAsServiceId(10),
721
+ currentTimeslot: tryAsTimeSlot(16),
722
+ });
569
723
  const codeHash = Bytes.fill(HASH_SIZE, 0x12).asOpaque();
570
724
  const codeLength = tryAsU64(1024);
571
725
  const accumulateMinGas = tryAsServiceGas(10n);
@@ -583,7 +737,14 @@ describe("PartialState.newService", () => {
583
737
  describe("PartialState.updateValidatorsData", () => {
584
738
  it("should update validators data", () => {
585
739
  const state = partiallyUpdatedState();
586
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
740
+ const partialState = AccumulateExternalities.forService({
741
+ chainSpec: tinyChainSpec,
742
+ blake2b: blake2b,
743
+ updatedState: state,
744
+ currentServiceId: tryAsServiceId(0),
745
+ nextNewServiceIdCandidate: tryAsServiceId(10),
746
+ currentTimeslot: tryAsTimeSlot(16),
747
+ });
587
748
  // when
588
749
  const result = partialState.updateValidatorsData(asKnownSize([
589
750
  ValidatorData.create({
@@ -603,7 +764,14 @@ describe("PartialState.updateValidatorsData", () => {
603
764
  ...state.state.privilegedServices,
604
765
  delegator: tryAsServiceId(1),
605
766
  });
606
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
767
+ const partialState = AccumulateExternalities.forService({
768
+ chainSpec: tinyChainSpec,
769
+ blake2b: blake2b,
770
+ updatedState: state,
771
+ currentServiceId: tryAsServiceId(0),
772
+ nextNewServiceIdCandidate: tryAsServiceId(10),
773
+ currentTimeslot: tryAsTimeSlot(16),
774
+ });
607
775
  // when
608
776
  const result = partialState.updateValidatorsData(asKnownSize([
609
777
  ValidatorData.create({
@@ -621,7 +789,14 @@ describe("PartialState.updateValidatorsData", () => {
621
789
  describe("PartialState.checkpoint", () => {
622
790
  it("should checkpoint the updates", () => {
623
791
  const state = partiallyUpdatedState();
624
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
792
+ const partialState = AccumulateExternalities.forService({
793
+ chainSpec: tinyChainSpec,
794
+ blake2b: blake2b,
795
+ updatedState: state,
796
+ currentServiceId: tryAsServiceId(0),
797
+ nextNewServiceIdCandidate: tryAsServiceId(10),
798
+ currentTimeslot: tryAsTimeSlot(16),
799
+ });
625
800
  const preimageHash = Bytes.fill(HASH_SIZE, 0xa).asOpaque();
626
801
  // put something into updated state
627
802
  const status = partialState.requestPreimage(preimageHash, tryAsU64(5));
@@ -640,7 +815,14 @@ describe("PartialState.upgradeService", () => {
640
815
  throw new Error("Invalid service!");
641
816
  }
642
817
  const service = maybeService;
643
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
818
+ const partialState = AccumulateExternalities.forService({
819
+ chainSpec: tinyChainSpec,
820
+ blake2b: blake2b,
821
+ updatedState: state,
822
+ currentServiceId: tryAsServiceId(0),
823
+ nextNewServiceIdCandidate: tryAsServiceId(10),
824
+ currentTimeslot: tryAsTimeSlot(16),
825
+ });
644
826
  const codeHash = Bytes.fill(HASH_SIZE, 0xcd).asOpaque();
645
827
  const gas = tryAsU64(1000n);
646
828
  const allowance = tryAsU64(2000n);
@@ -663,20 +845,46 @@ describe("PartialState.upgradeService", () => {
663
845
  });
664
846
  });
665
847
  describe("PartialState.updateAuthorizationQueue", () => {
666
- it("should update the authorization queue for a given core index", () => {
848
+ it("should update the authorization queue and transfer the assigner for the given core", () => {
667
849
  const state = partiallyUpdatedState();
668
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
850
+ const initialPrivileged = state.state.privilegedServices;
851
+ const partialState = AccumulateExternalities.forService({
852
+ chainSpec: tinyChainSpec,
853
+ blake2b: blake2b,
854
+ updatedState: state,
855
+ currentServiceId: tryAsServiceId(0),
856
+ nextNewServiceIdCandidate: tryAsServiceId(10),
857
+ currentTimeslot: tryAsTimeSlot(16),
858
+ });
669
859
  const coreIndex = tryAsCoreIndex(0);
670
- const assigners = tryAsServiceId(0);
860
+ const newAssigner = tryAsServiceId(99);
671
861
  const queue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
672
862
  // when
673
- partialState.updateAuthorizationQueue(coreIndex, queue, assigners);
863
+ const result = partialState.updateAuthorizationQueue(coreIndex, queue, newAssigner);
674
864
  // then
865
+ deepEqual(result, Result.ok(OK));
675
866
  assert.deepStrictEqual(state.stateUpdate.authorizationQueues.get(coreIndex), queue);
867
+ // the privilegedServices update must be written, with only the targeted
868
+ // core's assigner transferred; all other fields must be preserved.
869
+ const updated = state.stateUpdate.privilegedServices;
870
+ assert.ok(updated !== null, "stateUpdate.privilegedServices should be written");
871
+ assert.strictEqual(updated.assigners[0], newAssigner);
872
+ assert.strictEqual(updated.assigners[1], initialPrivileged.assigners[1]);
873
+ assert.strictEqual(updated.manager, initialPrivileged.manager);
874
+ assert.strictEqual(updated.delegator, initialPrivileged.delegator);
875
+ assert.strictEqual(updated.registrar, initialPrivileged.registrar);
876
+ assert.strictEqual(updated.autoAccumulateServices, initialPrivileged.autoAccumulateServices);
676
877
  });
677
878
  it("should return InvalidServiceId when given auth manager is invalid", () => {
678
879
  const state = partiallyUpdatedState();
679
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
880
+ const partialState = AccumulateExternalities.forService({
881
+ chainSpec: tinyChainSpec,
882
+ blake2b: blake2b,
883
+ updatedState: state,
884
+ currentServiceId: tryAsServiceId(0),
885
+ nextNewServiceIdCandidate: tryAsServiceId(10),
886
+ currentTimeslot: tryAsTimeSlot(16),
887
+ });
680
888
  const coreIndex = tryAsCoreIndex(0);
681
889
  const assigners = null;
682
890
  const queue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
@@ -685,6 +893,8 @@ describe("PartialState.updateAuthorizationQueue", () => {
685
893
  // then
686
894
  deepEqual(result, Result.error(UpdatePrivilegesError.InvalidServiceId, () => "New auth manager is null for core 0"));
687
895
  assert.deepStrictEqual(state.stateUpdate.authorizationQueues.get(coreIndex), undefined);
896
+ // no partial privilegedServices write on error
897
+ assert.strictEqual(state.stateUpdate.privilegedServices, null);
688
898
  });
689
899
  it("should return UnprivilegedService when current service is not privileged", () => {
690
900
  const state = partiallyUpdatedState();
@@ -692,7 +902,14 @@ describe("PartialState.updateAuthorizationQueue", () => {
692
902
  ...state.state.privilegedServices,
693
903
  assigners: asOpaqueType(FixedSizeArray.new([tryAsServiceId(1), tryAsServiceId(2)], tinyChainSpec.coresCount)),
694
904
  });
695
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
905
+ const partialState = AccumulateExternalities.forService({
906
+ chainSpec: tinyChainSpec,
907
+ blake2b: blake2b,
908
+ updatedState: state,
909
+ currentServiceId: tryAsServiceId(0),
910
+ nextNewServiceIdCandidate: tryAsServiceId(10),
911
+ currentTimeslot: tryAsTimeSlot(16),
912
+ });
696
913
  const coreIndex = tryAsCoreIndex(0);
697
914
  const assigners = tryAsServiceId(0);
698
915
  const queue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
@@ -701,6 +918,8 @@ describe("PartialState.updateAuthorizationQueue", () => {
701
918
  // then
702
919
  deepEqual(result, Result.error(UpdatePrivilegesError.UnprivilegedService, () => "Service 0 not assigner for core 0 (expected: 1)"));
703
920
  assert.deepStrictEqual(state.stateUpdate.authorizationQueues.get(coreIndex), undefined);
921
+ // no partial privilegedServices write on error
922
+ assert.strictEqual(state.stateUpdate.privilegedServices, null);
704
923
  });
705
924
  it("should return UnprivilegedService before InvalidServiceId if given auth manager is incorrect, but current servis is also unprivileged", () => {
706
925
  const state = partiallyUpdatedState();
@@ -708,7 +927,14 @@ describe("PartialState.updateAuthorizationQueue", () => {
708
927
  ...state.state.privilegedServices,
709
928
  assigners: asOpaqueType(FixedSizeArray.new([tryAsServiceId(1), tryAsServiceId(2)], tinyChainSpec.coresCount)),
710
929
  });
711
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
930
+ const partialState = AccumulateExternalities.forService({
931
+ chainSpec: tinyChainSpec,
932
+ blake2b: blake2b,
933
+ updatedState: state,
934
+ currentServiceId: tryAsServiceId(0),
935
+ nextNewServiceIdCandidate: tryAsServiceId(10),
936
+ currentTimeslot: tryAsTimeSlot(16),
937
+ });
712
938
  const coreIndex = tryAsCoreIndex(0);
713
939
  const assigners = null;
714
940
  const queue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
@@ -717,12 +943,87 @@ describe("PartialState.updateAuthorizationQueue", () => {
717
943
  // then
718
944
  deepEqual(result, Result.error(UpdatePrivilegesError.UnprivilegedService, () => "Service 0 not assigner for core 0 (expected: 1)"));
719
945
  assert.deepStrictEqual(state.stateUpdate.authorizationQueues.get(coreIndex), undefined);
946
+ // no partial privilegedServices write on error
947
+ assert.strictEqual(state.stateUpdate.privilegedServices, null);
948
+ });
949
+ it("should succeed on a self-transfer using CURRENT_SERVICE_ID", () => {
950
+ const state = partiallyUpdatedState();
951
+ // inject a service info for CURRENT_SERVICE_ID so it can act as the
952
+ // current (and assigning) service on core 0
953
+ const baseService = state.state.services.get(tryAsServiceId(0));
954
+ if (baseService === undefined) {
955
+ throw new Error("Invalid service!");
956
+ }
957
+ state.state.services.set(CURRENT_SERVICE_ID, InMemoryService.new(CURRENT_SERVICE_ID, {
958
+ info: baseService.data.info,
959
+ preimages: HashDictionary.new(),
960
+ lookupHistory: HashDictionary.new(),
961
+ storage: new Map(),
962
+ }));
963
+ state.state.privilegedServices = PrivilegedServices.create({
964
+ ...state.state.privilegedServices,
965
+ assigners: asOpaqueType(FixedSizeArray.new([CURRENT_SERVICE_ID, tryAsServiceId(0)], tinyChainSpec.coresCount)),
966
+ });
967
+ const partialState = AccumulateExternalities.forService({
968
+ chainSpec: tinyChainSpec,
969
+ blake2b: blake2b,
970
+ updatedState: state,
971
+ currentServiceId: CURRENT_SERVICE_ID,
972
+ nextNewServiceIdCandidate: tryAsServiceId(10),
973
+ currentTimeslot: tryAsTimeSlot(16),
974
+ });
975
+ const coreIndex = tryAsCoreIndex(0);
976
+ const queue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
977
+ // when
978
+ const result = partialState.updateAuthorizationQueue(coreIndex, queue, CURRENT_SERVICE_ID);
979
+ // then
980
+ deepEqual(result, Result.ok(OK));
981
+ assert.deepStrictEqual(state.stateUpdate.authorizationQueues.get(coreIndex), queue);
982
+ const updated = state.stateUpdate.privilegedServices;
983
+ assert.ok(updated !== null, "stateUpdate.privilegedServices should be written");
984
+ assert.strictEqual(updated.assigners[0], CURRENT_SERVICE_ID);
985
+ assert.strictEqual(updated.assigners[1], tryAsServiceId(0));
986
+ });
987
+ it("should prevent the previous assigner from re-assigning after transfer", () => {
988
+ const state = partiallyUpdatedState();
989
+ const partialState = AccumulateExternalities.forService({
990
+ chainSpec: tinyChainSpec,
991
+ blake2b: blake2b,
992
+ updatedState: state,
993
+ currentServiceId: tryAsServiceId(0),
994
+ nextNewServiceIdCandidate: tryAsServiceId(10),
995
+ currentTimeslot: tryAsTimeSlot(16),
996
+ });
997
+ const coreIndex = tryAsCoreIndex(0);
998
+ const newAssigner = tryAsServiceId(99);
999
+ const firstQueue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
1000
+ const secondQueue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xff).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
1001
+ // when: first call succeeds and transfers the assigner to service 99
1002
+ const first = partialState.updateAuthorizationQueue(coreIndex, firstQueue, newAssigner);
1003
+ // and the previous assigner (service 0) immediately tries to re-assign
1004
+ const second = partialState.updateAuthorizationQueue(coreIndex, secondQueue, tryAsServiceId(0));
1005
+ // then
1006
+ deepEqual(first, Result.ok(OK));
1007
+ deepEqual(second, Result.error(UpdatePrivilegesError.UnprivilegedService, () => "Service 0 not assigner for core 0 (expected: 99)"));
1008
+ // the first queue remains — the failing second call must not overwrite it
1009
+ assert.deepStrictEqual(state.stateUpdate.authorizationQueues.get(coreIndex), firstQueue);
1010
+ // and the transferred assigner is still in place
1011
+ const updated = state.stateUpdate.privilegedServices;
1012
+ assert.ok(updated !== null);
1013
+ assert.strictEqual(updated.assigners[0], newAssigner);
720
1014
  });
721
1015
  });
722
1016
  describe("PartialState.updatePrivilegedServices", () => {
723
1017
  it("should update privileged services", () => {
724
1018
  const state = partiallyUpdatedState();
725
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1019
+ const partialState = AccumulateExternalities.forService({
1020
+ chainSpec: tinyChainSpec,
1021
+ blake2b: blake2b,
1022
+ updatedState: state,
1023
+ currentServiceId: tryAsServiceId(0),
1024
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1025
+ currentTimeslot: tryAsTimeSlot(16),
1026
+ });
726
1027
  const manager = tryAsServiceId(1);
727
1028
  const assigners = tryAsPerCore(new Array(tinyChainSpec.coresCount).fill(tryAsServiceId(2)), tinyChainSpec);
728
1029
  const delegator = tryAsServiceId(3);
@@ -745,7 +1046,14 @@ describe("PartialState.updatePrivilegedServices", () => {
745
1046
  });
746
1047
  it("should return InvalidService when given manager is invalid service id", () => {
747
1048
  const state = partiallyUpdatedState();
748
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1049
+ const partialState = AccumulateExternalities.forService({
1050
+ chainSpec: tinyChainSpec,
1051
+ blake2b: blake2b,
1052
+ updatedState: state,
1053
+ currentServiceId: tryAsServiceId(0),
1054
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1055
+ currentTimeslot: tryAsTimeSlot(16),
1056
+ });
749
1057
  const manager = null;
750
1058
  const assigners = tryAsPerCore(new Array(tinyChainSpec.coresCount).fill(tryAsServiceId(2)), tinyChainSpec);
751
1059
  const delegator = tryAsServiceId(3);
@@ -762,7 +1070,14 @@ describe("PartialState.updatePrivilegedServices", () => {
762
1070
  });
763
1071
  it("should return InvalidService when given validator is invalid service id", () => {
764
1072
  const state = partiallyUpdatedState();
765
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1073
+ const partialState = AccumulateExternalities.forService({
1074
+ chainSpec: tinyChainSpec,
1075
+ blake2b: blake2b,
1076
+ updatedState: state,
1077
+ currentServiceId: tryAsServiceId(0),
1078
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1079
+ currentTimeslot: tryAsTimeSlot(16),
1080
+ });
766
1081
  const manager = tryAsServiceId(1);
767
1082
  const assigners = tryAsPerCore(new Array(tinyChainSpec.coresCount).fill(tryAsServiceId(2)), tinyChainSpec);
768
1083
  const delegator = null;
@@ -779,7 +1094,14 @@ describe("PartialState.updatePrivilegedServices", () => {
779
1094
  });
780
1095
  it("should return InvalidService when given registrar is invalid service id", () => {
781
1096
  const state = partiallyUpdatedState();
782
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1097
+ const partialState = AccumulateExternalities.forService({
1098
+ chainSpec: tinyChainSpec,
1099
+ blake2b: blake2b,
1100
+ updatedState: state,
1101
+ currentServiceId: tryAsServiceId(0),
1102
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1103
+ currentTimeslot: tryAsTimeSlot(16),
1104
+ });
783
1105
  const manager = tryAsServiceId(1);
784
1106
  const assigners = tryAsPerCore(new Array(tinyChainSpec.coresCount).fill(tryAsServiceId(2)), tinyChainSpec);
785
1107
  const delegator = tryAsServiceId(3);
@@ -803,7 +1125,7 @@ describe("PartialState.transfer", () => {
803
1125
  throw new Error("Invalid service!");
804
1126
  }
805
1127
  const service = maybeService;
806
- state.state.services.set(tryAsServiceId(1), new InMemoryService(tryAsServiceId(1), {
1128
+ state.state.services.set(tryAsServiceId(1), InMemoryService.new(tryAsServiceId(1), {
807
1129
  info: ServiceAccountInfo.create({
808
1130
  ...service.data.info,
809
1131
  onTransferMinGas: tryAsServiceGas(1000),
@@ -819,7 +1141,14 @@ describe("PartialState.transfer", () => {
819
1141
  };
820
1142
  it("should perform a successful transfer", () => {
821
1143
  const { state, service } = partiallyUpdatedStateWithSecondService();
822
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1144
+ const partialState = AccumulateExternalities.forService({
1145
+ chainSpec: tinyChainSpec,
1146
+ blake2b: blake2b,
1147
+ updatedState: state,
1148
+ currentServiceId: tryAsServiceId(0),
1149
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1150
+ currentTimeslot: tryAsTimeSlot(16),
1151
+ });
823
1152
  const destinationId = tryAsServiceId(1);
824
1153
  const amount = tryAsU64(500n);
825
1154
  const gas = tryAsServiceGas(1000n);
@@ -852,7 +1181,14 @@ describe("PartialState.transfer", () => {
852
1181
  });
853
1182
  it("should return DestinationNotFound error if destination doesnt exist", () => {
854
1183
  const { state } = partiallyUpdatedStateWithSecondService();
855
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1184
+ const partialState = AccumulateExternalities.forService({
1185
+ chainSpec: tinyChainSpec,
1186
+ blake2b: blake2b,
1187
+ updatedState: state,
1188
+ currentServiceId: tryAsServiceId(0),
1189
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1190
+ currentTimeslot: tryAsTimeSlot(16),
1191
+ });
856
1192
  const amount = tryAsU64(100n);
857
1193
  const gas = tryAsServiceGas(1000n);
858
1194
  const memo = Bytes.fill(TRANSFER_MEMO_BYTES, 0xbb);
@@ -863,7 +1199,14 @@ describe("PartialState.transfer", () => {
863
1199
  });
864
1200
  it("should return GasTooLow error if gas is below destination's minimum", () => {
865
1201
  const { state } = partiallyUpdatedStateWithSecondService();
866
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1202
+ const partialState = AccumulateExternalities.forService({
1203
+ chainSpec: tinyChainSpec,
1204
+ blake2b: blake2b,
1205
+ updatedState: state,
1206
+ currentServiceId: tryAsServiceId(0),
1207
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1208
+ currentTimeslot: tryAsTimeSlot(16),
1209
+ });
867
1210
  const destinationId = tryAsServiceId(1);
868
1211
  const amount = tryAsU64(100n);
869
1212
  const gas = tryAsServiceGas(999n); // too low
@@ -875,7 +1218,14 @@ describe("PartialState.transfer", () => {
875
1218
  });
876
1219
  it("should return BalanceBelowThreshold error if balance would fall too low", () => {
877
1220
  const { state } = partiallyUpdatedStateWithSecondService();
878
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1221
+ const partialState = AccumulateExternalities.forService({
1222
+ chainSpec: tinyChainSpec,
1223
+ blake2b: blake2b,
1224
+ updatedState: state,
1225
+ currentServiceId: tryAsServiceId(0),
1226
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1227
+ currentTimeslot: tryAsTimeSlot(16),
1228
+ });
879
1229
  const destinationId = tryAsServiceId(1);
880
1230
  const amount = tryAsU64(9999999999n); // dangerously high
881
1231
  const gas = tryAsServiceGas(1000n);
@@ -890,7 +1240,14 @@ describe("PartialState.yield", () => {
890
1240
  it("should yield root", () => {
891
1241
  const currentServiceId = tryAsServiceId(0);
892
1242
  const state = partiallyUpdatedState();
893
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(10), tryAsTimeSlot(16));
1243
+ const partialState = AccumulateExternalities.forService({
1244
+ chainSpec: tinyChainSpec,
1245
+ blake2b: blake2b,
1246
+ updatedState: state,
1247
+ currentServiceId: currentServiceId,
1248
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1249
+ currentTimeslot: tryAsTimeSlot(16),
1250
+ });
894
1251
  const expectedYieldedRoot = Bytes.fill(HASH_SIZE, 0xef);
895
1252
  // when
896
1253
  partialState.yield(Bytes.fill(HASH_SIZE, 0xef));
@@ -916,19 +1273,19 @@ describe("PartialState.providePreimage", () => {
916
1273
  ? [
917
1274
  [
918
1275
  preimage.hash,
919
- [new LookupHistoryItem(preimage.hash, tryAsU32(preimage.blob.length), tryAsLookupHistorySlots([]))],
1276
+ [LookupHistoryItem.new(preimage.hash, tryAsU32(preimage.blob.length), tryAsLookupHistorySlots([]))],
920
1277
  ],
921
1278
  ]
922
1279
  : []);
923
1280
  if (self) {
924
1281
  // we need to replace the existing service
925
- state.state.services.set(service.serviceId, new InMemoryService(service.serviceId, {
1282
+ state.state.services.set(service.serviceId, InMemoryService.new(service.serviceId, {
926
1283
  ...service.data,
927
1284
  preimages,
928
1285
  lookupHistory,
929
1286
  }));
930
1287
  }
931
- const secondService = new InMemoryService(tryAsServiceId(1), {
1288
+ const secondService = InMemoryService.new(tryAsServiceId(1), {
932
1289
  info: ServiceAccountInfo.create({
933
1290
  ...service.data.info,
934
1291
  onTransferMinGas: tryAsServiceGas(1000),
@@ -948,7 +1305,14 @@ describe("PartialState.providePreimage", () => {
948
1305
  self: false,
949
1306
  requested: true,
950
1307
  });
951
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1308
+ const partialState = AccumulateExternalities.forService({
1309
+ chainSpec: tinyChainSpec,
1310
+ blake2b: blake2b,
1311
+ updatedState: state,
1312
+ currentServiceId: tryAsServiceId(0),
1313
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1314
+ currentTimeslot: tryAsTimeSlot(16),
1315
+ });
952
1316
  const serviceId = tryAsServiceId(1);
953
1317
  assert.deepStrictEqual(state.stateUpdate.services.preimages.size, 0);
954
1318
  // when
@@ -986,7 +1350,14 @@ describe("PartialState.providePreimage", () => {
986
1350
  });
987
1351
  it("should provide a preimage for itself", () => {
988
1352
  const { state, preimage } = partiallyUpdatedStateWithSecondService({ self: true, requested: true });
989
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1353
+ const partialState = AccumulateExternalities.forService({
1354
+ chainSpec: tinyChainSpec,
1355
+ blake2b: blake2b,
1356
+ updatedState: state,
1357
+ currentServiceId: tryAsServiceId(0),
1358
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1359
+ currentTimeslot: tryAsTimeSlot(16),
1360
+ });
990
1361
  const serviceId = tryAsServiceId(0);
991
1362
  assert.deepStrictEqual(state.stateUpdate.services.preimages.size, 0);
992
1363
  // when
@@ -1014,7 +1385,14 @@ describe("PartialState.providePreimage", () => {
1014
1385
  self: false,
1015
1386
  requested: false,
1016
1387
  });
1017
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1388
+ const partialState = AccumulateExternalities.forService({
1389
+ chainSpec: tinyChainSpec,
1390
+ blake2b: blake2b,
1391
+ updatedState: state,
1392
+ currentServiceId: tryAsServiceId(0),
1393
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1394
+ currentTimeslot: tryAsTimeSlot(16),
1395
+ });
1018
1396
  const serviceId = tryAsServiceId(1);
1019
1397
  assert.deepStrictEqual(state.stateUpdate.services.preimages.size, 0);
1020
1398
  // when
@@ -1029,7 +1407,14 @@ describe("PartialState.providePreimage", () => {
1029
1407
  requested: true,
1030
1408
  available: true,
1031
1409
  });
1032
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1410
+ const partialState = AccumulateExternalities.forService({
1411
+ chainSpec: tinyChainSpec,
1412
+ blake2b: blake2b,
1413
+ updatedState: state,
1414
+ currentServiceId: tryAsServiceId(0),
1415
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1416
+ currentTimeslot: tryAsTimeSlot(16),
1417
+ });
1033
1418
  const serviceId = tryAsServiceId(1);
1034
1419
  const updates = state.stateUpdate.services.preimages.get(serviceId) ?? [];
1035
1420
  updates.push(UpdatePreimage.provide({
@@ -1067,7 +1452,14 @@ describe("PartialState.providePreimage", () => {
1067
1452
  requested: true,
1068
1453
  available: true,
1069
1454
  });
1070
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1455
+ const partialState = AccumulateExternalities.forService({
1456
+ chainSpec: tinyChainSpec,
1457
+ blake2b: blake2b,
1458
+ updatedState: state,
1459
+ currentServiceId: tryAsServiceId(0),
1460
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1461
+ currentTimeslot: tryAsTimeSlot(16),
1462
+ });
1071
1463
  const serviceId = tryAsServiceId(0);
1072
1464
  // when
1073
1465
  const result = partialState.providePreimage(serviceId, preimage.blob);
@@ -1081,7 +1473,14 @@ describe("PartialState.providePreimage", () => {
1081
1473
  requested: true,
1082
1474
  available: false,
1083
1475
  });
1084
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1476
+ const partialState = AccumulateExternalities.forService({
1477
+ chainSpec: tinyChainSpec,
1478
+ blake2b: blake2b,
1479
+ updatedState: state,
1480
+ currentServiceId: tryAsServiceId(0),
1481
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1482
+ currentTimeslot: tryAsTimeSlot(16),
1483
+ });
1085
1484
  const serviceId = tryAsServiceId(0);
1086
1485
  assert.deepStrictEqual(state.stateUpdate.services.preimages, new Map());
1087
1486
  // when
@@ -1112,7 +1511,14 @@ describe("PartialState.providePreimage", () => {
1112
1511
  requested: true,
1113
1512
  available: false,
1114
1513
  });
1115
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1514
+ const partialState = AccumulateExternalities.forService({
1515
+ chainSpec: tinyChainSpec,
1516
+ blake2b: blake2b,
1517
+ updatedState: state,
1518
+ currentServiceId: tryAsServiceId(0),
1519
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1520
+ currentTimeslot: tryAsTimeSlot(16),
1521
+ });
1116
1522
  const serviceId = tryAsServiceId(1);
1117
1523
  assert.deepStrictEqual(state.stateUpdate.services.preimages, new Map());
1118
1524
  // when
@@ -1170,7 +1576,7 @@ describe("PartialState.eject", () => {
1170
1576
  let lookupHistory = HashDictionary.new();
1171
1577
  if (overrides.tombstone !== undefined) {
1172
1578
  const { hash, length, slots } = overrides.tombstone;
1173
- const item = new LookupHistoryItem(hash, length, slots);
1579
+ const item = LookupHistoryItem.new(hash, length, slots);
1174
1580
  lookupHistory = HashDictionary.fromEntries([[hash, [item]]]);
1175
1581
  if (item.slots.length === 1 || item.slots.length === 2) {
1176
1582
  preimages = HashDictionary.fromEntries([
@@ -1184,7 +1590,7 @@ describe("PartialState.eject", () => {
1184
1590
  ]);
1185
1591
  }
1186
1592
  }
1187
- const destinationService = new InMemoryService(destinationId, {
1593
+ const destinationService = InMemoryService.new(destinationId, {
1188
1594
  info: ServiceAccountInfo.create({
1189
1595
  ...baseService.data.info,
1190
1596
  codeHash,
@@ -1200,7 +1606,14 @@ describe("PartialState.eject", () => {
1200
1606
  }
1201
1607
  it("should return InvalidService if destination is null", () => {
1202
1608
  const state = partiallyUpdatedState();
1203
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1609
+ const partialState = AccumulateExternalities.forService({
1610
+ chainSpec: tinyChainSpec,
1611
+ blake2b: blake2b,
1612
+ updatedState: state,
1613
+ currentServiceId: tryAsServiceId(0),
1614
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1615
+ currentTimeslot: tryAsTimeSlot(16),
1616
+ });
1204
1617
  const tombstone = Bytes.fill(HASH_SIZE, 0xef).asOpaque();
1205
1618
  // when
1206
1619
  const result = partialState.eject(null, tombstone);
@@ -1210,7 +1623,14 @@ describe("PartialState.eject", () => {
1210
1623
  });
1211
1624
  it("should return InvalidService if destination service does not exist", () => {
1212
1625
  const state = partiallyUpdatedState();
1213
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1626
+ const partialState = AccumulateExternalities.forService({
1627
+ chainSpec: tinyChainSpec,
1628
+ blake2b: blake2b,
1629
+ updatedState: state,
1630
+ currentServiceId: tryAsServiceId(0),
1631
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1632
+ currentTimeslot: tryAsTimeSlot(16),
1633
+ });
1214
1634
  const nonExistentServiceId = tryAsServiceId(99); // not present in stateUpdate
1215
1635
  const tombstone = Bytes.fill(HASH_SIZE, 0xee).asOpaque();
1216
1636
  // when
@@ -1233,7 +1653,14 @@ describe("PartialState.eject", () => {
1233
1653
  slots: tryAsLookupHistorySlots([0, 1].map((x) => tryAsTimeSlot(x))),
1234
1654
  },
1235
1655
  });
1236
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(50));
1656
+ const partialState = AccumulateExternalities.forService({
1657
+ chainSpec: tinyChainSpec,
1658
+ blake2b: blake2b,
1659
+ updatedState: state,
1660
+ currentServiceId: tryAsServiceId(0),
1661
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1662
+ currentTimeslot: tryAsTimeSlot(50),
1663
+ });
1237
1664
  // when
1238
1665
  const correctEjectResult = partialState.eject(destinationId, tombstone); // correct eject
1239
1666
  assert.strictEqual(correctEjectResult.isOk, true);
@@ -1248,7 +1675,14 @@ describe("PartialState.eject", () => {
1248
1675
  codeHash: Bytes.fill(HASH_SIZE, 0x99).asOpaque(), // wrong codeHash
1249
1676
  });
1250
1677
  const tombstone = Bytes.fill(HASH_SIZE, 0xec).asOpaque();
1251
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1678
+ const partialState = AccumulateExternalities.forService({
1679
+ chainSpec: tinyChainSpec,
1680
+ blake2b: blake2b,
1681
+ updatedState: state,
1682
+ currentServiceId: tryAsServiceId(0),
1683
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1684
+ currentTimeslot: tryAsTimeSlot(16),
1685
+ });
1252
1686
  // when
1253
1687
  const result = partialState.eject(destinationId, tombstone);
1254
1688
  // then
@@ -1261,7 +1695,14 @@ describe("PartialState.eject", () => {
1261
1695
  storageUtilisationCount: tryAsU32(2 + 1), // off by 1
1262
1696
  });
1263
1697
  const tombstone = Bytes.fill(HASH_SIZE, 0xeb).asOpaque();
1264
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1698
+ const partialState = AccumulateExternalities.forService({
1699
+ chainSpec: tinyChainSpec,
1700
+ blake2b: blake2b,
1701
+ updatedState: state,
1702
+ currentServiceId: tryAsServiceId(0),
1703
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1704
+ currentTimeslot: tryAsTimeSlot(16),
1705
+ });
1265
1706
  // when
1266
1707
  const result = partialState.eject(destinationId, tombstone);
1267
1708
  // then
@@ -1273,7 +1714,14 @@ describe("PartialState.eject", () => {
1273
1714
  const tombstone = Bytes.fill(HASH_SIZE, 0xea).asOpaque();
1274
1715
  // destination service has valid codeHash and config, but no preimage or lookup history
1275
1716
  const destinationId = setupEjectableService(state.state);
1276
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1717
+ const partialState = AccumulateExternalities.forService({
1718
+ chainSpec: tinyChainSpec,
1719
+ blake2b: blake2b,
1720
+ updatedState: state,
1721
+ currentServiceId: tryAsServiceId(0),
1722
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1723
+ currentTimeslot: tryAsTimeSlot(16),
1724
+ });
1277
1725
  // when
1278
1726
  const result = partialState.eject(destinationId, tombstone);
1279
1727
  // then
@@ -1292,7 +1740,14 @@ describe("PartialState.eject", () => {
1292
1740
  slots: tryAsLookupHistorySlots([1].map((x) => tryAsTimeSlot(x))),
1293
1741
  },
1294
1742
  });
1295
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
1743
+ const partialState = AccumulateExternalities.forService({
1744
+ chainSpec: tinyChainSpec,
1745
+ blake2b: blake2b,
1746
+ updatedState: state,
1747
+ currentServiceId: tryAsServiceId(0),
1748
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1749
+ currentTimeslot: tryAsTimeSlot(16),
1750
+ });
1296
1751
  // when
1297
1752
  const result = partialState.eject(destinationId, tombstone);
1298
1753
  // then
@@ -1311,7 +1766,14 @@ describe("PartialState.eject", () => {
1311
1766
  slots: tryAsLookupHistorySlots([1, 11].map((x) => tryAsTimeSlot(x))),
1312
1767
  },
1313
1768
  });
1314
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(17));
1769
+ const partialState = AccumulateExternalities.forService({
1770
+ chainSpec: tinyChainSpec,
1771
+ blake2b: blake2b,
1772
+ updatedState: state,
1773
+ currentServiceId: tryAsServiceId(0),
1774
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1775
+ currentTimeslot: tryAsTimeSlot(17),
1776
+ });
1315
1777
  // when
1316
1778
  const result = partialState.eject(destinationId, tombstone);
1317
1779
  // then
@@ -1332,7 +1794,14 @@ describe("PartialState.eject", () => {
1332
1794
  slots: tryAsLookupHistorySlots([0, 1].map((x) => tryAsTimeSlot(x))),
1333
1795
  },
1334
1796
  });
1335
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(50));
1797
+ const partialState = AccumulateExternalities.forService({
1798
+ chainSpec: tinyChainSpec,
1799
+ blake2b: blake2b,
1800
+ updatedState: state,
1801
+ currentServiceId: tryAsServiceId(0),
1802
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1803
+ currentTimeslot: tryAsTimeSlot(50),
1804
+ });
1336
1805
  // set the balance to overflow
1337
1806
  const currentService = state.state.services.get(tryAsServiceId(0));
1338
1807
  if (currentService === undefined) {
@@ -1362,7 +1831,14 @@ describe("PartialState.eject", () => {
1362
1831
  slots: tryAsLookupHistorySlots([0, 1].map((x) => tryAsTimeSlot(x))),
1363
1832
  },
1364
1833
  });
1365
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(50));
1834
+ const partialState = AccumulateExternalities.forService({
1835
+ chainSpec: tinyChainSpec,
1836
+ blake2b: blake2b,
1837
+ updatedState: state,
1838
+ currentServiceId: tryAsServiceId(0),
1839
+ nextNewServiceIdCandidate: tryAsServiceId(10),
1840
+ currentTimeslot: tryAsTimeSlot(50),
1841
+ });
1366
1842
  // when
1367
1843
  const result = partialState.eject(destinationId, tombstone);
1368
1844
  // then
@@ -1379,12 +1855,12 @@ describe("AccumulateServiceExternalities", () => {
1379
1855
  }
1380
1856
  const state = InMemoryState.empty(tinyChainSpec);
1381
1857
  state.services = services;
1382
- return new PartiallyUpdatedState(state);
1858
+ return PartiallyUpdatedState.new(state);
1383
1859
  };
1384
1860
  const prepareService = (serviceId, { storage, preimages, info, } = {}) => {
1385
1861
  const initialStorage = storage ?? new Map();
1386
1862
  const storageUtilisationBytes = Array.from(initialStorage.values()).reduce((sum, item) => sum + (item?.value.length ?? 0), 0);
1387
- return new InMemoryService(serviceId, {
1863
+ return InMemoryService.new(serviceId, {
1388
1864
  info: ServiceAccountInfo.create({
1389
1865
  balance: tryAsU64(2 ** 32),
1390
1866
  accumulateMinGas: tryAsServiceGas(1000),
@@ -1417,7 +1893,14 @@ describe("AccumulateServiceExternalities", () => {
1417
1893
  const serviceId = null;
1418
1894
  const state = prepareState([prepareService(currentServiceId)]);
1419
1895
  const expectedServiceInfo = null;
1420
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(42), tryAsTimeSlot(16));
1896
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
1897
+ chainSpec: tinyChainSpec,
1898
+ blake2b: blake2b,
1899
+ updatedState: state,
1900
+ currentServiceId: currentServiceId,
1901
+ nextNewServiceIdCandidate: tryAsServiceId(42),
1902
+ currentTimeslot: tryAsTimeSlot(16),
1903
+ });
1421
1904
  const serviceInfo = accumulateServiceExternalities.getServiceInfo(serviceId);
1422
1905
  assert.strictEqual(serviceInfo, expectedServiceInfo);
1423
1906
  });
@@ -1426,7 +1909,14 @@ describe("AccumulateServiceExternalities", () => {
1426
1909
  const serviceId = tryAsServiceId(5);
1427
1910
  const state = prepareState([prepareService(currentServiceId)]);
1428
1911
  const expectedServiceInfo = null;
1429
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(42), tryAsTimeSlot(16));
1912
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
1913
+ chainSpec: tinyChainSpec,
1914
+ blake2b: blake2b,
1915
+ updatedState: state,
1916
+ currentServiceId: currentServiceId,
1917
+ nextNewServiceIdCandidate: tryAsServiceId(42),
1918
+ currentTimeslot: tryAsTimeSlot(16),
1919
+ });
1430
1920
  const serviceInfo = accumulateServiceExternalities.getServiceInfo(serviceId);
1431
1921
  assert.strictEqual(serviceInfo, expectedServiceInfo);
1432
1922
  });
@@ -1435,7 +1925,14 @@ describe("AccumulateServiceExternalities", () => {
1435
1925
  const serviceId = tryAsServiceId(5);
1436
1926
  const state = prepareState([prepareService(currentServiceId), prepareService(serviceId)]);
1437
1927
  const expectedServiceInfo = prepareService(serviceId).getInfo();
1438
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(42), tryAsTimeSlot(16));
1928
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
1929
+ chainSpec: tinyChainSpec,
1930
+ blake2b: blake2b,
1931
+ updatedState: state,
1932
+ currentServiceId: currentServiceId,
1933
+ nextNewServiceIdCandidate: tryAsServiceId(42),
1934
+ currentTimeslot: tryAsTimeSlot(16),
1935
+ });
1439
1936
  const serviceInfo = accumulateServiceExternalities.getServiceInfo(serviceId);
1440
1937
  assert.deepStrictEqual(serviceInfo, expectedServiceInfo);
1441
1938
  });
@@ -1447,7 +1944,14 @@ describe("AccumulateServiceExternalities", () => {
1447
1944
  const hash = Bytes.fill(HASH_SIZE, 1).asOpaque();
1448
1945
  const state = prepareState([prepareService(currentServiceId)]);
1449
1946
  const expectedResult = null;
1450
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(42), tryAsTimeSlot(16));
1947
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
1948
+ chainSpec: tinyChainSpec,
1949
+ blake2b: blake2b,
1950
+ updatedState: state,
1951
+ currentServiceId: currentServiceId,
1952
+ nextNewServiceIdCandidate: tryAsServiceId(42),
1953
+ currentTimeslot: tryAsTimeSlot(16),
1954
+ });
1451
1955
  const result = accumulateServiceExternalities.lookup(serviceId, hash);
1452
1956
  assert.strictEqual(result, expectedResult);
1453
1957
  });
@@ -1457,7 +1961,14 @@ describe("AccumulateServiceExternalities", () => {
1457
1961
  const hash = Bytes.fill(HASH_SIZE, 1).asOpaque();
1458
1962
  const state = prepareState([prepareService(currentServiceId)]);
1459
1963
  const expectedResult = null;
1460
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(42), tryAsTimeSlot(16));
1964
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
1965
+ chainSpec: tinyChainSpec,
1966
+ blake2b: blake2b,
1967
+ updatedState: state,
1968
+ currentServiceId: currentServiceId,
1969
+ nextNewServiceIdCandidate: tryAsServiceId(42),
1970
+ currentTimeslot: tryAsTimeSlot(16),
1971
+ });
1461
1972
  const result = accumulateServiceExternalities.lookup(serviceId, hash);
1462
1973
  assert.strictEqual(result, expectedResult);
1463
1974
  });
@@ -1469,7 +1980,14 @@ describe("AccumulateServiceExternalities", () => {
1469
1980
  const service = prepareService(currentServiceId, { preimages });
1470
1981
  const state = prepareState([service]);
1471
1982
  const expectedResult = null;
1472
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(42), tryAsTimeSlot(16));
1983
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
1984
+ chainSpec: tinyChainSpec,
1985
+ blake2b: blake2b,
1986
+ updatedState: state,
1987
+ currentServiceId: currentServiceId,
1988
+ nextNewServiceIdCandidate: tryAsServiceId(42),
1989
+ currentTimeslot: tryAsTimeSlot(16),
1990
+ });
1473
1991
  const result = accumulateServiceExternalities.lookup(currentServiceId, requestedHash);
1474
1992
  assert.strictEqual(result, expectedResult);
1475
1993
  });
@@ -1480,7 +1998,14 @@ describe("AccumulateServiceExternalities", () => {
1480
1998
  const preimages = preparePreimages([[requestedHash, expectedResult]]);
1481
1999
  const service = prepareService(serviceId, { preimages });
1482
2000
  const state = prepareState([service]);
1483
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, serviceId, tryAsServiceId(42), tryAsTimeSlot(16));
2001
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
2002
+ chainSpec: tinyChainSpec,
2003
+ blake2b: blake2b,
2004
+ updatedState: state,
2005
+ currentServiceId: serviceId,
2006
+ nextNewServiceIdCandidate: tryAsServiceId(42),
2007
+ currentTimeslot: tryAsTimeSlot(16),
2008
+ });
1484
2009
  const result = accumulateServiceExternalities.lookup(serviceId, requestedHash);
1485
2010
  assert.deepStrictEqual(result, expectedResult);
1486
2011
  });
@@ -1491,7 +2016,14 @@ describe("AccumulateServiceExternalities", () => {
1491
2016
  const serviceId = null;
1492
2017
  const hash = Bytes.fill(HASH_SIZE, 1).asOpaque();
1493
2018
  const state = prepareState([prepareService(currentServiceId)]);
1494
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(42), tryAsTimeSlot(16));
2019
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
2020
+ chainSpec: tinyChainSpec,
2021
+ blake2b: blake2b,
2022
+ updatedState: state,
2023
+ currentServiceId: currentServiceId,
2024
+ nextNewServiceIdCandidate: tryAsServiceId(42),
2025
+ currentTimeslot: tryAsTimeSlot(16),
2026
+ });
1495
2027
  const result = accumulateServiceExternalities.read(serviceId, hash);
1496
2028
  assert.strictEqual(result, null);
1497
2029
  });
@@ -1500,7 +2032,14 @@ describe("AccumulateServiceExternalities", () => {
1500
2032
  const serviceId = tryAsServiceId(33);
1501
2033
  const hash = Bytes.fill(HASH_SIZE, 1).asOpaque();
1502
2034
  const state = prepareState([prepareService(currentServiceId)]);
1503
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(42), tryAsTimeSlot(16));
2035
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
2036
+ chainSpec: tinyChainSpec,
2037
+ blake2b: blake2b,
2038
+ updatedState: state,
2039
+ currentServiceId: currentServiceId,
2040
+ nextNewServiceIdCandidate: tryAsServiceId(42),
2041
+ currentTimeslot: tryAsTimeSlot(16),
2042
+ });
1504
2043
  const result = accumulateServiceExternalities.read(serviceId, hash);
1505
2044
  assert.strictEqual(result, null);
1506
2045
  });
@@ -1516,7 +2055,14 @@ describe("AccumulateServiceExternalities", () => {
1516
2055
  }));
1517
2056
  const service = prepareService(serviceId, { storage: initialStorage });
1518
2057
  const state = prepareState([prepareService(currentServiceId), service]);
1519
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(42), tryAsTimeSlot(16));
2058
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
2059
+ chainSpec: tinyChainSpec,
2060
+ blake2b: blake2b,
2061
+ updatedState: state,
2062
+ currentServiceId: currentServiceId,
2063
+ nextNewServiceIdCandidate: tryAsServiceId(42),
2064
+ currentTimeslot: tryAsTimeSlot(16),
2065
+ });
1520
2066
  const result = accumulateServiceExternalities.read(serviceId, key);
1521
2067
  assert.strictEqual(result, value);
1522
2068
  });
@@ -1525,7 +2071,14 @@ describe("AccumulateServiceExternalities", () => {
1525
2071
  const hash = Bytes.fill(HASH_SIZE, 1).asOpaque();
1526
2072
  const blob = BytesBlob.empty();
1527
2073
  const state = prepareState([prepareService(currentServiceId)]);
1528
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(42), tryAsTimeSlot(16));
2074
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
2075
+ chainSpec: tinyChainSpec,
2076
+ blake2b: blake2b,
2077
+ updatedState: state,
2078
+ currentServiceId: currentServiceId,
2079
+ nextNewServiceIdCandidate: tryAsServiceId(42),
2080
+ currentTimeslot: tryAsTimeSlot(16),
2081
+ });
1529
2082
  assert.strictEqual(state.stateUpdate.services.storage.size, 0);
1530
2083
  accumulateServiceExternalities.write(hash, blob);
1531
2084
  assert.strictEqual(state.stateUpdate.services.storage.size, 1);
@@ -1538,7 +2091,14 @@ describe("AccumulateServiceExternalities", () => {
1538
2091
  const newBlob = BytesBlob.parseBlob("0x11111111");
1539
2092
  initialStorage.set(key.toString(), StorageItem.create({ key, value }));
1540
2093
  const state = prepareState([prepareService(currentServiceId, { storage: initialStorage })]);
1541
- const accumulateServiceExternalities = new AccumulateExternalities(tinyChainSpec, blake2b, state, currentServiceId, tryAsServiceId(42), tryAsTimeSlot(16));
2094
+ const accumulateServiceExternalities = AccumulateExternalities.forService({
2095
+ chainSpec: tinyChainSpec,
2096
+ blake2b: blake2b,
2097
+ updatedState: state,
2098
+ currentServiceId: currentServiceId,
2099
+ nextNewServiceIdCandidate: tryAsServiceId(42),
2100
+ currentTimeslot: tryAsTimeSlot(16),
2101
+ });
1542
2102
  accumulateServiceExternalities.write(key, newBlob);
1543
2103
  assert.strictEqual(state.stateUpdate.services.storage.size, 1);
1544
2104
  const result = accumulateServiceExternalities.read(currentServiceId, key);