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,512 +0,0 @@
|
|
|
1
|
-
import {test} from 'brittle';
|
|
2
|
-
import b4a from 'b4a';
|
|
3
|
-
import Autobase from 'autobase';
|
|
4
|
-
import Hypercore from 'hypercore';
|
|
5
|
-
|
|
6
|
-
import V1BroadcastTransactionResponse, {extractRequiredVaFromDecodedTx} from '../../../../src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js';
|
|
7
|
-
import {V1ProtocolError} from '../../../../src/core/network/protocols/v1/V1ProtocolError.js';
|
|
8
|
-
import Check from '../../../../src/utils/check.js';
|
|
9
|
-
import {
|
|
10
|
-
unsafeEncodeApplyOperation,
|
|
11
|
-
unsafeDecodeApplyOperation,
|
|
12
|
-
} from '../../../../src/utils/protobuf/operationHelpers.js';
|
|
13
|
-
import {addressToBuffer} from '../../../../src/core/state/utils/address.js';
|
|
14
|
-
import {publicKeyToAddress} from '../../../../src/utils/helpers.js';
|
|
15
|
-
import {OperationType, ResultCode} from '../../../../src/utils/constants.js';
|
|
16
|
-
import { config } from '../../../helpers/config.js';
|
|
17
|
-
import protobufFixtures from '../../../fixtures/protobuf.fixtures.js';
|
|
18
|
-
import { testKeyPair1 } from '../../../fixtures/apply.fixtures.js';
|
|
19
|
-
|
|
20
|
-
const remotePublicKey = b4a.from(testKeyPair1.publicKey, 'hex');
|
|
21
|
-
const remoteAddressBuffer = addressToBuffer(publicKeyToAddress(remotePublicKey, config), config.addressPrefix);
|
|
22
|
-
const writerKey = b4a.alloc(32, 2);
|
|
23
|
-
|
|
24
|
-
const createState = (overrides = {}) => ({
|
|
25
|
-
verifyProofOfPublication: async () => ({ ok: true }),
|
|
26
|
-
getRegisteredWriterKey: async () => remoteAddressBuffer,
|
|
27
|
-
getNodeEntry: async () => ({
|
|
28
|
-
isWriter: true,
|
|
29
|
-
wk: writerKey,
|
|
30
|
-
}),
|
|
31
|
-
...overrides
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const createValidator = (stateOverrides = {}) =>
|
|
35
|
-
new V1BroadcastTransactionResponse(createState(stateOverrides), config);
|
|
36
|
-
|
|
37
|
-
const overrideCheckMethods = (t, overrides) => {
|
|
38
|
-
const originals = {};
|
|
39
|
-
for (const [name, impl] of Object.entries(overrides)) {
|
|
40
|
-
originals[name] = Check.prototype[name];
|
|
41
|
-
Check.prototype[name] = impl;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
t.teardown(() => {
|
|
45
|
-
for (const [name, original] of Object.entries(originals)) {
|
|
46
|
-
Check.prototype[name] = original;
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
const overrideFunction = (t, target, key, replacement) => {
|
|
52
|
-
const original = target[key];
|
|
53
|
-
target[key] = replacement;
|
|
54
|
-
t.teardown(() => {
|
|
55
|
-
target[key] = original;
|
|
56
|
-
});
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
test('extractRequiredVaFromDecodedTx throws VALIDATOR_TX_OBJECT_INVALID for non-object', t => {
|
|
60
|
-
try {
|
|
61
|
-
extractRequiredVaFromDecodedTx(null);
|
|
62
|
-
t.fail('expected throw');
|
|
63
|
-
} catch (err) {
|
|
64
|
-
t.is(err.resultCode, ResultCode.VALIDATOR_TX_OBJECT_INVALID);
|
|
65
|
-
}
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
test('extractRequiredVaFromDecodedTx throws VALIDATOR_VA_MISSING when va is missing', t => {
|
|
69
|
-
try {
|
|
70
|
-
extractRequiredVaFromDecodedTx({type: 1, txo: {tx: b4a.alloc(32)}});
|
|
71
|
-
t.fail('expected throw');
|
|
72
|
-
} catch (err) {
|
|
73
|
-
t.is(err.resultCode, ResultCode.VALIDATOR_VA_MISSING);
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('extractRequiredVaFromDecodedTx returns va buffer when present', t => {
|
|
78
|
-
const va = b4a.alloc(39, 1);
|
|
79
|
-
const extracted = extractRequiredVaFromDecodedTx({
|
|
80
|
-
type: OperationType.TX,
|
|
81
|
-
txo: {va}
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
t.ok(b4a.equals(extracted, va));
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('validate skips proof validation when result code is non-OK', async t => {
|
|
88
|
-
const validator = createValidator();
|
|
89
|
-
let proofCalled = false;
|
|
90
|
-
|
|
91
|
-
validator.isPayloadSchemaValid = () => true;
|
|
92
|
-
validator.validateResponseType = () => true;
|
|
93
|
-
validator.validatePeerCorrectness = () => true;
|
|
94
|
-
validator.validateSignature = async () => true;
|
|
95
|
-
validator.verifyProofOfPublication = async () => {
|
|
96
|
-
proofCalled = true;
|
|
97
|
-
return {};
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
const payload = {
|
|
101
|
-
broadcast_transaction_response: {
|
|
102
|
-
result: ResultCode.TIMEOUT,
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
const result = await validator.validate(
|
|
107
|
-
payload,
|
|
108
|
-
{ remotePublicKey: b4a.alloc(32, 1) },
|
|
109
|
-
{},
|
|
110
|
-
null
|
|
111
|
-
);
|
|
112
|
-
|
|
113
|
-
t.is(result, true);
|
|
114
|
-
t.absent(proofCalled);
|
|
115
|
-
});
|
|
116
|
-
|
|
117
|
-
test('validate runs proof validation pipeline when result code is OK', async t => {
|
|
118
|
-
const validator = createValidator();
|
|
119
|
-
const calls = [];
|
|
120
|
-
|
|
121
|
-
validator.isPayloadSchemaValid = () => calls.push('schema');
|
|
122
|
-
validator.validateResponseType = () => calls.push('type');
|
|
123
|
-
validator.validatePeerCorrectness = () => calls.push('peer');
|
|
124
|
-
validator.validateSignature = async () => calls.push('signature');
|
|
125
|
-
validator.verifyProofOfPublication = async () => {
|
|
126
|
-
calls.push('proof');
|
|
127
|
-
return { proof: {}, manifest: {} };
|
|
128
|
-
};
|
|
129
|
-
validator.assertProofPayloadMatchesRequestPayload = async () => {
|
|
130
|
-
calls.push('assert-proof-payload');
|
|
131
|
-
return {
|
|
132
|
-
validatorDecodedTx: { type: OperationType.TX, txo: { va: remoteAddressBuffer } },
|
|
133
|
-
manifest: {}
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
|
-
validator.validateDecodedCompletePayloadSchema = () => calls.push('schema-complete');
|
|
137
|
-
validator.validateWritingKey = async () => {
|
|
138
|
-
calls.push('writer-key');
|
|
139
|
-
return {
|
|
140
|
-
writerKeyFromManifest: writerKey,
|
|
141
|
-
validatorAddressCorrelatedWithManifest: remoteAddressBuffer
|
|
142
|
-
};
|
|
143
|
-
};
|
|
144
|
-
validator.validateValidatorCorrectness = async () => calls.push('validator-correctness');
|
|
145
|
-
|
|
146
|
-
const result = await validator.validate(
|
|
147
|
-
{ broadcast_transaction_response: { result: ResultCode.OK } },
|
|
148
|
-
{ remotePublicKey },
|
|
149
|
-
{ requestTxData: b4a.alloc(1), requestedTo: b4a.toString(remotePublicKey, 'hex') },
|
|
150
|
-
{}
|
|
151
|
-
);
|
|
152
|
-
|
|
153
|
-
t.is(result, true);
|
|
154
|
-
t.alike(calls, [
|
|
155
|
-
'schema',
|
|
156
|
-
'type',
|
|
157
|
-
'peer',
|
|
158
|
-
'signature',
|
|
159
|
-
'proof',
|
|
160
|
-
'assert-proof-payload',
|
|
161
|
-
'schema-complete',
|
|
162
|
-
'writer-key',
|
|
163
|
-
'validator-correctness'
|
|
164
|
-
]);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test('validate rejects TX_COMMITTED_RECEIPT_MISSING as validator internal error', async t => {
|
|
168
|
-
const validator = createValidator();
|
|
169
|
-
|
|
170
|
-
validator.isPayloadSchemaValid = () => true;
|
|
171
|
-
validator.validateResponseType = () => true;
|
|
172
|
-
validator.validatePeerCorrectness = () => true;
|
|
173
|
-
validator.validateSignature = async () => true;
|
|
174
|
-
|
|
175
|
-
const payload = {
|
|
176
|
-
broadcast_transaction_response: {
|
|
177
|
-
result: ResultCode.TX_COMMITTED_RECEIPT_MISSING,
|
|
178
|
-
}
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
try {
|
|
182
|
-
await validator.validate(
|
|
183
|
-
payload,
|
|
184
|
-
{ remotePublicKey: b4a.alloc(32, 1) },
|
|
185
|
-
{},
|
|
186
|
-
null
|
|
187
|
-
);
|
|
188
|
-
t.fail('expected validate to throw');
|
|
189
|
-
} catch (error) {
|
|
190
|
-
t.ok(error instanceof V1ProtocolError);
|
|
191
|
-
t.is(error.resultCode, ResultCode.TX_COMMITTED_RECEIPT_MISSING);
|
|
192
|
-
t.is(error.endConnection, true);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
test('validateDecodedCompletePayloadSchema throws for missing, unknown and unsupported types', t => {
|
|
197
|
-
const validator = createValidator();
|
|
198
|
-
|
|
199
|
-
try {
|
|
200
|
-
validator.validateDecodedCompletePayloadSchema({});
|
|
201
|
-
t.fail('expected missing type to throw');
|
|
202
|
-
} catch (error) {
|
|
203
|
-
t.is(error.resultCode, ResultCode.VALIDATOR_RESPONSE_TX_TYPE_INVALID);
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
try {
|
|
207
|
-
validator.validateDecodedCompletePayloadSchema({ type: 9999 });
|
|
208
|
-
t.fail('expected unknown type to throw');
|
|
209
|
-
} catch (error) {
|
|
210
|
-
t.is(error.resultCode, ResultCode.VALIDATOR_RESPONSE_TX_TYPE_UNKNOWN);
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
try {
|
|
214
|
-
validator.validateDecodedCompletePayloadSchema({ type: OperationType.ADD_ADMIN });
|
|
215
|
-
t.fail('expected unsupported type to throw');
|
|
216
|
-
} catch (error) {
|
|
217
|
-
t.is(error.resultCode, ResultCode.VALIDATOR_RESPONSE_TX_TYPE_UNSUPPORTED);
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
test('validateDecodedCompletePayloadSchema selects proper validators for supported operation types', t => {
|
|
222
|
-
const validator = createValidator();
|
|
223
|
-
const called = [];
|
|
224
|
-
|
|
225
|
-
overrideCheckMethods(t, {
|
|
226
|
-
validateRoleAccessOperation: () => {
|
|
227
|
-
called.push('role');
|
|
228
|
-
return true;
|
|
229
|
-
},
|
|
230
|
-
validateBootstrapDeploymentOperation: () => {
|
|
231
|
-
called.push('bootstrap');
|
|
232
|
-
return true;
|
|
233
|
-
},
|
|
234
|
-
validateTransactionOperation: () => {
|
|
235
|
-
called.push('tx');
|
|
236
|
-
return true;
|
|
237
|
-
},
|
|
238
|
-
validateTransferOperation: () => {
|
|
239
|
-
called.push('transfer');
|
|
240
|
-
return true;
|
|
241
|
-
},
|
|
242
|
-
});
|
|
243
|
-
|
|
244
|
-
validator.validateDecodedCompletePayloadSchema({ type: OperationType.ADD_WRITER });
|
|
245
|
-
validator.validateDecodedCompletePayloadSchema({ type: OperationType.BOOTSTRAP_DEPLOYMENT });
|
|
246
|
-
validator.validateDecodedCompletePayloadSchema({ type: OperationType.TX });
|
|
247
|
-
validator.validateDecodedCompletePayloadSchema({ type: OperationType.TRANSFER });
|
|
248
|
-
|
|
249
|
-
t.alike(called, ['role', 'bootstrap', 'tx', 'transfer']);
|
|
250
|
-
});
|
|
251
|
-
|
|
252
|
-
test('validateDecodedCompletePayloadSchema throws VALIDATOR_RESPONSE_SCHEMA_INVALID when selected validator fails', t => {
|
|
253
|
-
const validator = createValidator();
|
|
254
|
-
|
|
255
|
-
overrideCheckMethods(t, {
|
|
256
|
-
validateTransactionOperation: () => false,
|
|
257
|
-
});
|
|
258
|
-
|
|
259
|
-
try {
|
|
260
|
-
validator.validateDecodedCompletePayloadSchema({ type: OperationType.TX });
|
|
261
|
-
t.fail('expected schema invalid');
|
|
262
|
-
} catch (error) {
|
|
263
|
-
t.is(error.resultCode, ResultCode.VALIDATOR_RESPONSE_SCHEMA_INVALID);
|
|
264
|
-
}
|
|
265
|
-
});
|
|
266
|
-
|
|
267
|
-
test('verifyProofOfPublication delegates verification to state instance', async t => {
|
|
268
|
-
const validator = createValidator({
|
|
269
|
-
verifyProofOfPublication: receivedProof => {
|
|
270
|
-
t.ok(b4a.equals(receivedProof, proof));
|
|
271
|
-
return { ok: true };
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
const proof = b4a.from('deadbeef', 'hex');
|
|
275
|
-
|
|
276
|
-
const result = await validator.verifyProofOfPublication({
|
|
277
|
-
broadcast_transaction_response: {
|
|
278
|
-
proof,
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
t.alike(result, { ok: true });
|
|
283
|
-
});
|
|
284
|
-
|
|
285
|
-
test('assertProofPayloadMatchesRequestPayload throws when pending request tx data is missing', async t => {
|
|
286
|
-
const validator = createValidator();
|
|
287
|
-
|
|
288
|
-
try {
|
|
289
|
-
await validator.assertProofPayloadMatchesRequestPayload(
|
|
290
|
-
{ proof: { block: { value: b4a.alloc(1) }, manifest: {} } },
|
|
291
|
-
{ requestTxData: null }
|
|
292
|
-
);
|
|
293
|
-
t.fail('expected missing tx data to throw');
|
|
294
|
-
} catch (error) {
|
|
295
|
-
t.is(error.resultCode, ResultCode.PENDING_REQUEST_MISSING_TX_DATA);
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
test('assertProofPayloadMatchesRequestPayload throws PROOF_PAYLOAD_MISMATCH when decoded payloads differ', async t => {
|
|
300
|
-
const validator = createValidator();
|
|
301
|
-
|
|
302
|
-
const requestTxData = unsafeEncodeApplyOperation(protobufFixtures.validPartialTransactionOperation);
|
|
303
|
-
const responseTxData = unsafeEncodeApplyOperation(protobufFixtures.validPartialTransferOperation);
|
|
304
|
-
|
|
305
|
-
overrideFunction(t, Autobase, 'decodeValue', async () => responseTxData);
|
|
306
|
-
|
|
307
|
-
try {
|
|
308
|
-
await validator.assertProofPayloadMatchesRequestPayload(
|
|
309
|
-
{
|
|
310
|
-
proof: {
|
|
311
|
-
block: { value: b4a.alloc(1) },
|
|
312
|
-
manifest: {}
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
{ requestTxData }
|
|
316
|
-
);
|
|
317
|
-
t.fail('expected payload mismatch');
|
|
318
|
-
} catch (error) {
|
|
319
|
-
t.is(error.resultCode, ResultCode.PROOF_PAYLOAD_MISMATCH);
|
|
320
|
-
}
|
|
321
|
-
});
|
|
322
|
-
|
|
323
|
-
test('assertProofPayloadMatchesRequestPayload strips validator metadata before comparison', async t => {
|
|
324
|
-
const validator = createValidator();
|
|
325
|
-
|
|
326
|
-
const requestPayload = structuredClone(protobufFixtures.validTransactionOperation);
|
|
327
|
-
requestPayload.txo.va = null;
|
|
328
|
-
requestPayload.txo.vn = null;
|
|
329
|
-
requestPayload.txo.vs = null;
|
|
330
|
-
const requestTxData = unsafeEncodeApplyOperation(requestPayload);
|
|
331
|
-
const responseTxData = unsafeEncodeApplyOperation(protobufFixtures.validTransactionOperation);
|
|
332
|
-
const manifest = { signers: [] };
|
|
333
|
-
|
|
334
|
-
overrideFunction(t, Autobase, 'decodeValue', async () => responseTxData);
|
|
335
|
-
|
|
336
|
-
const result = await validator.assertProofPayloadMatchesRequestPayload(
|
|
337
|
-
{
|
|
338
|
-
proof: {
|
|
339
|
-
block: { value: b4a.alloc(1) },
|
|
340
|
-
manifest,
|
|
341
|
-
}
|
|
342
|
-
},
|
|
343
|
-
{ requestTxData }
|
|
344
|
-
);
|
|
345
|
-
|
|
346
|
-
t.is(result.validatorDecodedTx.type, OperationType.TX);
|
|
347
|
-
t.alike(result.manifest, manifest);
|
|
348
|
-
|
|
349
|
-
const decodedResponse = unsafeDecodeApplyOperation(responseTxData);
|
|
350
|
-
t.alike(result.validatorDecodedTx, decodedResponse);
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
test('validateWritingKey throws when writer key is not registered', async t => {
|
|
354
|
-
const validator = createValidator({
|
|
355
|
-
getRegisteredWriterKey: async () => null
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
overrideFunction(t, Hypercore, 'key', () => writerKey);
|
|
359
|
-
|
|
360
|
-
try {
|
|
361
|
-
await validator.validateWritingKey({}, {});
|
|
362
|
-
t.fail('expected validateWritingKey to throw');
|
|
363
|
-
} catch (error) {
|
|
364
|
-
t.is(error.resultCode, ResultCode.VALIDATOR_WRITER_KEY_NOT_REGISTERED);
|
|
365
|
-
}
|
|
366
|
-
});
|
|
367
|
-
|
|
368
|
-
test('validateWritingKey returns writer key and correlated validator address', async t => {
|
|
369
|
-
const registeredAddress = b4a.alloc(39, 7);
|
|
370
|
-
const validator = createValidator({
|
|
371
|
-
getRegisteredWriterKey: async writerKeyHex => {
|
|
372
|
-
t.is(writerKeyHex, b4a.toString(writerKey, 'hex'));
|
|
373
|
-
return registeredAddress;
|
|
374
|
-
}
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
overrideFunction(t, Hypercore, 'key', () => writerKey);
|
|
378
|
-
|
|
379
|
-
const result = await validator.validateWritingKey({}, {});
|
|
380
|
-
|
|
381
|
-
t.ok(b4a.equals(result.writerKeyFromManifest, writerKey));
|
|
382
|
-
t.ok(b4a.equals(result.validatorAddressCorrelatedWithManifest, registeredAddress));
|
|
383
|
-
});
|
|
384
|
-
|
|
385
|
-
test('validateValidatorCorrectness throws VALIDATOR_ADDRESS_MISMATCH when tx va differs from connection-derived address', async t => {
|
|
386
|
-
const validator = createValidator({
|
|
387
|
-
getNodeEntry: async () => null
|
|
388
|
-
});
|
|
389
|
-
|
|
390
|
-
try {
|
|
391
|
-
await validator.validateValidatorCorrectness(
|
|
392
|
-
{ txo: { va: b4a.alloc(remoteAddressBuffer.length, 9) } },
|
|
393
|
-
remotePublicKey,
|
|
394
|
-
writerKey,
|
|
395
|
-
remoteAddressBuffer
|
|
396
|
-
);
|
|
397
|
-
t.fail('expected address mismatch');
|
|
398
|
-
} catch (error) {
|
|
399
|
-
t.is(error.resultCode, ResultCode.VALIDATOR_ADDRESS_MISMATCH);
|
|
400
|
-
}
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
test('validateValidatorCorrectness throws VALIDATOR_ADDRESS_MISMATCH when tx va differs from manifest-correlated address', async t => {
|
|
404
|
-
const validator = createValidator({
|
|
405
|
-
getNodeEntry: async () => null
|
|
406
|
-
});
|
|
407
|
-
|
|
408
|
-
try {
|
|
409
|
-
await validator.validateValidatorCorrectness(
|
|
410
|
-
{ txo: { va: remoteAddressBuffer } },
|
|
411
|
-
remotePublicKey,
|
|
412
|
-
writerKey,
|
|
413
|
-
b4a.alloc(remoteAddressBuffer.length, 8)
|
|
414
|
-
);
|
|
415
|
-
t.fail('expected address mismatch');
|
|
416
|
-
} catch (error) {
|
|
417
|
-
t.is(error.resultCode, ResultCode.VALIDATOR_ADDRESS_MISMATCH);
|
|
418
|
-
}
|
|
419
|
-
});
|
|
420
|
-
|
|
421
|
-
test('validateValidatorCorrectness throws VALIDATOR_NODE_ENTRY_NOT_FOUND when state has no node entry', async t => {
|
|
422
|
-
const validator = createValidator({
|
|
423
|
-
getNodeEntry: async () => null
|
|
424
|
-
});
|
|
425
|
-
|
|
426
|
-
try {
|
|
427
|
-
await validator.validateValidatorCorrectness(
|
|
428
|
-
{ txo: { va: remoteAddressBuffer } },
|
|
429
|
-
remotePublicKey,
|
|
430
|
-
writerKey,
|
|
431
|
-
remoteAddressBuffer
|
|
432
|
-
);
|
|
433
|
-
t.fail('expected missing node entry');
|
|
434
|
-
} catch (error) {
|
|
435
|
-
t.is(error.resultCode, ResultCode.VALIDATOR_NODE_ENTRY_NOT_FOUND);
|
|
436
|
-
}
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
test('validateValidatorCorrectness throws VALIDATOR_NODE_NOT_WRITER when node is not a writer', async t => {
|
|
440
|
-
const validator = createValidator({
|
|
441
|
-
getNodeEntry: async () => ({
|
|
442
|
-
isWriter: false,
|
|
443
|
-
wk: writerKey,
|
|
444
|
-
})
|
|
445
|
-
});
|
|
446
|
-
|
|
447
|
-
try {
|
|
448
|
-
await validator.validateValidatorCorrectness(
|
|
449
|
-
{ txo: { va: remoteAddressBuffer } },
|
|
450
|
-
remotePublicKey,
|
|
451
|
-
writerKey,
|
|
452
|
-
remoteAddressBuffer
|
|
453
|
-
);
|
|
454
|
-
t.fail('expected node-not-writer');
|
|
455
|
-
} catch (error) {
|
|
456
|
-
t.is(error.resultCode, ResultCode.VALIDATOR_NODE_NOT_WRITER);
|
|
457
|
-
}
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
test('validateValidatorCorrectness throws VALIDATOR_WRITER_KEY_MISMATCH when state writer key differs', async t => {
|
|
461
|
-
const validator = createValidator({
|
|
462
|
-
getNodeEntry: async () => ({
|
|
463
|
-
isWriter: true,
|
|
464
|
-
wk: b4a.alloc(32, 99),
|
|
465
|
-
})
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
try {
|
|
469
|
-
await validator.validateValidatorCorrectness(
|
|
470
|
-
{ txo: { va: remoteAddressBuffer } },
|
|
471
|
-
remotePublicKey,
|
|
472
|
-
writerKey,
|
|
473
|
-
remoteAddressBuffer
|
|
474
|
-
);
|
|
475
|
-
t.fail('expected writer-key mismatch');
|
|
476
|
-
} catch (error) {
|
|
477
|
-
t.is(error.resultCode, ResultCode.VALIDATOR_WRITER_KEY_MISMATCH);
|
|
478
|
-
}
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
test('validateValidatorCorrectness passes when validator address and writer key are consistent', async t => {
|
|
482
|
-
const validator = createValidator({
|
|
483
|
-
getNodeEntry: async () => ({
|
|
484
|
-
isWriter: true,
|
|
485
|
-
wk: writerKey,
|
|
486
|
-
})
|
|
487
|
-
});
|
|
488
|
-
|
|
489
|
-
await validator.validateValidatorCorrectness(
|
|
490
|
-
{ txo: { va: remoteAddressBuffer } },
|
|
491
|
-
remotePublicKey,
|
|
492
|
-
writerKey,
|
|
493
|
-
remoteAddressBuffer
|
|
494
|
-
);
|
|
495
|
-
|
|
496
|
-
t.pass();
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
test('validateIfResultCodeIsValidatorInternalError throws only for TX_COMMITTED_RECEIPT_MISSING', t => {
|
|
500
|
-
const validator = createValidator();
|
|
501
|
-
|
|
502
|
-
try {
|
|
503
|
-
validator.validateIfResultCodeIsValidatorInternalError(ResultCode.TX_COMMITTED_RECEIPT_MISSING);
|
|
504
|
-
t.fail('expected internal error result code to throw');
|
|
505
|
-
} catch (error) {
|
|
506
|
-
t.is(error.resultCode, ResultCode.TX_COMMITTED_RECEIPT_MISSING);
|
|
507
|
-
t.is(error.endConnection, true);
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
validator.validateIfResultCodeIsValidatorInternalError(ResultCode.OK);
|
|
511
|
-
t.pass();
|
|
512
|
-
});
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import test from 'brittle';
|
|
2
|
-
import b4a from 'b4a';
|
|
3
|
-
|
|
4
|
-
import V1LivenessRequest from '../../../../src/core/network/protocols/v1/validators/V1LivenessRequest.js';
|
|
5
|
-
import { config } from '../../../helpers/config.js';
|
|
6
|
-
import { errorMessageIncludes } from '../../../helpers/regexHelper.js';
|
|
7
|
-
|
|
8
|
-
test('V1LivenessRequest.validate runs schema and signature validation', async t => {
|
|
9
|
-
const validator = new V1LivenessRequest(config);
|
|
10
|
-
const calls = [];
|
|
11
|
-
|
|
12
|
-
validator.isPayloadSchemaValid = () => calls.push('schema');
|
|
13
|
-
validator.validateSignature = async () => calls.push('signature');
|
|
14
|
-
|
|
15
|
-
const result = await validator.validate({}, b4a.alloc(32, 1));
|
|
16
|
-
|
|
17
|
-
t.is(result, true);
|
|
18
|
-
t.alike(calls, ['schema', 'signature']);
|
|
19
|
-
});
|
|
20
|
-
|
|
21
|
-
test('V1LivenessRequest.validate propagates signature validation errors', async t => {
|
|
22
|
-
const validator = new V1LivenessRequest(config);
|
|
23
|
-
validator.isPayloadSchemaValid = () => true;
|
|
24
|
-
validator.validateSignature = async () => {
|
|
25
|
-
throw new Error('signature failed');
|
|
26
|
-
};
|
|
27
|
-
|
|
28
|
-
await t.exception(
|
|
29
|
-
async () => validator.validate({}, b4a.alloc(32, 1)),
|
|
30
|
-
errorMessageIncludes('signature failed')
|
|
31
|
-
);
|
|
32
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import test from 'brittle';
|
|
2
|
-
import b4a from 'b4a';
|
|
3
|
-
|
|
4
|
-
import V1LivenessResponse from '../../../../src/core/network/protocols/v1/validators/V1LivenessResponse.js';
|
|
5
|
-
import { config } from '../../../helpers/config.js';
|
|
6
|
-
import { errorMessageIncludes } from '../../../helpers/regexHelper.js';
|
|
7
|
-
|
|
8
|
-
test('V1LivenessResponse.validate runs all validation steps in order', async t => {
|
|
9
|
-
const validator = new V1LivenessResponse(config);
|
|
10
|
-
const calls = [];
|
|
11
|
-
|
|
12
|
-
validator.isPayloadSchemaValid = () => calls.push('schema');
|
|
13
|
-
validator.validateResponseType = () => calls.push('responseType');
|
|
14
|
-
validator.validatePeerCorrectness = () => calls.push('peer');
|
|
15
|
-
validator.validateSignature = async () => calls.push('signature');
|
|
16
|
-
|
|
17
|
-
const result = await validator.validate(
|
|
18
|
-
{},
|
|
19
|
-
{ remotePublicKey: b4a.alloc(32, 1) },
|
|
20
|
-
{ requestedTo: b4a.toString(b4a.alloc(32, 1), 'hex') }
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
t.is(result, true);
|
|
24
|
-
t.alike(calls, ['schema', 'responseType', 'peer', 'signature']);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
test('V1LivenessResponse.validate propagates response-type errors', async t => {
|
|
28
|
-
const validator = new V1LivenessResponse(config);
|
|
29
|
-
|
|
30
|
-
validator.isPayloadSchemaValid = () => true;
|
|
31
|
-
validator.validateResponseType = () => {
|
|
32
|
-
throw new Error('invalid response type');
|
|
33
|
-
};
|
|
34
|
-
validator.validatePeerCorrectness = () => true;
|
|
35
|
-
validator.validateSignature = async () => true;
|
|
36
|
-
|
|
37
|
-
await t.exception(
|
|
38
|
-
async () => validator.validate(
|
|
39
|
-
{},
|
|
40
|
-
{ remotePublicKey: b4a.alloc(32, 1) },
|
|
41
|
-
{ requestedTo: b4a.toString(b4a.alloc(32, 1), 'hex') }
|
|
42
|
-
),
|
|
43
|
-
errorMessageIncludes('invalid response type')
|
|
44
|
-
);
|
|
45
|
-
});
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import {test} from 'brittle';
|
|
2
|
-
|
|
3
|
-
import {ResultCode} from '../../../../src/utils/constants.js';
|
|
4
|
-
|
|
5
|
-
const expectedResultCodeMap = Object.freeze({
|
|
6
|
-
UNSPECIFIED: 0,
|
|
7
|
-
OK: 1,
|
|
8
|
-
INVALID_PAYLOAD: 2,
|
|
9
|
-
RATE_LIMITED: 3,
|
|
10
|
-
SIGNATURE_INVALID: 4,
|
|
11
|
-
UNEXPECTED_ERROR: 5,
|
|
12
|
-
TIMEOUT: 6,
|
|
13
|
-
NODE_HAS_NO_WRITE_ACCESS: 7,
|
|
14
|
-
TX_ACCEPTED_PROOF_UNAVAILABLE: 8,
|
|
15
|
-
NODE_OVERLOADED: 9,
|
|
16
|
-
TX_ALREADY_PENDING: 10,
|
|
17
|
-
OPERATION_TYPE_UNKNOWN: 11,
|
|
18
|
-
SCHEMA_VALIDATION_FAILED: 12,
|
|
19
|
-
REQUESTER_ADDRESS_INVALID: 13,
|
|
20
|
-
REQUESTER_PUBLIC_KEY_INVALID: 14,
|
|
21
|
-
TX_HASH_MISMATCH: 15,
|
|
22
|
-
TX_SIGNATURE_INVALID: 16,
|
|
23
|
-
TX_EXPIRED: 17,
|
|
24
|
-
TX_ALREADY_EXISTS: 18,
|
|
25
|
-
OPERATION_ALREADY_COMPLETED: 19,
|
|
26
|
-
REQUESTER_NOT_FOUND: 20,
|
|
27
|
-
INSUFFICIENT_FEE_BALANCE: 21,
|
|
28
|
-
EXTERNAL_BOOTSTRAP_EQUALS_MSB_BOOTSTRAP: 22,
|
|
29
|
-
SELF_VALIDATION_FORBIDDEN: 23,
|
|
30
|
-
ROLE_NODE_ENTRY_NOT_FOUND: 24,
|
|
31
|
-
ROLE_NODE_ALREADY_WRITER: 25,
|
|
32
|
-
ROLE_NODE_NOT_WHITELISTED: 26,
|
|
33
|
-
ROLE_NODE_NOT_WRITER: 27,
|
|
34
|
-
ROLE_NODE_IS_INDEXER: 28,
|
|
35
|
-
ROLE_ADMIN_ENTRY_MISSING: 29,
|
|
36
|
-
ROLE_INVALID_RECOVERY_CASE: 30,
|
|
37
|
-
ROLE_UNKNOWN_OPERATION: 31,
|
|
38
|
-
ROLE_INVALID_WRITER_KEY: 32,
|
|
39
|
-
ROLE_INSUFFICIENT_FEE_BALANCE: 33,
|
|
40
|
-
MSB_BOOTSTRAP_MISMATCH: 34,
|
|
41
|
-
EXTERNAL_BOOTSTRAP_NOT_DEPLOYED: 35,
|
|
42
|
-
EXTERNAL_BOOTSTRAP_TX_MISSING: 36,
|
|
43
|
-
EXTERNAL_BOOTSTRAP_MISMATCH: 37,
|
|
44
|
-
BOOTSTRAP_ALREADY_EXISTS: 38,
|
|
45
|
-
TRANSFER_RECIPIENT_ADDRESS_INVALID: 39,
|
|
46
|
-
TRANSFER_RECIPIENT_PUBLIC_KEY_INVALID: 40,
|
|
47
|
-
TRANSFER_AMOUNT_TOO_LARGE: 41,
|
|
48
|
-
TRANSFER_SENDER_NOT_FOUND: 42,
|
|
49
|
-
TRANSFER_INSUFFICIENT_BALANCE: 43,
|
|
50
|
-
TRANSFER_RECIPIENT_BALANCE_OVERFLOW: 44,
|
|
51
|
-
TX_HASH_INVALID_FORMAT: 45,
|
|
52
|
-
INTERNAL_ENQUEUE_VALIDATION_FAILED: 46,
|
|
53
|
-
TX_COMMITTED_RECEIPT_MISSING: 47,
|
|
54
|
-
VALIDATOR_RESPONSE_TX_TYPE_INVALID: 48,
|
|
55
|
-
VALIDATOR_RESPONSE_TX_TYPE_UNKNOWN: 49,
|
|
56
|
-
VALIDATOR_RESPONSE_TX_TYPE_UNSUPPORTED: 50,
|
|
57
|
-
VALIDATOR_RESPONSE_SCHEMA_INVALID: 51,
|
|
58
|
-
PENDING_REQUEST_MISSING_TX_DATA: 52,
|
|
59
|
-
PROOF_PAYLOAD_MISMATCH: 53,
|
|
60
|
-
VALIDATOR_WRITER_KEY_NOT_REGISTERED: 54,
|
|
61
|
-
VALIDATOR_ADDRESS_MISMATCH: 55,
|
|
62
|
-
VALIDATOR_NODE_ENTRY_NOT_FOUND: 56,
|
|
63
|
-
VALIDATOR_NODE_NOT_WRITER: 57,
|
|
64
|
-
VALIDATOR_WRITER_KEY_MISMATCH: 58,
|
|
65
|
-
VALIDATOR_TX_OBJECT_INVALID: 59,
|
|
66
|
-
VALIDATOR_VA_MISSING: 60,
|
|
67
|
-
TX_INVALID_PAYLOAD: 61
|
|
68
|
-
});
|
|
69
|
-
|
|
70
|
-
test('ResultCode values are unique', t => {
|
|
71
|
-
const values = Object.values(ResultCode);
|
|
72
|
-
t.is(new Set(values).size, values.length);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
test('ResultCode preserves existing numeric values (append-only)', t => {
|
|
76
|
-
t.alike(ResultCode, expectedResultCodeMap);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
test('ResultCode does not expose deprecated alias', t => {
|
|
80
|
-
t.absent(
|
|
81
|
-
Object.prototype.hasOwnProperty.call(ResultCode, 'TX_ACCEPTED_RECEIPT_MISSING'),
|
|
82
|
-
'deprecated alias should not be present'
|
|
83
|
-
);
|
|
84
|
-
});
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { default as test } from 'brittle';
|
|
2
|
-
|
|
3
|
-
async function runV1ValidationSchemaTests() {
|
|
4
|
-
test.pause();
|
|
5
|
-
await import('./v1ValidationSchema/livenessRequest.test.js');
|
|
6
|
-
await import('./v1ValidationSchema/livenessResponse.test.js');
|
|
7
|
-
await import('./v1ValidationSchema/broadcastTransactionRequest.test.js');
|
|
8
|
-
await import('./v1ValidationSchema/broadcastTransactionResponse.test.js');
|
|
9
|
-
test.resume();
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
await runV1ValidationSchemaTests();
|
|
13
|
-
|