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,46 +0,0 @@
1
- import b4a from 'b4a';
2
- import OperationValidationScenarioBase from '../common/base/OperationValidationScenarioBase.js';
3
- import { safeDecodeApplyOperation } from '../../../../../src/utils/protobuf/operationHelpers.js';
4
- import deploymentEntryUtils from '../../../../../src/core/state/utils/deploymentEntry.js';
5
- import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
6
- import {
7
- setupTxOperationScenario,
8
- buildTxOperationPayload,
9
- assertTxOperationFailureState
10
- } from './txOperationScenarioHelpers.js';
11
-
12
- export default function txOperationInvalidSubnetCreatorAddressScenario() {
13
- new OperationValidationScenarioBase({
14
- title: 'State.apply txOperation rejects payloads when subnet creator address is invalid',
15
- setupScenario: setupTxOperationScenario,
16
- buildValidPayload: buildTxOperationPayload,
17
- mutatePayload: async (_t, validPayload) => validPayload,
18
- applyInvalidPayload: async (context, invalidPayload, _t, validPayload) => {
19
- const node = context.txOperation?.validatorPeer ?? context.peers?.[1];
20
- const payload = validPayload ?? invalidPayload;
21
- const decoded = safeDecodeApplyOperation(payload);
22
- const fallbackTxHash = decoded?.txo?.tx ?? b4a.alloc(32, 0x11);
23
- const originalDecode = deploymentEntryUtils.decode;
24
-
25
- // Force decode to yield an invalid address buffer so bufferToAddress returns null.
26
- deploymentEntryUtils.decode = () => ({
27
- txHash: fallbackTxHash,
28
- address: b4a.alloc(1, 0x01)
29
- });
30
-
31
- try {
32
- await node.base.append(payload);
33
- await node.base.update();
34
- await eventFlush();
35
- } finally {
36
- deploymentEntryUtils.decode = originalDecode;
37
- }
38
- },
39
- assertStateUnchanged: (t, context, _valid, invalidPayload) =>
40
- assertTxOperationFailureState(t, context, {
41
- payload: invalidPayload,
42
- validatorEntryBefore: null
43
- }),
44
- expectedLogs: ['Invalid subnet creator address.']
45
- }).performScenario();
46
- }
@@ -1,21 +0,0 @@
1
- import { test } from 'brittle';
2
- import {
3
- setupTxOperationScenario,
4
- buildTxOperationPayload,
5
- assertTxOperationSuccessState
6
- } from './txOperationScenarioHelpers.js';
7
- import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
8
-
9
- export default function txOperationRequesterCreatorHappyPathScenario() {
10
- test('State.apply txOperation with requester as subnetwork creator (no bonus, 50% to validator)', async t => {
11
- const context = await setupTxOperationScenario(t, { creatorPeerKind: 'requester' });
12
- const payload = await buildTxOperationPayload(context);
13
- const validatorPeer = context.txOperation?.validatorPeer ?? context.adminBootstrap;
14
-
15
- await validatorPeer.base.append(payload);
16
- await validatorPeer.base.update();
17
- await eventFlush();
18
-
19
- await assertTxOperationSuccessState(t, context, { payload, distribution: 'requesterIsCreator' });
20
- });
21
- }
@@ -1,432 +0,0 @@
1
- import b4a from 'b4a';
2
- import { applyStateMessageFactory } from '../../../../../src/messages/state/applyStateMessageFactory.js';
3
- import {
4
- deriveIndexerSequenceState,
5
- eventFlush
6
- } from '../../../../helpers/autobaseTestHelpers.js';
7
- import {
8
- setupAdminNetwork,
9
- initializeBalances,
10
- whitelistAddress
11
- } from '../common/commonScenarioHelper.js';
12
- import { promotePeerToWriter } from '../addWriter/addWriterScenarioHelpers.js';
13
- import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
14
- import addressUtils from '../../../../../src/core/state/utils/address.js';
15
- import deploymentEntryUtils from '../../../../../src/core/state/utils/deploymentEntry.js';
16
- import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
17
- import { toBalance, PERCENT_25, PERCENT_50, PERCENT_75 } from '../../../../../src/core/state/utils/balance.js';
18
- import { EntryType } from '../../../../../src/utils/constants.js';
19
- import { decimalStringToBigInt, bigIntTo16ByteBuffer } from '../../../../../src/utils/amountSerialization.js';
20
- import {
21
- buildBootstrapDeploymentPayload
22
- } from '../bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js';
23
- import {
24
- safeDecodeApplyOperation,
25
- safeEncodeApplyOperation
26
- } from '../../../../../src/utils/protobuf/operationHelpers.js';
27
- import { config } from '../../../../helpers/config.js';
28
-
29
- const DEFAULT_FUNDING = bigIntTo16ByteBuffer(decimalStringToBigInt('10'));
30
- const DEFAULT_CONTENT_HASH = b4a.alloc(32, 0xab);
31
-
32
- function selectValidatorPeer(context, offset = 0) {
33
- const peers = context.peers.slice(1);
34
- if (!peers.length) {
35
- throw new Error('TxOperation scenarios require at least one non-admin peer.');
36
- }
37
- return peers[Math.min(offset, peers.length - 1)];
38
- }
39
-
40
- function selectDeployerPeer(context, offset = 1) {
41
- const peers = context.peers.slice(1);
42
- if (peers.length < 2) {
43
- throw new Error('TxOperation scenarios require a deployer peer.');
44
- }
45
- return peers[Math.min(offset, peers.length - 1)];
46
- }
47
-
48
- function selectBroadcasterPeer(context, offset = 2) {
49
- const peers = context.peers.slice(1);
50
- if (peers.length < 3) {
51
- throw new Error('TxOperation scenarios require a broadcaster peer.');
52
- }
53
- return peers[Math.min(offset, peers.length - 1)];
54
- }
55
-
56
- export async function setupTxOperationScenario(
57
- t,
58
- {
59
- nodes = 4,
60
- validatorInitialBalance = DEFAULT_FUNDING,
61
- deployerInitialBalance = DEFAULT_FUNDING,
62
- broadcasterInitialBalance = DEFAULT_FUNDING,
63
- contentHash = DEFAULT_CONTENT_HASH,
64
- creatorPeerKind = 'deployer' // 'deployer' | 'validator' | 'requester'
65
- } = {}
66
- ) {
67
- const context = await setupAdminNetwork(t, { nodes: Math.max(nodes, 4) });
68
- const validatorPeer = selectValidatorPeer(context);
69
- const deployerPeer = selectDeployerPeer(context);
70
- const broadcasterPeer = selectBroadcasterPeer(context);
71
-
72
- await initializeBalances(context, [
73
- [validatorPeer.wallet.address, validatorInitialBalance],
74
- [deployerPeer.wallet.address, deployerInitialBalance],
75
- [broadcasterPeer.wallet.address, broadcasterInitialBalance]
76
- ]);
77
-
78
- context.addWriterScenario = { writerInitialBalance: validatorInitialBalance };
79
- await whitelistAddress(context, validatorPeer.wallet.address);
80
- await whitelistAddress(context, deployerPeer.wallet.address);
81
- await whitelistAddress(context, broadcasterPeer.wallet.address);
82
-
83
- await promotePeerToWriter(t, context, { readerPeer: validatorPeer });
84
- await context.sync();
85
-
86
- const creatorPeer =
87
- creatorPeerKind === 'validator'
88
- ? validatorPeer
89
- : creatorPeerKind === 'requester'
90
- ? broadcasterPeer
91
- : deployerPeer;
92
- const bootstrapValidatorPeer =
93
- creatorPeerKind === 'validator' ? context.adminBootstrap : validatorPeer;
94
-
95
- const externalBootstrap = b4a.from(creatorPeer.base.local.key);
96
- const bootstrapPayload = await buildBootstrapDeploymentPayload(context, {
97
- validatorPeer: bootstrapValidatorPeer,
98
- deployerPeer: creatorPeer,
99
- externalBootstrap
100
- });
101
-
102
- await bootstrapValidatorPeer.base.append(bootstrapPayload);
103
- await bootstrapValidatorPeer.base.update();
104
- await eventFlush();
105
- await context.sync();
106
-
107
- const validatorEntryBefore = await validatorPeer.base.view.get(validatorPeer.wallet.address);
108
- const deployerEntryBefore = await validatorPeer.base.view.get(creatorPeer.wallet.address);
109
- const requesterEntryBefore = await validatorPeer.base.view.get(broadcasterPeer.wallet.address);
110
- const txValidity = await deriveIndexerSequenceState(validatorPeer.base);
111
-
112
- context.txOperation = {
113
- validatorPeer,
114
- deployerPeer: creatorPeer,
115
- creatorPeer,
116
- broadcasterPeer,
117
- externalBootstrap,
118
- msbBootstrap: b4a.from(context.bootstrap.base.local.key),
119
- txValidity,
120
- contentHash,
121
- validatorEntryBefore: validatorEntryBefore ? { value: b4a.from(validatorEntryBefore.value) } : null,
122
- deployerEntryBefore: deployerEntryBefore ? { value: b4a.from(deployerEntryBefore.value) } : null,
123
- requesterEntryBefore: requesterEntryBefore ? { value: b4a.from(requesterEntryBefore.value) } : null
124
- };
125
-
126
- return context;
127
- }
128
-
129
- export async function buildTxOperationPayload(
130
- context,
131
- {
132
- validatorPeer = context.txOperation?.validatorPeer ?? selectValidatorPeer(context),
133
- broadcasterPeer = context.txOperation?.broadcasterPeer ?? selectBroadcasterPeer(context),
134
- externalBootstrap = context.txOperation?.externalBootstrap ?? b4a.from(broadcasterPeer.base.local.key),
135
- msbBootstrap = context.txOperation?.msbBootstrap ?? b4a.from(context.bootstrap.base.local.key),
136
- txValidity = context.txOperation?.txValidity ?? null,
137
- contentHash = context.txOperation?.contentHash ?? DEFAULT_CONTENT_HASH,
138
- writerKeyBuffer = broadcasterPeer.base.local.key
139
- } = {}
140
- ) {
141
- const resolvedTxValidity = txValidity ?? (await deriveIndexerSequenceState(validatorPeer.base));
142
-
143
- const partial = await applyStateMessageFactory(broadcasterPeer.wallet, config)
144
- .buildPartialTransactionOperationMessage(
145
- broadcasterPeer.wallet.address,
146
- writerKeyBuffer.toString('hex'),
147
- resolvedTxValidity.toString('hex'),
148
- contentHash.toString('hex'),
149
- externalBootstrap.toString('hex'),
150
- msbBootstrap.toString('hex'),
151
- 'json'
152
- );
153
-
154
- const payload = await applyStateMessageFactory(validatorPeer.wallet, config)
155
- .buildCompleteTransactionOperationMessage(
156
- partial.address,
157
- b4a.from(partial.txo.tx, 'hex'),
158
- b4a.from(partial.txo.txv, 'hex'),
159
- b4a.from(partial.txo.iw, 'hex'),
160
- b4a.from(partial.txo.in, 'hex'),
161
- b4a.from(partial.txo.ch, 'hex'),
162
- b4a.from(partial.txo.is, 'hex'),
163
- b4a.from(partial.txo.bs, 'hex'),
164
- b4a.from(partial.txo.mbs, 'hex')
165
- );
166
- return safeEncodeApplyOperation(payload);
167
- }
168
-
169
- export async function buildTxOperationPayloadWithTxValidity(context, txValidity, options = {}) {
170
- if (!b4a.isBuffer(txValidity)) {
171
- throw new Error('buildTxOperationPayloadWithTxValidity requires a tx validity buffer.');
172
- }
173
- return buildTxOperationPayload(context, { ...options, txValidity });
174
- }
175
-
176
- export async function assertTxOperationSuccessState(
177
- t,
178
- context,
179
- {
180
- payload,
181
- validatorPeer = context.txOperation?.validatorPeer ?? selectValidatorPeer(context),
182
- deployerPeer = context.txOperation?.deployerPeer ?? selectDeployerPeer(context),
183
- broadcasterPeer = context.txOperation?.broadcasterPeer ?? selectBroadcasterPeer(context),
184
- creatorPeer = context.txOperation?.creatorPeer ?? deployerPeer,
185
- validatorEntryBefore = context.txOperation?.validatorEntryBefore?.value ?? null,
186
- deployerEntryBefore = context.txOperation?.deployerEntryBefore?.value ?? null,
187
- requesterEntryBefore = context.txOperation?.requesterEntryBefore?.value ?? null,
188
- distribution = 'standard', // 'standard' | 'requesterIsCreator' | 'validatorIsCreator'
189
- skipSync = false
190
- } = {}
191
- ) {
192
- if (!payload) throw new Error('assertTxOperationSuccessState requires the processed payload.');
193
-
194
- const decoded = safeDecodeApplyOperation(payload);
195
- t.ok(decoded, 'txOperation payload decodes');
196
- if (!decoded?.txo) return;
197
-
198
- const txHashBuffer = decoded.txo.tx;
199
- const requesterAddressBuffer = decoded.address;
200
- const validatorAddressBuffer = decoded.txo.va;
201
- const externalBootstrap = decoded.txo.bs;
202
- const msbBootstrap = decoded.txo.mbs;
203
-
204
- t.ok(requesterAddressBuffer, 'payload carries requester address');
205
- t.ok(validatorAddressBuffer, 'payload carries validator address');
206
- t.ok(txHashBuffer, 'payload exposes tx hash');
207
- if (externalBootstrap) {
208
- t.ok(b4a.equals(externalBootstrap, context.txOperation?.externalBootstrap), 'payload external bootstrap matches deployment');
209
- }
210
- if (msbBootstrap) {
211
- t.ok(b4a.equals(msbBootstrap, context.txOperation?.msbBootstrap), 'payload MSB bootstrap matches network');
212
- }
213
-
214
- const requesterAddress = addressUtils.bufferToAddress(requesterAddressBuffer, config.addressPrefix);
215
- const validatorAddress = addressUtils.bufferToAddress(validatorAddressBuffer, config.addressPrefix);
216
-
217
- t.is(requesterAddress, broadcasterPeer.wallet.address, 'requester matches broadcaster');
218
- t.is(validatorAddress, validatorPeer.wallet.address, 'validator matches selected peer');
219
-
220
- if (!validatorEntryBefore || !deployerEntryBefore || !requesterEntryBefore) {
221
- throw new Error('assertTxOperationSuccessState requires entry snapshots.');
222
- }
223
-
224
- const feeAmount = toBalance(transactionUtils.FEE);
225
- t.ok(feeAmount, 'fee decodes');
226
- if (!feeAmount) return;
227
-
228
- const requesterBeforeDecoded = nodeEntryUtils.decode(requesterEntryBefore);
229
- const validatorBeforeDecoded = nodeEntryUtils.decode(validatorEntryBefore);
230
- const deployerBeforeDecoded = nodeEntryUtils.decode(deployerEntryBefore);
231
-
232
- t.ok(requesterBeforeDecoded, 'requester entry before decodes');
233
- t.ok(validatorBeforeDecoded, 'validator entry before decodes');
234
- t.ok(deployerBeforeDecoded, 'deployer entry before decodes');
235
- if (!requesterBeforeDecoded || !validatorBeforeDecoded || !deployerBeforeDecoded) return;
236
-
237
- const requesterBalanceBefore = toBalance(requesterBeforeDecoded.balance);
238
- const validatorBalanceBefore = toBalance(validatorBeforeDecoded.balance);
239
- const deployerBalanceBefore = toBalance(deployerBeforeDecoded.balance);
240
-
241
- t.ok(requesterBalanceBefore, 'requester balance before decodes');
242
- t.ok(validatorBalanceBefore, 'validator balance before decodes');
243
- t.ok(deployerBalanceBefore, 'deployer balance before decodes');
244
- if (!requesterBalanceBefore || !validatorBalanceBefore || !deployerBalanceBefore) return;
245
-
246
- const expectedRequesterBalance = requesterBalanceBefore.sub(feeAmount);
247
- let expectedValidatorBalance = validatorBalanceBefore.add(feeAmount.percentage(PERCENT_50));
248
- let expectedDeployerBalance = deployerBalanceBefore.add(feeAmount.percentage(PERCENT_25));
249
-
250
- if (distribution === 'validatorIsCreator') {
251
- expectedValidatorBalance = validatorBalanceBefore.add(feeAmount.percentage(PERCENT_75));
252
- expectedDeployerBalance = null; // same as validator
253
- }
254
-
255
- if (distribution === 'requesterIsCreator') {
256
- expectedDeployerBalance = null; // requester is creator, no bonus
257
- }
258
-
259
- await context.sync();
260
- const requesterAfter = await validatorPeer.base.view.get(broadcasterPeer.wallet.address);
261
- const validatorAfter = await validatorPeer.base.view.get(validatorPeer.wallet.address);
262
- const deployerAfter = await validatorPeer.base.view.get(deployerPeer.wallet.address);
263
-
264
- t.ok(requesterAfter?.value, 'requester entry exists after tx');
265
- t.ok(validatorAfter?.value, 'validator entry exists after tx');
266
- t.ok(deployerAfter?.value, 'deployer entry exists after tx');
267
-
268
- const requesterDecoded = requesterAfter?.value ? nodeEntryUtils.decode(requesterAfter.value) : null;
269
- const validatorDecoded = validatorAfter?.value ? nodeEntryUtils.decode(validatorAfter.value) : null;
270
- const deployerDecoded = deployerAfter?.value ? nodeEntryUtils.decode(deployerAfter.value) : null;
271
-
272
- t.ok(requesterDecoded, 'requester entry decodes after tx');
273
- t.ok(validatorDecoded, 'validator entry decodes after tx');
274
- t.ok(deployerDecoded, 'deployer entry decodes after tx');
275
- if (!requesterDecoded || !validatorDecoded || !deployerDecoded) return;
276
-
277
- t.ok(
278
- b4a.equals(requesterDecoded.balance, expectedRequesterBalance.value),
279
- 'requester balance reduced by full fee'
280
- );
281
- t.ok(
282
- b4a.equals(validatorDecoded.balance, expectedValidatorBalance.value),
283
- distribution === 'validatorIsCreator'
284
- ? 'validator rewarded with 75% fee when creator'
285
- : 'validator rewarded with 50% fee'
286
- );
287
-
288
- if (distribution === 'standard') {
289
- t.ok(
290
- b4a.equals(deployerDecoded.balance, expectedDeployerBalance.value),
291
- 'deployer rewarded with 25% fee'
292
- );
293
- }
294
-
295
- if (distribution === 'requesterIsCreator') {
296
- t.ok(
297
- b4a.equals(requesterDecoded.balance, expectedRequesterBalance.value),
298
- 'requester pays full fee and receives no creator reward'
299
- );
300
- }
301
-
302
- if (distribution === 'validatorIsCreator') {
303
- // deployer is validator; nothing to assert on separate deployer entry
304
- }
305
-
306
- t.is(requesterDecoded.isWhitelisted, true, 'requester stays whitelisted');
307
- t.is(validatorDecoded.isWriter, true, 'validator remains a writer');
308
-
309
- const txEntry = await validatorPeer.base.view.get(txHashBuffer.toString('hex'));
310
- t.ok(txEntry, 'tx hash recorded for replay protection');
311
-
312
- const deploymentKey = `${EntryType.DEPLOYMENT}${externalBootstrap.toString('hex')}`;
313
- const deploymentEntry = await validatorPeer.base.view.get(deploymentKey);
314
- t.ok(deploymentEntry, 'deployment entry remains present after tx');
315
- const decodedDeployment = deploymentEntryUtils.decode(deploymentEntry?.value, config.addressLength);
316
- t.ok(decodedDeployment, 'deployment entry decodes after tx');
317
- if (decodedDeployment?.address) {
318
- const creatorAddress = addressUtils.bufferToAddress(decodedDeployment.address, config.addressPrefix);
319
- t.is(
320
- creatorAddress,
321
- creatorPeer.wallet.address,
322
- 'deployment entry still bound to subnetwork creator'
323
- );
324
- }
325
-
326
- if (!skipSync) {
327
- await context.sync();
328
- const replicaTxEntry = await broadcasterPeer.base.view.get(txHashBuffer.toString('hex'));
329
- t.ok(replicaTxEntry, 'tx entry replicated to broadcaster');
330
- }
331
- }
332
-
333
- export async function assertTxOperationFailureState(
334
- t,
335
- context,
336
- {
337
- payload,
338
- validatorPeer = context.txOperation?.validatorPeer ?? selectValidatorPeer(context),
339
- deployerPeer = context.txOperation?.deployerPeer ?? selectDeployerPeer(context),
340
- broadcasterPeer = context.txOperation?.broadcasterPeer ?? selectBroadcasterPeer(context),
341
- validatorEntryBefore = context.txOperation?.validatorEntryBefore?.value ?? null,
342
- deployerEntryBefore = context.txOperation?.deployerEntryBefore?.value ?? null,
343
- requesterEntryBefore = context.txOperation?.requesterEntryBefore?.value ?? null
344
- } = {}
345
- ) {
346
- if (!payload) throw new Error('assertTxOperationFailureState requires payload.');
347
-
348
- const decoded = safeDecodeApplyOperation(payload);
349
- t.ok(decoded, 'invalid tx payload decodes');
350
-
351
- if (validatorEntryBefore) {
352
- const after = await validatorPeer.base.view.get(validatorPeer.wallet.address);
353
- t.ok(after, 'validator entry still exists after rejection');
354
- if (after?.value) {
355
- t.ok(b4a.equals(after.value, validatorEntryBefore), 'validator entry unchanged after rejection');
356
- }
357
- }
358
-
359
- if (deployerEntryBefore) {
360
- const after = await validatorPeer.base.view.get(deployerPeer.wallet.address);
361
- t.ok(after, 'deployer entry still exists after rejection');
362
- if (after?.value) {
363
- t.ok(b4a.equals(after.value, deployerEntryBefore), 'deployer entry unchanged after rejection');
364
- }
365
- }
366
-
367
- if (requesterEntryBefore) {
368
- const after = await validatorPeer.base.view.get(broadcasterPeer.wallet.address);
369
- t.ok(after, 'requester entry still exists after rejection');
370
- if (after?.value) {
371
- t.ok(b4a.equals(after.value, requesterEntryBefore), 'requester entry unchanged after rejection');
372
- }
373
- }
374
-
375
- const txHashBuffer = decoded?.txo?.tx;
376
- if (txHashBuffer) {
377
- const txEntry = await validatorPeer.base.view.get(txHashBuffer.toString('hex'));
378
- t.is(txEntry, null, 'tx hash not recorded after rejection');
379
- }
380
- }
381
-
382
- export async function appendInvalidTxPayload(context, invalidPayload) {
383
- const node =
384
- context.bootstrap ?? context.adminBootstrap ?? context.txOperation?.validatorPeer ?? context.peers?.[0];
385
- await node.base.append(invalidPayload);
386
- await node.base.update();
387
- await eventFlush();
388
- }
389
-
390
- export function mutateBootstrapEqualMbs(t, validPayload) {
391
- const decoded = safeDecodeApplyOperation(validPayload);
392
- t.ok(decoded, 'fixtures decode');
393
- if (!decoded?.txo) return validPayload;
394
- decoded.txo.bs = decoded.txo.mbs;
395
- return safeEncodeApplyOperation(decoded);
396
- }
397
-
398
- export function mutateMbsMismatch(t, validPayload) {
399
- const decoded = safeDecodeApplyOperation(validPayload);
400
- t.ok(decoded, 'fixtures decode');
401
- if (!decoded?.txo) return validPayload;
402
- decoded.txo.mbs = b4a.alloc(decoded.txo.mbs?.length ?? 32, 0x7e);
403
- return safeEncodeApplyOperation(decoded);
404
- }
405
-
406
- export function mutateValidatorSignature(t, validPayload) {
407
- const decoded = safeDecodeApplyOperation(validPayload);
408
- t.ok(decoded, 'fixtures decode');
409
- const parent = decoded?.txo;
410
- if (!parent?.vs) return validPayload;
411
- const mutated = b4a.from(parent.vs);
412
- mutated[mutated.length - 1] ^= 0xff;
413
- parent.vs = mutated;
414
- return safeEncodeApplyOperation(decoded);
415
- }
416
-
417
- export function mutateBootstrapUnregistered(t, validPayload) {
418
- const decoded = safeDecodeApplyOperation(validPayload);
419
- t.ok(decoded, 'fixtures decode');
420
- const parent = decoded?.txo;
421
- if (!parent?.bs) return validPayload;
422
- const mutated = b4a.alloc(parent.bs.length, 0x24);
423
- parent.bs = mutated;
424
- return safeEncodeApplyOperation(decoded);
425
- }
426
-
427
- export default {
428
- setupTxOperationScenario,
429
- buildTxOperationPayload,
430
- assertTxOperationSuccessState,
431
- assertTxOperationFailureState
432
- };
@@ -1,21 +0,0 @@
1
- import { test } from 'brittle';
2
- import {
3
- setupTxOperationScenario,
4
- buildTxOperationPayload,
5
- assertTxOperationSuccessState
6
- } from './txOperationScenarioHelpers.js';
7
- import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
8
-
9
- export default function txOperationStandardHappyPathScenario() {
10
- test('State.apply txOperation processes subnetwork tx - happy path', async t => {
11
- const context = await setupTxOperationScenario(t);
12
- const payload = await buildTxOperationPayload(context);
13
- const validatorPeer = context.txOperation?.validatorPeer ?? context.adminBootstrap;
14
-
15
- await validatorPeer.base.append(payload);
16
- await validatorPeer.base.update();
17
- await eventFlush();
18
-
19
- await assertTxOperationSuccessState(t, context, { payload });
20
- });
21
- }
@@ -1,26 +0,0 @@
1
- import { createTransferFeeGuardScenario } from './txOperationTransferFeeGuardScenarioFactory.js';
2
- import { toBalance } from '../../../../../src/core/state/utils/balance.js';
3
- import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
4
-
5
- export default function txOperationTransferFeeAddCreatorBalanceFailureScenario() {
6
- createTransferFeeGuardScenario({
7
- title: 'State.transferFeeTxOperation rejects when adding fee to subnetwork creator balance fails',
8
- applyPatch: async () => {
9
- const feeAmount = toBalance(transactionUtils.FEE);
10
- const balanceProto = Object.getPrototypeOf(feeAmount);
11
- const originalAdd = balanceProto.add;
12
- let calls = 0;
13
- balanceProto.add = function (...args) {
14
- calls += 1;
15
- // validator add first, creator add second -> fail on second
16
- if (calls === 2) return null;
17
- return originalAdd.apply(this, args);
18
- };
19
-
20
- return () => {
21
- balanceProto.add = originalAdd;
22
- };
23
- },
24
- expectedLogs: ['Failed to add fee to subnetwork creator balance.']
25
- }).performScenario();
26
- }
@@ -1,25 +0,0 @@
1
- import { createTransferFeeGuardScenario } from './txOperationTransferFeeGuardScenarioFactory.js';
2
- import { toBalance } from '../../../../../src/core/state/utils/balance.js';
3
- import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
4
-
5
- export default function txOperationTransferFeeAddValidatorBalanceFailureScenario() {
6
- createTransferFeeGuardScenario({
7
- title: 'State.transferFeeTxOperation rejects when adding fee to validator balance fails',
8
- applyPatch: async () => {
9
- const feeAmount = toBalance(transactionUtils.FEE);
10
- const balanceProto = Object.getPrototypeOf(feeAmount);
11
- const originalAdd = balanceProto.add;
12
- let calls = 0;
13
- balanceProto.add = function (...args) {
14
- calls += 1;
15
- if (calls === 1) return null;
16
- return originalAdd.apply(this, args);
17
- };
18
-
19
- return () => {
20
- balanceProto.add = originalAdd;
21
- };
22
- },
23
- expectedLogs: ['Failed to add fee to validator balance.']
24
- }).performScenario();
25
- }
@@ -1,27 +0,0 @@
1
- import { createTransferFeeGuardScenario } from './txOperationTransferFeeGuardScenarioFactory.js';
2
- import { toBalance } from '../../../../../src/core/state/utils/balance.js';
3
- import transactionUtils from '../../../../../src/core/state/utils/transaction.js';
4
-
5
- export default function txOperationTransferFeeAddValidatorBonusFailureScenario() {
6
- createTransferFeeGuardScenario({
7
- title: 'State.transferFeeTxOperation rejects when adding validator bonus fee fails',
8
- setupOptions: { creatorPeerKind: 'validator' },
9
- applyPatch: async () => {
10
- const feeAmount = toBalance(transactionUtils.FEE);
11
- const balanceProto = Object.getPrototypeOf(feeAmount);
12
- const originalAdd = balanceProto.add;
13
- let calls = 0;
14
- balanceProto.add = function (...args) {
15
- calls += 1;
16
- // first add (50%) ok, second (bonus) fails
17
- if (calls === 2) return null;
18
- return originalAdd.apply(this, args);
19
- };
20
-
21
- return () => {
22
- balanceProto.add = originalAdd;
23
- };
24
- },
25
- expectedLogs: ['Failed to add bonus fee to validator balance.']
26
- }).performScenario();
27
- }
@@ -1,18 +0,0 @@
1
- import b4a from 'b4a';
2
- import { createTransferFeeGuardScenario, patchBatchGet } from './txOperationTransferFeeGuardScenarioFactory.js';
3
-
4
- export default function txOperationTransferFeeDecodeCreatorEntryScenario() {
5
- createTransferFeeGuardScenario({
6
- title: 'State.transferFeeTxOperation rejects undecodable subnetwork creator entry',
7
- applyPatch: async ({ context, node }) => {
8
- const creatorAddressString = context.txOperation?.deployerPeer?.wallet.address;
9
- const matcher = key => {
10
- if (!creatorAddressString) return false;
11
- if (typeof key === 'string') return key === creatorAddressString;
12
- return b4a.isBuffer(key) && b4a.toString(key, 'ascii') === creatorAddressString;
13
- };
14
- return patchBatchGet(node, matcher, () => ({ value: b4a.alloc(0) }));
15
- },
16
- expectedLogs: ['Invalid subnetwork creator node entry, can not to decode.']
17
- }).performScenario();
18
- }
@@ -1,17 +0,0 @@
1
- import b4a from 'b4a';
2
- import { createTransferFeeGuardScenario, patchBatchGet } from './txOperationTransferFeeGuardScenarioFactory.js';
3
-
4
- export default function txOperationTransferFeeDecodeRequesterEntryScenario() {
5
- createTransferFeeGuardScenario({
6
- title: 'State.transferFeeTxOperation rejects undecodable requester node entry',
7
- applyPatch: async ({ node, decoded, requesterAddressString }) => {
8
- const matcher = key => {
9
- if (!requesterAddressString) return false;
10
- if (typeof key === 'string') return key === requesterAddressString;
11
- return b4a.isBuffer(key) && b4a.toString(key, 'ascii') === requesterAddressString;
12
- };
13
- return patchBatchGet(node, matcher, () => ({ value: b4a.alloc(0) }));
14
- },
15
- expectedLogs: ['Invalid requester node entry, can not to decode.']
16
- }).performScenario();
17
- }
@@ -1,31 +0,0 @@
1
- import b4a from 'b4a';
2
- import nodeEntryUtils from '../../../../../src/core/state/utils/nodeEntry.js';
3
- import { createTransferFeeGuardScenario } from './txOperationTransferFeeGuardScenarioFactory.js';
4
-
5
- export default function txOperationTransferFeeDecodeValidatorEntryScenario() {
6
- createTransferFeeGuardScenario({
7
- title: 'State.transferFeeTxOperation rejects undecodable validator node entry',
8
- applyPatch: async ({ node, decoded }) => {
9
- const validatorAddressString = decoded?.txo?.va
10
- ? decoded.txo.va.toString('ascii')
11
- : node.wallet.address;
12
- const validatorEntry = await node.base.view.get(validatorAddressString);
13
- const validatorEntryBuffer = validatorEntry?.value ? b4a.from(validatorEntry.value) : null;
14
- const originalDecode = nodeEntryUtils.decode;
15
- let calls = 0;
16
-
17
- nodeEntryUtils.decode = entry => {
18
- if (validatorEntryBuffer && b4a.equals(entry, validatorEntryBuffer)) {
19
- calls += 1;
20
- if (calls === 2) return null; // first decode for validator checks ok, second fails
21
- }
22
- return originalDecode(entry);
23
- };
24
-
25
- return () => {
26
- nodeEntryUtils.decode = originalDecode;
27
- };
28
- },
29
- expectedLogs: ['Invalid validator node entry, can not to decode.']
30
- }).performScenario();
31
- }