trac-msb 0.2.18 → 0.2.19

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 +52 -24
  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,116 +0,0 @@
1
- import request from "supertest"
2
- import b4a from "b4a"
3
- import { buildRpcSelfTransferPayload, waitForConnection } from "../../../helpers/transactionPayloads.mjs"
4
-
5
- const toBase64 = (value) => b4a.toString(b4a.from(JSON.stringify(value)), "base64")
6
-
7
- export const registerBroadcastTransactionTests = (context) => {
8
- describe("POST /v1/broadcast-transaction", () => {
9
- it("broadcasts transaction and returns lengths", async () => {
10
- const { payload } = await buildRpcSelfTransferPayload(
11
- context,
12
- context.rpcMsb.state,
13
- 1n
14
- );
15
- await waitForConnection(context.rpcMsb)
16
- const res = await request(context.server)
17
- .post("/v1/broadcast-transaction")
18
- .set("Accept", "application/json")
19
- .send(JSON.stringify({ payload }))
20
-
21
- expect(res.statusCode).toBe(200)
22
- expect(res.body).toMatchObject({
23
- result: {
24
- message: "Transaction broadcasted successfully.",
25
- signedLength: expect.any(Number),
26
- unsignedLength: expect.any(Number),
27
- tx: expect.any(String)
28
- }
29
- })
30
- })
31
-
32
- it("returns 400 when payload is missing", async () => {
33
- await waitForConnection(context.rpcMsb)
34
- const res = await request(context.server)
35
- .post("/v1/broadcast-transaction")
36
- .set("Accept", "application/json")
37
- .send(JSON.stringify({}))
38
-
39
- expect(res.statusCode).toBe(400)
40
- expect(res.body).toEqual({ error: "Payload is missing." })
41
- })
42
-
43
- it("returns 400 when payload is not base64", async () => {
44
- await waitForConnection(context.rpcMsb)
45
- const res = await request(context.server)
46
- .post("/v1/broadcast-transaction")
47
- .set("Accept", "application/json")
48
- .send(JSON.stringify({ payload: "not-base64" }))
49
-
50
- expect(res.statusCode).toBe(400)
51
- expect(res.body).toEqual({ error: "Payload must be a valid base64 string." })
52
- })
53
-
54
- it("returns 400 when decoded payload is not valid JSON", async () => {
55
- const invalidJsonBase64 = b4a.toString(b4a.from("{{invalid"), "base64")
56
-
57
- await waitForConnection(context.rpcMsb)
58
- const res = await request(context.server)
59
- .post("/v1/broadcast-transaction")
60
- .set("Accept", "application/json")
61
- .send(JSON.stringify({ payload: invalidJsonBase64 }))
62
-
63
- expect(res.statusCode).toBe(400)
64
- expect(res.body).toEqual({ error: "Decoded payload is not valid JSON." })
65
- })
66
-
67
- it("returns 400 for invalid transaction structure", async () => {
68
- const invalidStructure = {
69
- type: 1,
70
- address: context.wallet.address,
71
- }
72
-
73
- await waitForConnection(context.rpcMsb)
74
- const res = await request(context.server)
75
- .post("/v1/broadcast-transaction")
76
- .set("Accept", "application/json")
77
- .send(JSON.stringify({ payload: toBase64(invalidStructure) }))
78
-
79
- expect(res.statusCode).toBe(400)
80
- expect(res.body).toEqual({ error: "Invalid payload structure." })
81
- })
82
-
83
- it("returns 413 when payload exceeds size limit", async () => {
84
- const largeString = "a".repeat(2_100_000);
85
- const payload = toBase64({ type: 1, address: context.wallet.address, txo: { large: largeString } });
86
-
87
- await waitForConnection(context.rpcMsb);
88
- const res = await request(context.server)
89
- .post("/v1/broadcast-transaction")
90
- .set("Accept", "application/json")
91
- .send(JSON.stringify({ payload }));
92
-
93
- expect(res.statusCode).toBe(413);
94
- });
95
-
96
-
97
- it("returns 429 on repeated broadcast failures", async () => {
98
- const { payload } = await buildRpcSelfTransferPayload(context, context.rpcMsb.state, 1n);
99
- const originalMethod = context.rpcMsb.broadcastPartialTransaction;
100
- context.rpcMsb.broadcastPartialTransaction = async () => false;
101
-
102
- try {
103
- await waitForConnection(context.rpcMsb);
104
- const res = await request(context.server)
105
- .post("/v1/broadcast-transaction")
106
- .set("Accept", "application/json")
107
- .send(JSON.stringify({ payload }));
108
-
109
- expect(res.statusCode).toBe(429);
110
- expect(res.body).toEqual({ error: "Failed to broadcast transaction after multiple attempts." });
111
- } finally {
112
- context.rpcMsb.broadcastPartialTransaction = originalMethod;
113
- }
114
- });
115
- })
116
- }
@@ -1,19 +0,0 @@
1
- import request from "supertest"
2
-
3
- export const registerConfirmedLengthTests = (context) => {
4
- describe("GET /v1/confirmed-length", () => {
5
- it("returns confirmed length", async () => {
6
- const res = await request(context.server).get("/v1/confirmed-length")
7
- expect(res.statusCode).toBe(200)
8
- expect(res.body).toEqual({ confirmed_length: expect.any(Number) })
9
- })
10
-
11
- it("matches signed length from state", async () => {
12
- const res = await request(context.server).get("/v1/confirmed-length")
13
- expect(res.statusCode).toBe(200)
14
-
15
- const signedLength = context.rpcMsb.state.getSignedLength()
16
- expect(res.body).toEqual({ confirmed_length: signedLength })
17
- })
18
- })
19
- }
@@ -1,11 +0,0 @@
1
- import request from "supertest"
2
-
3
- export const registerFeeTests = (context) => {
4
- describe("GET /v1/fee", () => {
5
- it("returns fee", async () => {
6
- const res = await request(context.server).get("/v1/fee")
7
- expect(res.statusCode).toBe(200)
8
- expect(res.body).toEqual({ fee: expect.stringMatching(/^-?\d+(\.\d+)?$/) })
9
- })
10
- })
11
- }
@@ -1,33 +0,0 @@
1
- import request from "supertest"
2
-
3
- export const registerHealthTests = (context) => {
4
- describe("GET /v1/health", () => {
5
- it("should return 200 and ok:true when healthy", async () => {
6
- const res = await request(context.server).get("/v1/health")
7
- expect(res.statusCode).toBe(200)
8
- expect(res.body).toEqual({ ok: true })
9
- })
10
-
11
- it("should return 503 when the state is unavailable", async () => {
12
- const originalState = context.rpcMsb.state;
13
- Object.defineProperty(context.rpcMsb, 'state', {
14
- get: () => null,
15
- configurable: true
16
- });
17
-
18
- try {
19
- const res = await request(context.server).get("/v1/health")
20
-
21
- expect(res.statusCode).toBe(503)
22
- expect(res.body).toEqual({
23
- error: "Could not connect to RPC server"
24
- })
25
- } finally {
26
- Object.defineProperty(context.rpcMsb, 'state', {
27
- get: () => originalState,
28
- configurable: true
29
- });
30
- }
31
- })
32
- })
33
- }
@@ -1,95 +0,0 @@
1
- import { createServer } from "../../../rpc/create_server.js"
2
- import { initTemporaryDirectory } from '../../helpers/setupApplyTests.js'
3
- import { testKeyPair1, testKeyPair2, testKeyPair3 } from '../../fixtures/apply.fixtures.js'
4
- import { randomBytes, setupMsbAdmin, setupMsbWriter, removeTemporaryDirectory, setupMsbPeer, tryToSyncWriters, waitForNodeState } from "../../helpers/setupApplyTests.js"
5
- import { registerAccountTests } from "./account/account.test.mjs"
6
- import { registerBalanceTests } from "./balance/balance.test.mjs"
7
- import { registerBroadcastTransactionTests } from "./broadcast-transaction/broadcast-transaction.test.mjs"
8
- import { registerConfirmedLengthTests } from "./confirmed-length/confirmed-length.test.mjs"
9
- import { registerFeeTests } from "./fee/fee.test.mjs"
10
- import { registerTxHashesTests } from "./tx-hashes/tx-hashes.test.mjs"
11
- import { registerTxPayloadsBulkTests } from "./tx-payloads-bulk/tx-payloads-bulk.test.mjs"
12
- import { registerTxDetailsTests } from "./tx-details/tx-details.test.mjs"
13
- import { registerTxTests } from "./tx/tx.test.mjs"
14
- import { registerTxvTests } from "./txv/txv.test.mjs"
15
- import { registerUnconfirmedLengthTests } from "./unconfirmed-length/unconfirmed-length.test.mjs"
16
- import { registerHealthTests } from "./health/health.test.mjs"
17
-
18
- let toClose
19
- let tmpDirectory
20
- const additionalPeers = []
21
-
22
- const testContext = {
23
- writerMsb: null,
24
- rpcMsb: null,
25
- server: null,
26
- wallet: null,
27
- adminWallet: null,
28
- }
29
-
30
- const setupNetwork = async () => {
31
- tmpDirectory = await initTemporaryDirectory()
32
- const rpcOpts = {
33
- bootstrap: randomBytes(32).toString('hex'),
34
- channel: randomBytes(32).toString('hex'),
35
- enableRoleRequester: false,
36
- enableWallet: true,
37
- enableValidatorObserver: true,
38
- enableInteractiveMode: false,
39
- disableRateLimit: true,
40
- enableTxApplyLogs: false,
41
- storesDirectory: `${tmpDirectory}/admin/`,
42
- }
43
-
44
- const admin = await setupMsbAdmin(testKeyPair1, tmpDirectory, rpcOpts)
45
- const writer = await setupMsbWriter(admin, 'writer', testKeyPair2, tmpDirectory, admin.options);
46
- additionalPeers.push(writer)
47
- const reader = await setupMsbPeer('peer-2', testKeyPair3, tmpDirectory, { ...admin.options, enable_wallet: false });
48
- additionalPeers.push(reader)
49
- await tryToSyncWriters(admin, writer, reader)
50
- await waitForNodeState(reader, writer.wallet.address, {
51
- wk: writer.msb.state.writingKey,
52
- isWhitelisted: true,
53
- isWriter: true,
54
- isIndexer: false,
55
- })
56
- return { writer, admin, reader }
57
- }
58
-
59
- beforeAll(async () => {
60
- const { admin, writer, reader } = await setupNetwork()
61
- const server = createServer(reader.msb, reader.config)
62
- toClose = admin.msb
63
- Object.assign(testContext, {
64
- writerMsb: writer.msb,
65
- rpcMsb: reader.msb,
66
- server,
67
- wallet: writer.msb.wallet,
68
- adminWallet: admin.wallet,
69
- })
70
- })
71
-
72
- afterAll(async () => {
73
- const peersToClose = [...new Set(additionalPeers.map(peer => peer?.msb).filter(Boolean))]
74
- await Promise.all([
75
- toClose?.close(),
76
- ...peersToClose.map(instance => instance.close())
77
- ])
78
- await removeTemporaryDirectory(tmpDirectory)
79
- })
80
-
81
- // The order here is important since the OPs change the network state. We wont boot up an instance before each because the tests are to verify rpc structure and the decision is to spare ci resources.
82
- describe("API acceptance tests", () => {
83
- registerConfirmedLengthTests(testContext)
84
- registerUnconfirmedLengthTests(testContext)
85
- registerTxvTests(testContext)
86
- registerFeeTests(testContext)
87
- registerTxHashesTests(testContext)
88
- registerTxTests(testContext)
89
- registerBalanceTests(testContext)
90
- registerBroadcastTransactionTests(testContext)
91
- registerTxPayloadsBulkTests(testContext)
92
- registerTxDetailsTests(testContext)
93
- registerAccountTests(testContext)
94
- registerHealthTests(testContext)
95
- })
@@ -1,133 +0,0 @@
1
- import request from "supertest"
2
- import { buildRpcSelfTransferPayload, waitForConnection } from "../../../helpers/transactionPayloads.mjs"
3
- import { sleep } from "../../../../src/utils/helpers.js"
4
-
5
- const TX_ENDPOINT_TIMEOUT_MS = 4000
6
- const TX_ENDPOINT_RETRY_INTERVAL_MS = 100
7
-
8
- const waitForStatusCode = async (requestFactory, expectedStatusCode, timeoutMs = TX_ENDPOINT_TIMEOUT_MS) => {
9
- const startedAt = Date.now()
10
- let response = null
11
-
12
- while ((Date.now() - startedAt) < timeoutMs) {
13
- response = await requestFactory()
14
- if (response.statusCode === expectedStatusCode) {
15
- return response
16
- }
17
- await sleep(TX_ENDPOINT_RETRY_INTERVAL_MS)
18
- }
19
-
20
- return response
21
- }
22
-
23
- export const registerTxTests = (context) => {
24
- describe("GET /v1/tx/:hash", () => {
25
- it("returns tx details for a broadcasted transaction", async () => {
26
- const { payload, txHashHex } = await buildRpcSelfTransferPayload(
27
- context,
28
- context.rpcMsb.state,
29
- 1n
30
- );
31
-
32
- await waitForConnection(context.rpcMsb)
33
- const broadcastRes = await request(context.server)
34
- .post("/v1/broadcast-transaction")
35
- .set("Accept", "application/json")
36
- .send(JSON.stringify({ payload }))
37
- expect(broadcastRes.statusCode).toBe(200)
38
-
39
- const res = await waitForStatusCode(
40
- () => request(context.server).get(`/v1/tx/${txHashHex}`),
41
- 200
42
- )
43
- expect(res.statusCode).toBe(200)
44
- expect(res.body).toMatchObject({ txDetails: expect.any(Object) })
45
- })
46
-
47
- it("returns 404 for non-existent transaction hash", async () => {
48
- const nonExistentHash = "0b4d1c1dac48af13212f616601d7399457476a0b644850875b7f4b79df6ff89c"
49
- const res = await request(context.server).get(`/v1/tx/${nonExistentHash}`)
50
- expect(res.statusCode).toBe(404)
51
- expect(res.body).toEqual({ txDetails: null })
52
- })
53
-
54
- it("returns 400 for invalid hash format (too short)", async () => {
55
- const invalidHash = '0'.repeat(63)
56
- const res = await request(context.server).get(`/v1/tx/${invalidHash}`)
57
- expect(res.statusCode).toBe(400)
58
- expect(res.body).toEqual({ error: "Invalid transaction hash format" })
59
- })
60
-
61
- it("returns 400 for invalid hash format (non-hex)", async () => {
62
- const invalidHash = 'Z'.repeat(64)
63
- const res = await request(context.server).get(`/v1/tx/${invalidHash}`)
64
- expect(res.statusCode).toBe(400)
65
- expect(res.body).toEqual({ error: "Invalid transaction hash format" })
66
- })
67
-
68
- it("returns 400 when no hash provided", async () => {
69
- const res = await request(context.server).get('/v1/tx')
70
- expect(res.statusCode).toBe(400)
71
- expect(res.body).toEqual({ error: "Transaction hash is required" })
72
- })
73
-
74
- it("returns 400 for hash with invalid characters", async () => {
75
- const invalidHash = '0b4d1c1dac48$af13212f6166017399457476a0b644850875b7f4b79df6ff89c'
76
- const res = await request(context.server).get(`/v1/tx/${invalidHash}`)
77
- expect(res.statusCode).toBe(400)
78
- expect(res.body).toEqual({ error: "Invalid transaction hash format" })
79
- })
80
-
81
- it("returns 400 for hash with special characters", async () => {
82
- const invalidHash = '!@#$%^&*'.repeat(8)
83
- const res = await request(context.server).get(`/v1/tx/${invalidHash}`)
84
- expect(res.statusCode).toBe(400)
85
- expect(res.body).toEqual({ error: "Invalid transaction hash format" })
86
- })
87
-
88
- it("returns 400 for hash with spaces", async () => {
89
- const invalidHash = '0b4d1c1dac48af13212f616601d7399457476a0b644850875b7 4b79df6ff89c'
90
- const res = await request(context.server).get(`/v1/tx/${invalidHash}`)
91
- expect(res.statusCode).toBe(400)
92
- expect(res.body).toEqual({ error: "Invalid transaction hash format" })
93
- })
94
-
95
- it("returns 400 for hash with 0x prefix", async () => {
96
- const hash = "0x" + "0".repeat(62)
97
- const res = await request(context.server).get(`/v1/tx/${hash}`)
98
- expect(res.statusCode).toBe(400)
99
- expect(res.body).toEqual({ error: "Invalid transaction hash format" })
100
- })
101
-
102
- it("returns 400 for odd-length hex", async () => {
103
- const hash = "a".repeat(63)
104
- const res = await request(context.server).get(`/v1/tx/${hash}`)
105
- expect(res.statusCode).toBe(400)
106
- expect(res.body).toEqual({ error: "Invalid transaction hash format" })
107
- })
108
-
109
-
110
- it("accepts uppercase hex", async () => {
111
- const { payload, txHashHex } = await buildRpcSelfTransferPayload(context, context.rpcMsb.state, 1n);
112
-
113
- // Send the transaction
114
- await request(context.server)
115
- .post("/v1/broadcast-transaction")
116
- .send(JSON.stringify({ payload }));
117
-
118
- // Waits for the node indexer to process
119
- await new Promise(resolve => setTimeout(resolve, 500));
120
-
121
- const uppercaseHash = txHashHex.toUpperCase();
122
- const res = await request(context.server).get(`/v1/tx/${uppercaseHash}`);
123
-
124
- expect(res.statusCode).toBe(200);
125
- });
126
-
127
- it("returns 400 for trailing space hash", async () => {
128
- const hash = "a".repeat(64) + "%20" // Forcing space
129
- const res = await request(context.server).get(`/v1/tx/${hash}`)
130
- expect(res.statusCode).toBe(400)
131
- })
132
- })
133
- }
@@ -1,241 +0,0 @@
1
- import request from "supertest"
2
- import { buildRpcSelfTransferPayload, waitForConnection } from "../../../helpers/transactionPayloads.mjs"
3
- import { sleep } from "../../../../src/utils/helpers.js"
4
-
5
- const TX_DETAILS_TIMEOUT_MS = 4000
6
- const TX_DETAILS_RETRY_INTERVAL_MS = 100
7
-
8
- const waitForStatusCode = async (requestFactory, expectedStatusCode, timeoutMs = TX_DETAILS_TIMEOUT_MS) => {
9
- const startedAt = Date.now()
10
- let response = null
11
-
12
- while ((Date.now() - startedAt) < timeoutMs) {
13
- response = await requestFactory()
14
- if (response.statusCode === expectedStatusCode) {
15
- return response
16
- }
17
- await sleep(TX_DETAILS_RETRY_INTERVAL_MS)
18
- }
19
-
20
- return response
21
- }
22
-
23
- export const registerTxDetailsTests = (context) => {
24
- describe("GET /v1/tx/details", () => {
25
- it("returns 200 for broadcasted hash (confirmed and unconfirmed)", async () => {
26
- const { payload, txHashHex } = await buildRpcSelfTransferPayload(
27
- context,
28
- context.rpcMsb.state,
29
- 1n
30
- );
31
-
32
- await waitForConnection(context.rpcMsb)
33
- const broadcastRes = await request(context.server)
34
- .post("/v1/broadcast-transaction")
35
- .set("Accept", "application/json")
36
- .send(JSON.stringify({ payload }))
37
- expect(broadcastRes.statusCode).toBe(200)
38
-
39
- const resConfirmed = await waitForStatusCode(
40
- () => request(context.server)
41
- .get(`/v1/tx/details/${txHashHex}?confirmed=true`),
42
- 200
43
- )
44
- expect(resConfirmed.statusCode).toBe(200)
45
-
46
- expect(resConfirmed.body).toMatchObject({
47
- txDetails: expect.any(Object),
48
- confirmed_length: expect.any(Number),
49
- fee: expect.any(String)
50
- })
51
-
52
- const resUnconfirmed = await waitForStatusCode(
53
- () => request(context.server)
54
- .get(`/v1/tx/details/${txHashHex}?confirmed=false`),
55
- 200
56
- )
57
- expect(resUnconfirmed.statusCode).toBe(200)
58
-
59
- expect(resUnconfirmed.body).toMatchObject({
60
- txDetails: expect.any(Object),
61
- confirmed_length: expect.any(Number),
62
- fee: expect.any(String)
63
- })
64
- })
65
-
66
- it("handles null confirmed_length for unconfirmed transaction", async () => {
67
- const { payload, txHashHex } = await buildRpcSelfTransferPayload(
68
- context,
69
- context.rpcMsb.state,
70
- 1n
71
- );
72
-
73
- const originalGetConfirmedLength = context.rpcMsb.state.getTransactionConfirmedLength
74
- context.rpcMsb.state.getTransactionConfirmedLength = async () => null
75
-
76
- try {
77
-
78
- await waitForConnection(context.rpcMsb)
79
- const broadcastRes = await request(context.server)
80
- .post("/v1/broadcast-transaction")
81
- .set("Accept", "application/json")
82
- .send(JSON.stringify({ payload }))
83
- expect(broadcastRes.statusCode).toBe(200)
84
-
85
- const res = await waitForStatusCode(
86
- () => request(context.server)
87
- .get(`/v1/tx/details/${txHashHex}?confirmed=false`),
88
- 200
89
- )
90
- expect(res.statusCode).toBe(200)
91
-
92
- expect(res.body).toMatchObject({
93
- txDetails: expect.any(Object),
94
- confirmed_length: 0,
95
- fee: '0'
96
- })
97
- } finally {
98
- context.rpcMsb.state.getTransactionConfirmedLength = originalGetConfirmedLength
99
- }
100
- })
101
-
102
- it("returns 404 for non-existent transaction hash", async () => {
103
- const nonExistentHash = "0b4d1c1dac48af13212f616601d7399457476a0b644850875b7f4b79df6ff89c"
104
- const res = await request(context.server)
105
- .get(`/v1/tx/details/${nonExistentHash}`)
106
-
107
- expect(res.statusCode).toBe(404)
108
- expect(res.body).toEqual({
109
- error: `No payload found for tx hash: ${nonExistentHash}`
110
- })
111
- })
112
-
113
- it("returns 400 for invalid hash format (too short)", async () => {
114
- const invalidHash = '0'.repeat(63)
115
- const res = await request(context.server)
116
- .get(`/v1/tx/details/${invalidHash}`)
117
-
118
- expect(res.statusCode).toBe(400)
119
- expect(res.body).toEqual({
120
- error: "Invalid transaction hash format"
121
- })
122
- })
123
-
124
- it("returns 400 for invalid hash format (non-hex)", async () => {
125
- const invalidHash = 'Z'.repeat(64)
126
- const res = await request(context.server)
127
- .get(`/v1/tx/details/${invalidHash}`)
128
-
129
- expect(res.statusCode).toBe(400)
130
- expect(res.body).toEqual({
131
- error: "Invalid transaction hash format"
132
- })
133
- })
134
-
135
- it("returns 400 for invalid confirmed parameter", async () => {
136
- const hash = "0b4d1c1dac48af13212f616601d7399457476a0b644850875b7f4b79df6ff89c"
137
-
138
- const res = await request(context.server)
139
- .get(`/v1/tx/details/${hash}?confirmed=invalid`)
140
-
141
- expect(res.statusCode).toBe(400)
142
- expect(res.body).toEqual({
143
- error: 'Parameter "confirmed" must be exactly "true" or "false"'
144
- })
145
- })
146
-
147
- it("returns 400 for invalid confirmed parameter case (UPPERCASE)", async () => {
148
- const hash = "0b4d1c1dac48af13212f616601d7399457476a0b644850875b7f4b79df6ff89c"
149
- const res = await request(context.server).get(`/v1/tx/details/${hash}?confirmed=TRUE`)
150
- expect(res.statusCode).toBe(400)
151
- expect(res.body).toEqual({
152
- error: 'Parameter "confirmed" must be exactly "true" or "false"'
153
- })
154
- })
155
-
156
- it("returns 400 when no hash provided", async () => {
157
- const res = await request(context.server)
158
- .get('/v1/tx/details')
159
-
160
- expect(res.statusCode).toBe(400)
161
- expect(res.body).toEqual({
162
- error: "Transaction hash is required"
163
- })
164
- })
165
-
166
- it("returns 400 for hash with invalid characters", async () => {
167
- const invalidHash = '0b4d1c1dac48$af13212f6166017399457476a0b644850875b7f4b79df6ff89c'
168
- const res = await request(context.server)
169
- .get(`/v1/tx/details/${invalidHash}`)
170
-
171
- expect(res.statusCode).toBe(400)
172
- expect(res.body).toEqual({
173
- error: "Invalid transaction hash format"
174
- })
175
- })
176
-
177
- it("returns 400 for hash with special characters", async () => {
178
- const invalidHash = '!@#$%^&*'.repeat(8)
179
- const res = await request(context.server)
180
- .get(`/v1/tx/details/${invalidHash}`)
181
-
182
- expect(res.statusCode).toBe(400)
183
- expect(res.body).toEqual({
184
- error: "Invalid transaction hash format"
185
- })
186
- })
187
-
188
- it("returns 400 for hash with spaces", async () => {
189
- const invalidHash = '0b4d1c1dac48af13212f616601d7399457476a0b644850875b7 4b79df6ff89c'
190
- const res = await request(context.server)
191
- .get(`/v1/tx/details/${invalidHash}`)
192
-
193
- expect(res.statusCode).toBe(400)
194
- expect(res.body).toEqual({
195
- error: "Invalid transaction hash format"
196
- })
197
- })
198
-
199
- it("returns 400 for hash with 0x prefix", async () => {
200
- const hash = "0x" + "0".repeat(62)
201
- const res = await request(context.server).get(`/v1/tx/details/${hash}`)
202
- expect(res.statusCode).toBe(400)
203
- expect(res.body).toEqual({ error: "Invalid transaction hash format" })
204
- })
205
-
206
- it("returns 400 for odd-length hex", async () => {
207
- const hash = "a".repeat(63)
208
- const res = await request(context.server).get(`/v1/tx/details/${hash}`)
209
- expect(res.statusCode).toBe(400)
210
- expect(res.body).toEqual({ error: "Invalid transaction hash format" })
211
- })
212
-
213
- it("accepts uppercase hex", async () => {
214
- const { payload, txHashHex } = await buildRpcSelfTransferPayload(
215
- context,
216
- context.rpcMsb.state,
217
- 1n
218
- );
219
-
220
- await waitForConnection(context.rpcMsb);
221
- await request(context.server)
222
- .post("/v1/broadcast-transaction")
223
- .send(JSON.stringify({ payload }));
224
-
225
- const upperHash = txHashHex.toUpperCase();
226
- const res = await request(context.server)
227
- .get(`/v1/tx/details/${upperHash}?confirmed=false`);
228
-
229
- expect(res.statusCode).toBe(200);
230
- });
231
-
232
- it("returns 400 for trailing space hash", async () => {
233
- const hash = "a".repeat(64) + " ";
234
- const res = await request(context.server)
235
- .get(`/v1/tx/details/${encodeURIComponent(hash)}`);
236
-
237
- expect(res.statusCode).toBe(400);
238
- expect(res.body).toEqual({ error: "Invalid transaction hash format" });
239
- });
240
- })
241
- }