trac-msb 0.2.18 → 0.2.20

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 (381) hide show
  1. package/README.md +62 -2
  2. package/SECURITY.md +9 -6
  3. package/cli/commandHandler.js +272 -0
  4. package/cli/handlers.js +210 -0
  5. package/cli/interactive.js +182 -0
  6. package/msb.mjs +7 -8
  7. package/package.json +25 -8
  8. package/rpc/create_server.js +44 -44
  9. package/rpc/handlers.js +43 -56
  10. package/rpc/routes/index.js +8 -8
  11. package/rpc/rpc_server.js +6 -2
  12. package/rpc/utils/helpers.js +46 -66
  13. package/scripts/pear-runner.js +170 -0
  14. package/src/config/args.js +60 -13
  15. package/src/config/config.js +138 -10
  16. package/src/config/env.js +36 -18
  17. package/src/core/network/Network.js +130 -34
  18. package/src/core/network/protocols/ProtocolInterface.js +5 -5
  19. package/src/core/network/protocols/connectionPolicies.js +86 -0
  20. package/src/core/network/protocols/legacy/NetworkMessageRouter.js +1 -1
  21. package/src/core/network/protocols/legacy/handlers/BaseStateOperationHandler.js +2 -2
  22. package/src/core/network/protocols/legacy/handlers/LegacyGetRequestHandler.js +3 -3
  23. package/src/core/network/protocols/legacy/handlers/LegacyRoleOperationHandler.js +1 -1
  24. package/src/core/network/protocols/legacy/handlers/LegacySubnetworkOperationHandler.js +1 -1
  25. package/src/core/network/protocols/legacy/handlers/LegacyTransferOperationHandler.js +1 -1
  26. package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
  27. package/src/core/network/protocols/shared/validators/PartialBootstrapDeploymentValidator.js +2 -2
  28. package/src/core/network/protocols/shared/validators/PartialOperationValidator.js +23 -23
  29. package/src/core/network/protocols/shared/validators/PartialRoleAccessValidator.js +14 -14
  30. package/src/core/network/protocols/shared/validators/PartialTransactionValidator.js +5 -5
  31. package/src/core/network/protocols/shared/validators/PartialTransferValidator.js +12 -11
  32. package/src/core/network/protocols/v1/V1ProtocolError.js +5 -69
  33. package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +3 -2
  34. package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +130 -247
  35. package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +6 -5
  36. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +84 -0
  37. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +128 -0
  38. package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +26 -0
  39. package/src/core/network/protocols/v1/validators/V1BaseOperation.js +32 -31
  40. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +5 -3
  41. package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +34 -50
  42. package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +1 -1
  43. package/src/core/network/services/ConnectionManager.js +11 -10
  44. package/src/core/network/services/MessageOrchestrator.js +53 -17
  45. package/src/core/network/services/PendingRequestService.js +22 -19
  46. package/src/core/network/services/TransactionCommitService.js +36 -36
  47. package/src/core/network/services/TransactionPoolService.js +39 -39
  48. package/src/core/network/services/TransactionRateLimiterService.js +8 -4
  49. package/src/core/network/services/ValidatorObserverService.js +397 -110
  50. package/src/core/state/State.js +190 -138
  51. package/src/core/state/utils/address.js +4 -9
  52. package/src/core/state/utils/balance.js +7 -7
  53. package/src/core/state/utils/roles.js +1 -1
  54. package/src/index.js +316 -275
  55. package/src/messages/network/v1/NetworkMessageBuilder.js +12 -21
  56. package/src/messages/network/v1/networkMessageFactory.js +1 -1
  57. package/src/messages/state/ApplyStateMessageBuilder.js +6 -6
  58. package/src/messages/state/applyStateMessageFactory.js +1 -1
  59. package/src/utils/buffer.js +1 -1
  60. package/src/utils/check.js +12 -13
  61. package/src/utils/constants.js +7 -0
  62. package/src/utils/errors.js +20 -0
  63. package/src/utils/fileUtils.js +12 -3
  64. package/src/utils/helpers.js +2 -2
  65. package/src/utils/migrationUtils.js +3 -3
  66. package/.dockerignore +0 -16
  67. package/CODE_OF_CONDUCT.md +0 -128
  68. package/docker-compose.yml +0 -17
  69. package/dockerfile +0 -41
  70. package/docs/fee_distribution.md +0 -89
  71. package/docs/trac_network_http_api.openapi.yaml +0 -889
  72. package/migration/.gitkeep +0 -0
  73. package/proto/applyOperations.proto +0 -117
  74. package/proto/network/v1/enums/message_type.proto +0 -16
  75. package/proto/network/v1/enums/result_code.proto +0 -84
  76. package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
  77. package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
  78. package/proto/network/v1/messages/liveness_request.proto +0 -8
  79. package/proto/network/v1/messages/liveness_response.proto +0 -11
  80. package/proto/network/v1/network_message.proto +0 -22
  81. package/rpc/rpc_services.js +0 -181
  82. package/scripts/generate-protobufs.js +0 -67
  83. package/src/core/network/identity/NetworkWalletFactory.js +0 -77
  84. package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
  85. package/src/utils/cli.js +0 -130
  86. package/src/utils/cliCommands.js +0 -280
  87. package/tests/acceptance/v1/account/account.test.mjs +0 -129
  88. package/tests/acceptance/v1/balance/balance.test.mjs +0 -54
  89. package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +0 -116
  90. package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +0 -19
  91. package/tests/acceptance/v1/fee/fee.test.mjs +0 -11
  92. package/tests/acceptance/v1/health/health.test.mjs +0 -33
  93. package/tests/acceptance/v1/rpc.test.mjs +0 -95
  94. package/tests/acceptance/v1/tx/tx.test.mjs +0 -133
  95. package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -241
  96. package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +0 -72
  97. package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +0 -27
  98. package/tests/acceptance/v1/txv/txv.test.mjs +0 -11
  99. package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +0 -11
  100. package/tests/fixtures/apply.fixtures.js +0 -77
  101. package/tests/fixtures/assembleMessage.fixtures.js +0 -41
  102. package/tests/fixtures/check.fixtures.js +0 -428
  103. package/tests/fixtures/networkV1.fixtures.js +0 -59
  104. package/tests/fixtures/protobuf.fixtures.js +0 -388
  105. package/tests/helpers/StateNetworkFactory.js +0 -155
  106. package/tests/helpers/address.js +0 -6
  107. package/tests/helpers/autobaseTestHelpers.js +0 -419
  108. package/tests/helpers/config.js +0 -4
  109. package/tests/helpers/createTestSignature.js +0 -13
  110. package/tests/helpers/regexHelper.js +0 -3
  111. package/tests/helpers/setupApplyTests.js +0 -587
  112. package/tests/helpers/transactionPayloads.mjs +0 -92
  113. package/tests/helpers/wrapper.js +0 -28
  114. package/tests/unit/messages/messages.test.js +0 -12
  115. package/tests/unit/messages/network/NetworkMessageBuilder.test.js +0 -436
  116. package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -347
  117. package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +0 -525
  118. package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +0 -237
  119. package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
  120. package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
  121. package/tests/unit/network/ProtocolSession.test.js +0 -127
  122. package/tests/unit/network/networkModule.test.js +0 -13
  123. package/tests/unit/network/services/ConnectionManager.test.js +0 -450
  124. package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
  125. package/tests/unit/network/services/PendingRequestService.test.js +0 -431
  126. package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
  127. package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
  128. package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
  129. package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
  130. package/tests/unit/network/services/services.test.js +0 -17
  131. package/tests/unit/network/utils/v1TestUtils.js +0 -153
  132. package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
  133. package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
  134. package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
  135. package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
  136. package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
  137. package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
  138. package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
  139. package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
  140. package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
  141. package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
  142. package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
  143. package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
  144. package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
  145. package/tests/unit/network/v1/v1.handlers.test.js +0 -15
  146. package/tests/unit/network/v1/v1.test.js +0 -19
  147. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
  148. package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
  149. package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
  150. package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
  151. package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
  152. package/tests/unit/state/State.test.js +0 -80
  153. package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +0 -42
  154. package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +0 -276
  155. package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +0 -30
  156. package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +0 -78
  157. package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +0 -30
  158. package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +0 -68
  159. package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +0 -159
  160. package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +0 -39
  161. package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +0 -167
  162. package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +0 -21
  163. package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +0 -21
  164. package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +0 -186
  165. package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +0 -443
  166. package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +0 -32
  167. package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +0 -297
  168. package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +0 -41
  169. package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +0 -32
  170. package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +0 -149
  171. package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +0 -21
  172. package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +0 -21
  173. package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +0 -19
  174. package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +0 -19
  175. package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +0 -21
  176. package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +0 -21
  177. package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +0 -766
  178. package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +0 -50
  179. package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +0 -29
  180. package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +0 -29
  181. package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +0 -21
  182. package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +0 -37
  183. package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +0 -42
  184. package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +0 -106
  185. package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +0 -54
  186. package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +0 -54
  187. package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +0 -29
  188. package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +0 -309
  189. package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +0 -30
  190. package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +0 -881
  191. package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +0 -435
  192. package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +0 -78
  193. package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +0 -98
  194. package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +0 -66
  195. package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +0 -55
  196. package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +0 -103
  197. package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +0 -60
  198. package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +0 -189
  199. package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +0 -220
  200. package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +0 -82
  201. package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +0 -111
  202. package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +0 -45
  203. package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +0 -82
  204. package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +0 -189
  205. package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +0 -156
  206. package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +0 -36
  207. package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +0 -531
  208. package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +0 -74
  209. package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +0 -19
  210. package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +0 -32
  211. package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +0 -19
  212. package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +0 -19
  213. package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +0 -38
  214. package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +0 -91
  215. package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +0 -19
  216. package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +0 -266
  217. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +0 -143
  218. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +0 -26
  219. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +0 -94
  220. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +0 -37
  221. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +0 -86
  222. package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +0 -347
  223. package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +0 -57
  224. package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +0 -429
  225. package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +0 -120
  226. package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +0 -130
  227. package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +0 -93
  228. package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +0 -108
  229. package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +0 -126
  230. package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +0 -121
  231. package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +0 -50
  232. package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +0 -56
  233. package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +0 -52
  234. package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +0 -198
  235. package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +0 -52
  236. package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +0 -15
  237. package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +0 -11
  238. package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +0 -15
  239. package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +0 -11
  240. package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +0 -11
  241. package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +0 -11
  242. package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +0 -40
  243. package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +0 -114
  244. package/tests/unit/state/apply/common/commonScenarioHelper.js +0 -103
  245. package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +0 -36
  246. package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +0 -36
  247. package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +0 -29
  248. package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +0 -66
  249. package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +0 -84
  250. package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +0 -47
  251. package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +0 -85
  252. package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +0 -52
  253. package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +0 -54
  254. package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +0 -73
  255. package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +0 -71
  256. package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +0 -31
  257. package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +0 -142
  258. package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +0 -87
  259. package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +0 -71
  260. package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +0 -73
  261. package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +0 -36
  262. package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +0 -44
  263. package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +0 -25
  264. package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +0 -98
  265. package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +0 -202
  266. package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +0 -17
  267. package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +0 -44
  268. package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +0 -19
  269. package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +0 -18
  270. package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +0 -315
  271. package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +0 -18
  272. package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +0 -43
  273. package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +0 -53
  274. package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +0 -24
  275. package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +0 -204
  276. package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +0 -161
  277. package/tests/unit/state/apply/missing-tests.md +0 -18
  278. package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +0 -58
  279. package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +0 -98
  280. package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +0 -167
  281. package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +0 -429
  282. package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +0 -22
  283. package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +0 -20
  284. package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +0 -291
  285. package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +0 -87
  286. package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +0 -38
  287. package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +0 -32
  288. package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +0 -21
  289. package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +0 -19
  290. package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +0 -19
  291. package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +0 -21
  292. package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +0 -21
  293. package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +0 -19
  294. package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +0 -348
  295. package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +0 -113
  296. package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +0 -33
  297. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +0 -21
  298. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +0 -26
  299. package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +0 -22
  300. package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +0 -307
  301. package/tests/unit/state/apply/state.apply.test.js +0 -24
  302. package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +0 -819
  303. package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +0 -22
  304. package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +0 -146
  305. package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +0 -63
  306. package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +0 -67
  307. package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +0 -31
  308. package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +0 -31
  309. package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +0 -22
  310. package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +0 -8
  311. package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +0 -66
  312. package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +0 -31
  313. package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +0 -31
  314. package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +0 -1170
  315. package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +0 -38
  316. package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +0 -38
  317. package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +0 -38
  318. package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +0 -38
  319. package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +0 -318
  320. package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +0 -70
  321. package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +0 -23
  322. package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +0 -48
  323. package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +0 -39
  324. package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +0 -46
  325. package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +0 -21
  326. package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +0 -432
  327. package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +0 -21
  328. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +0 -26
  329. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +0 -25
  330. package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +0 -27
  331. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +0 -18
  332. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +0 -17
  333. package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +0 -31
  334. package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +0 -49
  335. package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +0 -93
  336. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +0 -28
  337. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +0 -29
  338. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +0 -28
  339. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +0 -17
  340. package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +0 -33
  341. package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +0 -18
  342. package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +0 -25
  343. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +0 -26
  344. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +0 -25
  345. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +0 -26
  346. package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +0 -27
  347. package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +0 -21
  348. package/tests/unit/state/stateModule.test.js +0 -23
  349. package/tests/unit/state/stateTestUtils.js +0 -32
  350. package/tests/unit/state/utils/address.test.js +0 -63
  351. package/tests/unit/state/utils/adminEntry.test.js +0 -52
  352. package/tests/unit/state/utils/balance.test.js +0 -320
  353. package/tests/unit/state/utils/lengthEntry.test.js +0 -54
  354. package/tests/unit/state/utils/nodeEntry.test.js +0 -298
  355. package/tests/unit/state/utils/roles.test.js +0 -44
  356. package/tests/unit/unit.test.js +0 -14
  357. package/tests/unit/utils/amountSerialization/amountSerialization.test.js +0 -237
  358. package/tests/unit/utils/buffer/buffer.test.js +0 -251
  359. package/tests/unit/utils/check/adminControlOperation.test.js +0 -156
  360. package/tests/unit/utils/check/balanceInitializationOperation.test.js +0 -54
  361. package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +0 -104
  362. package/tests/unit/utils/check/check.test.js +0 -17
  363. package/tests/unit/utils/check/common.test.js +0 -419
  364. package/tests/unit/utils/check/coreAdminOperation.test.js +0 -95
  365. package/tests/unit/utils/check/roleAccessOperation.test.js +0 -255
  366. package/tests/unit/utils/check/transactionOperation.test.js +0 -107
  367. package/tests/unit/utils/check/transferOperation.test.js +0 -102
  368. package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
  369. package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +0 -95
  370. package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +0 -149
  371. package/tests/unit/utils/helpers/helpers.test.js +0 -11
  372. package/tests/unit/utils/helpers/isHexString.test.js +0 -12
  373. package/tests/unit/utils/helpers/normalizeHex.test.js +0 -82
  374. package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +0 -100
  375. package/tests/unit/utils/normalizers/normalizers.test.js +0 -469
  376. package/tests/unit/utils/protobuf/applyOperations.test.js +0 -91
  377. package/tests/unit/utils/protobuf/operationHelpers.test.js +0 -303
  378. package/tests/unit/utils/protobuf/protobuf.test.js +0 -12
  379. package/tests/unit/utils/type/type.test.js +0 -25
  380. package/tests/unit/utils/utils.test.js +0 -21
  381. package/whitelist/.gitkeep +0 -0
@@ -1,94 +0,0 @@
1
- import b4a from 'b4a';
2
- import {
3
- setupBootstrapDeploymentScenario,
4
- buildBootstrapDeploymentPayload,
5
- assertBootstrapDeploymentFailureState
6
- } from './bootstrapDeploymentScenarioHelpers.js';
7
- import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
8
- import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
9
-
10
- function removeValidatorFields(t, validPayload) {
11
- const decoded = safeDecodeApplyOperation(validPayload);
12
- t.ok(decoded, 'valid payload decodes before mutation');
13
- if (!decoded?.bdo) return validPayload;
14
- const mutated = safeEncodeApplyOperation({
15
- type: decoded.type,
16
- address: decoded.address,
17
- bdo: {
18
- tx: decoded.bdo.tx,
19
- txv: decoded.bdo.txv,
20
- bs: decoded.bdo.bs,
21
- ic: decoded.bdo.ic,
22
- in: decoded.bdo.in,
23
- is: decoded.bdo.is
24
- }
25
- });
26
- const roundtrip = safeDecodeApplyOperation(mutated);
27
- t.ok(roundtrip, 'mutated payload decodes');
28
- return mutated;
29
- }
30
-
31
- async function assertStateUnchanged(t, context, validPayload) {
32
- const decoded = safeDecodeApplyOperation(validPayload);
33
- t.ok(decoded, 'valid payload decodes for assertions');
34
- if (!decoded) return;
35
-
36
- const { validatorEntryBefore, deployerEntryBefore, externalBootstrap } = context.bootstrapDeployment ?? {};
37
- const validatorPeer = context.bootstrapDeployment?.validatorPeer ?? context.peers?.[1];
38
- const deployerPeer = context.bootstrapDeployment?.deployerPeer ?? context.peers?.[2];
39
-
40
- const validatorEntryAfter = await validatorPeer.base.view.get(validatorPeer.wallet.address);
41
- t.ok(validatorEntryAfter, 'validator entry still exists after rejected incomplete op');
42
- if (validatorEntryBefore?.value && validatorEntryAfter?.value) {
43
- t.ok(
44
- b4a.equals(validatorEntryAfter.value, validatorEntryBefore.value),
45
- 'validator entry remains unchanged after incomplete op'
46
- );
47
- }
48
-
49
- const deployerEntryAfter = await validatorPeer.base.view.get(deployerPeer.wallet.address);
50
- t.ok(deployerEntryAfter, 'deployer entry still exists after rejected incomplete op');
51
- if (deployerEntryBefore?.value && deployerEntryAfter?.value) {
52
- const before = nodeEntryUtils.decode(deployerEntryBefore.value);
53
- const after = nodeEntryUtils.decode(deployerEntryAfter.value);
54
- t.ok(before, 'deployer entry before decodes');
55
- t.ok(after, 'deployer entry after decodes');
56
- if (before && after) {
57
- t.ok(b4a.equals(after.balance, before.balance), 'deployer balance unchanged after incomplete op');
58
- t.ok(
59
- b4a.equals(after.stakedBalance, before.stakedBalance),
60
- 'deployer stake unchanged after incomplete op'
61
- );
62
- }
63
- }
64
-
65
- const bootstrapBuffer = externalBootstrap ?? decoded?.bdo?.bs;
66
- if (bootstrapBuffer) {
67
- const deploymentKey = `${EntryType.DEPLOYMENT}${bootstrapBuffer.toString('hex')}`;
68
- const deploymentEntry = await validatorPeer.base.view.get(deploymentKey);
69
- t.is(deploymentEntry, null, 'deployment entry not created after incomplete op');
70
- }
71
-
72
- const txHashBuffer = decoded?.bdo?.tx;
73
- if (txHashBuffer) {
74
- const txEntry = await validatorPeer.base.view.get(txHashBuffer.toString('hex'));
75
- t.is(txEntry, null, 'tx hash not recorded after incomplete op');
76
- }
77
- }
78
-
79
- export default function bootstrapDeploymentIncompleteOperationScenario() {
80
- new OperationValidationScenarioBase({
81
- title: 'State.apply bootstrapDeployment rejects operations missing validator cosignature',
82
- setupScenario: setupBootstrapDeploymentScenario,
83
- buildValidPayload: buildBootstrapDeploymentPayload,
84
- mutatePayload: removeValidatorFields,
85
- applyInvalidPayload: async (context, invalidPayload) => {
86
- const { bootstrap } = context;
87
- await bootstrap.base.append(invalidPayload);
88
- await bootstrap.base.update();
89
- },
90
- assertStateUnchanged: (t, context, _validPayload, invalidPayload) =>
91
- assertBootstrapDeploymentFailureState(t, context, { payload: invalidPayload }),
92
- expectedLogs: ['Contract schema validation failed.']
93
- }).performScenario();
94
- }
@@ -1,37 +0,0 @@
1
- import b4a from 'b4a';
2
- import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
3
- import {
4
- setupBootstrapDeploymentScenario,
5
- buildBootstrapDeploymentPayload,
6
- assertBootstrapDeploymentFailureState
7
- } from './bootstrapDeploymentScenarioHelpers.js';
8
- import deploymentEntryUtils from '../../../../../src/core/state/utils/deploymentEntry.js';
9
-
10
- async function applyPayloadWithEncodeFailure(context, invalidPayload) {
11
- const node = context.bootstrapDeployment?.validatorPeer ?? context.bootstrap ?? context.peers?.[0];
12
- const originalEncode = deploymentEntryUtils.encode;
13
- deploymentEntryUtils.encode = () => b4a.alloc(0);
14
-
15
- try {
16
- await node.base.append(invalidPayload);
17
- await node.base.update();
18
- } finally {
19
- deploymentEntryUtils.encode = originalEncode;
20
- }
21
- }
22
-
23
- export default function bootstrapDeploymentInvalidDeploymentEntryScenario() {
24
- new OperationValidationScenarioBase({
25
- title: 'State.apply bootstrapDeployment rejects payloads when deployment entry cannot be encoded',
26
- setupScenario: setupBootstrapDeploymentScenario,
27
- buildValidPayload: buildBootstrapDeploymentPayload,
28
- mutatePayload: (_t, validPayload) => validPayload,
29
- applyInvalidPayload: applyPayloadWithEncodeFailure,
30
- assertStateUnchanged: (t, context, _valid, invalidPayload) =>
31
- assertBootstrapDeploymentFailureState(t, context, {
32
- payload: invalidPayload,
33
- skipValidatorEquality: true
34
- }),
35
- expectedLogs: ['Invalid deployment entry.']
36
- }).performScenario();
37
- }
@@ -1,86 +0,0 @@
1
- import { test } from 'brittle';
2
- import b4a from 'b4a';
3
- import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
4
- import {
5
- setupBootstrapDeploymentScenario,
6
- buildBootstrapDeploymentPayload,
7
- assertBootstrapDeploymentSuccessState
8
- } from './bootstrapDeploymentScenarioHelpers.js';
9
- import { EntryType } from '../../../../../src/utils/constants.js';
10
- import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
11
-
12
- const DOUBLE_FUNDING = bigIntTo16ByteBuffer(decimalStringToBigInt('20'));
13
-
14
- export default function bootstrapDeploymentMultipleBootstrapScenario() {
15
- test(
16
- 'State.apply bootstrapDeployment allows a requester to register multiple external bootstraps',
17
- async t => {
18
- const context = await setupBootstrapDeploymentScenario(t, {
19
- nodes: 4,
20
- deployerInitialBalance: DOUBLE_FUNDING,
21
- validatorInitialBalance: DOUBLE_FUNDING
22
- });
23
-
24
- const validatorPeer = context.bootstrapDeployment?.validatorPeer ?? context.peers[1];
25
- const deployerPeer = context.bootstrapDeployment?.deployerPeer ?? context.peers[2];
26
- const extraPeer = context.peers.at(-1);
27
-
28
- const firstBootstrap = context.bootstrapDeployment?.externalBootstrap ?? b4a.from(deployerPeer.base.local.key);
29
- const secondBootstrap = extraPeer ? b4a.from(extraPeer.base.local.key) : b4a.alloc(firstBootstrap.length, 0x02);
30
- const secondChannel = extraPeer ? b4a.from(extraPeer.base.local.key) : b4a.alloc(firstBootstrap.length, 0x03);
31
-
32
- const validatorEntryBefore1 = await validatorPeer.base.view.get(validatorPeer.wallet.address);
33
- const deployerEntryBefore1 = await validatorPeer.base.view.get(deployerPeer.wallet.address);
34
-
35
- const firstPayload = await buildBootstrapDeploymentPayload(context, {
36
- externalBootstrap: firstBootstrap
37
- });
38
-
39
- await validatorPeer.base.append(firstPayload);
40
- await validatorPeer.base.update();
41
- await eventFlush();
42
-
43
- await assertBootstrapDeploymentSuccessState(t, context, {
44
- payload: firstPayload,
45
- externalBootstrap: firstBootstrap,
46
- validatorEntryBefore: validatorEntryBefore1?.value,
47
- deployerEntryBefore: deployerEntryBefore1?.value
48
- });
49
-
50
- const validatorEntryBefore2 = await validatorPeer.base.view.get(validatorPeer.wallet.address);
51
- const deployerEntryBefore2 = await validatorPeer.base.view.get(deployerPeer.wallet.address);
52
-
53
- const secondPayload = await buildBootstrapDeploymentPayload(context, {
54
- externalBootstrap: secondBootstrap,
55
- channel: secondChannel
56
- });
57
-
58
- await validatorPeer.base.append(secondPayload);
59
- await validatorPeer.base.update();
60
- await eventFlush();
61
-
62
- await assertBootstrapDeploymentSuccessState(t, context, {
63
- payload: secondPayload,
64
- externalBootstrap: secondBootstrap,
65
- channel: secondChannel,
66
- validatorEntryBefore: validatorEntryBefore2?.value,
67
- deployerEntryBefore: deployerEntryBefore2?.value
68
- });
69
-
70
- const firstKey = `${EntryType.DEPLOYMENT}${firstBootstrap.toString('hex')}`;
71
- const secondKey = `${EntryType.DEPLOYMENT}${secondBootstrap.toString('hex')}`;
72
-
73
- const firstEntry = await validatorPeer.base.view.get(firstKey);
74
- const secondEntry = await validatorPeer.base.view.get(secondKey);
75
- t.ok(firstEntry, 'first deployment entry stored on validator view');
76
- t.ok(secondEntry, 'second deployment entry stored on validator view');
77
-
78
- await context.sync();
79
-
80
- const firstEntryReplica = await deployerPeer.base.view.get(firstKey);
81
- const secondEntryReplica = await deployerPeer.base.view.get(secondKey);
82
- t.ok(firstEntryReplica, 'first deployment entry replicated to deployer view');
83
- t.ok(secondEntryReplica, 'second deployment entry replicated to deployer view');
84
- }
85
- );
86
- }
@@ -1,347 +0,0 @@
1
- import b4a from 'b4a';
2
- import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
3
- import { deriveIndexerSequenceState } from '../../../../helpers/autobaseTestHelpers.js';
4
- import {
5
- setupAdminNetwork,
6
- initializeBalances,
7
- whitelistAddress
8
- } from '../common/commonScenarioHelper.js';
9
- import {
10
- promotePeerToWriter,
11
- assertValidatorReward
12
- } from '../addWriter/addWriterScenarioHelpers.js';
13
- import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
14
- import deploymentEntryUtils from '../../../../../src/core/state/utils/deploymentEntry.js';
15
- import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
16
- import addressUtils from '../../../../../src/core/state/utils/address.js';
17
- import { toBalance } from '../../../../../src/core/state/utils/balance.js';
18
- import { EntryType } from '../../../../../src/utils/constants.js';
19
- import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
20
- import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
21
- import { config } from '../../../../helpers/config.js';
22
-
23
- const DEFAULT_FUNDING = bigIntTo16ByteBuffer(decimalStringToBigInt('10'));
24
-
25
- export function selectBootstrapValidatorPeer(context, offset = 0) {
26
- const peers = context.peers.slice(1);
27
- if (!peers.length) {
28
- throw new Error('Bootstrap deployment scenarios require a validator peer.');
29
- }
30
- return peers[Math.min(offset, peers.length - 1)];
31
- }
32
-
33
- export function selectBootstrapDeployerPeer(context, offset = 1) {
34
- const peers = context.peers.slice(1);
35
- if (peers.length < 2) {
36
- throw new Error('Bootstrap deployment scenarios require a deployer peer.');
37
- }
38
- return peers[Math.min(offset, peers.length - 1)];
39
- }
40
-
41
- export async function setupBootstrapDeploymentScenario(
42
- t,
43
- {
44
- nodes = 3,
45
- validatorInitialBalance = DEFAULT_FUNDING,
46
- deployerInitialBalance = DEFAULT_FUNDING,
47
- externalBootstrap = null,
48
- channel = null
49
- } = {}
50
- ) {
51
- const context = await setupAdminNetwork(t, { nodes: Math.max(nodes, 3) });
52
- const validatorPeer = selectBootstrapValidatorPeer(context);
53
- const deployerPeer = selectBootstrapDeployerPeer(context);
54
-
55
- context.addWriterScenario = { writerInitialBalance: validatorInitialBalance };
56
-
57
- await initializeBalances(context, [
58
- [validatorPeer.wallet.address, validatorInitialBalance],
59
- [deployerPeer.wallet.address, deployerInitialBalance]
60
- ]);
61
-
62
- await whitelistAddress(context, validatorPeer.wallet.address);
63
- await whitelistAddress(context, deployerPeer.wallet.address);
64
-
65
- await promotePeerToWriter(t, context, { readerPeer: validatorPeer });
66
- await context.sync();
67
-
68
- const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
69
- const resolvedExternalBootstrap = externalBootstrap ?? b4a.from(deployerPeer.base.local.key);
70
- const resolvedChannel = channel ?? b4a.from(validatorPeer.base.local.key);
71
-
72
- const validatorEntryBefore = await validatorPeer.base.view.get(validatorPeer.wallet.address);
73
- const deployerEntryBefore = await validatorPeer.base.view.get(deployerPeer.wallet.address);
74
-
75
- context.bootstrapDeployment = {
76
- validatorPeer,
77
- deployerPeer,
78
- externalBootstrap: resolvedExternalBootstrap,
79
- channel: resolvedChannel,
80
- txValidity,
81
- validatorEntryBefore: validatorEntryBefore
82
- ? { value: b4a.from(validatorEntryBefore.value) }
83
- : null,
84
- deployerEntryBefore: deployerEntryBefore ? { value: b4a.from(deployerEntryBefore.value) } : null
85
- };
86
-
87
- return context;
88
- }
89
-
90
- export async function buildBootstrapDeploymentPayload(context, options = {}) {
91
- const validatorPeer =
92
- options.validatorPeer ??
93
- context.bootstrapDeployment?.validatorPeer ??
94
- selectBootstrapValidatorPeer(context);
95
- const deployerPeer =
96
- options.deployerPeer ??
97
- context.bootstrapDeployment?.deployerPeer ??
98
- selectBootstrapDeployerPeer(context);
99
-
100
- const externalBootstrap =
101
- options.externalBootstrap ??
102
- context.bootstrapDeployment?.externalBootstrap ??
103
- b4a.from(deployerPeer.base.local.key);
104
- const channel =
105
- options.channel ?? context.bootstrapDeployment?.channel ?? b4a.from(validatorPeer.base.local.key);
106
- const txValidity =
107
- options.txValidity ??
108
- context.bootstrapDeployment?.txValidity ??
109
- (await deriveIndexerSequenceState(validatorPeer.base));
110
-
111
- const partial = await applyStateMessageFactory(deployerPeer.wallet, config)
112
- .buildPartialBootstrapDeploymentMessage(
113
- deployerPeer.wallet.address,
114
- externalBootstrap.toString('hex'),
115
- channel.toString('hex'),
116
- txValidity.toString('hex'),
117
- 'json'
118
- );
119
-
120
- const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
121
- .buildCompleteBootstrapDeploymentMessage(
122
- partial.address,
123
- b4a.from(partial.bdo.tx, 'hex'),
124
- b4a.from(partial.bdo.txv, 'hex'),
125
- b4a.from(partial.bdo.bs, 'hex'),
126
- b4a.from(partial.bdo.ic, 'hex'),
127
- b4a.from(partial.bdo.in, 'hex'),
128
- b4a.from(partial.bdo.is, 'hex')
129
- );
130
- return safeEncodeApplyOperation(payload);
131
- }
132
-
133
- export async function buildBootstrapDeploymentPayloadWithTxValidity(context, txValidity, options = {}) {
134
- return buildBootstrapDeploymentPayload(context, {
135
- ...options,
136
- txValidity
137
- });
138
- }
139
-
140
- export async function assertBootstrapDeploymentSuccessState(
141
- t,
142
- context,
143
- {
144
- payload = null,
145
- validatorPeer = context.bootstrapDeployment?.validatorPeer ?? selectBootstrapValidatorPeer(context),
146
- deployerPeer = context.bootstrapDeployment?.deployerPeer ?? selectBootstrapDeployerPeer(context),
147
- externalBootstrap = context.bootstrapDeployment?.externalBootstrap ?? null,
148
- channel = context.bootstrapDeployment?.channel ?? null,
149
- validatorEntryBefore = context.bootstrapDeployment?.validatorEntryBefore?.value ?? null,
150
- deployerEntryBefore = context.bootstrapDeployment?.deployerEntryBefore?.value ?? null,
151
- txValidity = context.bootstrapDeployment?.txValidity ?? null,
152
- skipSync = false
153
- } = {}
154
- ) {
155
- if (!payload) throw new Error('assertBootstrapDeploymentSuccessState requires the processed payload.');
156
- if (!validatorEntryBefore) {
157
- throw new Error('assertBootstrapDeploymentSuccessState requires the validator entry before execution.');
158
- }
159
- if (!deployerEntryBefore) {
160
- throw new Error('assertBootstrapDeploymentSuccessState requires the deployer entry before execution.');
161
- }
162
-
163
- const bootstrapBuffer = externalBootstrap ?? b4a.from(deployerPeer.base.local.key);
164
- const channelBuffer = channel ?? b4a.from(validatorPeer.base.local.key);
165
- const decodedOperation = safeDecodeApplyOperation(payload);
166
- t.ok(decodedOperation, 'bootstrapDeployment payload decodes');
167
-
168
- const requesterAddressBuffer = decodedOperation?.address;
169
- const validatorAddressBuffer = decodedOperation?.bdo?.va;
170
- const txHashBuffer = decodedOperation?.bdo?.tx;
171
- const txValidityBuffer = decodedOperation?.bdo?.txv;
172
- const channelFromPayload = decodedOperation?.bdo?.ic;
173
- const bootstrapFromPayload = decodedOperation?.bdo?.bs;
174
-
175
- t.ok(requesterAddressBuffer, 'payload carries requester address');
176
- t.ok(validatorAddressBuffer, 'payload carries validator address');
177
- t.ok(txHashBuffer, 'payload exposes tx hash');
178
-
179
- const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer, config.addressPrefix);
180
- const validatorAddress = addressUtils.bufferToAddress(validatorAddressBuffer, config.addressPrefix);
181
-
182
- if (requesterAddress) {
183
- t.is(requesterAddress, deployerPeer.wallet.address, 'payload signed by expected requester');
184
- }
185
- if (validatorAddress) {
186
- t.is(validatorAddress, validatorPeer.wallet.address, 'payload signed by expected validator');
187
- }
188
-
189
- if (bootstrapFromPayload) {
190
- t.ok(b4a.equals(bootstrapFromPayload, bootstrapBuffer), 'payload carries external bootstrap');
191
- }
192
- if (channelFromPayload) {
193
- t.ok(b4a.equals(channelFromPayload, channelBuffer), 'payload carries expected channel');
194
- }
195
- if (txValidity && txValidityBuffer) {
196
- t.ok(b4a.equals(txValidityBuffer, txValidity), 'payload tx validity matches current indexer state');
197
- }
198
-
199
- const decodedValidatorBefore = nodeEntryUtils.decode(validatorEntryBefore);
200
- t.ok(decodedValidatorBefore, 'validator entry before bootstrapDeployment decodes');
201
- if (!decodedValidatorBefore) return;
202
-
203
- await assertRequesterPaidFee(t, validatorPeer.base, deployerPeer.wallet.address, deployerEntryBefore);
204
- await assertValidatorReward(t, validatorPeer, b4a.from(decodedValidatorBefore.balance));
205
- await assertDeploymentEntry(t, validatorPeer.base, {
206
- bootstrapBuffer,
207
- txHashBuffer,
208
- requesterAddressBuffer
209
- });
210
-
211
- if (!skipSync) {
212
- await context.sync();
213
- await assertRequesterPaidFee(t, deployerPeer.base, deployerPeer.wallet.address, deployerEntryBefore);
214
- await assertDeploymentEntry(t, deployerPeer.base, {
215
- bootstrapBuffer,
216
- txHashBuffer,
217
- requesterAddressBuffer
218
- });
219
- }
220
- }
221
-
222
- export async function assertBootstrapDeploymentFailureState(
223
- t,
224
- context,
225
- { payload, bootstrapBufferOverride = null, skipValidatorEquality = false } = {}
226
- ) {
227
- if (!payload) throw new Error('assertBootstrapDeploymentFailureState requires a payload.');
228
-
229
- const decoded = safeDecodeApplyOperation(payload);
230
- t.ok(decoded, 'invalid payload decodes for assertions');
231
- if (!decoded) return;
232
-
233
- const validatorPeer = context.bootstrapDeployment?.validatorPeer ?? context.peers?.[1];
234
- const deployerPeer = context.bootstrapDeployment?.deployerPeer ?? context.peers?.[2];
235
- const validatorEntryBefore = context.bootstrapDeployment?.validatorEntryBefore?.value ?? null;
236
- const deployerEntryBefore = context.bootstrapDeployment?.deployerEntryBefore?.value ?? null;
237
-
238
- if (validatorPeer) {
239
- const after = await validatorPeer.base.view.get(validatorPeer.wallet.address);
240
- t.ok(after, 'validator entry still exists after rejection');
241
- if (!skipValidatorEquality && validatorEntryBefore && after?.value) {
242
- t.ok(b4a.equals(after.value, validatorEntryBefore), 'validator entry remains unchanged');
243
- }
244
- }
245
-
246
- if (deployerPeer) {
247
- const after = await validatorPeer.base.view.get(deployerPeer.wallet.address);
248
- t.ok(after, 'deployer entry still exists after rejection');
249
- if (deployerEntryBefore && after?.value) {
250
- const beforeDecoded = nodeEntryUtils.decode(deployerEntryBefore);
251
- const afterDecoded = nodeEntryUtils.decode(after.value);
252
- t.ok(beforeDecoded, 'deployer entry before decodes');
253
- t.ok(afterDecoded, 'deployer entry after decodes');
254
- if (beforeDecoded && afterDecoded) {
255
- t.ok(b4a.equals(afterDecoded.balance, beforeDecoded.balance), 'deployer balance unchanged');
256
- t.ok(
257
- b4a.equals(afterDecoded.stakedBalance, beforeDecoded.stakedBalance),
258
- 'deployer stake unchanged'
259
- );
260
- }
261
- }
262
- }
263
-
264
- const bootstrapBuffer = bootstrapBufferOverride ?? decoded?.bdo?.bs ?? context.bootstrapDeployment?.externalBootstrap;
265
- if (bootstrapBuffer && validatorPeer) {
266
- const deploymentKey = `${EntryType.DEPLOYMENT}${bootstrapBuffer.toString('hex')}`;
267
- const deploymentEntry = await validatorPeer.base.view.get(deploymentKey);
268
- t.is(deploymentEntry, null, 'deployment entry not created after rejection');
269
- }
270
-
271
- const txHashBuffer = decoded?.bdo?.tx;
272
- if (txHashBuffer && validatorPeer) {
273
- const txEntry = await validatorPeer.base.view.get(txHashBuffer.toString('hex'));
274
- t.is(txEntry, null, 'tx hash not recorded after rejection');
275
- }
276
- }
277
-
278
- export function mutateToNetworkBootstrap(t, payload, context) {
279
- const decoded = safeDecodeApplyOperation(payload);
280
- t.ok(decoded, 'valid payload decodes before mutation');
281
- if (!decoded?.bdo) return payload;
282
- const bootstrapKey = context.bootstrap?.base?.local?.key;
283
- t.ok(bootstrapKey, 'network bootstrap key available');
284
- if (!bootstrapKey) return payload;
285
- decoded.bdo.bs = bootstrapKey;
286
- return safeEncodeApplyOperation(decoded);
287
- }
288
-
289
- export async function appendInvalidPayload(context, invalidPayload) {
290
- const node = context.bootstrap ?? context.adminBootstrap ?? context.peers?.[0];
291
- await node.base.append(invalidPayload);
292
- await node.base.update();
293
- }
294
-
295
- async function assertRequesterPaidFee(t, base, address, entryBeforeValue) {
296
- const beforeEntry = nodeEntryUtils.decode(entryBeforeValue);
297
- t.ok(beforeEntry, 'deployer entry before bootstrapDeployment decodes');
298
- if (!beforeEntry) return;
299
-
300
- const beforeBalance = toBalance(beforeEntry.balance);
301
- t.ok(beforeBalance, 'deployer balance before bootstrapDeployment decodes');
302
- if (!beforeBalance) return;
303
-
304
- const expectedBalance = beforeBalance.sub(toBalance(transactionUtils.FEE));
305
- t.ok(expectedBalance, 'deployer balance after fee computation succeeds');
306
- if (!expectedBalance) return;
307
-
308
- const entry = await base.view.get(address);
309
- t.ok(entry, 'deployer entry exists after bootstrapDeployment');
310
- const decoded = nodeEntryUtils.decode(entry?.value);
311
- t.ok(decoded, 'deployer entry decodes after bootstrapDeployment');
312
- if (!decoded) return;
313
-
314
- t.is(decoded.isWhitelisted, true, 'deployer remains whitelisted');
315
- t.is(decoded.isWriter, false, 'deployer not promoted to writer');
316
- t.is(decoded.isIndexer, false, 'deployer not promoted to indexer');
317
- t.ok(
318
- b4a.equals(decoded.balance, expectedBalance.value),
319
- 'deployer balance reduced by bootstrapDeployment fee'
320
- );
321
- }
322
-
323
- async function assertDeploymentEntry(
324
- t,
325
- base,
326
- { bootstrapBuffer, txHashBuffer, requesterAddressBuffer }
327
- ) {
328
- if (!txHashBuffer) {
329
- t.fail('bootstrapDeployment tx hash missing');
330
- return;
331
- }
332
- const deploymentKey = `${EntryType.DEPLOYMENT}${bootstrapBuffer.toString('hex')}`;
333
- const deploymentEntry = await base.view.get(deploymentKey);
334
- t.ok(deploymentEntry, 'deployment entry stored');
335
- const decodedDeployment = deploymentEntryUtils.decode(deploymentEntry?.value, config.addressLength);
336
- t.ok(decodedDeployment?.txHash, 'deployment entry decodes');
337
- if (!decodedDeployment || !decodedDeployment.txHash) return;
338
-
339
- t.ok(b4a.equals(decodedDeployment.txHash, txHashBuffer), 'deployment entry stores tx hash');
340
- t.ok(
341
- b4a.equals(decodedDeployment.address, requesterAddressBuffer),
342
- 'deployment entry binds bootstrap to requester address'
343
- );
344
-
345
- const txEntry = await base.view.get(txHashBuffer.toString('hex'));
346
- t.ok(txEntry, 'bootstrapDeployment transaction recorded for replay protection');
347
- }
@@ -1,57 +0,0 @@
1
- import b4a from 'b4a';
2
- import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
3
- import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
4
- import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
5
- import {
6
- setupBootstrapDeploymentScenario,
7
- buildBootstrapDeploymentPayload,
8
- assertBootstrapDeploymentFailureState
9
- } from './bootstrapDeploymentScenarioHelpers.js';
10
-
11
- export default function bootstrapDeploymentInvalidValidatorNodeEntryScenario() {
12
- new OperationValidationScenarioBase({
13
- title: 'State.apply bootstrapDeployment rejects payloads when validator node entry becomes invalid',
14
- setupScenario: setupBootstrapDeploymentScenario,
15
- buildValidPayload: buildBootstrapDeploymentPayload,
16
- mutatePayload: (_t, payload) => payload,
17
- applyInvalidPayload: applyWithValidatorDecodeFailureOnSecondRead,
18
- assertStateUnchanged: (t, context, _valid, invalidPayload) =>
19
- assertBootstrapDeploymentFailureState(t, context, {
20
- payload: invalidPayload,
21
- skipValidatorEquality: true
22
- }),
23
- expectedLogs: ['Invalid validator node entry.']
24
- }).performScenario();
25
- }
26
-
27
- async function applyWithValidatorDecodeFailureOnSecondRead(context, payload) {
28
- const node = context.bootstrapDeployment?.validatorPeer ?? context.bootstrap ?? context.adminBootstrap;
29
- const validatorPeer = context.bootstrapDeployment?.validatorPeer ?? context.peers?.[1];
30
- if (!node?.base || !validatorPeer?.base?.local?.key) {
31
- throw new Error('Validator node entry invalidation scenario requires validator peer and writable base.');
32
- }
33
-
34
- const validatorWk = validatorPeer.base.local.key;
35
- const originalDecode = nodeEntryUtils.decode;
36
- let hasReturnedValid = false;
37
-
38
- nodeEntryUtils.decode = function patchedDecode(buffer) {
39
- const decoded = originalDecode(buffer);
40
- if (decoded && b4a.equals(decoded.wk, validatorWk)) {
41
- if (!hasReturnedValid) {
42
- hasReturnedValid = true;
43
- return decoded;
44
- }
45
- return null;
46
- }
47
- return decoded;
48
- };
49
-
50
- try {
51
- await node.base.append(payload);
52
- await node.base.update();
53
- await eventFlush();
54
- } finally {
55
- nodeEntryUtils.decode = originalDecode;
56
- }
57
- }