@typeberry/lib 0.5.10-7338c21 → 0.5.10-9ffd7ac

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 (443) 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/index.test.js +1 -1
  7. package/packages/core/codec/skip.d.ts +2 -1
  8. package/packages/core/codec/skip.d.ts.map +1 -1
  9. package/packages/core/codec/skip.js +3 -0
  10. package/packages/core/codec/view.js +2 -2
  11. package/packages/core/collections/multi-map.d.ts +2 -1
  12. package/packages/core/collections/multi-map.d.ts.map +1 -1
  13. package/packages/core/collections/multi-map.js +3 -0
  14. package/packages/core/collections/multi-map.test.js +2 -2
  15. package/packages/core/concurrent/parent.js +4 -1
  16. package/packages/core/crypto/ed25519.d.ts +2 -5
  17. package/packages/core/crypto/ed25519.d.ts.map +1 -1
  18. package/packages/core/crypto/ed25519.js +4 -1
  19. package/packages/core/hash/hash.d.ts +4 -2
  20. package/packages/core/hash/hash.d.ts.map +1 -1
  21. package/packages/core/hash/hash.js +6 -1
  22. package/packages/core/networking/quic-network.d.ts +3 -2
  23. package/packages/core/networking/quic-network.d.ts.map +1 -1
  24. package/packages/core/networking/quic-network.js +3 -0
  25. package/packages/core/networking/quic-peer.d.ts +2 -1
  26. package/packages/core/networking/quic-peer.d.ts.map +1 -1
  27. package/packages/core/networking/quic-peer.js +5 -2
  28. package/packages/core/networking/quic-stream.d.ts +2 -1
  29. package/packages/core/networking/quic-stream.d.ts.map +1 -1
  30. package/packages/core/networking/quic-stream.js +3 -0
  31. package/packages/core/networking/setup.js +2 -2
  32. package/packages/core/pvm-host-calls/bin.js +2 -2
  33. package/packages/core/pvm-host-calls/ecalli-trace-logger.test.js +1 -1
  34. package/packages/core/pvm-host-calls/host-call-memory.d.ts +2 -1
  35. package/packages/core/pvm-host-calls/host-call-memory.d.ts.map +1 -1
  36. package/packages/core/pvm-host-calls/host-call-memory.js +3 -0
  37. package/packages/core/pvm-host-calls/host-call-memory.test.js +1 -1
  38. package/packages/core/pvm-host-calls/host-call-registers.d.ts +5 -1
  39. package/packages/core/pvm-host-calls/host-call-registers.d.ts.map +1 -1
  40. package/packages/core/pvm-host-calls/host-call-registers.js +11 -1
  41. package/packages/core/pvm-host-calls/host-call-registers.test.js +2 -2
  42. package/packages/core/pvm-host-calls/host-calls-executor.d.ts +2 -1
  43. package/packages/core/pvm-host-calls/host-calls-executor.d.ts.map +1 -1
  44. package/packages/core/pvm-host-calls/host-calls-executor.js +5 -2
  45. package/packages/core/pvm-host-calls/host-calls.d.ts +4 -2
  46. package/packages/core/pvm-host-calls/host-calls.d.ts.map +1 -1
  47. package/packages/core/pvm-host-calls/host-calls.js +9 -4
  48. package/packages/core/pvm-host-calls/pvm-instance-manager.js +1 -1
  49. package/packages/core/pvm-interpreter/args-decoder/args-decoder.js +1 -1
  50. package/packages/core/pvm-interpreter/args-decoder/args-decoder.test.js +3 -3
  51. package/packages/core/pvm-interpreter/args-decoder/args-decoding-results.js +11 -11
  52. package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.d.ts +2 -1
  53. package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.d.ts.map +1 -1
  54. package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.js +3 -0
  55. package/packages/core/pvm-interpreter/args-decoder/decoders/extended-with-immediate-decoder.test.js +2 -2
  56. package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.d.ts +2 -1
  57. package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.d.ts.map +1 -1
  58. package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.js +3 -0
  59. package/packages/core/pvm-interpreter/args-decoder/decoders/immediate-decoder.test.js +26 -26
  60. package/packages/core/pvm-interpreter/basic-blocks/basic-blocks.test.js +8 -8
  61. package/packages/core/pvm-interpreter/bin.js +1 -1
  62. package/packages/core/pvm-interpreter/debugger-adapter.d.ts +2 -1
  63. package/packages/core/pvm-interpreter/debugger-adapter.d.ts.map +1 -1
  64. package/packages/core/pvm-interpreter/debugger-adapter.js +6 -3
  65. package/packages/core/pvm-interpreter/gas.js +4 -1
  66. package/packages/core/pvm-interpreter/interpreter.d.ts +2 -1
  67. package/packages/core/pvm-interpreter/interpreter.d.ts.map +1 -1
  68. package/packages/core/pvm-interpreter/interpreter.js +19 -16
  69. package/packages/core/pvm-interpreter/memory/memory-builder.js +2 -2
  70. package/packages/core/pvm-interpreter/memory/memory-builder.test.js +7 -7
  71. package/packages/core/pvm-interpreter/memory/memory.d.ts +2 -1
  72. package/packages/core/pvm-interpreter/memory/memory.d.ts.map +1 -1
  73. package/packages/core/pvm-interpreter/memory/memory.js +4 -1
  74. package/packages/core/pvm-interpreter/memory/memory.test.js +31 -31
  75. package/packages/core/pvm-interpreter/memory/pages/readable-page.d.ts +2 -1
  76. package/packages/core/pvm-interpreter/memory/pages/readable-page.d.ts.map +1 -1
  77. package/packages/core/pvm-interpreter/memory/pages/readable-page.js +3 -0
  78. package/packages/core/pvm-interpreter/memory/pages/readable-page.test.js +3 -3
  79. package/packages/core/pvm-interpreter/memory/pages/writeable-page.d.ts +2 -1
  80. package/packages/core/pvm-interpreter/memory/pages/writeable-page.d.ts.map +1 -1
  81. package/packages/core/pvm-interpreter/memory/pages/writeable-page.js +3 -0
  82. package/packages/core/pvm-interpreter/memory/pages/writeable-page.test.js +4 -4
  83. package/packages/core/pvm-interpreter/ops/bit-ops.d.ts +2 -1
  84. package/packages/core/pvm-interpreter/ops/bit-ops.d.ts.map +1 -1
  85. package/packages/core/pvm-interpreter/ops/bit-ops.js +3 -0
  86. package/packages/core/pvm-interpreter/ops/bit-ops.test.js +3 -3
  87. package/packages/core/pvm-interpreter/ops/bit-rotation-ops.d.ts +2 -1
  88. package/packages/core/pvm-interpreter/ops/bit-rotation-ops.d.ts.map +1 -1
  89. package/packages/core/pvm-interpreter/ops/bit-rotation-ops.js +3 -0
  90. package/packages/core/pvm-interpreter/ops/bit-rotation-ops.test.js +5 -5
  91. package/packages/core/pvm-interpreter/ops/boolean-ops.d.ts +2 -1
  92. package/packages/core/pvm-interpreter/ops/boolean-ops.d.ts.map +1 -1
  93. package/packages/core/pvm-interpreter/ops/boolean-ops.js +3 -0
  94. package/packages/core/pvm-interpreter/ops/boolean-ops.test.js +3 -3
  95. package/packages/core/pvm-interpreter/ops/branch-ops.d.ts +2 -1
  96. package/packages/core/pvm-interpreter/ops/branch-ops.d.ts.map +1 -1
  97. package/packages/core/pvm-interpreter/ops/branch-ops.js +3 -0
  98. package/packages/core/pvm-interpreter/ops/branch-ops.test.js +4 -4
  99. package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.d.ts +2 -1
  100. package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.d.ts.map +1 -1
  101. package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.js +3 -0
  102. package/packages/core/pvm-interpreter/ops/dynamic-jump-ops.test.js +5 -5
  103. package/packages/core/pvm-interpreter/ops/host-call-ops.d.ts +2 -1
  104. package/packages/core/pvm-interpreter/ops/host-call-ops.d.ts.map +1 -1
  105. package/packages/core/pvm-interpreter/ops/host-call-ops.js +3 -0
  106. package/packages/core/pvm-interpreter/ops/host-call-ops.test.js +2 -2
  107. package/packages/core/pvm-interpreter/ops/load-ops.d.ts +2 -1
  108. package/packages/core/pvm-interpreter/ops/load-ops.d.ts.map +1 -1
  109. package/packages/core/pvm-interpreter/ops/load-ops.js +3 -0
  110. package/packages/core/pvm-interpreter/ops/load-ops.test.js +10 -10
  111. package/packages/core/pvm-interpreter/ops/math-ops.d.ts +2 -1
  112. package/packages/core/pvm-interpreter/ops/math-ops.d.ts.map +1 -1
  113. package/packages/core/pvm-interpreter/ops/math-ops.js +3 -0
  114. package/packages/core/pvm-interpreter/ops/math-ops.test.js +3 -3
  115. package/packages/core/pvm-interpreter/ops/memory-ops.d.ts +2 -1
  116. package/packages/core/pvm-interpreter/ops/memory-ops.d.ts.map +1 -1
  117. package/packages/core/pvm-interpreter/ops/memory-ops.js +3 -0
  118. package/packages/core/pvm-interpreter/ops/memory-ops.test.js +3 -3
  119. package/packages/core/pvm-interpreter/ops/move-ops.d.ts +2 -1
  120. package/packages/core/pvm-interpreter/ops/move-ops.d.ts.map +1 -1
  121. package/packages/core/pvm-interpreter/ops/move-ops.js +3 -0
  122. package/packages/core/pvm-interpreter/ops/move-ops.test.js +3 -3
  123. package/packages/core/pvm-interpreter/ops/no-args-ops.d.ts +2 -1
  124. package/packages/core/pvm-interpreter/ops/no-args-ops.d.ts.map +1 -1
  125. package/packages/core/pvm-interpreter/ops/no-args-ops.js +3 -0
  126. package/packages/core/pvm-interpreter/ops/no-args-ops.test.js +2 -2
  127. package/packages/core/pvm-interpreter/ops/shift-ops.d.ts +2 -1
  128. package/packages/core/pvm-interpreter/ops/shift-ops.d.ts.map +1 -1
  129. package/packages/core/pvm-interpreter/ops/shift-ops.js +3 -0
  130. package/packages/core/pvm-interpreter/ops/shift-ops.test.js +3 -3
  131. package/packages/core/pvm-interpreter/ops/store-ops.d.ts +2 -1
  132. package/packages/core/pvm-interpreter/ops/store-ops.d.ts.map +1 -1
  133. package/packages/core/pvm-interpreter/ops/store-ops.js +3 -0
  134. package/packages/core/pvm-interpreter/ops/store-ops.test.js +7 -7
  135. package/packages/core/pvm-interpreter/ops-dispatchers/no-args-dispatcher.test.js +1 -1
  136. package/packages/core/pvm-interpreter/ops-dispatchers/one-imm-dispatcher.test.js +4 -4
  137. package/packages/core/pvm-interpreter/ops-dispatchers/one-offset-dispatcher.test.js +2 -2
  138. package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-one-ext-imm-dispatcher.test.js +4 -4
  139. package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-one-imm-dispatcher.test.js +7 -7
  140. package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-one-imm-one-offset-dispatcher.test.js +10 -10
  141. package/packages/core/pvm-interpreter/ops-dispatchers/one-reg-two-imms-dispatcher.test.js +5 -5
  142. package/packages/core/pvm-interpreter/ops-dispatchers/three-regs-dispatcher.test.js +7 -7
  143. package/packages/core/pvm-interpreter/ops-dispatchers/two-imms-dispatcher.test.js +5 -5
  144. package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-dispatcher.test.js +6 -6
  145. package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-one-imm-dispatcher.test.js +11 -11
  146. package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-one-offset-dispatcher.test.js +2 -2
  147. package/packages/core/pvm-interpreter/ops-dispatchers/two-regs-two-imms-dispatcher.test.js +14 -14
  148. package/packages/core/pvm-interpreter/program-decoder/jump-table.d.ts +5 -2
  149. package/packages/core/pvm-interpreter/program-decoder/jump-table.d.ts.map +1 -1
  150. package/packages/core/pvm-interpreter/program-decoder/jump-table.js +9 -4
  151. package/packages/core/pvm-interpreter/program-decoder/jump-table.test.js +6 -6
  152. package/packages/core/pvm-interpreter/program-decoder/mask.d.ts +2 -1
  153. package/packages/core/pvm-interpreter/program-decoder/mask.d.ts.map +1 -1
  154. package/packages/core/pvm-interpreter/program-decoder/mask.js +3 -0
  155. package/packages/core/pvm-interpreter/program-decoder/mask.test.js +10 -10
  156. package/packages/core/pvm-interpreter/program-decoder/program-decoder.d.ts +2 -1
  157. package/packages/core/pvm-interpreter/program-decoder/program-decoder.d.ts.map +1 -1
  158. package/packages/core/pvm-interpreter/program-decoder/program-decoder.js +6 -3
  159. package/packages/core/pvm-interpreter/program-decoder/program-decoder.test.js +5 -5
  160. package/packages/core/pvm-interpreter/program.js +3 -3
  161. package/packages/core/pvm-interpreter/registers.d.ts +5 -2
  162. package/packages/core/pvm-interpreter/registers.d.ts.map +1 -1
  163. package/packages/core/pvm-interpreter/registers.js +10 -6
  164. package/packages/core/pvm-interpreter/registers.test.js +10 -10
  165. package/packages/core/pvm-interpreter/spi-decoder/decode-standard-program.d.ts +6 -3
  166. package/packages/core/pvm-interpreter/spi-decoder/decode-standard-program.d.ts.map +1 -1
  167. package/packages/core/pvm-interpreter/spi-decoder/decode-standard-program.js +11 -2
  168. package/packages/core/pvm-interpreter-ananas/index.d.ts +6 -3
  169. package/packages/core/pvm-interpreter-ananas/index.d.ts.map +1 -1
  170. package/packages/core/pvm-interpreter-ananas/index.js +12 -3
  171. package/packages/core/trie/nodes.d.ts +7 -2
  172. package/packages/core/trie/nodes.d.ts.map +1 -1
  173. package/packages/core/trie/nodes.js +20 -11
  174. package/packages/core/trie/nodesDb.d.ts +3 -1
  175. package/packages/core/trie/nodesDb.d.ts.map +1 -1
  176. package/packages/core/trie/nodesDb.js +6 -0
  177. package/packages/core/trie/trie.js +2 -2
  178. package/packages/extensions/ipc/index.js +5 -2
  179. package/packages/extensions/ipc/jamnp/handler.d.ts +4 -2
  180. package/packages/extensions/ipc/jamnp/handler.d.ts.map +1 -1
  181. package/packages/extensions/ipc/jamnp/handler.js +9 -3
  182. package/packages/extensions/ipc/jamnp/server.js +3 -3
  183. package/packages/extensions/ipc/server.d.ts +2 -1
  184. package/packages/extensions/ipc/server.d.ts.map +1 -1
  185. package/packages/extensions/ipc/server.js +4 -1
  186. package/packages/jam/block/header.js +1 -1
  187. package/packages/jam/config/chain-spec.d.ts +2 -1
  188. package/packages/jam/config/chain-spec.d.ts.map +1 -1
  189. package/packages/jam/config/chain-spec.js +5 -2
  190. package/packages/jam/config/network.d.ts +2 -7
  191. package/packages/jam/config/network.d.ts.map +1 -1
  192. package/packages/jam/config/network.js +3 -0
  193. package/packages/jam/config-node/jip-chain-spec.js +1 -1
  194. package/packages/jam/database/blocks.test.js +1 -1
  195. package/packages/jam/database/states.d.ts +2 -1
  196. package/packages/jam/database/states.d.ts.map +1 -1
  197. package/packages/jam/database/states.js +3 -0
  198. package/packages/jam/database/states.test.js +1 -1
  199. package/packages/jam/database-lmdb/blocks.d.ts +2 -1
  200. package/packages/jam/database-lmdb/blocks.d.ts.map +1 -1
  201. package/packages/jam/database-lmdb/blocks.js +3 -0
  202. package/packages/jam/database-lmdb/root.d.ts +2 -1
  203. package/packages/jam/database-lmdb/root.d.ts.map +1 -1
  204. package/packages/jam/database-lmdb/root.js +3 -0
  205. package/packages/jam/database-lmdb/states.d.ts +2 -1
  206. package/packages/jam/database-lmdb/states.d.ts.map +1 -1
  207. package/packages/jam/database-lmdb/states.js +3 -0
  208. package/packages/jam/database-lmdb/states.test.js +9 -9
  209. package/packages/jam/executor/pvm-executor.js +24 -24
  210. package/packages/jam/fuzz-proto/v1/handler.d.ts +2 -1
  211. package/packages/jam/fuzz-proto/v1/handler.d.ts.map +1 -1
  212. package/packages/jam/fuzz-proto/v1/handler.js +3 -0
  213. package/packages/jam/fuzz-proto/v1/handler.test.js +10 -10
  214. package/packages/jam/in-core/externalities/refine.js +1 -1
  215. package/packages/jam/in-core/externalities/refine.test.js +3 -3
  216. package/packages/jam/in-core/in-core.d.ts +2 -1
  217. package/packages/jam/in-core/in-core.d.ts.map +1 -1
  218. package/packages/jam/in-core/in-core.js +3 -0
  219. package/packages/jam/in-core/in-core.test.js +6 -6
  220. package/packages/jam/in-core/is-authorized.test.js +2 -2
  221. package/packages/jam/in-core/refine.js +1 -1
  222. package/packages/jam/jam-host-calls/accumulate/assign.d.ts +2 -1
  223. package/packages/jam/jam-host-calls/accumulate/assign.d.ts.map +1 -1
  224. package/packages/jam/jam-host-calls/accumulate/assign.js +3 -0
  225. package/packages/jam/jam-host-calls/accumulate/assign.test.js +8 -9
  226. package/packages/jam/jam-host-calls/accumulate/bless.d.ts +2 -1
  227. package/packages/jam/jam-host-calls/accumulate/bless.d.ts.map +1 -1
  228. package/packages/jam/jam-host-calls/accumulate/bless.js +3 -0
  229. package/packages/jam/jam-host-calls/accumulate/bless.test.js +11 -12
  230. package/packages/jam/jam-host-calls/accumulate/checkpoint.d.ts +2 -1
  231. package/packages/jam/jam-host-calls/accumulate/checkpoint.d.ts.map +1 -1
  232. package/packages/jam/jam-host-calls/accumulate/checkpoint.js +4 -1
  233. package/packages/jam/jam-host-calls/accumulate/checkpoint.test.js +2 -3
  234. package/packages/jam/jam-host-calls/accumulate/designate.d.ts +2 -1
  235. package/packages/jam/jam-host-calls/accumulate/designate.d.ts.map +1 -1
  236. package/packages/jam/jam-host-calls/accumulate/designate.js +3 -0
  237. package/packages/jam/jam-host-calls/accumulate/designate.test.js +5 -6
  238. package/packages/jam/jam-host-calls/accumulate/eject.d.ts +2 -1
  239. package/packages/jam/jam-host-calls/accumulate/eject.d.ts.map +1 -1
  240. package/packages/jam/jam-host-calls/accumulate/eject.js +3 -0
  241. package/packages/jam/jam-host-calls/accumulate/eject.test.js +8 -9
  242. package/packages/jam/jam-host-calls/accumulate/forget.d.ts +2 -1
  243. package/packages/jam/jam-host-calls/accumulate/forget.d.ts.map +1 -1
  244. package/packages/jam/jam-host-calls/accumulate/forget.js +3 -0
  245. package/packages/jam/jam-host-calls/accumulate/forget.test.js +5 -6
  246. package/packages/jam/jam-host-calls/accumulate/new.d.ts +2 -1
  247. package/packages/jam/jam-host-calls/accumulate/new.d.ts.map +1 -1
  248. package/packages/jam/jam-host-calls/accumulate/new.js +3 -0
  249. package/packages/jam/jam-host-calls/accumulate/new.test.js +9 -10
  250. package/packages/jam/jam-host-calls/accumulate/provide.d.ts +2 -1
  251. package/packages/jam/jam-host-calls/accumulate/provide.d.ts.map +1 -1
  252. package/packages/jam/jam-host-calls/accumulate/provide.js +3 -0
  253. package/packages/jam/jam-host-calls/accumulate/provide.test.js +8 -9
  254. package/packages/jam/jam-host-calls/accumulate/query.d.ts +2 -1
  255. package/packages/jam/jam-host-calls/accumulate/query.d.ts.map +1 -1
  256. package/packages/jam/jam-host-calls/accumulate/query.js +3 -0
  257. package/packages/jam/jam-host-calls/accumulate/query.test.js +8 -9
  258. package/packages/jam/jam-host-calls/accumulate/solicit.d.ts +2 -1
  259. package/packages/jam/jam-host-calls/accumulate/solicit.d.ts.map +1 -1
  260. package/packages/jam/jam-host-calls/accumulate/solicit.js +3 -0
  261. package/packages/jam/jam-host-calls/accumulate/solicit.test.js +7 -8
  262. package/packages/jam/jam-host-calls/accumulate/transfer.d.ts +2 -1
  263. package/packages/jam/jam-host-calls/accumulate/transfer.d.ts.map +1 -1
  264. package/packages/jam/jam-host-calls/accumulate/transfer.js +3 -0
  265. package/packages/jam/jam-host-calls/accumulate/transfer.test.js +9 -10
  266. package/packages/jam/jam-host-calls/accumulate/upgrade.d.ts +2 -1
  267. package/packages/jam/jam-host-calls/accumulate/upgrade.d.ts.map +1 -1
  268. package/packages/jam/jam-host-calls/accumulate/upgrade.js +3 -0
  269. package/packages/jam/jam-host-calls/accumulate/upgrade.test.js +4 -5
  270. package/packages/jam/jam-host-calls/accumulate/yield.d.ts +2 -1
  271. package/packages/jam/jam-host-calls/accumulate/yield.d.ts.map +1 -1
  272. package/packages/jam/jam-host-calls/accumulate/yield.js +3 -0
  273. package/packages/jam/jam-host-calls/accumulate/yield.test.js +4 -5
  274. package/packages/jam/jam-host-calls/externalities/refine-externalities.test.js +9 -9
  275. package/packages/jam/jam-host-calls/externalities/state-update.d.ts +2 -3
  276. package/packages/jam/jam-host-calls/externalities/state-update.d.ts.map +1 -1
  277. package/packages/jam/jam-host-calls/externalities/state-update.js +5 -2
  278. package/packages/jam/jam-host-calls/externalities/test-accounts.js +2 -2
  279. package/packages/jam/jam-host-calls/general/fetch.d.ts +2 -1
  280. package/packages/jam/jam-host-calls/general/fetch.d.ts.map +1 -1
  281. package/packages/jam/jam-host-calls/general/fetch.js +3 -0
  282. package/packages/jam/jam-host-calls/general/fetch.test.js +27 -28
  283. package/packages/jam/jam-host-calls/general/gas.d.ts +2 -1
  284. package/packages/jam/jam-host-calls/general/gas.d.ts.map +1 -1
  285. package/packages/jam/jam-host-calls/general/gas.js +3 -0
  286. package/packages/jam/jam-host-calls/general/gas.test.js +4 -5
  287. package/packages/jam/jam-host-calls/general/info.d.ts +2 -1
  288. package/packages/jam/jam-host-calls/general/info.d.ts.map +1 -1
  289. package/packages/jam/jam-host-calls/general/info.js +3 -0
  290. package/packages/jam/jam-host-calls/general/info.test.js +6 -7
  291. package/packages/jam/jam-host-calls/general/log.d.ts +2 -1
  292. package/packages/jam/jam-host-calls/general/log.d.ts.map +1 -1
  293. package/packages/jam/jam-host-calls/general/log.js +3 -0
  294. package/packages/jam/jam-host-calls/general/lookup.d.ts +2 -1
  295. package/packages/jam/jam-host-calls/general/lookup.d.ts.map +1 -1
  296. package/packages/jam/jam-host-calls/general/lookup.js +3 -0
  297. package/packages/jam/jam-host-calls/general/lookup.test.js +8 -9
  298. package/packages/jam/jam-host-calls/general/read.d.ts +2 -1
  299. package/packages/jam/jam-host-calls/general/read.d.ts.map +1 -1
  300. package/packages/jam/jam-host-calls/general/read.js +3 -0
  301. package/packages/jam/jam-host-calls/general/read.test.js +11 -12
  302. package/packages/jam/jam-host-calls/general/write.d.ts +2 -1
  303. package/packages/jam/jam-host-calls/general/write.d.ts.map +1 -1
  304. package/packages/jam/jam-host-calls/general/write.js +3 -0
  305. package/packages/jam/jam-host-calls/general/write.test.js +10 -11
  306. package/packages/jam/jam-host-calls/refine/export.d.ts +2 -1
  307. package/packages/jam/jam-host-calls/refine/export.d.ts.map +1 -1
  308. package/packages/jam/jam-host-calls/refine/export.js +3 -0
  309. package/packages/jam/jam-host-calls/refine/export.test.js +6 -7
  310. package/packages/jam/jam-host-calls/refine/expunge.d.ts +2 -1
  311. package/packages/jam/jam-host-calls/refine/expunge.d.ts.map +1 -1
  312. package/packages/jam/jam-host-calls/refine/expunge.js +3 -0
  313. package/packages/jam/jam-host-calls/refine/expunge.test.js +3 -4
  314. package/packages/jam/jam-host-calls/refine/historical-lookup.d.ts +2 -1
  315. package/packages/jam/jam-host-calls/refine/historical-lookup.d.ts.map +1 -1
  316. package/packages/jam/jam-host-calls/refine/historical-lookup.js +3 -0
  317. package/packages/jam/jam-host-calls/refine/historical-lookup.test.js +11 -12
  318. package/packages/jam/jam-host-calls/refine/invoke.d.ts +2 -1
  319. package/packages/jam/jam-host-calls/refine/invoke.d.ts.map +1 -1
  320. package/packages/jam/jam-host-calls/refine/invoke.js +4 -1
  321. package/packages/jam/jam-host-calls/refine/invoke.test.js +10 -11
  322. package/packages/jam/jam-host-calls/refine/machine.d.ts +2 -1
  323. package/packages/jam/jam-host-calls/refine/machine.d.ts.map +1 -1
  324. package/packages/jam/jam-host-calls/refine/machine.js +3 -0
  325. package/packages/jam/jam-host-calls/refine/machine.test.js +6 -7
  326. package/packages/jam/jam-host-calls/refine/pages.d.ts +2 -1
  327. package/packages/jam/jam-host-calls/refine/pages.d.ts.map +1 -1
  328. package/packages/jam/jam-host-calls/refine/pages.js +3 -0
  329. package/packages/jam/jam-host-calls/refine/pages.test.js +3 -4
  330. package/packages/jam/jam-host-calls/refine/peek.d.ts +2 -1
  331. package/packages/jam/jam-host-calls/refine/peek.d.ts.map +1 -1
  332. package/packages/jam/jam-host-calls/refine/peek.js +3 -0
  333. package/packages/jam/jam-host-calls/refine/peek.test.js +3 -4
  334. package/packages/jam/jam-host-calls/refine/poke.d.ts +2 -1
  335. package/packages/jam/jam-host-calls/refine/poke.d.ts.map +1 -1
  336. package/packages/jam/jam-host-calls/refine/poke.js +3 -0
  337. package/packages/jam/jam-host-calls/refine/poke.test.js +3 -4
  338. package/packages/jam/jamnp-s/network.js +1 -1
  339. package/packages/jam/jamnp-s/peers.d.ts +2 -1
  340. package/packages/jam/jamnp-s/peers.d.ts.map +1 -1
  341. package/packages/jam/jamnp-s/peers.js +3 -0
  342. package/packages/jam/jamnp-s/protocol/ce-128-block-request.d.ts +4 -2
  343. package/packages/jam/jamnp-s/protocol/ce-128-block-request.d.ts.map +1 -1
  344. package/packages/jam/jamnp-s/protocol/ce-128-block-request.js +6 -0
  345. package/packages/jam/jamnp-s/protocol/ce-128-block-request.test.js +2 -2
  346. package/packages/jam/jamnp-s/protocol/ce-129-state-request.d.ts +4 -2
  347. package/packages/jam/jamnp-s/protocol/ce-129-state-request.d.ts.map +1 -1
  348. package/packages/jam/jamnp-s/protocol/ce-129-state-request.js +6 -0
  349. package/packages/jam/jamnp-s/protocol/ce-129-state-request.test.js +4 -4
  350. package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.d.ts +4 -2
  351. package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.d.ts.map +1 -1
  352. package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.js +6 -0
  353. package/packages/jam/jamnp-s/protocol/ce-131-ce-132-safrole-ticket-distribution.test.js +2 -2
  354. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts +4 -1
  355. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.d.ts.map +1 -1
  356. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.js +7 -0
  357. package/packages/jam/jamnp-s/protocol/ce-133-work-package-submission.test.js +2 -2
  358. package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.d.ts +5 -2
  359. package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.d.ts.map +1 -1
  360. package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.js +7 -0
  361. package/packages/jam/jamnp-s/protocol/ce-134-work-package-sharing.test.js +2 -2
  362. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.d.ts +4 -2
  363. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.d.ts.map +1 -1
  364. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.js +6 -0
  365. package/packages/jam/jamnp-s/protocol/ce-135-work-report-distribution.test.js +2 -2
  366. package/packages/jam/jamnp-s/protocol/up-0-block-announcement.d.ts +2 -1
  367. package/packages/jam/jamnp-s/protocol/up-0-block-announcement.d.ts.map +1 -1
  368. package/packages/jam/jamnp-s/protocol/up-0-block-announcement.js +3 -0
  369. package/packages/jam/jamnp-s/stream-manager.d.ts +2 -1
  370. package/packages/jam/jamnp-s/stream-manager.d.ts.map +1 -1
  371. package/packages/jam/jamnp-s/stream-manager.js +4 -1
  372. package/packages/jam/jamnp-s/tasks/sync.js +4 -4
  373. package/packages/jam/jamnp-s/tasks/sync.test.js +4 -4
  374. package/packages/jam/jamnp-s/tasks/ticket-distribution.js +2 -2
  375. package/packages/jam/jamnp-s/tasks/ticket-distribution.test.js +1 -1
  376. package/packages/jam/node/common.d.ts.map +1 -1
  377. package/packages/jam/node/common.js +3 -3
  378. package/packages/jam/rpc-client/index.d.ts +4 -2
  379. package/packages/jam/rpc-client/index.d.ts.map +1 -1
  380. package/packages/jam/rpc-client/index.js +7 -1
  381. package/packages/jam/state/in-memory-state-view.d.ts +2 -1
  382. package/packages/jam/state/in-memory-state-view.d.ts.map +1 -1
  383. package/packages/jam/state/in-memory-state-view.js +3 -0
  384. package/packages/jam/state/in-memory-state.d.ts +16 -21
  385. package/packages/jam/state/in-memory-state.d.ts.map +1 -1
  386. package/packages/jam/state/in-memory-state.js +10 -6
  387. package/packages/jam/state/in-memory-state.test.js +2 -2
  388. package/packages/jam/state/service.d.ts +2 -6
  389. package/packages/jam/state/service.d.ts.map +1 -1
  390. package/packages/jam/state/service.js +3 -0
  391. package/packages/jam/state/test.utils.js +3 -3
  392. package/packages/jam/state-json/accounts.js +5 -5
  393. package/packages/jam/state-merkleization/in-memory-state-codec.d.ts +3 -34
  394. package/packages/jam/state-merkleization/in-memory-state-codec.d.ts.map +1 -1
  395. package/packages/jam/state-merkleization/in-memory-state-codec.js +1 -1
  396. package/packages/jam/state-merkleization/serialized-state-view.d.ts +8 -3
  397. package/packages/jam/state-merkleization/serialized-state-view.d.ts.map +1 -1
  398. package/packages/jam/state-merkleization/serialized-state-view.js +6 -3
  399. package/packages/jam/state-merkleization/serialized-state.d.ts +2 -3
  400. package/packages/jam/state-merkleization/serialized-state.d.ts.map +1 -1
  401. package/packages/jam/state-merkleization/serialized-state.js +10 -2
  402. package/packages/jam/state-merkleization/serialized-state.test.js +1 -1
  403. package/packages/jam/transition/accumulate/accumulate.js +10 -3
  404. package/packages/jam/transition/accumulate/accumulate.test.js +1 -1
  405. package/packages/jam/transition/block-verifier.d.ts +2 -1
  406. package/packages/jam/transition/block-verifier.d.ts.map +1 -1
  407. package/packages/jam/transition/block-verifier.js +3 -0
  408. package/packages/jam/transition/block-verifier.test.js +8 -8
  409. package/packages/jam/transition/chain-stf.d.ts +12 -4
  410. package/packages/jam/transition/chain-stf.d.ts.map +1 -1
  411. package/packages/jam/transition/chain-stf.js +7 -3
  412. package/packages/jam/transition/externalities/accumulate-externalities.d.ts +20 -6
  413. package/packages/jam/transition/externalities/accumulate-externalities.d.ts.map +1 -1
  414. package/packages/jam/transition/externalities/accumulate-externalities.js +29 -22
  415. package/packages/jam/transition/externalities/accumulate-externalities.test.js +590 -100
  416. package/packages/jam/transition/externalities/refine-fetch-externalities.d.ts +2 -1
  417. package/packages/jam/transition/externalities/refine-fetch-externalities.d.ts.map +1 -1
  418. package/packages/jam/transition/externalities/refine-fetch-externalities.js +3 -0
  419. package/packages/jam/transition/externalities/refine-fetch-externalities.test.js +1 -1
  420. package/packages/jam/transition/hasher.d.ts +2 -1
  421. package/packages/jam/transition/hasher.d.ts.map +1 -1
  422. package/packages/jam/transition/hasher.js +5 -2
  423. package/packages/jam/transition/hasher.test.js +1 -1
  424. package/packages/jam/transition/preimages.test.js +4 -4
  425. package/packages/jam/transition/reports/test.utils.js +1 -1
  426. package/packages/workers/api-node/config.js +4 -4
  427. package/packages/workers/api-node/port.d.ts +2 -1
  428. package/packages/workers/api-node/port.d.ts.map +1 -1
  429. package/packages/workers/api-node/port.js +4 -1
  430. package/packages/workers/api-node/port.test.js +2 -2
  431. package/packages/workers/api-node/protocol.js +2 -2
  432. package/packages/workers/block-authorship/generator.d.ts +13 -2
  433. package/packages/workers/block-authorship/generator.d.ts.map +1 -1
  434. package/packages/workers/block-authorship/generator.js +13 -9
  435. package/packages/workers/block-authorship/generator.test.js +16 -2
  436. package/packages/workers/block-authorship/main.d.ts.map +1 -1
  437. package/packages/workers/block-authorship/main.js +8 -1
  438. package/packages/workers/importer/finality.test.js +1 -1
  439. package/packages/workers/importer/importer.d.ts +23 -6
  440. package/packages/workers/importer/importer.d.ts.map +1 -1
  441. package/packages/workers/importer/importer.js +34 -19
  442. package/packages/workers/importer/main.d.ts.map +1 -1
  443. package/packages/workers/importer/main.js +13 -5
@@ -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);
@@ -666,7 +848,14 @@ describe("PartialState.updateAuthorizationQueue", () => {
666
848
  it("should update the authorization queue and transfer the assigner for the given core", () => {
667
849
  const state = partiallyUpdatedState();
668
850
  const initialPrivileged = state.state.privilegedServices;
669
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
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
+ });
670
859
  const coreIndex = tryAsCoreIndex(0);
671
860
  const newAssigner = tryAsServiceId(99);
672
861
  const queue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
@@ -688,7 +877,14 @@ describe("PartialState.updateAuthorizationQueue", () => {
688
877
  });
689
878
  it("should return InvalidServiceId when given auth manager is invalid", () => {
690
879
  const state = partiallyUpdatedState();
691
- 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
+ });
692
888
  const coreIndex = tryAsCoreIndex(0);
693
889
  const assigners = null;
694
890
  const queue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
@@ -706,7 +902,14 @@ describe("PartialState.updateAuthorizationQueue", () => {
706
902
  ...state.state.privilegedServices,
707
903
  assigners: asOpaqueType(FixedSizeArray.new([tryAsServiceId(1), tryAsServiceId(2)], tinyChainSpec.coresCount)),
708
904
  });
709
- 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
+ });
710
913
  const coreIndex = tryAsCoreIndex(0);
711
914
  const assigners = tryAsServiceId(0);
712
915
  const queue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
@@ -724,7 +927,14 @@ describe("PartialState.updateAuthorizationQueue", () => {
724
927
  ...state.state.privilegedServices,
725
928
  assigners: asOpaqueType(FixedSizeArray.new([tryAsServiceId(1), tryAsServiceId(2)], tinyChainSpec.coresCount)),
726
929
  });
727
- 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
+ });
728
938
  const coreIndex = tryAsCoreIndex(0);
729
939
  const assigners = null;
730
940
  const queue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
@@ -744,7 +954,7 @@ describe("PartialState.updateAuthorizationQueue", () => {
744
954
  if (baseService === undefined) {
745
955
  throw new Error("Invalid service!");
746
956
  }
747
- state.state.services.set(CURRENT_SERVICE_ID, new InMemoryService(CURRENT_SERVICE_ID, {
957
+ state.state.services.set(CURRENT_SERVICE_ID, InMemoryService.new(CURRENT_SERVICE_ID, {
748
958
  info: baseService.data.info,
749
959
  preimages: HashDictionary.new(),
750
960
  lookupHistory: HashDictionary.new(),
@@ -754,7 +964,14 @@ describe("PartialState.updateAuthorizationQueue", () => {
754
964
  ...state.state.privilegedServices,
755
965
  assigners: asOpaqueType(FixedSizeArray.new([CURRENT_SERVICE_ID, tryAsServiceId(0)], tinyChainSpec.coresCount)),
756
966
  });
757
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, CURRENT_SERVICE_ID, tryAsServiceId(10), tryAsTimeSlot(16));
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
+ });
758
975
  const coreIndex = tryAsCoreIndex(0);
759
976
  const queue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
760
977
  // when
@@ -769,7 +986,14 @@ describe("PartialState.updateAuthorizationQueue", () => {
769
986
  });
770
987
  it("should prevent the previous assigner from re-assigning after transfer", () => {
771
988
  const state = partiallyUpdatedState();
772
- const partialState = new AccumulateExternalities(tinyChainSpec, blake2b, state, tryAsServiceId(0), tryAsServiceId(10), tryAsTimeSlot(16));
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
+ });
773
997
  const coreIndex = tryAsCoreIndex(0);
774
998
  const newAssigner = tryAsServiceId(99);
775
999
  const firstQueue = FixedSizeArray.new(Array.from({ length: AUTHORIZATION_QUEUE_SIZE }, () => Bytes.fill(HASH_SIZE, 0xee).asOpaque()), AUTHORIZATION_QUEUE_SIZE);
@@ -792,7 +1016,14 @@ describe("PartialState.updateAuthorizationQueue", () => {
792
1016
  describe("PartialState.updatePrivilegedServices", () => {
793
1017
  it("should update privileged services", () => {
794
1018
  const state = partiallyUpdatedState();
795
- 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
+ });
796
1027
  const manager = tryAsServiceId(1);
797
1028
  const assigners = tryAsPerCore(new Array(tinyChainSpec.coresCount).fill(tryAsServiceId(2)), tinyChainSpec);
798
1029
  const delegator = tryAsServiceId(3);
@@ -815,7 +1046,14 @@ describe("PartialState.updatePrivilegedServices", () => {
815
1046
  });
816
1047
  it("should return InvalidService when given manager is invalid service id", () => {
817
1048
  const state = partiallyUpdatedState();
818
- 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
+ });
819
1057
  const manager = null;
820
1058
  const assigners = tryAsPerCore(new Array(tinyChainSpec.coresCount).fill(tryAsServiceId(2)), tinyChainSpec);
821
1059
  const delegator = tryAsServiceId(3);
@@ -832,7 +1070,14 @@ describe("PartialState.updatePrivilegedServices", () => {
832
1070
  });
833
1071
  it("should return InvalidService when given validator is invalid service id", () => {
834
1072
  const state = partiallyUpdatedState();
835
- 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
+ });
836
1081
  const manager = tryAsServiceId(1);
837
1082
  const assigners = tryAsPerCore(new Array(tinyChainSpec.coresCount).fill(tryAsServiceId(2)), tinyChainSpec);
838
1083
  const delegator = null;
@@ -849,7 +1094,14 @@ describe("PartialState.updatePrivilegedServices", () => {
849
1094
  });
850
1095
  it("should return InvalidService when given registrar is invalid service id", () => {
851
1096
  const state = partiallyUpdatedState();
852
- 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
+ });
853
1105
  const manager = tryAsServiceId(1);
854
1106
  const assigners = tryAsPerCore(new Array(tinyChainSpec.coresCount).fill(tryAsServiceId(2)), tinyChainSpec);
855
1107
  const delegator = tryAsServiceId(3);
@@ -873,7 +1125,7 @@ describe("PartialState.transfer", () => {
873
1125
  throw new Error("Invalid service!");
874
1126
  }
875
1127
  const service = maybeService;
876
- state.state.services.set(tryAsServiceId(1), new InMemoryService(tryAsServiceId(1), {
1128
+ state.state.services.set(tryAsServiceId(1), InMemoryService.new(tryAsServiceId(1), {
877
1129
  info: ServiceAccountInfo.create({
878
1130
  ...service.data.info,
879
1131
  onTransferMinGas: tryAsServiceGas(1000),
@@ -889,7 +1141,14 @@ describe("PartialState.transfer", () => {
889
1141
  };
890
1142
  it("should perform a successful transfer", () => {
891
1143
  const { state, service } = partiallyUpdatedStateWithSecondService();
892
- 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
+ });
893
1152
  const destinationId = tryAsServiceId(1);
894
1153
  const amount = tryAsU64(500n);
895
1154
  const gas = tryAsServiceGas(1000n);
@@ -922,7 +1181,14 @@ describe("PartialState.transfer", () => {
922
1181
  });
923
1182
  it("should return DestinationNotFound error if destination doesnt exist", () => {
924
1183
  const { state } = partiallyUpdatedStateWithSecondService();
925
- 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
+ });
926
1192
  const amount = tryAsU64(100n);
927
1193
  const gas = tryAsServiceGas(1000n);
928
1194
  const memo = Bytes.fill(TRANSFER_MEMO_BYTES, 0xbb);
@@ -933,7 +1199,14 @@ describe("PartialState.transfer", () => {
933
1199
  });
934
1200
  it("should return GasTooLow error if gas is below destination's minimum", () => {
935
1201
  const { state } = partiallyUpdatedStateWithSecondService();
936
- 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
+ });
937
1210
  const destinationId = tryAsServiceId(1);
938
1211
  const amount = tryAsU64(100n);
939
1212
  const gas = tryAsServiceGas(999n); // too low
@@ -945,7 +1218,14 @@ describe("PartialState.transfer", () => {
945
1218
  });
946
1219
  it("should return BalanceBelowThreshold error if balance would fall too low", () => {
947
1220
  const { state } = partiallyUpdatedStateWithSecondService();
948
- 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
+ });
949
1229
  const destinationId = tryAsServiceId(1);
950
1230
  const amount = tryAsU64(9999999999n); // dangerously high
951
1231
  const gas = tryAsServiceGas(1000n);
@@ -960,7 +1240,14 @@ describe("PartialState.yield", () => {
960
1240
  it("should yield root", () => {
961
1241
  const currentServiceId = tryAsServiceId(0);
962
1242
  const state = partiallyUpdatedState();
963
- 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
+ });
964
1251
  const expectedYieldedRoot = Bytes.fill(HASH_SIZE, 0xef);
965
1252
  // when
966
1253
  partialState.yield(Bytes.fill(HASH_SIZE, 0xef));
@@ -986,19 +1273,19 @@ describe("PartialState.providePreimage", () => {
986
1273
  ? [
987
1274
  [
988
1275
  preimage.hash,
989
- [new LookupHistoryItem(preimage.hash, tryAsU32(preimage.blob.length), tryAsLookupHistorySlots([]))],
1276
+ [LookupHistoryItem.new(preimage.hash, tryAsU32(preimage.blob.length), tryAsLookupHistorySlots([]))],
990
1277
  ],
991
1278
  ]
992
1279
  : []);
993
1280
  if (self) {
994
1281
  // we need to replace the existing service
995
- state.state.services.set(service.serviceId, new InMemoryService(service.serviceId, {
1282
+ state.state.services.set(service.serviceId, InMemoryService.new(service.serviceId, {
996
1283
  ...service.data,
997
1284
  preimages,
998
1285
  lookupHistory,
999
1286
  }));
1000
1287
  }
1001
- const secondService = new InMemoryService(tryAsServiceId(1), {
1288
+ const secondService = InMemoryService.new(tryAsServiceId(1), {
1002
1289
  info: ServiceAccountInfo.create({
1003
1290
  ...service.data.info,
1004
1291
  onTransferMinGas: tryAsServiceGas(1000),
@@ -1018,7 +1305,14 @@ describe("PartialState.providePreimage", () => {
1018
1305
  self: false,
1019
1306
  requested: true,
1020
1307
  });
1021
- 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
+ });
1022
1316
  const serviceId = tryAsServiceId(1);
1023
1317
  assert.deepStrictEqual(state.stateUpdate.services.preimages.size, 0);
1024
1318
  // when
@@ -1056,7 +1350,14 @@ describe("PartialState.providePreimage", () => {
1056
1350
  });
1057
1351
  it("should provide a preimage for itself", () => {
1058
1352
  const { state, preimage } = partiallyUpdatedStateWithSecondService({ self: true, requested: true });
1059
- 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
+ });
1060
1361
  const serviceId = tryAsServiceId(0);
1061
1362
  assert.deepStrictEqual(state.stateUpdate.services.preimages.size, 0);
1062
1363
  // when
@@ -1084,7 +1385,14 @@ describe("PartialState.providePreimage", () => {
1084
1385
  self: false,
1085
1386
  requested: false,
1086
1387
  });
1087
- 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
+ });
1088
1396
  const serviceId = tryAsServiceId(1);
1089
1397
  assert.deepStrictEqual(state.stateUpdate.services.preimages.size, 0);
1090
1398
  // when
@@ -1099,7 +1407,14 @@ describe("PartialState.providePreimage", () => {
1099
1407
  requested: true,
1100
1408
  available: true,
1101
1409
  });
1102
- 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
+ });
1103
1418
  const serviceId = tryAsServiceId(1);
1104
1419
  const updates = state.stateUpdate.services.preimages.get(serviceId) ?? [];
1105
1420
  updates.push(UpdatePreimage.provide({
@@ -1137,7 +1452,14 @@ describe("PartialState.providePreimage", () => {
1137
1452
  requested: true,
1138
1453
  available: true,
1139
1454
  });
1140
- 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
+ });
1141
1463
  const serviceId = tryAsServiceId(0);
1142
1464
  // when
1143
1465
  const result = partialState.providePreimage(serviceId, preimage.blob);
@@ -1151,7 +1473,14 @@ describe("PartialState.providePreimage", () => {
1151
1473
  requested: true,
1152
1474
  available: false,
1153
1475
  });
1154
- 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
+ });
1155
1484
  const serviceId = tryAsServiceId(0);
1156
1485
  assert.deepStrictEqual(state.stateUpdate.services.preimages, new Map());
1157
1486
  // when
@@ -1182,7 +1511,14 @@ describe("PartialState.providePreimage", () => {
1182
1511
  requested: true,
1183
1512
  available: false,
1184
1513
  });
1185
- 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
+ });
1186
1522
  const serviceId = tryAsServiceId(1);
1187
1523
  assert.deepStrictEqual(state.stateUpdate.services.preimages, new Map());
1188
1524
  // when
@@ -1240,7 +1576,7 @@ describe("PartialState.eject", () => {
1240
1576
  let lookupHistory = HashDictionary.new();
1241
1577
  if (overrides.tombstone !== undefined) {
1242
1578
  const { hash, length, slots } = overrides.tombstone;
1243
- const item = new LookupHistoryItem(hash, length, slots);
1579
+ const item = LookupHistoryItem.new(hash, length, slots);
1244
1580
  lookupHistory = HashDictionary.fromEntries([[hash, [item]]]);
1245
1581
  if (item.slots.length === 1 || item.slots.length === 2) {
1246
1582
  preimages = HashDictionary.fromEntries([
@@ -1254,7 +1590,7 @@ describe("PartialState.eject", () => {
1254
1590
  ]);
1255
1591
  }
1256
1592
  }
1257
- const destinationService = new InMemoryService(destinationId, {
1593
+ const destinationService = InMemoryService.new(destinationId, {
1258
1594
  info: ServiceAccountInfo.create({
1259
1595
  ...baseService.data.info,
1260
1596
  codeHash,
@@ -1270,7 +1606,14 @@ describe("PartialState.eject", () => {
1270
1606
  }
1271
1607
  it("should return InvalidService if destination is null", () => {
1272
1608
  const state = partiallyUpdatedState();
1273
- 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
+ });
1274
1617
  const tombstone = Bytes.fill(HASH_SIZE, 0xef).asOpaque();
1275
1618
  // when
1276
1619
  const result = partialState.eject(null, tombstone);
@@ -1280,7 +1623,14 @@ describe("PartialState.eject", () => {
1280
1623
  });
1281
1624
  it("should return InvalidService if destination service does not exist", () => {
1282
1625
  const state = partiallyUpdatedState();
1283
- 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
+ });
1284
1634
  const nonExistentServiceId = tryAsServiceId(99); // not present in stateUpdate
1285
1635
  const tombstone = Bytes.fill(HASH_SIZE, 0xee).asOpaque();
1286
1636
  // when
@@ -1303,7 +1653,14 @@ describe("PartialState.eject", () => {
1303
1653
  slots: tryAsLookupHistorySlots([0, 1].map((x) => tryAsTimeSlot(x))),
1304
1654
  },
1305
1655
  });
1306
- 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
+ });
1307
1664
  // when
1308
1665
  const correctEjectResult = partialState.eject(destinationId, tombstone); // correct eject
1309
1666
  assert.strictEqual(correctEjectResult.isOk, true);
@@ -1318,7 +1675,14 @@ describe("PartialState.eject", () => {
1318
1675
  codeHash: Bytes.fill(HASH_SIZE, 0x99).asOpaque(), // wrong codeHash
1319
1676
  });
1320
1677
  const tombstone = Bytes.fill(HASH_SIZE, 0xec).asOpaque();
1321
- 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
+ });
1322
1686
  // when
1323
1687
  const result = partialState.eject(destinationId, tombstone);
1324
1688
  // then
@@ -1331,7 +1695,14 @@ describe("PartialState.eject", () => {
1331
1695
  storageUtilisationCount: tryAsU32(2 + 1), // off by 1
1332
1696
  });
1333
1697
  const tombstone = Bytes.fill(HASH_SIZE, 0xeb).asOpaque();
1334
- 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
+ });
1335
1706
  // when
1336
1707
  const result = partialState.eject(destinationId, tombstone);
1337
1708
  // then
@@ -1343,7 +1714,14 @@ describe("PartialState.eject", () => {
1343
1714
  const tombstone = Bytes.fill(HASH_SIZE, 0xea).asOpaque();
1344
1715
  // destination service has valid codeHash and config, but no preimage or lookup history
1345
1716
  const destinationId = setupEjectableService(state.state);
1346
- 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
+ });
1347
1725
  // when
1348
1726
  const result = partialState.eject(destinationId, tombstone);
1349
1727
  // then
@@ -1362,7 +1740,14 @@ describe("PartialState.eject", () => {
1362
1740
  slots: tryAsLookupHistorySlots([1].map((x) => tryAsTimeSlot(x))),
1363
1741
  },
1364
1742
  });
1365
- 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
+ });
1366
1751
  // when
1367
1752
  const result = partialState.eject(destinationId, tombstone);
1368
1753
  // then
@@ -1381,7 +1766,14 @@ describe("PartialState.eject", () => {
1381
1766
  slots: tryAsLookupHistorySlots([1, 11].map((x) => tryAsTimeSlot(x))),
1382
1767
  },
1383
1768
  });
1384
- 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
+ });
1385
1777
  // when
1386
1778
  const result = partialState.eject(destinationId, tombstone);
1387
1779
  // then
@@ -1402,7 +1794,14 @@ describe("PartialState.eject", () => {
1402
1794
  slots: tryAsLookupHistorySlots([0, 1].map((x) => tryAsTimeSlot(x))),
1403
1795
  },
1404
1796
  });
1405
- 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
+ });
1406
1805
  // set the balance to overflow
1407
1806
  const currentService = state.state.services.get(tryAsServiceId(0));
1408
1807
  if (currentService === undefined) {
@@ -1432,7 +1831,14 @@ describe("PartialState.eject", () => {
1432
1831
  slots: tryAsLookupHistorySlots([0, 1].map((x) => tryAsTimeSlot(x))),
1433
1832
  },
1434
1833
  });
1435
- 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
+ });
1436
1842
  // when
1437
1843
  const result = partialState.eject(destinationId, tombstone);
1438
1844
  // then
@@ -1449,12 +1855,12 @@ describe("AccumulateServiceExternalities", () => {
1449
1855
  }
1450
1856
  const state = InMemoryState.empty(tinyChainSpec);
1451
1857
  state.services = services;
1452
- return new PartiallyUpdatedState(state);
1858
+ return PartiallyUpdatedState.new(state);
1453
1859
  };
1454
1860
  const prepareService = (serviceId, { storage, preimages, info, } = {}) => {
1455
1861
  const initialStorage = storage ?? new Map();
1456
1862
  const storageUtilisationBytes = Array.from(initialStorage.values()).reduce((sum, item) => sum + (item?.value.length ?? 0), 0);
1457
- return new InMemoryService(serviceId, {
1863
+ return InMemoryService.new(serviceId, {
1458
1864
  info: ServiceAccountInfo.create({
1459
1865
  balance: tryAsU64(2 ** 32),
1460
1866
  accumulateMinGas: tryAsServiceGas(1000),
@@ -1487,7 +1893,14 @@ describe("AccumulateServiceExternalities", () => {
1487
1893
  const serviceId = null;
1488
1894
  const state = prepareState([prepareService(currentServiceId)]);
1489
1895
  const expectedServiceInfo = null;
1490
- 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
+ });
1491
1904
  const serviceInfo = accumulateServiceExternalities.getServiceInfo(serviceId);
1492
1905
  assert.strictEqual(serviceInfo, expectedServiceInfo);
1493
1906
  });
@@ -1496,7 +1909,14 @@ describe("AccumulateServiceExternalities", () => {
1496
1909
  const serviceId = tryAsServiceId(5);
1497
1910
  const state = prepareState([prepareService(currentServiceId)]);
1498
1911
  const expectedServiceInfo = null;
1499
- 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
+ });
1500
1920
  const serviceInfo = accumulateServiceExternalities.getServiceInfo(serviceId);
1501
1921
  assert.strictEqual(serviceInfo, expectedServiceInfo);
1502
1922
  });
@@ -1505,7 +1925,14 @@ describe("AccumulateServiceExternalities", () => {
1505
1925
  const serviceId = tryAsServiceId(5);
1506
1926
  const state = prepareState([prepareService(currentServiceId), prepareService(serviceId)]);
1507
1927
  const expectedServiceInfo = prepareService(serviceId).getInfo();
1508
- 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
+ });
1509
1936
  const serviceInfo = accumulateServiceExternalities.getServiceInfo(serviceId);
1510
1937
  assert.deepStrictEqual(serviceInfo, expectedServiceInfo);
1511
1938
  });
@@ -1517,7 +1944,14 @@ describe("AccumulateServiceExternalities", () => {
1517
1944
  const hash = Bytes.fill(HASH_SIZE, 1).asOpaque();
1518
1945
  const state = prepareState([prepareService(currentServiceId)]);
1519
1946
  const expectedResult = null;
1520
- 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
+ });
1521
1955
  const result = accumulateServiceExternalities.lookup(serviceId, hash);
1522
1956
  assert.strictEqual(result, expectedResult);
1523
1957
  });
@@ -1527,7 +1961,14 @@ describe("AccumulateServiceExternalities", () => {
1527
1961
  const hash = Bytes.fill(HASH_SIZE, 1).asOpaque();
1528
1962
  const state = prepareState([prepareService(currentServiceId)]);
1529
1963
  const expectedResult = null;
1530
- 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
+ });
1531
1972
  const result = accumulateServiceExternalities.lookup(serviceId, hash);
1532
1973
  assert.strictEqual(result, expectedResult);
1533
1974
  });
@@ -1539,7 +1980,14 @@ describe("AccumulateServiceExternalities", () => {
1539
1980
  const service = prepareService(currentServiceId, { preimages });
1540
1981
  const state = prepareState([service]);
1541
1982
  const expectedResult = null;
1542
- 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
+ });
1543
1991
  const result = accumulateServiceExternalities.lookup(currentServiceId, requestedHash);
1544
1992
  assert.strictEqual(result, expectedResult);
1545
1993
  });
@@ -1550,7 +1998,14 @@ describe("AccumulateServiceExternalities", () => {
1550
1998
  const preimages = preparePreimages([[requestedHash, expectedResult]]);
1551
1999
  const service = prepareService(serviceId, { preimages });
1552
2000
  const state = prepareState([service]);
1553
- 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
+ });
1554
2009
  const result = accumulateServiceExternalities.lookup(serviceId, requestedHash);
1555
2010
  assert.deepStrictEqual(result, expectedResult);
1556
2011
  });
@@ -1561,7 +2016,14 @@ describe("AccumulateServiceExternalities", () => {
1561
2016
  const serviceId = null;
1562
2017
  const hash = Bytes.fill(HASH_SIZE, 1).asOpaque();
1563
2018
  const state = prepareState([prepareService(currentServiceId)]);
1564
- 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
+ });
1565
2027
  const result = accumulateServiceExternalities.read(serviceId, hash);
1566
2028
  assert.strictEqual(result, null);
1567
2029
  });
@@ -1570,7 +2032,14 @@ describe("AccumulateServiceExternalities", () => {
1570
2032
  const serviceId = tryAsServiceId(33);
1571
2033
  const hash = Bytes.fill(HASH_SIZE, 1).asOpaque();
1572
2034
  const state = prepareState([prepareService(currentServiceId)]);
1573
- 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
+ });
1574
2043
  const result = accumulateServiceExternalities.read(serviceId, hash);
1575
2044
  assert.strictEqual(result, null);
1576
2045
  });
@@ -1586,7 +2055,14 @@ describe("AccumulateServiceExternalities", () => {
1586
2055
  }));
1587
2056
  const service = prepareService(serviceId, { storage: initialStorage });
1588
2057
  const state = prepareState([prepareService(currentServiceId), service]);
1589
- 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
+ });
1590
2066
  const result = accumulateServiceExternalities.read(serviceId, key);
1591
2067
  assert.strictEqual(result, value);
1592
2068
  });
@@ -1595,7 +2071,14 @@ describe("AccumulateServiceExternalities", () => {
1595
2071
  const hash = Bytes.fill(HASH_SIZE, 1).asOpaque();
1596
2072
  const blob = BytesBlob.empty();
1597
2073
  const state = prepareState([prepareService(currentServiceId)]);
1598
- 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
+ });
1599
2082
  assert.strictEqual(state.stateUpdate.services.storage.size, 0);
1600
2083
  accumulateServiceExternalities.write(hash, blob);
1601
2084
  assert.strictEqual(state.stateUpdate.services.storage.size, 1);
@@ -1608,7 +2091,14 @@ describe("AccumulateServiceExternalities", () => {
1608
2091
  const newBlob = BytesBlob.parseBlob("0x11111111");
1609
2092
  initialStorage.set(key.toString(), StorageItem.create({ key, value }));
1610
2093
  const state = prepareState([prepareService(currentServiceId, { storage: initialStorage })]);
1611
- 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
+ });
1612
2102
  accumulateServiceExternalities.write(key, newBlob);
1613
2103
  assert.strictEqual(state.stateUpdate.services.storage.size, 1);
1614
2104
  const result = accumulateServiceExternalities.read(currentServiceId, key);