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.
- package/README.md +62 -2
- package/SECURITY.md +9 -6
- package/cli/commandHandler.js +272 -0
- package/cli/handlers.js +210 -0
- package/cli/interactive.js +182 -0
- package/msb.mjs +7 -8
- package/package.json +25 -8
- package/rpc/create_server.js +44 -44
- package/rpc/handlers.js +43 -56
- package/rpc/routes/index.js +8 -8
- package/rpc/rpc_server.js +6 -2
- package/rpc/utils/helpers.js +46 -66
- package/scripts/pear-runner.js +170 -0
- package/src/config/args.js +60 -13
- package/src/config/config.js +138 -10
- package/src/config/env.js +36 -18
- package/src/core/network/Network.js +52 -24
- package/src/core/network/protocols/ProtocolInterface.js +5 -5
- package/src/core/network/protocols/connectionPolicies.js +86 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +1 -1
- package/src/core/network/protocols/legacy/handlers/BaseStateOperationHandler.js +2 -2
- package/src/core/network/protocols/legacy/handlers/LegacyGetRequestHandler.js +3 -3
- package/src/core/network/protocols/legacy/handlers/LegacyRoleOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacySubnetworkOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacyTransferOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
- package/src/core/network/protocols/shared/validators/PartialBootstrapDeploymentValidator.js +2 -2
- package/src/core/network/protocols/shared/validators/PartialOperationValidator.js +23 -23
- package/src/core/network/protocols/shared/validators/PartialRoleAccessValidator.js +14 -14
- package/src/core/network/protocols/shared/validators/PartialTransactionValidator.js +5 -5
- package/src/core/network/protocols/shared/validators/PartialTransferValidator.js +12 -11
- package/src/core/network/protocols/v1/V1ProtocolError.js +5 -69
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +3 -2
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +130 -247
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +6 -5
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +84 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +128 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +26 -0
- package/src/core/network/protocols/v1/validators/V1BaseOperation.js +32 -31
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +5 -3
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +34 -50
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +1 -1
- package/src/core/network/services/ConnectionManager.js +11 -10
- package/src/core/network/services/MessageOrchestrator.js +53 -17
- package/src/core/network/services/PendingRequestService.js +22 -19
- package/src/core/network/services/TransactionCommitService.js +36 -36
- package/src/core/network/services/TransactionPoolService.js +39 -39
- package/src/core/network/services/TransactionRateLimiterService.js +8 -4
- package/src/core/network/services/ValidatorObserverService.js +397 -110
- package/src/core/state/State.js +190 -138
- package/src/core/state/utils/address.js +4 -9
- package/src/core/state/utils/balance.js +7 -7
- package/src/core/state/utils/roles.js +1 -1
- package/src/index.js +316 -275
- package/src/messages/network/v1/NetworkMessageBuilder.js +12 -21
- package/src/messages/network/v1/networkMessageFactory.js +1 -1
- package/src/messages/state/ApplyStateMessageBuilder.js +6 -6
- package/src/messages/state/applyStateMessageFactory.js +1 -1
- package/src/utils/buffer.js +1 -1
- package/src/utils/check.js +12 -13
- package/src/utils/constants.js +7 -0
- package/src/utils/errors.js +20 -0
- package/src/utils/fileUtils.js +12 -3
- package/src/utils/helpers.js +2 -2
- package/src/utils/migrationUtils.js +3 -3
- package/.dockerignore +0 -16
- package/CODE_OF_CONDUCT.md +0 -128
- package/docker-compose.yml +0 -17
- package/dockerfile +0 -41
- package/docs/fee_distribution.md +0 -89
- package/docs/trac_network_http_api.openapi.yaml +0 -889
- package/migration/.gitkeep +0 -0
- package/proto/applyOperations.proto +0 -117
- package/proto/network/v1/enums/message_type.proto +0 -16
- package/proto/network/v1/enums/result_code.proto +0 -84
- package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
- package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
- package/proto/network/v1/messages/liveness_request.proto +0 -8
- package/proto/network/v1/messages/liveness_response.proto +0 -11
- package/proto/network/v1/network_message.proto +0 -22
- package/rpc/rpc_services.js +0 -181
- package/scripts/generate-protobufs.js +0 -67
- package/src/core/network/identity/NetworkWalletFactory.js +0 -77
- package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
- package/src/utils/cli.js +0 -130
- package/src/utils/cliCommands.js +0 -280
- package/tests/acceptance/v1/account/account.test.mjs +0 -129
- package/tests/acceptance/v1/balance/balance.test.mjs +0 -54
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +0 -116
- package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +0 -19
- package/tests/acceptance/v1/fee/fee.test.mjs +0 -11
- package/tests/acceptance/v1/health/health.test.mjs +0 -33
- package/tests/acceptance/v1/rpc.test.mjs +0 -95
- package/tests/acceptance/v1/tx/tx.test.mjs +0 -133
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -241
- package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +0 -72
- package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +0 -27
- package/tests/acceptance/v1/txv/txv.test.mjs +0 -11
- package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +0 -11
- package/tests/fixtures/apply.fixtures.js +0 -77
- package/tests/fixtures/assembleMessage.fixtures.js +0 -41
- package/tests/fixtures/check.fixtures.js +0 -428
- package/tests/fixtures/networkV1.fixtures.js +0 -59
- package/tests/fixtures/protobuf.fixtures.js +0 -388
- package/tests/helpers/StateNetworkFactory.js +0 -155
- package/tests/helpers/address.js +0 -6
- package/tests/helpers/autobaseTestHelpers.js +0 -419
- package/tests/helpers/config.js +0 -4
- package/tests/helpers/createTestSignature.js +0 -13
- package/tests/helpers/regexHelper.js +0 -3
- package/tests/helpers/setupApplyTests.js +0 -587
- package/tests/helpers/transactionPayloads.mjs +0 -92
- package/tests/helpers/wrapper.js +0 -28
- package/tests/unit/messages/messages.test.js +0 -12
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +0 -436
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -347
- package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +0 -525
- package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +0 -237
- package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
- package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
- package/tests/unit/network/ProtocolSession.test.js +0 -127
- package/tests/unit/network/networkModule.test.js +0 -13
- package/tests/unit/network/services/ConnectionManager.test.js +0 -450
- package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
- package/tests/unit/network/services/PendingRequestService.test.js +0 -431
- package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
- package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
- package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
- package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
- package/tests/unit/network/services/services.test.js +0 -17
- package/tests/unit/network/utils/v1TestUtils.js +0 -153
- package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
- package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
- package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
- package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
- package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
- package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
- package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
- package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
- package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
- package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
- package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
- package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
- package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
- package/tests/unit/network/v1/v1.handlers.test.js +0 -15
- package/tests/unit/network/v1/v1.test.js +0 -19
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
- package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
- package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
- package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
- package/tests/unit/state/State.test.js +0 -80
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +0 -42
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +0 -276
- package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +0 -78
- package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +0 -68
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +0 -159
- package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +0 -39
- package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +0 -167
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +0 -186
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +0 -443
- package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +0 -32
- package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +0 -297
- package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +0 -41
- package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +0 -149
- package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +0 -766
- package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +0 -50
- package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +0 -37
- package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +0 -42
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +0 -106
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +0 -309
- package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +0 -30
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +0 -881
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +0 -435
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +0 -78
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +0 -98
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +0 -66
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +0 -55
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +0 -103
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +0 -60
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +0 -189
- package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +0 -220
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +0 -111
- package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +0 -45
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +0 -189
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +0 -156
- package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +0 -36
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +0 -531
- package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +0 -74
- package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +0 -32
- package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +0 -38
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +0 -91
- package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +0 -266
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +0 -143
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +0 -26
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +0 -94
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +0 -37
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +0 -86
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +0 -347
- package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +0 -57
- package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +0 -429
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +0 -120
- package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +0 -130
- package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +0 -93
- package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +0 -108
- package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +0 -126
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +0 -121
- package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +0 -50
- package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +0 -56
- package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +0 -198
- package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +0 -40
- package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +0 -114
- package/tests/unit/state/apply/common/commonScenarioHelper.js +0 -103
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +0 -29
- package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +0 -66
- package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +0 -84
- package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +0 -47
- package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +0 -85
- package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +0 -52
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +0 -54
- package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +0 -73
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +0 -71
- package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +0 -31
- package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +0 -142
- package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +0 -87
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +0 -71
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +0 -73
- package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +0 -44
- package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +0 -25
- package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +0 -98
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +0 -202
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +0 -17
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +0 -44
- package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +0 -19
- package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +0 -18
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +0 -315
- package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +0 -18
- package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +0 -43
- package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +0 -53
- package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +0 -24
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +0 -204
- package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +0 -161
- package/tests/unit/state/apply/missing-tests.md +0 -18
- package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +0 -58
- package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +0 -98
- package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +0 -167
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +0 -429
- package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +0 -22
- package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +0 -20
- package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +0 -291
- package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +0 -87
- package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +0 -38
- package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +0 -348
- package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +0 -113
- package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +0 -33
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +0 -26
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +0 -22
- package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +0 -307
- package/tests/unit/state/apply/state.apply.test.js +0 -24
- package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +0 -819
- package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +0 -22
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +0 -146
- package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +0 -63
- package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +0 -67
- package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +0 -22
- package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +0 -8
- package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +0 -66
- package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +0 -1170
- package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +0 -318
- package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +0 -70
- package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +0 -23
- package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +0 -48
- package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +0 -39
- package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +0 -46
- package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +0 -432
- package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +0 -31
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +0 -49
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +0 -93
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +0 -29
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +0 -33
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/stateModule.test.js +0 -23
- package/tests/unit/state/stateTestUtils.js +0 -32
- package/tests/unit/state/utils/address.test.js +0 -63
- package/tests/unit/state/utils/adminEntry.test.js +0 -52
- package/tests/unit/state/utils/balance.test.js +0 -320
- package/tests/unit/state/utils/lengthEntry.test.js +0 -54
- package/tests/unit/state/utils/nodeEntry.test.js +0 -298
- package/tests/unit/state/utils/roles.test.js +0 -44
- package/tests/unit/unit.test.js +0 -14
- package/tests/unit/utils/amountSerialization/amountSerialization.test.js +0 -237
- package/tests/unit/utils/buffer/buffer.test.js +0 -251
- package/tests/unit/utils/check/adminControlOperation.test.js +0 -156
- package/tests/unit/utils/check/balanceInitializationOperation.test.js +0 -54
- package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +0 -104
- package/tests/unit/utils/check/check.test.js +0 -17
- package/tests/unit/utils/check/common.test.js +0 -419
- package/tests/unit/utils/check/coreAdminOperation.test.js +0 -95
- package/tests/unit/utils/check/roleAccessOperation.test.js +0 -255
- package/tests/unit/utils/check/transactionOperation.test.js +0 -107
- package/tests/unit/utils/check/transferOperation.test.js +0 -102
- package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +0 -95
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +0 -149
- package/tests/unit/utils/helpers/helpers.test.js +0 -11
- package/tests/unit/utils/helpers/isHexString.test.js +0 -12
- package/tests/unit/utils/helpers/normalizeHex.test.js +0 -82
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +0 -100
- package/tests/unit/utils/normalizers/normalizers.test.js +0 -469
- package/tests/unit/utils/protobuf/applyOperations.test.js +0 -91
- package/tests/unit/utils/protobuf/operationHelpers.test.js +0 -303
- package/tests/unit/utils/protobuf/protobuf.test.js +0 -12
- package/tests/unit/utils/type/type.test.js +0 -25
- package/tests/unit/utils/utils.test.js +0 -21
- package/whitelist/.gitkeep +0 -0
|
@@ -1,450 +0,0 @@
|
|
|
1
|
-
import sinon from "sinon";
|
|
2
|
-
import { hook, test } from 'brittle'
|
|
3
|
-
import { default as EventEmitter } from "bare-events"
|
|
4
|
-
import { testKeyPair1, testKeyPair2, testKeyPair3, testKeyPair4, testKeyPair5, testKeyPair6, testKeyPair7, testKeyPair8 } from "../../../fixtures/apply.fixtures.js";
|
|
5
|
-
import ConnectionManager, { ConnectionManagerError } from "../../../../src/core/network/services/ConnectionManager.js";
|
|
6
|
-
import { tick } from "../../../helpers/setupApplyTests.js";
|
|
7
|
-
import b4a from 'b4a'
|
|
8
|
-
import { createConfig, ENV } from "../../../../src/config/env.js";
|
|
9
|
-
import { EventType, ResultCode } from "../../../../src/utils/constants.js";
|
|
10
|
-
|
|
11
|
-
const createConnection = (key) => {
|
|
12
|
-
const emitter = new EventEmitter()
|
|
13
|
-
emitter.protocolSession = {
|
|
14
|
-
has: (name) => name === 'legacy',
|
|
15
|
-
send: sinon.stub().resolves(),
|
|
16
|
-
};
|
|
17
|
-
emitter.connected = true
|
|
18
|
-
emitter.remotePublicKey = b4a.from(key, 'hex')
|
|
19
|
-
|
|
20
|
-
return { key: b4a.from(key, 'hex'), connection: emitter }
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const createV1Connection = (key, sendHealthCheckStub = sinon.stub().resolves(ResultCode.OK)) => {
|
|
24
|
-
const emitter = new EventEmitter()
|
|
25
|
-
emitter.protocolSession = {
|
|
26
|
-
sendHealthCheck: sendHealthCheckStub
|
|
27
|
-
};
|
|
28
|
-
emitter.connected = true
|
|
29
|
-
emitter.remotePublicKey = b4a.from(key, 'hex')
|
|
30
|
-
emitter.end = sinon.stub()
|
|
31
|
-
|
|
32
|
-
return { key: b4a.from(key, 'hex'), connection: emitter }
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const makeHealthCheckService = () => {
|
|
36
|
-
const emitter = new EventEmitter();
|
|
37
|
-
emitter.has = sinon.stub().returns(true);
|
|
38
|
-
emitter.stop = sinon.stub();
|
|
39
|
-
return emitter;
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
const makeManager = (maxValidators = 6, conns = connections) => {
|
|
43
|
-
const merged = createConfig(ENV.DEVELOPMENT, { maxValidators })
|
|
44
|
-
const connectionManager = new ConnectionManager(merged)
|
|
45
|
-
|
|
46
|
-
conns.forEach(({ key, connection }) => {
|
|
47
|
-
connectionManager.addValidator(key, connection)
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
return connectionManager
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const reset = () => {
|
|
54
|
-
sinon.restore()
|
|
55
|
-
connections.forEach(connection => {
|
|
56
|
-
connection.connection.protocolSession.send.resetHistory()
|
|
57
|
-
})
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
let connections
|
|
61
|
-
hook('Initialize state', async () => {
|
|
62
|
-
connections = [
|
|
63
|
-
createConnection(testKeyPair1.publicKey),
|
|
64
|
-
createConnection(testKeyPair2.publicKey),
|
|
65
|
-
createConnection(testKeyPair3.publicKey),
|
|
66
|
-
createConnection(testKeyPair4.publicKey),
|
|
67
|
-
]
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('ConnectionManager', () => {
|
|
71
|
-
test('addValidator', async t => {
|
|
72
|
-
test('adds a validator', async t => {
|
|
73
|
-
reset()
|
|
74
|
-
const connectionManager = makeManager()
|
|
75
|
-
t.is(connectionManager.connectionCount(), connections.length, 'should have the same length')
|
|
76
|
-
const data = createConnection(testKeyPair5.publicKey)
|
|
77
|
-
connectionManager.addValidator(data.key, data.connection)
|
|
78
|
-
t.is(connectionManager.connectionCount(), connections.length + 1, 'should have the same length')
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
test('dont surpass maxConnections', async t => {
|
|
82
|
-
reset()
|
|
83
|
-
const maxConnections = 5
|
|
84
|
-
const connectionManager = makeManager(maxConnections)
|
|
85
|
-
t.is(connectionManager.connectionCount(), connections.length, 'should have the same length')
|
|
86
|
-
|
|
87
|
-
const toAdd = createConnection(testKeyPair5.publicKey)
|
|
88
|
-
connectionManager.addValidator(toAdd.key, toAdd.connection)
|
|
89
|
-
t.is(connectionManager.connectionCount(), maxConnections, 'should match the max connections')
|
|
90
|
-
|
|
91
|
-
const toNotAdd = createConnection(testKeyPair6.publicKey)
|
|
92
|
-
connectionManager.addValidator(toNotAdd.key, toNotAdd.connection)
|
|
93
|
-
t.is(connectionManager.connectionCount(), maxConnections, 'should not increase length')
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
test('does not add new validator when pool is full', async t => {
|
|
97
|
-
reset()
|
|
98
|
-
const maxConnections = 2
|
|
99
|
-
const localConnections = [
|
|
100
|
-
createConnection(testKeyPair1.publicKey),
|
|
101
|
-
createConnection(testKeyPair2.publicKey),
|
|
102
|
-
]
|
|
103
|
-
|
|
104
|
-
const connectionManager = makeManager(maxConnections)
|
|
105
|
-
localConnections.forEach(({ key, connection }) => {
|
|
106
|
-
connectionManager.addValidator(key, connection)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
t.is(connectionManager.connectionCount(), maxConnections, 'pool should be full')
|
|
110
|
-
|
|
111
|
-
const newConn = createConnection(testKeyPair3.publicKey)
|
|
112
|
-
connectionManager.addValidator(newConn.key, newConn.connection)
|
|
113
|
-
|
|
114
|
-
t.is(connectionManager.connectionCount(), maxConnections, 'should stay at max size')
|
|
115
|
-
t.not(connectionManager.connected(newConn.key), 'new validator should not be in the pool')
|
|
116
|
-
|
|
117
|
-
const remainingOld = localConnections.filter(c => connectionManager.connected(c.key)).length
|
|
118
|
-
t.is(remainingOld, 2, 'all of the old validators should remain')
|
|
119
|
-
})
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
test('connected', async t => {
|
|
123
|
-
test('true', async t => {
|
|
124
|
-
reset()
|
|
125
|
-
const connectionManager = makeManager()
|
|
126
|
-
connections.forEach(con => {
|
|
127
|
-
t.ok(connectionManager.connected(con.key), 'should respond true')
|
|
128
|
-
})
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
test('false', async t => {
|
|
132
|
-
reset()
|
|
133
|
-
const connectionManager = makeManager()
|
|
134
|
-
t.ok(!connectionManager.connected(testKeyPair6.publicKey), 'should respond false')
|
|
135
|
-
})
|
|
136
|
-
})
|
|
137
|
-
|
|
138
|
-
test('sendSingleMessage', async t => {
|
|
139
|
-
test('returns exact resultCode from protocolSession.send', async t => {
|
|
140
|
-
reset()
|
|
141
|
-
const data = createConnection(testKeyPair1.publicKey)
|
|
142
|
-
data.connection.protocolSession.send = sinon.stub().resolves(ResultCode.TIMEOUT)
|
|
143
|
-
const connectionManager = makeManager(6, [data])
|
|
144
|
-
|
|
145
|
-
const result = await connectionManager.sendSingleMessage({ payload: 1 }, testKeyPair1.publicKey)
|
|
146
|
-
|
|
147
|
-
t.is(result, ResultCode.TIMEOUT, 'should return the exact result code from protocol session')
|
|
148
|
-
t.ok(data.connection.protocolSession.send.calledOnce, 'should invoke protocolSession.send')
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
test('throws ConnectionManagerError when validator is disconnected', async t => {
|
|
152
|
-
reset()
|
|
153
|
-
const connectionManager = makeManager()
|
|
154
|
-
|
|
155
|
-
try {
|
|
156
|
-
await connectionManager.sendSingleMessage({ payload: 1 }, testKeyPair8.publicKey)
|
|
157
|
-
t.fail('expected sendSingleMessage to throw')
|
|
158
|
-
} catch (error) {
|
|
159
|
-
t.ok(error instanceof ConnectionManagerError, 'should throw ConnectionManagerError')
|
|
160
|
-
t.ok(error.message.includes('is not connected'), 'should include disconnected validator details')
|
|
161
|
-
}
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
test('throws ConnectionManagerError when protocolSession is missing', async t => {
|
|
165
|
-
reset()
|
|
166
|
-
const emitter = new EventEmitter()
|
|
167
|
-
emitter.connected = true
|
|
168
|
-
emitter.remotePublicKey = b4a.from(testKeyPair6.publicKey, 'hex')
|
|
169
|
-
emitter.end = sinon.stub()
|
|
170
|
-
const data = {
|
|
171
|
-
key: b4a.from(testKeyPair6.publicKey, 'hex'),
|
|
172
|
-
connection: emitter,
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const connectionManager = makeManager(6, [data])
|
|
176
|
-
|
|
177
|
-
try {
|
|
178
|
-
await connectionManager.sendSingleMessage({ payload: 1 }, testKeyPair6.publicKey)
|
|
179
|
-
t.fail('expected sendSingleMessage to throw')
|
|
180
|
-
} catch (error) {
|
|
181
|
-
t.ok(error instanceof ConnectionManagerError, 'should throw ConnectionManagerError')
|
|
182
|
-
t.ok(error.message.includes('no valid connection found'), 'should include protocol session details')
|
|
183
|
-
}
|
|
184
|
-
})
|
|
185
|
-
})
|
|
186
|
-
|
|
187
|
-
// Note: These tests were commented out because connectionManager.send is being deprecated. When it is completely removed, the tests should be deleted.
|
|
188
|
-
// test('send', async t => {
|
|
189
|
-
// // test('triggers send on messenger', async t => {
|
|
190
|
-
// // reset()
|
|
191
|
-
// // const connectionManager = makeManager()
|
|
192
|
-
|
|
193
|
-
// // const target = connectionManager.send([1,2,3,4])
|
|
194
|
-
|
|
195
|
-
// // const totalCalls = connections.reduce((sum, con) => sum + con.connection.protocolSession.send.callCount, 0)
|
|
196
|
-
// // t.is(totalCalls, 1, 'should send to exactly one validator')
|
|
197
|
-
// // t.ok(target, 'should return a target public key')
|
|
198
|
-
// // })
|
|
199
|
-
|
|
200
|
-
// test('does not throw on individual send errors', async t => {
|
|
201
|
-
// reset()
|
|
202
|
-
// const errorConnections = [
|
|
203
|
-
// createConnection(testKeyPair7.publicKey),
|
|
204
|
-
// createConnection(testKeyPair8.publicKey),
|
|
205
|
-
// ]
|
|
206
|
-
|
|
207
|
-
// errorConnections.forEach(con => {
|
|
208
|
-
// con.connection.protocolSession.send = sinon.stub().throws(new Error())
|
|
209
|
-
// })
|
|
210
|
-
|
|
211
|
-
// const connectionManager = makeManager(5, errorConnections)
|
|
212
|
-
|
|
213
|
-
// t.is(errorConnections.length, 2, 'should have two connections')
|
|
214
|
-
// connectionManager.send([1,2,3,4])
|
|
215
|
-
// t.ok(true, 'send should not throw even if individual sends fail')
|
|
216
|
-
// })
|
|
217
|
-
// })
|
|
218
|
-
|
|
219
|
-
test('on close', async t => {
|
|
220
|
-
test('removes from list', async t => {
|
|
221
|
-
reset()
|
|
222
|
-
const connectionManager = makeManager()
|
|
223
|
-
|
|
224
|
-
const connectionCount = connectionManager.connectionCount()
|
|
225
|
-
|
|
226
|
-
connections[1].connection.connected = false
|
|
227
|
-
connections[1].connection.emit('close')
|
|
228
|
-
await tick()
|
|
229
|
-
t.is(connectionCount, connectionManager.connectionCount() + 1, 'first on the list should have been called')
|
|
230
|
-
})
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
test('remove', async t => {
|
|
234
|
-
test('removes a validator by public key', async t => {
|
|
235
|
-
reset()
|
|
236
|
-
const connectionManager = makeManager()
|
|
237
|
-
const previousCount = connectionManager.connectionCount()
|
|
238
|
-
const lastValidator = connections.shift()
|
|
239
|
-
|
|
240
|
-
t.ok(connectionManager.connected(lastValidator.key), 'should be connected')
|
|
241
|
-
connectionManager.remove(lastValidator.key)
|
|
242
|
-
|
|
243
|
-
t.is(connectionManager.connectionCount(), previousCount - 1, 'should reduce the connection count')
|
|
244
|
-
t.ok(!connectionManager.connected(lastValidator.key), 'should be connected')
|
|
245
|
-
})
|
|
246
|
-
})
|
|
247
|
-
|
|
248
|
-
test('on close', async t => {
|
|
249
|
-
test('removes from list', async t => {
|
|
250
|
-
reset()
|
|
251
|
-
const connectionManager = makeManager()
|
|
252
|
-
|
|
253
|
-
const connectionCount = connectionManager.connectionCount()
|
|
254
|
-
|
|
255
|
-
connections[1].connection.connected = false
|
|
256
|
-
connections[1].connection.emit('close')
|
|
257
|
-
await tick()
|
|
258
|
-
t.is(connectionCount, connectionManager.connectionCount() + 1, 'first on the list should have been called')
|
|
259
|
-
})
|
|
260
|
-
})
|
|
261
|
-
|
|
262
|
-
test('health checks (strict)', async t => {
|
|
263
|
-
test('keeps validator on OK response', async t => {
|
|
264
|
-
try {
|
|
265
|
-
const v1Conn = createV1Connection(testKeyPair1.publicKey, sinon.stub().resolves(ResultCode.OK));
|
|
266
|
-
const connectionManager = makeManager(6, [v1Conn]);
|
|
267
|
-
const healthCheckService = makeHealthCheckService();
|
|
268
|
-
connectionManager.subscribeToHealthChecks(healthCheckService);
|
|
269
|
-
|
|
270
|
-
healthCheckService.emit(
|
|
271
|
-
EventType.VALIDATOR_HEALTH_CHECK,
|
|
272
|
-
testKeyPair1.publicKey,
|
|
273
|
-
"123456"
|
|
274
|
-
);
|
|
275
|
-
|
|
276
|
-
await tick();
|
|
277
|
-
t.ok(connectionManager.connected(v1Conn.key));
|
|
278
|
-
t.is(healthCheckService.stop.callCount, 0);
|
|
279
|
-
} finally {
|
|
280
|
-
sinon.restore();
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
test('removes validator on non-OK response', async t => {
|
|
285
|
-
try {
|
|
286
|
-
const v1Conn = createV1Connection(testKeyPair2.publicKey, sinon.stub().resolves(ResultCode.TIMEOUT));
|
|
287
|
-
const connectionManager = makeManager(6, [v1Conn]);
|
|
288
|
-
const healthCheckService = makeHealthCheckService();
|
|
289
|
-
connectionManager.subscribeToHealthChecks(healthCheckService);
|
|
290
|
-
|
|
291
|
-
healthCheckService.emit(
|
|
292
|
-
EventType.VALIDATOR_HEALTH_CHECK,
|
|
293
|
-
testKeyPair2.publicKey,
|
|
294
|
-
"123456"
|
|
295
|
-
);
|
|
296
|
-
|
|
297
|
-
await tick();
|
|
298
|
-
t.ok(!connectionManager.connected(v1Conn.key));
|
|
299
|
-
t.ok(healthCheckService.stop.callCount >= 1);
|
|
300
|
-
} finally {
|
|
301
|
-
sinon.restore();
|
|
302
|
-
}
|
|
303
|
-
});
|
|
304
|
-
|
|
305
|
-
test('removes validator on send rejection', async t => {
|
|
306
|
-
try {
|
|
307
|
-
const v1Conn = createV1Connection(testKeyPair3.publicKey, sinon.stub().rejects(new Error('boom')));
|
|
308
|
-
const connectionManager = makeManager(6, [v1Conn]);
|
|
309
|
-
const healthCheckService = makeHealthCheckService();
|
|
310
|
-
connectionManager.subscribeToHealthChecks(healthCheckService);
|
|
311
|
-
|
|
312
|
-
healthCheckService.emit(
|
|
313
|
-
EventType.VALIDATOR_HEALTH_CHECK,
|
|
314
|
-
testKeyPair3.publicKey,
|
|
315
|
-
"123456"
|
|
316
|
-
);
|
|
317
|
-
|
|
318
|
-
await tick();
|
|
319
|
-
t.ok(!connectionManager.connected(v1Conn.key));
|
|
320
|
-
t.ok(healthCheckService.stop.callCount >= 1);
|
|
321
|
-
} finally {
|
|
322
|
-
sinon.restore();
|
|
323
|
-
}
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
test('ignores malformed health check events', async t => {
|
|
327
|
-
try {
|
|
328
|
-
const v1Conn = createV1Connection(testKeyPair5.publicKey, sinon.stub().resolves(ResultCode.OK));
|
|
329
|
-
const connectionManager = makeManager(6, [v1Conn]);
|
|
330
|
-
let handler = null;
|
|
331
|
-
const healthCheckService = {
|
|
332
|
-
on: (_event, fn) => { handler = fn; },
|
|
333
|
-
off: () => {},
|
|
334
|
-
has: sinon.stub().returns(true),
|
|
335
|
-
stop: sinon.stub()
|
|
336
|
-
};
|
|
337
|
-
connectionManager.subscribeToHealthChecks(healthCheckService);
|
|
338
|
-
|
|
339
|
-
const cases = [
|
|
340
|
-
{ label: 'publicKey', publicKey: 123, requestId: 'abc' },
|
|
341
|
-
{ label: 'requestId', publicKey: testKeyPair5.publicKey, requestId: 456 },
|
|
342
|
-
{ label: 'undefined', publicKey: undefined, requestId: undefined },
|
|
343
|
-
];
|
|
344
|
-
|
|
345
|
-
for (const testCase of cases) {
|
|
346
|
-
await handler(testCase.publicKey, testCase.requestId);
|
|
347
|
-
t.pass(`ignored malformed payload: ${testCase.label}`);
|
|
348
|
-
}
|
|
349
|
-
} finally {
|
|
350
|
-
sinon.restore();
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
})
|
|
354
|
-
|
|
355
|
-
test('edge branches', async t => {
|
|
356
|
-
test('pickRandomValidator returns null for empty array', async t => {
|
|
357
|
-
reset()
|
|
358
|
-
const connectionManager = makeManager()
|
|
359
|
-
t.is(connectionManager.pickRandomValidator([]), null)
|
|
360
|
-
})
|
|
361
|
-
|
|
362
|
-
test('pickRandomConnectedValidator returns null when pool is empty', async t => {
|
|
363
|
-
reset()
|
|
364
|
-
const connectionManager = makeManager(6, [])
|
|
365
|
-
t.is(connectionManager.pickRandomConnectedValidator(), null)
|
|
366
|
-
})
|
|
367
|
-
|
|
368
|
-
test('remove missing validator keeps state unchanged', async t => {
|
|
369
|
-
reset()
|
|
370
|
-
const connectionManager = makeManager()
|
|
371
|
-
const before = connectionManager.connectionCount()
|
|
372
|
-
connectionManager.remove(testKeyPair8.publicKey)
|
|
373
|
-
t.is(connectionManager.connectionCount(), before)
|
|
374
|
-
})
|
|
375
|
-
|
|
376
|
-
test('remove handles connection.end throwing and still deletes validator', async t => {
|
|
377
|
-
reset()
|
|
378
|
-
const data = createConnection(testKeyPair7.publicKey)
|
|
379
|
-
data.connection.end = sinon.stub().throws(new Error('end boom'))
|
|
380
|
-
const connectionManager = makeManager(6, [data])
|
|
381
|
-
|
|
382
|
-
t.ok(connectionManager.connected(data.key))
|
|
383
|
-
connectionManager.remove(data.key)
|
|
384
|
-
t.absent(connectionManager.connected(data.key))
|
|
385
|
-
})
|
|
386
|
-
|
|
387
|
-
test('sent counters handle missing validators safely', async t => {
|
|
388
|
-
reset()
|
|
389
|
-
const connectionManager = makeManager()
|
|
390
|
-
t.is(connectionManager.getSentCount(testKeyPair8.publicKey), 0)
|
|
391
|
-
connectionManager.incrementSentCount(testKeyPair8.publicKey)
|
|
392
|
-
t.is(connectionManager.getSentCount(testKeyPair8.publicKey), 0)
|
|
393
|
-
})
|
|
394
|
-
|
|
395
|
-
test('subscribeToHealthChecks validates service interface', async t => {
|
|
396
|
-
reset()
|
|
397
|
-
const connectionManager = makeManager()
|
|
398
|
-
|
|
399
|
-
await t.exception(
|
|
400
|
-
() => connectionManager.subscribeToHealthChecks({ on() {} }),
|
|
401
|
-
/must implement on\/off/
|
|
402
|
-
)
|
|
403
|
-
})
|
|
404
|
-
|
|
405
|
-
test('health check removes validator when protocolSession is missing', async t => {
|
|
406
|
-
reset()
|
|
407
|
-
const emitter = new EventEmitter()
|
|
408
|
-
emitter.connected = true
|
|
409
|
-
emitter.remotePublicKey = b4a.from(testKeyPair6.publicKey, 'hex')
|
|
410
|
-
emitter.end = sinon.stub()
|
|
411
|
-
const data = {
|
|
412
|
-
key: b4a.from(testKeyPair6.publicKey, 'hex'),
|
|
413
|
-
connection: emitter
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
const connectionManager = makeManager(6, [data])
|
|
417
|
-
const healthCheckService = {
|
|
418
|
-
on: (_event, fn) => { healthCheckService.handler = fn; },
|
|
419
|
-
off: () => {},
|
|
420
|
-
has: sinon.stub().returns(true),
|
|
421
|
-
stop: sinon.stub(),
|
|
422
|
-
handler: null,
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
connectionManager.subscribeToHealthChecks(healthCheckService)
|
|
426
|
-
await healthCheckService.handler(testKeyPair6.publicKey, 'hc-1')
|
|
427
|
-
|
|
428
|
-
t.absent(connectionManager.connected(data.key))
|
|
429
|
-
t.ok(healthCheckService.stop.called)
|
|
430
|
-
})
|
|
431
|
-
|
|
432
|
-
test('remove tolerates health check service errors', async t => {
|
|
433
|
-
reset()
|
|
434
|
-
const data = createConnection(testKeyPair5.publicKey)
|
|
435
|
-
const connectionManager = makeManager(6, [data])
|
|
436
|
-
const healthCheckService = {
|
|
437
|
-
on: (_event, fn) => { healthCheckService.handler = fn; },
|
|
438
|
-
off: () => {},
|
|
439
|
-
has: sinon.stub().throws(new Error('has boom')),
|
|
440
|
-
stop: sinon.stub(),
|
|
441
|
-
handler: null,
|
|
442
|
-
}
|
|
443
|
-
connectionManager.subscribeToHealthChecks(healthCheckService)
|
|
444
|
-
|
|
445
|
-
connectionManager.remove(data.key)
|
|
446
|
-
|
|
447
|
-
t.absent(connectionManager.connected(data.key))
|
|
448
|
-
})
|
|
449
|
-
})
|
|
450
|
-
})
|