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,308 +0,0 @@
1
- import b4a from 'b4a';
2
-
3
- export const describeValue = (value) => {
4
- if (value === null) return 'null';
5
- if (value === undefined) return 'undefined';
6
- if (b4a.isBuffer(value)) return `buffer(len=${value.length})`;
7
- if (Number.isNaN(value)) return 'NaN';
8
- if (value === Infinity) return 'Infinity';
9
- if (Array.isArray(value)) return 'array';
10
- if (value instanceof Map) return 'map';
11
- if (value instanceof Set) return 'set';
12
- if (value instanceof Date) return 'date';
13
- if (value instanceof RegExp) return 'regexp';
14
- if (value instanceof Error) return `error(${value.message})`;
15
- if (typeof value === 'bigint') return `bigint(${value})`;
16
- return typeof value;
17
- };
18
-
19
- export const assertNoThrowAndAbsent = (t, validateFn, input, message) => {
20
- let result;
21
- t.execution(() => {
22
- result = validateFn(input);
23
- }, `${message} (no throw)`);
24
- t.absent(result, `${message} (should fail)`);
25
- };
26
-
27
- export function topLevelValidationTests(
28
- t,
29
- validateFn,
30
- validFixture,
31
- valueKey,
32
- notAllowedDataTypes,
33
- topFields,
34
- expectedType
35
- ) {
36
- t.test('strict mode', t => {
37
- const extraTopLevel = {
38
- ...validFixture,
39
- extra: b4a.from('redundant field', 'utf-8'),
40
- };
41
- t.absent(validateFn(extraTopLevel), 'Extra field should fail due to $$strict');
42
- t.absent(validateFn({}), 'Empty object should fail');
43
- });
44
-
45
- t.test('operation type', t => {
46
- const invalidOperationType = { ...validFixture, type: 'invalid-op' };
47
- t.absent(validateFn(invalidOperationType), 'Invalid operation type should fail');
48
-
49
- const notDefinedOperationType = { ...validFixture, type: 999 };
50
- t.absent(validateFn(notDefinedOperationType), 'Invalid operation type should fail');
51
-
52
- const zeroValue = { ...validFixture, type: 0 };
53
- t.absent(validateFn(zeroValue), 'Type with value 0 should fail');
54
-
55
- const negativeValue = { ...validFixture, type: -1 };
56
- t.absent(validateFn(negativeValue), 'Negative type value should fail');
57
-
58
- const wrongKnownType = { ...validFixture, type: expectedType + 1 };
59
- t.absent(validateFn(wrongKnownType), 'Wrong known type should fail');
60
- });
61
-
62
- t.test('nested objects', t => {
63
- const nestedObjectInsideValue = {
64
- ...validFixture,
65
- [valueKey]: {
66
- ...validFixture[valueKey],
67
- nested: { foo: b4a.from('bar', 'utf-8') }
68
- }
69
- };
70
- t.absent(validateFn(nestedObjectInsideValue), `Unexpected nested field inside -${valueKey}- should fail due to strict`);
71
-
72
- const nestedObjectInsideValue2 = {
73
- ...validFixture,
74
- nested: { foo: b4a.from('bar', 'utf-8') }
75
- };
76
- t.absent(validateFn(nestedObjectInsideValue2), 'Unexpected nested field inside general object should fail due to strict');
77
-
78
- const nestedObjectInsideType = {
79
- ...validFixture,
80
- type: {
81
- foo: b4a.from('bar', 'utf-8'),
82
- nested: { foo: b4a.from('bar', 'utf-8') }
83
- }
84
- };
85
- t.absent(validateFn(nestedObjectInsideType), 'Unexpected nested field inside `type` field should fail');
86
-
87
- const nestedObjectInsideId = {
88
- ...validFixture,
89
- id: {
90
- foo: b4a.from('bar', 'utf-8'),
91
- nested: { foo: b4a.from('bar', 'utf-8') }
92
- }
93
- };
94
- t.absent(validateFn(nestedObjectInsideId), 'Unexpected nested field inside `id` field should fail');
95
-
96
- const nestedObjectInsideTimestamp = {
97
- ...validFixture,
98
- timestamp: {
99
- foo: b4a.from('bar', 'utf-8'),
100
- nested: { foo: b4a.from('bar', 'utf-8') }
101
- }
102
- };
103
- t.absent(validateFn(nestedObjectInsideTimestamp), 'Unexpected nested field inside `timestamp` field should fail');
104
-
105
- const nestedObjectInsideCapabilities = {
106
- ...validFixture,
107
- capabilities: {
108
- foo: b4a.from('bar', 'utf-8'),
109
- nested: { foo: b4a.from('bar', 'utf-8') }
110
- }
111
- };
112
- t.absent(validateFn(nestedObjectInsideCapabilities), 'Unexpected nested field inside `capabilities` field should fail');
113
- });
114
-
115
- t.test('invalid data types', t => {
116
- for (const invalidDataType of notAllowedDataTypes) {
117
- if (typeof invalidDataType !== 'number') {
118
- const invalidTypeForType = { ...validFixture, type: invalidDataType };
119
- t.absent(
120
- validateFn(invalidTypeForType),
121
- `Invalid data type for 'type' key ${describeValue(invalidDataType)} should fail`
122
- );
123
- }
124
-
125
- if (typeof invalidDataType !== 'string') {
126
- const invalidTypeForId = { ...validFixture, id: invalidDataType };
127
- t.absent(
128
- validateFn(invalidTypeForId),
129
- `Invalid data type for 'id' key ${describeValue(invalidDataType)} should fail`
130
- );
131
- }
132
-
133
- if (typeof invalidDataType !== 'number') {
134
- const invalidTypeForTimestamp = { ...validFixture, timestamp: invalidDataType };
135
- t.absent(
136
- validateFn(invalidTypeForTimestamp),
137
- `Invalid data type for 'timestamp' key ${describeValue(invalidDataType)} should fail`
138
- );
139
- }
140
-
141
- if (!Array.isArray(invalidDataType)) {
142
- const invalidTypeForCapabilities = { ...validFixture, capabilities: invalidDataType };
143
- t.absent(
144
- validateFn(invalidTypeForCapabilities),
145
- `Invalid data type for 'capabilities' key ${describeValue(invalidDataType)} should fail`
146
- );
147
- }
148
-
149
- if (String(invalidDataType) !== '[object Object]') {
150
- const invalidTypeForPayload = { ...validFixture, [valueKey]: invalidDataType };
151
- t.absent(
152
- validateFn(invalidTypeForPayload),
153
- `Invalid data type for ${valueKey} key ${describeValue(invalidDataType)} should fail`
154
- );
155
- }
156
- }
157
-
158
- const invalidOperationTypeDiffType = { ...validFixture, type: "string" }
159
- t.absent(validateFn(invalidOperationTypeDiffType), 'Wrong type for `type` should fail')
160
-
161
- for (const mainField of topFields) {
162
- const missingFieldInvalidInput = { ...validFixture }
163
- delete missingFieldInvalidInput[mainField]
164
- t.absent(validateFn(missingFieldInvalidInput), `Missing ${mainField} should fail`);
165
- }
166
- });
167
- }
168
-
169
- export function headerFieldValueValidationTests(t, validateFn, validFixture) {
170
- t.absent(
171
- validateFn({...validFixture, id: ''}),
172
- 'empty id should fail'
173
- );
174
-
175
- t.absent(
176
- validateFn({...validFixture, id: 'x'.repeat(65)}),
177
- 'id longer than 64 chars should fail'
178
- );
179
-
180
- t.absent(
181
- validateFn({...validFixture, timestamp: 0}),
182
- 'timestamp 0 should fail'
183
- );
184
-
185
- t.absent(
186
- validateFn({...validFixture, timestamp: -1}),
187
- 'negative timestamp should fail'
188
- );
189
-
190
- t.absent(
191
- validateFn({...validFixture, timestamp: 1.1}),
192
- 'non-integer timestamp should fail'
193
- );
194
-
195
- t.absent(
196
- validateFn({...validFixture, timestamp: NaN}),
197
- 'timestamp NaN should fail'
198
- );
199
-
200
- t.absent(
201
- validateFn({...validFixture, timestamp: Infinity}),
202
- 'timestamp Infinity should fail'
203
- );
204
-
205
- t.absent(
206
- validateFn({...validFixture, timestamp: Number.MAX_SAFE_INTEGER + 1}),
207
- 'timestamp above MAX_SAFE_INTEGER should fail'
208
- );
209
-
210
- t.absent(
211
- validateFn({...validFixture, capabilities: 'cap:a'}),
212
- 'capabilities must be an array'
213
- );
214
-
215
- t.absent(
216
- validateFn({...validFixture, capabilities: [1]}),
217
- 'capabilities items must be strings'
218
- );
219
- }
220
-
221
- export function valueLevelValidationTests(
222
- t,
223
- validateFn,
224
- validFixture,
225
- valueKey,
226
- valueFields,
227
- notAllowedDataTypes,
228
- opts = {}
229
- ) {
230
- const skipInvalidType = opts.skipInvalidType || (() => false);
231
-
232
- for (const field of valueFields) {
233
- const missing = structuredClone(validFixture);
234
- delete missing[valueKey][field];
235
- t.absent(validateFn(missing), `Missing ${valueKey}.${field} should fail`);
236
- }
237
-
238
- t.test(`Invalid data types for each field in ${valueKey}`, t => {
239
- for (const field of valueFields) {
240
- for (const invalidType of notAllowedDataTypes) {
241
- if (skipInvalidType(field, invalidType)) continue;
242
-
243
- const withInvalidDataType = structuredClone(validFixture);
244
- withInvalidDataType[valueKey][field] = invalidType;
245
- t.absent(
246
- validateFn(withInvalidDataType),
247
- `Invalid data type for ${valueKey}.${field}: ${describeValue(invalidType)} should fail`
248
- );
249
- }
250
- }
251
- });
252
-
253
- t.test("Extra field in value", t => {
254
- const extraInValue = structuredClone(validFixture);
255
- extraInValue[valueKey].extraField = b4a.from('redundant', 'utf-8');
256
- t.absent(validateFn(extraInValue), 'Extra field should fail due to strict')
257
- });
258
- }
259
-
260
- export function fieldsBufferLengthTest(
261
- t,
262
- validateFn,
263
- validFixture,
264
- valueKey,
265
- requiredFieldLengthsForValue
266
- ) {
267
- for (const [field, expectedLen] of Object.entries(requiredFieldLengthsForValue)) {
268
- const emptyBuffer = b4a.alloc(0);
269
- const oneTooShort = b4a.alloc(expectedLen - 1, 0x01);
270
- const tooShort = b4a.alloc(expectedLen - 2, 0x01);
271
- const exact = b4a.alloc(expectedLen, 0x01);
272
- const oneTooLong = b4a.alloc(expectedLen + 1, 0x01);
273
- const tooLong = b4a.alloc(expectedLen + 2, 0x01);
274
-
275
- const buildValueLevel = (val) => ({
276
- ...validFixture,
277
- [valueKey]: {
278
- ...validFixture[valueKey],
279
- [field]: val
280
- }
281
- });
282
-
283
- const inputs = {
284
- emptyBufferInput: buildValueLevel(emptyBuffer),
285
- shortInput: buildValueLevel(tooShort),
286
- oneTooShortInput: buildValueLevel(oneTooShort),
287
- exactInput: buildValueLevel(exact),
288
- oneTooLongInput: buildValueLevel(oneTooLong),
289
- longInput: buildValueLevel(tooLong),
290
- };
291
-
292
- t.absent(validateFn(inputs.emptyBufferInput), `${valueKey}.${field} empty buffer (length ${emptyBuffer.length}) should fail`);
293
- t.absent(validateFn(inputs.shortInput), `${valueKey}.${field} too short (length ${tooShort.length}) should fail`);
294
- t.absent(validateFn(inputs.oneTooShortInput), `${valueKey}.${field} one too short (length ${oneTooShort.length}) should fail`);
295
- t.ok(validateFn(inputs.exactInput), `${valueKey}.${field} exact length (length ${exact.length}) should pass`);
296
- t.absent(validateFn(inputs.oneTooLongInput), `${valueKey}.${field} one too long (length ${oneTooLong.length}) should fail`);
297
- t.absent(validateFn(inputs.longInput), `${valueKey}.${field} too long (length ${tooLong.length}) should fail`);
298
- }
299
- }
300
-
301
- export function fieldsNonZeroBufferTest(t, validateFn, validFixture, valueKey, fields) {
302
- for (const field of fields) {
303
- const zeroFilled = structuredClone(validFixture);
304
- const len = zeroFilled[valueKey][field]?.length ?? 0;
305
- zeroFilled[valueKey][field] = b4a.alloc(len, 0);
306
- t.absent(validateFn(zeroFilled), `${valueKey}.${field} all-zero buffer should fail`);
307
- }
308
- }
@@ -1,90 +0,0 @@
1
- import test from 'brittle';
2
- import b4a from 'b4a';
3
-
4
- import V1ValidationSchema from '../../../../../src/core/network/protocols/v1/validators/V1ValidationSchema.js';
5
- import {
6
- NetworkOperationType,
7
- NONCE_BYTE_LENGTH,
8
- SIGNATURE_BYTE_LENGTH,
9
- } from '../../../../../src/utils/constants.js';
10
- import {not_allowed_data_types} from '../../../../fixtures/check.fixtures.js';
11
-
12
- import {
13
- fieldsBufferLengthTest,
14
- fieldsNonZeroBufferTest,
15
- headerFieldValueValidationTests,
16
- topLevelValidationTests,
17
- valueLevelValidationTests,
18
- } from './common.test.js';
19
-
20
- const v = new V1ValidationSchema();
21
-
22
- const validFixture = {
23
- type: NetworkOperationType.LIVENESS_REQUEST,
24
- id: 'test-id',
25
- timestamp: Date.now(),
26
- liveness_request: {
27
- nonce: b4a.alloc(NONCE_BYTE_LENGTH, 1),
28
- signature: b4a.alloc(SIGNATURE_BYTE_LENGTH, 2),
29
- },
30
- capabilities: ['cap:a', 'cap:b'],
31
- };
32
-
33
- const topFields = ['type', 'id', 'timestamp', 'liveness_request', 'capabilities'];
34
- const valueFields = ['nonce', 'signature'];
35
- const requiredLengths = {
36
- nonce: NONCE_BYTE_LENGTH,
37
- signature: SIGNATURE_BYTE_LENGTH,
38
- };
39
-
40
- test('V1ValidationSchema.validateV1LivenessRequest - happy path', t => {
41
- t.ok(v.validateV1LivenessRequest(validFixture), 'valid LIVENESS_REQUEST should pass');
42
- });
43
-
44
- test('V1ValidationSchema.validateV1LivenessRequest - top level validation', t => {
45
- topLevelValidationTests(
46
- t,
47
- v.validateV1LivenessRequest.bind(v),
48
- validFixture,
49
- 'liveness_request',
50
- not_allowed_data_types,
51
- topFields,
52
- NetworkOperationType.LIVENESS_REQUEST
53
- );
54
- });
55
-
56
- test('V1ValidationSchema.validateV1LivenessRequest - header field values', t => {
57
- headerFieldValueValidationTests(t, v.validateV1LivenessRequest.bind(v), validFixture);
58
- });
59
-
60
- test('V1ValidationSchema.validateV1LivenessRequest - payload validation', t => {
61
- valueLevelValidationTests(
62
- t,
63
- v.validateV1LivenessRequest.bind(v),
64
- validFixture,
65
- 'liveness_request',
66
- valueFields,
67
- not_allowed_data_types,
68
- );
69
- });
70
-
71
- test('V1ValidationSchema.validateV1LivenessRequest - buffer lengths', t => {
72
- fieldsBufferLengthTest(
73
- t,
74
- v.validateV1LivenessRequest.bind(v),
75
- validFixture,
76
- 'liveness_request',
77
- requiredLengths
78
- );
79
- });
80
-
81
- test('V1ValidationSchema.validateV1LivenessRequest - non-zero buffers', t => {
82
- fieldsNonZeroBufferTest(
83
- t,
84
- v.validateV1LivenessRequest.bind(v),
85
- validFixture,
86
- 'liveness_request',
87
- ['nonce', 'signature']
88
- );
89
- });
90
-
@@ -1,133 +0,0 @@
1
- import test from 'brittle';
2
- import b4a from 'b4a';
3
-
4
- import V1ValidationSchema from '../../../../../src/core/network/protocols/v1/validators/V1ValidationSchema.js';
5
- import {
6
- NetworkOperationType,
7
- NONCE_BYTE_LENGTH,
8
- ResultCode,
9
- SIGNATURE_BYTE_LENGTH,
10
- } from '../../../../../src/utils/constants.js';
11
- import {not_allowed_data_types} from '../../../../fixtures/check.fixtures.js';
12
-
13
- import {
14
- assertNoThrowAndAbsent,
15
- fieldsBufferLengthTest,
16
- fieldsNonZeroBufferTest,
17
- headerFieldValueValidationTests,
18
- topLevelValidationTests,
19
- valueLevelValidationTests,
20
- } from './common.test.js';
21
-
22
- const v = new V1ValidationSchema();
23
-
24
- const validFixture = {
25
- type: NetworkOperationType.LIVENESS_RESPONSE,
26
- id: 'test-id',
27
- timestamp: Date.now(),
28
- liveness_response: {
29
- nonce: b4a.alloc(NONCE_BYTE_LENGTH, 1),
30
- signature: b4a.alloc(SIGNATURE_BYTE_LENGTH, 2),
31
- result: ResultCode.OK,
32
- },
33
- capabilities: ['cap:a'],
34
- };
35
-
36
- const topFields = ['type', 'id', 'timestamp', 'liveness_response', 'capabilities'];
37
- const valueFields = ['nonce', 'signature', 'result'];
38
- const requiredLengths = {
39
- nonce: NONCE_BYTE_LENGTH,
40
- signature: SIGNATURE_BYTE_LENGTH,
41
- };
42
-
43
- test('V1ValidationSchema.validateV1LivenessResponse - happy path', t => {
44
- t.ok(v.validateV1LivenessResponse(validFixture), 'valid LIVENESS_RESPONSE should pass');
45
- });
46
-
47
- test('V1ValidationSchema.validateV1LivenessResponse - payload/type mismatch (request payload + response type)', t => {
48
- const op = structuredClone(validFixture);
49
- delete op.liveness_response;
50
- op.liveness_request = {
51
- nonce: b4a.alloc(NONCE_BYTE_LENGTH, 1),
52
- signature: b4a.alloc(SIGNATURE_BYTE_LENGTH, 2),
53
- };
54
-
55
- assertNoThrowAndAbsent(
56
- t,
57
- v.validateV1LivenessResponse.bind(v),
58
- op,
59
- 'liveness_request payload with type=LIVENESS_RESPONSE'
60
- );
61
- });
62
-
63
- test('V1ValidationSchema.validateV1LivenessResponse - top level validation', t => {
64
- topLevelValidationTests(
65
- t,
66
- v.validateV1LivenessResponse.bind(v),
67
- validFixture,
68
- 'liveness_response',
69
- not_allowed_data_types,
70
- topFields,
71
- NetworkOperationType.LIVENESS_RESPONSE
72
- );
73
- });
74
-
75
- test('V1ValidationSchema.validateV1LivenessResponse - header field values', t => {
76
- headerFieldValueValidationTests(t, v.validateV1LivenessResponse.bind(v), validFixture);
77
- });
78
-
79
- test('V1ValidationSchema.validateV1LivenessResponse - payload validation', t => {
80
- valueLevelValidationTests(
81
- t,
82
- v.validateV1LivenessResponse.bind(v),
83
- validFixture,
84
- 'liveness_response',
85
- valueFields,
86
- not_allowed_data_types,
87
- {
88
- skipInvalidType: (field, invalidType) => field === 'result' && typeof invalidType === 'number',
89
- }
90
- );
91
- });
92
-
93
- test('V1ValidationSchema.validateV1LivenessResponse - result value validation', t => {
94
- const negative = structuredClone(validFixture);
95
- negative.liveness_response.result = -1;
96
- t.absent(v.validateV1LivenessResponse(negative), 'negative result should fail');
97
-
98
- const nonInteger = structuredClone(validFixture);
99
- nonInteger.liveness_response.result = 1.1;
100
- t.absent(v.validateV1LivenessResponse(nonInteger), 'non-integer result should fail');
101
-
102
- const nan = structuredClone(validFixture);
103
- nan.liveness_response.result = NaN;
104
- t.absent(v.validateV1LivenessResponse(nan), 'result NaN should fail');
105
-
106
- const infinity = structuredClone(validFixture);
107
- infinity.liveness_response.result = Infinity;
108
- t.absent(v.validateV1LivenessResponse(infinity), 'result Infinity should fail');
109
-
110
- const unknownCode = structuredClone(validFixture);
111
- unknownCode.liveness_response.result = Math.max(...Object.values(ResultCode)) + 1;
112
- t.absent(v.validateV1LivenessResponse(unknownCode), 'unknown result code should fail');
113
- });
114
-
115
- test('V1ValidationSchema.validateV1LivenessResponse - buffer lengths', t => {
116
- fieldsBufferLengthTest(
117
- t,
118
- v.validateV1LivenessResponse.bind(v),
119
- validFixture,
120
- 'liveness_response',
121
- requiredLengths
122
- );
123
- });
124
-
125
- test('V1ValidationSchema.validateV1LivenessResponse - non-zero buffers', t => {
126
- fieldsNonZeroBufferTest(
127
- t,
128
- v.validateV1LivenessResponse.bind(v),
129
- validFixture,
130
- 'liveness_response',
131
- ['nonce', 'signature']
132
- );
133
- });
@@ -1,80 +0,0 @@
1
- import { test, hook } from 'brittle';
2
- import { encode, decode, ZERO_BALANCE } from '../../src/core/state/utils/nodeEntry.js';
3
- import esmock from "esmock";
4
- import sinon from "sinon";
5
- import { randomBuffer, tokenUnits } from './stateTestUtils.js';
6
- import { WRITER_BYTE_LENGTH, ADMIN_INITIAL_BALANCE } from '../../src/utils/constants.js';
7
- import { $TNK, toBalance } from '../../src/core/state/utils/balance.js';
8
- import b4a from 'b4a'
9
-
10
- let state
11
- hook('Initialize state', async () => {
12
- const checkout = sinon.stub().returns({ get: () => {
13
- return { value: encode({
14
- wk: randomBuffer(WRITER_BYTE_LENGTH),
15
- isWhitelisted: true,
16
- isWriter: true,
17
- isIndexer: true,
18
- balance: ADMIN_INITIAL_BALANCE })
19
- }
20
- }
21
- });
22
-
23
- const AutoBaseMock = sinon.stub().returns({ view: { checkout, core: { signedLength: 1 }} });
24
- const State = await esmock('../../src/core/state/State.js', {
25
- "autobase": AutoBaseMock
26
- });
27
- state = new State(null, null, null)
28
- });
29
-
30
- test('State#incrementBalance', () => {
31
- test('adds two balances and produce a node entry', async t => {
32
- const entry = await state.incrementBalance('adminAddress', $TNK(150n))
33
- t.is(toBalance(decode(entry).balance).asBigInt(), tokenUnits(1150n), 'balance matches');
34
- })
35
-
36
- test('do not add zero', async t => {
37
- const entry = await state.incrementBalance('adminAddress', $TNK(0n))
38
- t.is(entry, null, 'entry is null');
39
- })
40
-
41
- test('null entry', async t => {
42
- const AutoBaseMock = sinon.stub().returns({ view: { checkout: sinon.stub().returns({ get: () => ({ value: null }) }), core: { signedLength: 1 }} });
43
- const State = await esmock('../../src/core/state/State.js', {
44
- "autobase": AutoBaseMock
45
- });
46
- const entry = await new State(null, null, null).incrementBalance('adminAddress', $TNK(150n))
47
- t.is(entry, null, 'entry is null');
48
- })
49
- });
50
-
51
- test('State#derementBalance', async t => {
52
- test('subtract two balances and produce a node entry', async t => {
53
- const entry = await state.decrementBalance('adminAddress', $TNK(150n))
54
- t.is(toBalance(decode(entry).balance).asBigInt(), tokenUnits(850n), 'balance matches');
55
- })
56
-
57
- test('do not subtract zero', async t => {
58
- const entry = await state.decrementBalance('adminAddress', $TNK(0n))
59
- t.is(entry, null, 'entry is null');
60
- })
61
-
62
- test('do not produce negative balance', async t => {
63
- const entry = await state.decrementBalance('adminAddress', $TNK(1001n))
64
- t.is(entry, null, 'entry is null');
65
- })
66
-
67
- test('can zero balance', async t => {
68
- const entry = await state.decrementBalance('adminAddress', $TNK(1000n))
69
- t.ok(b4a.equals(decode(entry).balance, ZERO_BALANCE), 'balance matches');
70
- })
71
-
72
- test('null entry', async t => {
73
- const AutoBaseMock = sinon.stub().returns({ view: { checkout: sinon.stub().returns({ get: () => ({ value: null }) }), core: { signedLength: 1 }} });
74
- const State = await esmock('../../src/core/state/State.js', {
75
- "autobase": AutoBaseMock
76
- });
77
- const entry = await new State(null, null, null).decrementBalance('adminAddress', $TNK(150n))
78
- t.is(entry, null, 'entry is null');
79
- })
80
- });
@@ -1,42 +0,0 @@
1
- import { test } from 'brittle';
2
- import {
3
- eventFlush,
4
- deriveIndexerSequenceState
5
- } from '../../../../helpers/autobaseTestHelpers.js';
6
- import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
7
- import { toTerm } from '../../../../../src/core/state/utils/balance.js';
8
- import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
9
- import { safeEncodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
10
- import { setupAddAdminScenario, assertAdminState } from './addAdminScenarioHelpers.js';
11
- import { config } from '../../../../helpers/config.js';
12
-
13
- export default function addAdminHappyPathScenario() {
14
- test('State.apply addAdmin bootstraps admin node - happy path', async t => {
15
- const networkContext = await setupAddAdminScenario(t);
16
- const adminNode = networkContext.adminBootstrap;
17
- const readerNodes = networkContext.peers.slice(1);
18
- const reader = readerNodes[0];
19
-
20
- const txValidity = await deriveIndexerSequenceState(adminNode.base);
21
- const addAdminPayload = safeEncodeApplyOperation(
22
- await applyStateMessageFactory(adminNode.wallet, config)
23
- .buildCompleteAddAdminMessage(
24
- adminNode.wallet.address,
25
- adminNode.base.local.key,
26
- txValidity
27
- )
28
- );
29
-
30
- await adminNode.base.append(addAdminPayload);
31
- await adminNode.base.update();
32
- await eventFlush();
33
-
34
- await assertAdminState(t, adminNode.base, adminNode.wallet, adminNode.base.local.key, addAdminPayload);
35
-
36
- await networkContext.sync();
37
- await assertAdminState(t, reader.base, adminNode.wallet, adminNode.base.local.key, addAdminPayload);
38
-
39
- const readerNodeEntry = await reader.base.view.get(reader.wallet.address);
40
- t.is(readerNodeEntry, null, 'reader node remains without any role');
41
- });
42
- }