trac-msb 0.2.18 → 0.2.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +130 -34
- 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
package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js
DELETED
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import b4a from 'b4a';
|
|
2
|
-
import OperationValidationScenarioBase from '../../base/OperationValidationScenarioBase.js';
|
|
3
|
-
import { safeDecodeApplyOperation } from '../../../../../../../src/utils/protobuf/operationHelpers.js';
|
|
4
|
-
import addressUtils from '../../../../../../../src/core/state/utils/address.js';
|
|
5
|
-
import { eventFlush } from '../../../../../../helpers/autobaseTestHelpers.js';
|
|
6
|
-
import { config } from '../../../../../../helpers/config.js'
|
|
7
|
-
|
|
8
|
-
export const ValidatorEntryMutation = {
|
|
9
|
-
DELETE: Symbol('validator-entry-delete')
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
const DEFAULT_VALIDATOR_ADDRESS_PATH = ['rao', 'va'];
|
|
13
|
-
|
|
14
|
-
export default class ValidatorConsistencyScenarioBase extends OperationValidationScenarioBase {
|
|
15
|
-
constructor({
|
|
16
|
-
title,
|
|
17
|
-
setupScenario,
|
|
18
|
-
buildValidPayload,
|
|
19
|
-
assertStateUnchanged,
|
|
20
|
-
mutateEntry,
|
|
21
|
-
selectNode = defaultSelectNode,
|
|
22
|
-
validatorAddressPath = DEFAULT_VALIDATOR_ADDRESS_PATH,
|
|
23
|
-
expectedLogs,
|
|
24
|
-
applyInvalidPayload
|
|
25
|
-
}) {
|
|
26
|
-
if (typeof mutateEntry !== 'function') {
|
|
27
|
-
throw new Error('Validator consistency scenario requires a mutateEntry function.');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
super({
|
|
31
|
-
title,
|
|
32
|
-
setupScenario,
|
|
33
|
-
buildValidPayload,
|
|
34
|
-
mutatePayload: passThroughPayload,
|
|
35
|
-
applyInvalidPayload:
|
|
36
|
-
typeof applyInvalidPayload === 'function'
|
|
37
|
-
? applyInvalidPayload
|
|
38
|
-
: createApplyInvalidPayload({
|
|
39
|
-
selectNode,
|
|
40
|
-
validatorAddressPath,
|
|
41
|
-
mutateEntry
|
|
42
|
-
}),
|
|
43
|
-
assertStateUnchanged,
|
|
44
|
-
expectedLogs
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function passThroughPayload(_t, payload) {
|
|
50
|
-
return payload;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
function defaultSelectNode(context) {
|
|
54
|
-
return context.adminBootstrap ?? context.bootstrap ?? context.peers?.[0] ?? null;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function createApplyInvalidPayload({ selectNode, validatorAddressPath, mutateEntry }) {
|
|
58
|
-
return async (context, payload, t, validPayload) => {
|
|
59
|
-
const node = selectNode(context);
|
|
60
|
-
if (!node?.base) {
|
|
61
|
-
throw new Error('Validator consistency scenario requires a writable node.');
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
const validatorAddress = extractValidatorAddress(validPayload ?? payload, validatorAddressPath);
|
|
65
|
-
if (!validatorAddress) {
|
|
66
|
-
throw new Error('Validator address could not be derived from payload.');
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const cleanup = patchValidatorEntry({
|
|
70
|
-
base: node.base,
|
|
71
|
-
mutateEntry,
|
|
72
|
-
context,
|
|
73
|
-
t,
|
|
74
|
-
validatorAddressString: validatorAddress.string,
|
|
75
|
-
validatorAddressBuffer: validatorAddress.buffer
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
try {
|
|
79
|
-
await node.base.append(payload);
|
|
80
|
-
await node.base.update();
|
|
81
|
-
await eventFlush();
|
|
82
|
-
} finally {
|
|
83
|
-
await cleanup();
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function patchValidatorEntry({
|
|
89
|
-
base,
|
|
90
|
-
mutateEntry,
|
|
91
|
-
context,
|
|
92
|
-
t,
|
|
93
|
-
validatorAddressString,
|
|
94
|
-
validatorAddressBuffer
|
|
95
|
-
}) {
|
|
96
|
-
const originalApply = base._handlers.apply;
|
|
97
|
-
let shouldInterceptNextApply = true;
|
|
98
|
-
|
|
99
|
-
base._handlers.apply = async function patchedApply(nodes, view, baseCtx) {
|
|
100
|
-
if (!shouldInterceptNextApply) {
|
|
101
|
-
return originalApply.call(this, nodes, view, baseCtx);
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
shouldInterceptNextApply = false;
|
|
105
|
-
const originalBatch = view.batch;
|
|
106
|
-
view.batch = function patchedBatch(...args) {
|
|
107
|
-
const batch = originalBatch.apply(this, args);
|
|
108
|
-
if (!batch || typeof batch.get !== 'function') {
|
|
109
|
-
return batch;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const originalGet = batch.get.bind(batch);
|
|
113
|
-
let hasMutatedEntry = false;
|
|
114
|
-
|
|
115
|
-
batch.get = async key => {
|
|
116
|
-
if (
|
|
117
|
-
!hasMutatedEntry &&
|
|
118
|
-
isValidatorKeyMatch(key, validatorAddressString, validatorAddressBuffer)
|
|
119
|
-
) {
|
|
120
|
-
hasMutatedEntry = true;
|
|
121
|
-
const entry = await originalGet(key);
|
|
122
|
-
|
|
123
|
-
const mutation = await mutateEntry(entry, {
|
|
124
|
-
context,
|
|
125
|
-
t,
|
|
126
|
-
validatorAddress: validatorAddressString
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
return applyEntryMutation(entry, mutation);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
return originalGet(key);
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
return batch;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
try {
|
|
139
|
-
return await originalApply.call(this, nodes, view, baseCtx);
|
|
140
|
-
} finally {
|
|
141
|
-
view.batch = originalBatch;
|
|
142
|
-
}
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
return async () => {
|
|
146
|
-
base._handlers.apply = originalApply;
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
function applyEntryMutation(entry, mutation) {
|
|
151
|
-
if (typeof mutation === 'undefined') {
|
|
152
|
-
return entry;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
if (mutation === ValidatorEntryMutation.DELETE) {
|
|
156
|
-
return null;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
if (entry && (b4a.isBuffer(mutation) || mutation instanceof Uint8Array)) {
|
|
160
|
-
return {
|
|
161
|
-
...entry,
|
|
162
|
-
value: b4a.from(mutation)
|
|
163
|
-
};
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
if (mutation && typeof mutation === 'object') {
|
|
167
|
-
return mutation;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
throw new Error('Invalid validator entry mutation result.');
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function extractValidatorAddress(payloadBuffer, path) {
|
|
174
|
-
const decoded = safeDecodeApplyOperation(payloadBuffer);
|
|
175
|
-
if (!decoded) return null;
|
|
176
|
-
|
|
177
|
-
const value = Array.isArray(path) && path.length > 0 ? traversePath(decoded, path) : null;
|
|
178
|
-
if (!value || !b4a.isBuffer(value) || value.length === 0) {
|
|
179
|
-
return null;
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const addressString = addressUtils.bufferToAddress(value, config.addressPrefix);
|
|
183
|
-
if (!addressString) {
|
|
184
|
-
return null;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
return { buffer: value, string: addressString };
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
function traversePath(payload, path) {
|
|
191
|
-
return path.reduce((current, segment) => (current ? current[segment] : null), payload);
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
function isValidatorKeyMatch(key, targetString, targetBuffer) {
|
|
195
|
-
if (typeof key === 'string') {
|
|
196
|
-
return key === targetString;
|
|
197
|
-
}
|
|
198
|
-
if (b4a.isBuffer(key) && targetBuffer) {
|
|
199
|
-
return b4a.equals(key, targetBuffer);
|
|
200
|
-
}
|
|
201
|
-
return false;
|
|
202
|
-
}
|
package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import b4a from 'b4a';
|
|
2
|
-
import ValidatorEntryValidationScenarioBase from '../validatorEntryValidation/base/validatorEntryValidationScenarioBase.js';
|
|
3
|
-
|
|
4
|
-
export default class ValidatorEntryDecodeFailureScenario extends ValidatorEntryValidationScenarioBase {
|
|
5
|
-
constructor(options) {
|
|
6
|
-
super({
|
|
7
|
-
...options,
|
|
8
|
-
mutateEntry: entry => {
|
|
9
|
-
if (!entry?.value) {
|
|
10
|
-
throw new Error('Validator entry decode scenario requires an existing entry.');
|
|
11
|
-
}
|
|
12
|
-
return { ...entry, value: b4a.alloc(1) };
|
|
13
|
-
},
|
|
14
|
-
expectedLogs: options?.expectedLogs ?? ['Failed to decode validator entry.']
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
import OperationValidationScenarioBase from '../base/OperationValidationScenarioBase.js';
|
|
2
|
-
import { eventFlush } from '../../../../../helpers/autobaseTestHelpers.js';
|
|
3
|
-
|
|
4
|
-
export default class ValidatorEntryMissingScenario extends OperationValidationScenarioBase {
|
|
5
|
-
constructor({
|
|
6
|
-
title,
|
|
7
|
-
setupScenario,
|
|
8
|
-
buildValidPayload,
|
|
9
|
-
assertStateUnchanged,
|
|
10
|
-
selectNode = defaultSelectNode,
|
|
11
|
-
expectedLogs
|
|
12
|
-
}) {
|
|
13
|
-
super({
|
|
14
|
-
title,
|
|
15
|
-
setupScenario,
|
|
16
|
-
buildValidPayload,
|
|
17
|
-
mutatePayload: passThroughPayload,
|
|
18
|
-
applyInvalidPayload: createApplyInvalidPayload(selectNode),
|
|
19
|
-
assertStateUnchanged,
|
|
20
|
-
expectedLogs
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function passThroughPayload(_t, payload) {
|
|
26
|
-
return payload;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function defaultSelectNode(context) {
|
|
30
|
-
return context.adminBootstrap ?? context.bootstrap ?? context.peers?.[0] ?? null;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function createApplyInvalidPayload(selectNode) {
|
|
34
|
-
return async (context, payload) => {
|
|
35
|
-
const node = selectNode(context);
|
|
36
|
-
if (!node.base) {
|
|
37
|
-
throw new Error('Validator entry missing scenario requires a writable node.');
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
await node.base.append(payload);
|
|
41
|
-
await node.base.update();
|
|
42
|
-
await eventFlush();
|
|
43
|
-
};
|
|
44
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import b4a from 'b4a';
|
|
2
|
-
import { WRITER_MASK } from '../../../../../../src/core/state/utils/roles.js';
|
|
3
|
-
import ValidatorConsistencyScenarioBase from './base/validatorConsistencyScenarioBase.js';
|
|
4
|
-
|
|
5
|
-
export default class ValidatorInactiveScenario extends ValidatorConsistencyScenarioBase {
|
|
6
|
-
constructor(options) {
|
|
7
|
-
super({
|
|
8
|
-
...options,
|
|
9
|
-
mutateEntry: entry => {
|
|
10
|
-
if (!entry.value) {
|
|
11
|
-
throw new Error('Validator inactive scenario requires an existing validator entry.');
|
|
12
|
-
}
|
|
13
|
-
const mutated = b4a.from(entry.value);
|
|
14
|
-
mutated[0] &= ~WRITER_MASK;
|
|
15
|
-
return { ...entry, value: mutated };
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
}
|
package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import b4a from 'b4a';
|
|
2
|
-
import ValidatorConsistencyScenarioBase from './base/validatorConsistencyScenarioBase.js';
|
|
3
|
-
|
|
4
|
-
export default class ValidatorWriterKeyMismatchScenario extends ValidatorConsistencyScenarioBase {
|
|
5
|
-
constructor(options) {
|
|
6
|
-
super({
|
|
7
|
-
...options,
|
|
8
|
-
mutateEntry: entry => {
|
|
9
|
-
if (!entry.value) {
|
|
10
|
-
throw new Error('Validator writer key mismatch scenario requires an existing validator entry.');
|
|
11
|
-
}
|
|
12
|
-
const mutated = b4a.from(entry.value);
|
|
13
|
-
if (mutated.length > 33) mutated[1] ^= 0xff;
|
|
14
|
-
return { ...entry, value: mutated };
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,315 +0,0 @@
|
|
|
1
|
-
import b4a from 'b4a';
|
|
2
|
-
import OperationValidationScenarioBase from '../../base/OperationValidationScenarioBase.js';
|
|
3
|
-
import nodeEntryUtils from '../../../../../../../src/core/state/utils/nodeEntry.js';
|
|
4
|
-
import { safeDecodeApplyOperation } from '../../../../../../../src/utils/protobuf/operationHelpers.js';
|
|
5
|
-
import addressUtils from '../../../../../../../src/core/state/utils/address.js';
|
|
6
|
-
import { eventFlush } from '../../../../../../helpers/autobaseTestHelpers.js';
|
|
7
|
-
import { BALANCE_ZERO } from '../../../../../../../src/core/state/utils/balance.js';
|
|
8
|
-
import { config } from '../../../../../../helpers/config.js'
|
|
9
|
-
|
|
10
|
-
const DEFAULT_VALIDATOR_ADDRESS_PATH = ['rao', 'va'];
|
|
11
|
-
const VALIDATOR_ENTRY_MARK = Symbol('validator-entry-mark');
|
|
12
|
-
const VALIDATOR_BALANCE_MARK = Symbol('validator-balance-mark');
|
|
13
|
-
|
|
14
|
-
export default class ValidatorEntryValidationScenarioBase extends OperationValidationScenarioBase {
|
|
15
|
-
constructor({
|
|
16
|
-
title,
|
|
17
|
-
setupScenario,
|
|
18
|
-
buildValidPayload,
|
|
19
|
-
assertStateUnchanged,
|
|
20
|
-
mutateEntry = entryPassThrough,
|
|
21
|
-
mutateDecodedEntry = null,
|
|
22
|
-
selectNode = defaultSelectNode,
|
|
23
|
-
validatorAddressPath = DEFAULT_VALIDATOR_ADDRESS_PATH,
|
|
24
|
-
expectedLogs,
|
|
25
|
-
mutatePayload,
|
|
26
|
-
applyInvalidPayload,
|
|
27
|
-
failNextBalanceAdd = false,
|
|
28
|
-
failNextBalanceUpdate = false
|
|
29
|
-
}) {
|
|
30
|
-
if (typeof mutateEntry !== 'function') {
|
|
31
|
-
throw new Error('Validator entry validation scenario requires a mutateEntry function.');
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
super({
|
|
35
|
-
title,
|
|
36
|
-
setupScenario,
|
|
37
|
-
buildValidPayload,
|
|
38
|
-
mutatePayload: mutatePayload ?? passThroughPayload,
|
|
39
|
-
applyInvalidPayload:
|
|
40
|
-
typeof applyInvalidPayload === 'function'
|
|
41
|
-
? applyInvalidPayload
|
|
42
|
-
: createApplyInvalidPayload({
|
|
43
|
-
selectNode,
|
|
44
|
-
validatorAddressPath,
|
|
45
|
-
mutateEntry,
|
|
46
|
-
mutateDecodedEntry,
|
|
47
|
-
failNextBalanceAdd,
|
|
48
|
-
failNextBalanceUpdate
|
|
49
|
-
}),
|
|
50
|
-
assertStateUnchanged,
|
|
51
|
-
expectedLogs
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
function passThroughPayload(_t, payload) {
|
|
57
|
-
return payload;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function entryPassThrough(entry) {
|
|
61
|
-
return entry;
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function defaultSelectNode(context) {
|
|
65
|
-
return context.adminBootstrap ?? context.bootstrap ?? context.peers?.[0] ?? null;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function createApplyInvalidPayload({
|
|
69
|
-
selectNode,
|
|
70
|
-
validatorAddressPath,
|
|
71
|
-
mutateEntry,
|
|
72
|
-
mutateDecodedEntry,
|
|
73
|
-
failNextBalanceAdd,
|
|
74
|
-
failNextBalanceUpdate
|
|
75
|
-
}) {
|
|
76
|
-
return async (context, payload, t, validPayload) => {
|
|
77
|
-
const node = selectNode(context);
|
|
78
|
-
if (!node?.base) {
|
|
79
|
-
throw new Error('Validator entry validation scenario requires a writable node.');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const validatorAddress = extractValidatorAddress(validPayload ?? payload, validatorAddressPath);
|
|
83
|
-
if (!validatorAddress) {
|
|
84
|
-
throw new Error('Validator address could not be derived from payload.');
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
const cleanup = patchValidatorEntry({
|
|
88
|
-
base: node.base,
|
|
89
|
-
mutateEntry,
|
|
90
|
-
mutateDecodedEntry,
|
|
91
|
-
failNextBalanceAdd,
|
|
92
|
-
failNextBalanceUpdate,
|
|
93
|
-
context,
|
|
94
|
-
t,
|
|
95
|
-
validatorAddressString: validatorAddress.string,
|
|
96
|
-
validatorAddressBuffer: validatorAddress.buffer
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
try {
|
|
100
|
-
await node.base.append(payload);
|
|
101
|
-
await node.base.update();
|
|
102
|
-
await eventFlush();
|
|
103
|
-
} finally {
|
|
104
|
-
await cleanup();
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function patchValidatorEntry({
|
|
110
|
-
base,
|
|
111
|
-
mutateEntry,
|
|
112
|
-
mutateDecodedEntry,
|
|
113
|
-
failNextBalanceAdd,
|
|
114
|
-
failNextBalanceUpdate,
|
|
115
|
-
context,
|
|
116
|
-
t,
|
|
117
|
-
validatorAddressString,
|
|
118
|
-
validatorAddressBuffer
|
|
119
|
-
}) {
|
|
120
|
-
const originalApply = base._handlers.apply;
|
|
121
|
-
const originalDecode = nodeEntryUtils.decode;
|
|
122
|
-
const balancePrototype = Object.getPrototypeOf(BALANCE_ZERO);
|
|
123
|
-
const originalAdd = balancePrototype.add;
|
|
124
|
-
const originalUpdate = balancePrototype.update;
|
|
125
|
-
|
|
126
|
-
let shouldInterceptNextApply = true;
|
|
127
|
-
let targetEntryBuffer = null;
|
|
128
|
-
let shouldFailNextAdd = false;
|
|
129
|
-
let shouldMarkNextBalance = false;
|
|
130
|
-
|
|
131
|
-
const setTargetEntryBuffer = buffer => {
|
|
132
|
-
if (buffer && b4a.isBuffer(buffer)) {
|
|
133
|
-
targetEntryBuffer = b4a.from(buffer);
|
|
134
|
-
} else {
|
|
135
|
-
targetEntryBuffer = null;
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
const isTargetEntryBuffer = buffer =>
|
|
140
|
-
targetEntryBuffer &&
|
|
141
|
-
b4a.isBuffer(buffer) &&
|
|
142
|
-
buffer.length === targetEntryBuffer.length &&
|
|
143
|
-
b4a.equals(buffer, targetEntryBuffer);
|
|
144
|
-
|
|
145
|
-
nodeEntryUtils.decode = function patchedDecode(buffer) {
|
|
146
|
-
const decoded = originalDecode(buffer);
|
|
147
|
-
if (isTargetEntryBuffer(buffer)) {
|
|
148
|
-
markValidatorBuffer(buffer);
|
|
149
|
-
shouldFailNextAdd = failNextBalanceAdd;
|
|
150
|
-
shouldMarkNextBalance = failNextBalanceUpdate;
|
|
151
|
-
|
|
152
|
-
if (mutateDecodedEntry) {
|
|
153
|
-
const mutated = mutateDecodedEntry(decoded, {
|
|
154
|
-
context,
|
|
155
|
-
t,
|
|
156
|
-
validatorAddress: validatorAddressString
|
|
157
|
-
});
|
|
158
|
-
if (mutated && typeof mutated === 'object') {
|
|
159
|
-
return mutated;
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
return decoded;
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
balancePrototype.add = function patchedAdd(balance) {
|
|
167
|
-
if (shouldFailNextAdd) {
|
|
168
|
-
shouldFailNextAdd = false;
|
|
169
|
-
return null;
|
|
170
|
-
}
|
|
171
|
-
const result = originalAdd.call(this, balance);
|
|
172
|
-
if (shouldMarkNextBalance && result) {
|
|
173
|
-
shouldMarkNextBalance = false;
|
|
174
|
-
result[VALIDATOR_BALANCE_MARK] = true;
|
|
175
|
-
}
|
|
176
|
-
return result;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
balancePrototype.update = function patchedUpdate(nodeEntryBuffer) {
|
|
180
|
-
if (this?.[VALIDATOR_BALANCE_MARK]) {
|
|
181
|
-
this[VALIDATOR_BALANCE_MARK] = false;
|
|
182
|
-
return null;
|
|
183
|
-
}
|
|
184
|
-
return originalUpdate.call(this, nodeEntryBuffer);
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
base._handlers.apply = async function patchedApply(nodes, view, baseCtx) {
|
|
188
|
-
if (!shouldInterceptNextApply) {
|
|
189
|
-
return originalApply.call(this, nodes, view, baseCtx);
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
shouldInterceptNextApply = false;
|
|
193
|
-
const originalBatch = view.batch;
|
|
194
|
-
view.batch = function patchedBatch(...args) {
|
|
195
|
-
const batch = originalBatch.apply(this, args);
|
|
196
|
-
if (!batch || typeof batch.get !== 'function') {
|
|
197
|
-
return batch;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
const originalGet = batch.get.bind(batch);
|
|
201
|
-
let hasMutatedEntry = false;
|
|
202
|
-
|
|
203
|
-
batch.get = async key => {
|
|
204
|
-
if (
|
|
205
|
-
!hasMutatedEntry &&
|
|
206
|
-
isValidatorKeyMatch(key, validatorAddressString, validatorAddressBuffer)
|
|
207
|
-
) {
|
|
208
|
-
hasMutatedEntry = true;
|
|
209
|
-
const entry = await originalGet(key);
|
|
210
|
-
if (entry?.value && b4a.isBuffer(entry.value)) {
|
|
211
|
-
setTargetEntryBuffer(entry.value);
|
|
212
|
-
markValidatorBuffer(entry.value);
|
|
213
|
-
} else {
|
|
214
|
-
setTargetEntryBuffer(null);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
const mutation = await mutateEntry(entry, {
|
|
218
|
-
context,
|
|
219
|
-
t,
|
|
220
|
-
validatorAddress: validatorAddressString
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
const mutatedEntry = applyEntryMutation(entry, mutation);
|
|
224
|
-
if (mutatedEntry?.value && b4a.isBuffer(mutatedEntry.value)) {
|
|
225
|
-
setTargetEntryBuffer(mutatedEntry.value);
|
|
226
|
-
markValidatorBuffer(mutatedEntry.value);
|
|
227
|
-
} else if (mutatedEntry === null) {
|
|
228
|
-
setTargetEntryBuffer(null);
|
|
229
|
-
}
|
|
230
|
-
return mutatedEntry;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
return originalGet(key);
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
return batch;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
try {
|
|
240
|
-
return await originalApply.call(this, nodes, view, baseCtx);
|
|
241
|
-
} finally {
|
|
242
|
-
view.batch = originalBatch;
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
return async () => {
|
|
247
|
-
base._handlers.apply = originalApply;
|
|
248
|
-
nodeEntryUtils.decode = originalDecode;
|
|
249
|
-
const prototype = Object.getPrototypeOf(BALANCE_ZERO);
|
|
250
|
-
prototype.add = originalAdd;
|
|
251
|
-
prototype.update = originalUpdate;
|
|
252
|
-
};
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
function applyEntryMutation(entry, mutation) {
|
|
256
|
-
if (typeof mutation === 'undefined') {
|
|
257
|
-
return entry;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
if (mutation === null) {
|
|
261
|
-
return null;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (entry && (b4a.isBuffer(mutation) || mutation instanceof Uint8Array)) {
|
|
265
|
-
const wrapped = { ...entry, value: b4a.from(mutation) };
|
|
266
|
-
markValidatorBuffer(wrapped.value);
|
|
267
|
-
return wrapped;
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
if (mutation && typeof mutation === 'object') {
|
|
271
|
-
if (mutation.value && b4a.isBuffer(mutation.value)) {
|
|
272
|
-
markValidatorBuffer(mutation.value);
|
|
273
|
-
}
|
|
274
|
-
return mutation;
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
throw new Error('Invalid validator entry mutation result.');
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
function extractValidatorAddress(payloadBuffer, path) {
|
|
281
|
-
const decoded = safeDecodeApplyOperation(payloadBuffer);
|
|
282
|
-
if (!decoded) return null;
|
|
283
|
-
|
|
284
|
-
const value = Array.isArray(path) && path.length > 0 ? traversePath(decoded, path) : null;
|
|
285
|
-
if (!value || !b4a.isBuffer(value) || value.length === 0) {
|
|
286
|
-
return null;
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
const addressString = addressUtils.bufferToAddress(value, config.addressPrefix);
|
|
290
|
-
if (!addressString) {
|
|
291
|
-
return null;
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
return { buffer: value, string: addressString };
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
function traversePath(payload, path) {
|
|
298
|
-
return path.reduce((current, segment) => (current ? current[segment] : null), payload);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
function isValidatorKeyMatch(key, targetString, targetBuffer) {
|
|
302
|
-
if (typeof key === 'string') {
|
|
303
|
-
return key === targetString;
|
|
304
|
-
}
|
|
305
|
-
if (b4a.isBuffer(key) && targetBuffer) {
|
|
306
|
-
return b4a.equals(key, targetBuffer);
|
|
307
|
-
}
|
|
308
|
-
return false;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function markValidatorBuffer(buffer) {
|
|
312
|
-
if (buffer && typeof buffer === 'object') {
|
|
313
|
-
buffer[VALIDATOR_ENTRY_MARK] = true;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import b4a from 'b4a';
|
|
2
|
-
import ValidatorEntryValidationScenarioBase from './base/validatorEntryValidationScenarioBase.js';
|
|
3
|
-
|
|
4
|
-
export default class ValidatorEntryInvalidBalanceScenario extends ValidatorEntryValidationScenarioBase {
|
|
5
|
-
constructor(options) {
|
|
6
|
-
super({
|
|
7
|
-
...options,
|
|
8
|
-
mutateDecodedEntry: decoded => {
|
|
9
|
-
if (!decoded) return decoded;
|
|
10
|
-
return {
|
|
11
|
-
...decoded,
|
|
12
|
-
balance: b4a.alloc(1)
|
|
13
|
-
};
|
|
14
|
-
},
|
|
15
|
-
expectedLogs: options?.expectedLogs ?? ['Invalid validator balance.']
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { eventFlush } from '../../../../helpers/autobaseTestHelpers.js';
|
|
2
|
-
import OperationValidationScenarioBase from './base/OperationValidationScenarioBase.js';
|
|
3
|
-
|
|
4
|
-
export default class WriterKeyExistsValidationScenario extends OperationValidationScenarioBase {
|
|
5
|
-
constructor({
|
|
6
|
-
title,
|
|
7
|
-
setupScenario,
|
|
8
|
-
buildValidPayload,
|
|
9
|
-
assertStateUnchanged,
|
|
10
|
-
mutatePayload = passThroughPayload,
|
|
11
|
-
applyInvalidPayload,
|
|
12
|
-
expectedLogs
|
|
13
|
-
}) {
|
|
14
|
-
super({
|
|
15
|
-
title,
|
|
16
|
-
setupScenario,
|
|
17
|
-
buildValidPayload,
|
|
18
|
-
mutatePayload,
|
|
19
|
-
applyInvalidPayload: applyInvalidPayload ?? defaultApplyInvalidPayload,
|
|
20
|
-
assertStateUnchanged,
|
|
21
|
-
expectedLogs
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function passThroughPayload(_t, payload) {
|
|
27
|
-
return payload;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
async function defaultApplyInvalidPayload(context, invalidPayload, _t, validPayload) {
|
|
31
|
-
const adminNode = context.adminBootstrap ?? context.bootstrap;
|
|
32
|
-
if (!adminNode) {
|
|
33
|
-
throw new Error('Writer key validation scenario requires an admin bootstrap node.');
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
await adminNode.base.append(validPayload);
|
|
37
|
-
await adminNode.base.update();
|
|
38
|
-
await eventFlush();
|
|
39
|
-
|
|
40
|
-
await adminNode.base.append(invalidPayload);
|
|
41
|
-
await adminNode.base.update();
|
|
42
|
-
await eventFlush();
|
|
43
|
-
}
|