trac-msb 0.2.17 → 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 +33 -11
- 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 +163 -14
- package/src/config/env.js +57 -25
- package/src/core/network/Network.js +121 -56
- package/src/core/network/protocols/LegacyProtocol.js +21 -11
- package/src/core/network/protocols/NetworkMessages.js +38 -17
- package/src/core/network/protocols/ProtocolInterface.js +15 -3
- package/src/core/network/protocols/ProtocolSession.js +144 -17
- package/src/core/network/protocols/V1Protocol.js +37 -18
- package/src/core/network/protocols/connectionPolicies.js +174 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +26 -20
- package/src/core/network/protocols/{shared/handlers/base/BaseOperationHandler.js → legacy/handlers/BaseStateOperationHandler.js} +25 -14
- package/src/core/network/protocols/legacy/handlers/{GetRequestHandler.js → LegacyGetRequestHandler.js} +9 -9
- package/src/core/network/protocols/legacy/handlers/LegacyResponseHandler.js +23 -0
- package/src/core/network/protocols/{shared/handlers/RoleOperationHandler.js → legacy/handlers/LegacyRoleOperationHandler.js} +19 -12
- package/src/core/network/protocols/{shared/handlers/SubnetworkOperationHandler.js → legacy/handlers/LegacySubnetworkOperationHandler.js} +29 -18
- package/src/core/network/protocols/{shared/handlers/TransferOperationHandler.js → legacy/handlers/LegacyTransferOperationHandler.js} +18 -12
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
- package/src/core/network/protocols/shared/validators/{PartialBootstrapDeployment.js → PartialBootstrapDeploymentValidator.js} +9 -4
- package/src/core/network/protocols/shared/validators/{base/PartialOperation.js → PartialOperationValidator.js} +53 -31
- package/src/core/network/protocols/shared/validators/{PartialRoleAccess.js → PartialRoleAccessValidator.js} +51 -17
- package/src/core/network/protocols/shared/validators/{PartialTransaction.js → PartialTransactionValidator.js} +21 -7
- package/src/core/network/protocols/shared/validators/{PartialTransfer.js → PartialTransferValidator.js} +32 -14
- package/src/core/network/protocols/v1/NetworkMessageRouter.js +91 -7
- package/src/core/network/protocols/v1/V1ProtocolError.js +27 -0
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +66 -0
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +272 -0
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +88 -0
- 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 +212 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +28 -0
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +260 -0
- package/src/core/network/protocols/v1/validators/V1LivenessRequest.js +15 -0
- package/src/core/network/protocols/v1/validators/V1LivenessResponse.js +17 -0
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +210 -0
- package/src/core/network/services/ConnectionManager.js +149 -96
- package/src/core/network/services/MessageOrchestrator.js +197 -37
- package/src/core/network/services/PendingRequestService.js +175 -0
- package/src/core/network/services/TransactionCommitService.js +149 -0
- package/src/core/network/services/TransactionPoolService.js +129 -18
- package/src/core/network/services/TransactionRateLimiterService.js +57 -35
- package/src/core/network/services/ValidatorHealthCheckService.js +127 -0
- package/src/core/network/services/ValidatorObserverService.js +400 -121
- package/src/core/state/State.js +259 -156
- 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 +320 -278
- package/src/messages/network/v1/NetworkMessageBuilder.js +71 -100
- package/src/messages/network/v1/NetworkMessageDirector.js +16 -50
- 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/Scheduler.js +0 -8
- package/src/utils/buffer.js +1 -1
- package/src/utils/check.js +12 -13
- package/src/utils/constants.js +78 -5
- package/src/utils/deepEqualApplyPayload.js +40 -0
- package/src/utils/errors.js +20 -0
- package/src/utils/fileUtils.js +12 -3
- package/src/utils/helpers.js +10 -1
- package/src/utils/logger.js +25 -0
- package/src/utils/migrationUtils.js +3 -3
- package/src/utils/normalizers.js +38 -0
- package/src/utils/protobuf/networkV1.generated.cjs +2460 -0
- package/src/utils/protobuf/operationHelpers.js +24 -3
- package/.dockerignore +0 -16
- package/.github/workflows/acceptance-tests.yml +0 -38
- package/.github/workflows/lint-pr-title.yml +0 -26
- package/.github/workflows/publish.yml +0 -33
- package/.github/workflows/unit-tests.yml +0 -34
- 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.proto +0 -74
- package/rpc/rpc_services.js +0 -163
- package/scripts/generate-protobufs.js +0 -42
- package/src/core/network/identity/NetworkWalletFactory.js +0 -77
- package/src/core/network/protocols/legacy/handlers/ResponseHandler.js +0 -37
- package/src/utils/cli.js +0 -130
- package/src/utils/cliCommands.js +0 -280
- package/src/utils/protobuf/network.cjs +0 -840
- package/tests/acceptance/v1/account/account.test.mjs +0 -123
- 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 -111
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -213
- 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 -85
- 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 -276
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -201
- 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/ConnectionManager.test.js +0 -191
- package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
- package/tests/unit/network/networkModule.test.js +0 -10
- 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/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 -305
- 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 -20
- package/whitelist/.gitkeep +0 -0
|
@@ -1,469 +0,0 @@
|
|
|
1
|
-
import { test } from 'brittle';
|
|
2
|
-
import b4a from 'b4a';
|
|
3
|
-
|
|
4
|
-
import { config } from '../../../helpers/config.js';
|
|
5
|
-
import { randomAddress } from '../../state/stateTestUtils.js';
|
|
6
|
-
import { errorMessageIncludes } from '../../../helpers/regexHelper.js';
|
|
7
|
-
import { OperationType } from '../../../../src/utils/constants.js';
|
|
8
|
-
import {
|
|
9
|
-
normalizeBootstrapDeploymentOperation,
|
|
10
|
-
normalizeDecodedPayloadForJson,
|
|
11
|
-
normalizeRoleAccessOperation,
|
|
12
|
-
normalizeTransactionOperation,
|
|
13
|
-
normalizeTransferOperation
|
|
14
|
-
} from '../../../../src/utils/normalizers.js';
|
|
15
|
-
import { addressToBuffer } from '../../../../src/core/state/utils/address.js';
|
|
16
|
-
import { bigIntTo16ByteBuffer } from '../../../../src/utils/amountSerialization.js';
|
|
17
|
-
|
|
18
|
-
const hex = (value, bytes) => value.repeat(bytes);
|
|
19
|
-
const toBuffer = value => b4a.from(value, 'hex');
|
|
20
|
-
|
|
21
|
-
test('normalizeTransferOperation normalizes hex strings and addresses', t => {
|
|
22
|
-
const sender = randomAddress(config.addressPrefix);
|
|
23
|
-
const recipient = randomAddress(config.addressPrefix);
|
|
24
|
-
const tx = hex('11', 32);
|
|
25
|
-
const txv = hex('22', 32);
|
|
26
|
-
const nonce = hex('33', 32);
|
|
27
|
-
const amount = hex('44', 16);
|
|
28
|
-
const signature = hex('55', 64);
|
|
29
|
-
|
|
30
|
-
const payload = {
|
|
31
|
-
type: OperationType.TRANSFER,
|
|
32
|
-
address: sender,
|
|
33
|
-
tro: {
|
|
34
|
-
tx,
|
|
35
|
-
txv,
|
|
36
|
-
in: nonce,
|
|
37
|
-
to: recipient,
|
|
38
|
-
am: amount,
|
|
39
|
-
is: signature
|
|
40
|
-
}
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
const normalized = normalizeTransferOperation(payload, config);
|
|
44
|
-
|
|
45
|
-
t.is(normalized.type, OperationType.TRANSFER);
|
|
46
|
-
t.ok(b4a.equals(normalized.address, addressToBuffer(sender, config.addressPrefix)));
|
|
47
|
-
t.ok(b4a.equals(normalized.tro.tx, toBuffer(tx)));
|
|
48
|
-
t.ok(b4a.equals(normalized.tro.txv, toBuffer(txv)));
|
|
49
|
-
t.ok(b4a.equals(normalized.tro.in, toBuffer(nonce)));
|
|
50
|
-
t.ok(b4a.equals(normalized.tro.to, addressToBuffer(recipient, config.addressPrefix)));
|
|
51
|
-
t.ok(b4a.equals(normalized.tro.am, toBuffer(amount)));
|
|
52
|
-
t.ok(b4a.equals(normalized.tro.is, toBuffer(signature)));
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
test('normalizeTransferOperation accepts buffer inputs', t => {
|
|
56
|
-
const sender = randomAddress(config.addressPrefix);
|
|
57
|
-
const recipient = randomAddress(config.addressPrefix);
|
|
58
|
-
const tx = toBuffer(hex('aa', 32));
|
|
59
|
-
const txv = toBuffer(hex('bb', 32));
|
|
60
|
-
const nonce = toBuffer(hex('cc', 32));
|
|
61
|
-
const amount = toBuffer(hex('dd', 16));
|
|
62
|
-
const signature = toBuffer(hex('ee', 64));
|
|
63
|
-
|
|
64
|
-
const payload = {
|
|
65
|
-
type: OperationType.TRANSFER,
|
|
66
|
-
address: sender,
|
|
67
|
-
tro: {
|
|
68
|
-
tx,
|
|
69
|
-
txv,
|
|
70
|
-
in: nonce,
|
|
71
|
-
to: recipient,
|
|
72
|
-
am: amount,
|
|
73
|
-
is: signature
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
const normalized = normalizeTransferOperation(payload, config);
|
|
78
|
-
t.ok(b4a.equals(normalized.tro.tx, tx));
|
|
79
|
-
t.ok(b4a.equals(normalized.tro.txv, txv));
|
|
80
|
-
t.ok(b4a.equals(normalized.tro.in, nonce));
|
|
81
|
-
t.ok(b4a.equals(normalized.tro.am, amount));
|
|
82
|
-
t.ok(b4a.equals(normalized.tro.is, signature));
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
test('normalizeTransferOperation throws on missing payload fields', t => {
|
|
86
|
-
t.exception(
|
|
87
|
-
() => normalizeTransferOperation({ type: OperationType.TRANSFER }, config),
|
|
88
|
-
errorMessageIncludes('Invalid payload for transfer operation normalization.')
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
t.exception(
|
|
92
|
-
() => normalizeTransferOperation({ type: OperationType.TX, address: 'x', tro: {} }, config),
|
|
93
|
-
errorMessageIncludes('Missing required fields in transfer operation payload.')
|
|
94
|
-
);
|
|
95
|
-
|
|
96
|
-
const sender = randomAddress(config.addressPrefix);
|
|
97
|
-
const payload = {
|
|
98
|
-
type: OperationType.TRANSFER,
|
|
99
|
-
address: sender,
|
|
100
|
-
tro: {
|
|
101
|
-
tx: hex('11', 32),
|
|
102
|
-
txv: hex('22', 32),
|
|
103
|
-
in: hex('33', 32),
|
|
104
|
-
to: randomAddress(config.addressPrefix),
|
|
105
|
-
am: hex('44', 16)
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
t.exception(
|
|
109
|
-
() => normalizeTransferOperation(payload, config),
|
|
110
|
-
errorMessageIncludes('Missing required fields in transfer operation payload.')
|
|
111
|
-
);
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
test('normalizeTransferOperation throws on invalid hex string', t => {
|
|
115
|
-
const sender = randomAddress(config.addressPrefix);
|
|
116
|
-
const payload = {
|
|
117
|
-
type: OperationType.TRANSFER,
|
|
118
|
-
address: sender,
|
|
119
|
-
tro: {
|
|
120
|
-
tx: 'zz',
|
|
121
|
-
txv: hex('22', 32),
|
|
122
|
-
in: hex('33', 32),
|
|
123
|
-
to: randomAddress(config.addressPrefix),
|
|
124
|
-
am: hex('44', 16),
|
|
125
|
-
is: hex('55', 64)
|
|
126
|
-
}
|
|
127
|
-
};
|
|
128
|
-
t.exception(
|
|
129
|
-
() => normalizeTransferOperation(payload, config),
|
|
130
|
-
errorMessageIncludes('Invalid hex string')
|
|
131
|
-
);
|
|
132
|
-
});
|
|
133
|
-
|
|
134
|
-
test('normalizeTransactionOperation normalizes hex strings and addresses', t => {
|
|
135
|
-
const sender = randomAddress(config.addressPrefix);
|
|
136
|
-
const tx = hex('11', 32);
|
|
137
|
-
const txv = hex('22', 32);
|
|
138
|
-
const writerKey = hex('33', 32);
|
|
139
|
-
const contentHash = hex('44', 32);
|
|
140
|
-
const bootstrap = hex('55', 32);
|
|
141
|
-
const msbBootstrap = hex('66', 32);
|
|
142
|
-
const nonce = hex('77', 32);
|
|
143
|
-
const signature = hex('88', 64);
|
|
144
|
-
|
|
145
|
-
const payload = {
|
|
146
|
-
type: OperationType.TX,
|
|
147
|
-
address: sender,
|
|
148
|
-
txo: {
|
|
149
|
-
tx,
|
|
150
|
-
txv,
|
|
151
|
-
iw: writerKey,
|
|
152
|
-
ch: contentHash,
|
|
153
|
-
bs: bootstrap,
|
|
154
|
-
mbs: msbBootstrap,
|
|
155
|
-
in: nonce,
|
|
156
|
-
is: signature
|
|
157
|
-
}
|
|
158
|
-
};
|
|
159
|
-
|
|
160
|
-
const normalized = normalizeTransactionOperation(payload, config);
|
|
161
|
-
t.is(normalized.type, OperationType.TX);
|
|
162
|
-
t.ok(b4a.equals(normalized.address, addressToBuffer(sender, config.addressPrefix)));
|
|
163
|
-
t.ok(b4a.equals(normalized.txo.tx, toBuffer(tx)));
|
|
164
|
-
t.ok(b4a.equals(normalized.txo.txv, toBuffer(txv)));
|
|
165
|
-
t.ok(b4a.equals(normalized.txo.iw, toBuffer(writerKey)));
|
|
166
|
-
t.ok(b4a.equals(normalized.txo.ch, toBuffer(contentHash)));
|
|
167
|
-
t.ok(b4a.equals(normalized.txo.bs, toBuffer(bootstrap)));
|
|
168
|
-
t.ok(b4a.equals(normalized.txo.mbs, toBuffer(msbBootstrap)));
|
|
169
|
-
t.ok(b4a.equals(normalized.txo.in, toBuffer(nonce)));
|
|
170
|
-
t.ok(b4a.equals(normalized.txo.is, toBuffer(signature)));
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
test('normalizeTransactionOperation accepts buffer inputs', t => {
|
|
174
|
-
const sender = randomAddress(config.addressPrefix);
|
|
175
|
-
const tx = toBuffer(hex('aa', 32));
|
|
176
|
-
const txv = toBuffer(hex('bb', 32));
|
|
177
|
-
const writerKey = toBuffer(hex('cc', 32));
|
|
178
|
-
const contentHash = toBuffer(hex('dd', 32));
|
|
179
|
-
const bootstrap = toBuffer(hex('ee', 32));
|
|
180
|
-
const msbBootstrap = toBuffer(hex('ff', 32));
|
|
181
|
-
const nonce = toBuffer(hex('12', 32));
|
|
182
|
-
const signature = toBuffer(hex('34', 64));
|
|
183
|
-
|
|
184
|
-
const payload = {
|
|
185
|
-
type: OperationType.TX,
|
|
186
|
-
address: sender,
|
|
187
|
-
txo: {
|
|
188
|
-
tx,
|
|
189
|
-
txv,
|
|
190
|
-
iw: writerKey,
|
|
191
|
-
ch: contentHash,
|
|
192
|
-
bs: bootstrap,
|
|
193
|
-
mbs: msbBootstrap,
|
|
194
|
-
in: nonce,
|
|
195
|
-
is: signature
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const normalized = normalizeTransactionOperation(payload, config);
|
|
200
|
-
t.ok(b4a.equals(normalized.txo.tx, tx));
|
|
201
|
-
t.ok(b4a.equals(normalized.txo.txv, txv));
|
|
202
|
-
t.ok(b4a.equals(normalized.txo.iw, writerKey));
|
|
203
|
-
t.ok(b4a.equals(normalized.txo.ch, contentHash));
|
|
204
|
-
t.ok(b4a.equals(normalized.txo.bs, bootstrap));
|
|
205
|
-
t.ok(b4a.equals(normalized.txo.mbs, msbBootstrap));
|
|
206
|
-
t.ok(b4a.equals(normalized.txo.in, nonce));
|
|
207
|
-
t.ok(b4a.equals(normalized.txo.is, signature));
|
|
208
|
-
});
|
|
209
|
-
|
|
210
|
-
test('normalizeTransactionOperation throws on missing payload fields', t => {
|
|
211
|
-
t.exception(
|
|
212
|
-
() => normalizeTransactionOperation({ type: OperationType.TX }, config),
|
|
213
|
-
errorMessageIncludes('Invalid payload for transaction operation normalization.')
|
|
214
|
-
);
|
|
215
|
-
|
|
216
|
-
t.exception(
|
|
217
|
-
() => normalizeTransactionOperation({ type: OperationType.TRANSFER, address: 'x', txo: {} }, config),
|
|
218
|
-
errorMessageIncludes('Missing required fields in transaction operation payload.')
|
|
219
|
-
);
|
|
220
|
-
|
|
221
|
-
const sender = randomAddress(config.addressPrefix);
|
|
222
|
-
const payload = {
|
|
223
|
-
type: OperationType.TX,
|
|
224
|
-
address: sender,
|
|
225
|
-
txo: {
|
|
226
|
-
tx: hex('11', 32),
|
|
227
|
-
txv: hex('22', 32),
|
|
228
|
-
iw: hex('33', 32),
|
|
229
|
-
ch: hex('44', 32),
|
|
230
|
-
bs: hex('55', 32),
|
|
231
|
-
mbs: hex('66', 32),
|
|
232
|
-
in: hex('77', 32)
|
|
233
|
-
}
|
|
234
|
-
};
|
|
235
|
-
t.exception(
|
|
236
|
-
() => normalizeTransactionOperation(payload, config),
|
|
237
|
-
errorMessageIncludes('Missing required fields in transaction operation payload.')
|
|
238
|
-
);
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
test('normalizeTransactionOperation throws on invalid hex string', t => {
|
|
242
|
-
const sender = randomAddress(config.addressPrefix);
|
|
243
|
-
const payload = {
|
|
244
|
-
type: OperationType.TX,
|
|
245
|
-
address: sender,
|
|
246
|
-
txo: {
|
|
247
|
-
tx: 'zz',
|
|
248
|
-
txv: hex('22', 32),
|
|
249
|
-
iw: hex('33', 32),
|
|
250
|
-
ch: hex('44', 32),
|
|
251
|
-
bs: hex('55', 32),
|
|
252
|
-
mbs: hex('66', 32),
|
|
253
|
-
in: hex('77', 32),
|
|
254
|
-
is: hex('88', 64)
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
t.exception(
|
|
258
|
-
() => normalizeTransactionOperation(payload, config),
|
|
259
|
-
errorMessageIncludes('Invalid hex string')
|
|
260
|
-
);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
test('normalizeRoleAccessOperation normalizes hex strings and addresses', t => {
|
|
264
|
-
const sender = randomAddress(config.addressPrefix);
|
|
265
|
-
const payload = {
|
|
266
|
-
type: OperationType.ADD_WRITER,
|
|
267
|
-
address: sender,
|
|
268
|
-
rao: {
|
|
269
|
-
tx: hex('11', 32),
|
|
270
|
-
txv: hex('22', 32),
|
|
271
|
-
iw: hex('33', 32),
|
|
272
|
-
in: hex('44', 32),
|
|
273
|
-
is: hex('55', 64)
|
|
274
|
-
}
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
const normalized = normalizeRoleAccessOperation(payload, config);
|
|
278
|
-
t.is(normalized.type, OperationType.ADD_WRITER);
|
|
279
|
-
t.ok(b4a.equals(normalized.address, addressToBuffer(sender, config.addressPrefix)));
|
|
280
|
-
t.ok(b4a.equals(normalized.rao.tx, toBuffer(hex('11', 32))));
|
|
281
|
-
t.ok(b4a.equals(normalized.rao.txv, toBuffer(hex('22', 32))));
|
|
282
|
-
t.ok(b4a.equals(normalized.rao.iw, toBuffer(hex('33', 32))));
|
|
283
|
-
t.ok(b4a.equals(normalized.rao.in, toBuffer(hex('44', 32))));
|
|
284
|
-
t.ok(b4a.equals(normalized.rao.is, toBuffer(hex('55', 64))));
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
test('normalizeRoleAccessOperation accepts buffer inputs', t => {
|
|
288
|
-
const sender = randomAddress(config.addressPrefix);
|
|
289
|
-
const tx = toBuffer(hex('aa', 32));
|
|
290
|
-
const txv = toBuffer(hex('bb', 32));
|
|
291
|
-
const writerKey = toBuffer(hex('cc', 32));
|
|
292
|
-
const nonce = toBuffer(hex('dd', 32));
|
|
293
|
-
const signature = toBuffer(hex('ee', 64));
|
|
294
|
-
|
|
295
|
-
const payload = {
|
|
296
|
-
type: OperationType.REMOVE_WRITER,
|
|
297
|
-
address: sender,
|
|
298
|
-
rao: {
|
|
299
|
-
tx,
|
|
300
|
-
txv,
|
|
301
|
-
iw: writerKey,
|
|
302
|
-
in: nonce,
|
|
303
|
-
is: signature
|
|
304
|
-
}
|
|
305
|
-
};
|
|
306
|
-
|
|
307
|
-
const normalized = normalizeRoleAccessOperation(payload, config);
|
|
308
|
-
t.ok(b4a.equals(normalized.rao.tx, tx));
|
|
309
|
-
t.ok(b4a.equals(normalized.rao.txv, txv));
|
|
310
|
-
t.ok(b4a.equals(normalized.rao.iw, writerKey));
|
|
311
|
-
t.ok(b4a.equals(normalized.rao.in, nonce));
|
|
312
|
-
t.ok(b4a.equals(normalized.rao.is, signature));
|
|
313
|
-
});
|
|
314
|
-
|
|
315
|
-
test('normalizeRoleAccessOperation throws on missing payload fields', t => {
|
|
316
|
-
t.exception(
|
|
317
|
-
() => normalizeRoleAccessOperation({ type: OperationType.ADD_WRITER }, config),
|
|
318
|
-
errorMessageIncludes('Invalid payload for role access normalization.')
|
|
319
|
-
);
|
|
320
|
-
|
|
321
|
-
t.exception(
|
|
322
|
-
() => normalizeRoleAccessOperation({ type: OperationType.ADD_WRITER, address: 'x', rao: {} }, config),
|
|
323
|
-
errorMessageIncludes('Missing required fields in role access payload.')
|
|
324
|
-
);
|
|
325
|
-
});
|
|
326
|
-
|
|
327
|
-
test('normalizeRoleAccessOperation throws on invalid hex string', t => {
|
|
328
|
-
const sender = randomAddress(config.addressPrefix);
|
|
329
|
-
const payload = {
|
|
330
|
-
type: OperationType.ADD_WRITER,
|
|
331
|
-
address: sender,
|
|
332
|
-
rao: {
|
|
333
|
-
tx: 'zz',
|
|
334
|
-
txv: hex('22', 32),
|
|
335
|
-
iw: hex('33', 32),
|
|
336
|
-
in: hex('44', 32),
|
|
337
|
-
is: hex('55', 64)
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
t.exception(
|
|
341
|
-
() => normalizeRoleAccessOperation(payload, config),
|
|
342
|
-
errorMessageIncludes('Invalid hex string')
|
|
343
|
-
);
|
|
344
|
-
});
|
|
345
|
-
|
|
346
|
-
test('normalizeBootstrapDeploymentOperation normalizes hex strings and addresses', t => {
|
|
347
|
-
const sender = randomAddress(config.addressPrefix);
|
|
348
|
-
const payload = {
|
|
349
|
-
type: OperationType.BOOTSTRAP_DEPLOYMENT,
|
|
350
|
-
address: sender,
|
|
351
|
-
bdo: {
|
|
352
|
-
tx: hex('11', 32),
|
|
353
|
-
txv: hex('22', 32),
|
|
354
|
-
bs: hex('33', 32),
|
|
355
|
-
ic: hex('44', 32),
|
|
356
|
-
in: hex('55', 32),
|
|
357
|
-
is: hex('66', 64)
|
|
358
|
-
}
|
|
359
|
-
};
|
|
360
|
-
|
|
361
|
-
const normalized = normalizeBootstrapDeploymentOperation(payload, config);
|
|
362
|
-
t.is(normalized.type, OperationType.BOOTSTRAP_DEPLOYMENT);
|
|
363
|
-
t.ok(b4a.equals(normalized.address, addressToBuffer(sender, config.addressPrefix)));
|
|
364
|
-
t.ok(b4a.equals(normalized.bdo.tx, toBuffer(hex('11', 32))));
|
|
365
|
-
t.ok(b4a.equals(normalized.bdo.txv, toBuffer(hex('22', 32))));
|
|
366
|
-
t.ok(b4a.equals(normalized.bdo.bs, toBuffer(hex('33', 32))));
|
|
367
|
-
t.ok(b4a.equals(normalized.bdo.ic, toBuffer(hex('44', 32))));
|
|
368
|
-
t.ok(b4a.equals(normalized.bdo.in, toBuffer(hex('55', 32))));
|
|
369
|
-
t.ok(b4a.equals(normalized.bdo.is, toBuffer(hex('66', 64))));
|
|
370
|
-
});
|
|
371
|
-
|
|
372
|
-
test('normalizeBootstrapDeploymentOperation accepts buffer inputs', t => {
|
|
373
|
-
const sender = randomAddress(config.addressPrefix);
|
|
374
|
-
const tx = toBuffer(hex('aa', 32));
|
|
375
|
-
const txv = toBuffer(hex('bb', 32));
|
|
376
|
-
const bootstrap = toBuffer(hex('cc', 32));
|
|
377
|
-
const channel = toBuffer(hex('dd', 32));
|
|
378
|
-
const nonce = toBuffer(hex('ee', 32));
|
|
379
|
-
const signature = toBuffer(hex('ff', 64));
|
|
380
|
-
|
|
381
|
-
const payload = {
|
|
382
|
-
type: OperationType.BOOTSTRAP_DEPLOYMENT,
|
|
383
|
-
address: sender,
|
|
384
|
-
bdo: {
|
|
385
|
-
tx,
|
|
386
|
-
txv,
|
|
387
|
-
bs: bootstrap,
|
|
388
|
-
ic: channel,
|
|
389
|
-
in: nonce,
|
|
390
|
-
is: signature
|
|
391
|
-
}
|
|
392
|
-
};
|
|
393
|
-
|
|
394
|
-
const normalized = normalizeBootstrapDeploymentOperation(payload, config);
|
|
395
|
-
t.ok(b4a.equals(normalized.bdo.tx, tx));
|
|
396
|
-
t.ok(b4a.equals(normalized.bdo.txv, txv));
|
|
397
|
-
t.ok(b4a.equals(normalized.bdo.bs, bootstrap));
|
|
398
|
-
t.ok(b4a.equals(normalized.bdo.ic, channel));
|
|
399
|
-
t.ok(b4a.equals(normalized.bdo.in, nonce));
|
|
400
|
-
t.ok(b4a.equals(normalized.bdo.is, signature));
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
test('normalizeBootstrapDeploymentOperation throws on missing payload fields', t => {
|
|
404
|
-
t.exception(
|
|
405
|
-
() => normalizeBootstrapDeploymentOperation({ type: OperationType.BOOTSTRAP_DEPLOYMENT }, config),
|
|
406
|
-
errorMessageIncludes('Invalid payload for bootstrap deployment normalization.')
|
|
407
|
-
);
|
|
408
|
-
|
|
409
|
-
t.exception(
|
|
410
|
-
() => normalizeBootstrapDeploymentOperation({ type: OperationType.TX, address: 'x', bdo: {} }, config),
|
|
411
|
-
errorMessageIncludes('Missing required fields in bootstrap deployment payload.')
|
|
412
|
-
);
|
|
413
|
-
});
|
|
414
|
-
|
|
415
|
-
test('normalizeBootstrapDeploymentOperation throws on invalid hex string', t => {
|
|
416
|
-
const sender = randomAddress(config.addressPrefix);
|
|
417
|
-
const payload = {
|
|
418
|
-
type: OperationType.BOOTSTRAP_DEPLOYMENT,
|
|
419
|
-
address: sender,
|
|
420
|
-
bdo: {
|
|
421
|
-
tx: 'zz',
|
|
422
|
-
txv: hex('22', 32),
|
|
423
|
-
bs: hex('33', 32),
|
|
424
|
-
ic: hex('44', 32),
|
|
425
|
-
in: hex('55', 32),
|
|
426
|
-
is: hex('66', 64)
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
t.exception(
|
|
430
|
-
() => normalizeBootstrapDeploymentOperation(payload, config),
|
|
431
|
-
errorMessageIncludes('Invalid hex string')
|
|
432
|
-
);
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
test('normalizeDecodedPayloadForJson converts buffers to strings', t => {
|
|
436
|
-
const address = randomAddress(config.addressPrefix);
|
|
437
|
-
const addressBuf = addressToBuffer(address, config.addressPrefix);
|
|
438
|
-
const amountBuf = bigIntTo16ByteBuffer(1234n);
|
|
439
|
-
const otherBuf = b4a.from('abcd', 'hex');
|
|
440
|
-
|
|
441
|
-
const payload = {
|
|
442
|
-
address: addressBuf,
|
|
443
|
-
am: amountBuf,
|
|
444
|
-
nested: {
|
|
445
|
-
to: addressBuf,
|
|
446
|
-
amount: amountBuf,
|
|
447
|
-
other: otherBuf
|
|
448
|
-
}
|
|
449
|
-
};
|
|
450
|
-
|
|
451
|
-
const normalized = normalizeDecodedPayloadForJson(payload, config);
|
|
452
|
-
t.is(normalized.address, address);
|
|
453
|
-
t.is(normalized.am, '1234');
|
|
454
|
-
t.is(normalized.nested.to, address);
|
|
455
|
-
t.is(normalized.nested.amount, '1234');
|
|
456
|
-
t.is(normalized.nested.other, 'abcd');
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
test('normalizeDecodedPayloadForJson falls back to hex for invalid address buffers', t => {
|
|
460
|
-
const bad = b4a.from('deadbeef', 'hex');
|
|
461
|
-
const payload = { address: bad };
|
|
462
|
-
const normalized = normalizeDecodedPayloadForJson(payload, config);
|
|
463
|
-
t.is(normalized.address, b4a.toString(bad, 'hex'));
|
|
464
|
-
});
|
|
465
|
-
|
|
466
|
-
test('normalizeDecodedPayloadForJson returns input for non-objects', t => {
|
|
467
|
-
t.is(normalizeDecodedPayloadForJson(null, config), null);
|
|
468
|
-
t.is(normalizeDecodedPayloadForJson('value', config), 'value');
|
|
469
|
-
});
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import test from 'brittle';
|
|
2
|
-
import { safeDecodeApplyOperation, safeEncodeApplyOperation } from '../../../src/utils/protobuf/operationHelpers.js';
|
|
3
|
-
import b4a from 'b4a';
|
|
4
|
-
import fixtures from '../../fixtures/protobuf.fixtures.js';
|
|
5
|
-
//TODO add missing operations tests and fill fixtures with them
|
|
6
|
-
test('Happy path encode/decode roundtrip for protobuf applyOperation payloads', t => {
|
|
7
|
-
const payloadsHashMap = new Map([
|
|
8
|
-
["tx", fixtures.validTransactionOperation],
|
|
9
|
-
["addIndexer", fixtures.validAddIndexer],
|
|
10
|
-
["removeIndexer", fixtures.validRemoveIndexer],
|
|
11
|
-
["appendWhitelist", fixtures.validAppendWhitelist],
|
|
12
|
-
["banValidator", fixtures.validBanValidator],
|
|
13
|
-
["addAdmin", fixtures.validAddAdmin],
|
|
14
|
-
["addWriterComplete", fixtures.validCompleteAddWriter],
|
|
15
|
-
["addWriterPartial", fixtures.validPartialAddWriter],
|
|
16
|
-
["removeWriterComplete", fixtures.validCompleteRemoveWriter],
|
|
17
|
-
["removeWriterPartial", fixtures.validPartialRemoveWriter],
|
|
18
|
-
["adminRecoveryComplete", fixtures.validCompleteAdminRecovery],
|
|
19
|
-
["adminRecoveryPartial", fixtures.validPartialAdminRecovery],
|
|
20
|
-
]);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
for (const [key, value] of payloadsHashMap) {
|
|
24
|
-
const encoded = safeEncodeApplyOperation(value)
|
|
25
|
-
t.ok(encoded, 'encoded !== null')
|
|
26
|
-
t.ok(encoded instanceof Buffer || b4a.isBuffer(encoded), 'encoded to Buffer')
|
|
27
|
-
const decoded = safeDecodeApplyOperation(encoded)
|
|
28
|
-
t.ok(JSON.stringify(value) === JSON.stringify(decoded), `Payload with ${key} should be encoded and decoded correctly`);
|
|
29
|
-
}
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
test('safeEncodeAppyOperation - handles invalid payloads by returning a Buffer', t => {
|
|
33
|
-
for (const invalidPayload of fixtures.invalidPayloads) {
|
|
34
|
-
let encoded;
|
|
35
|
-
try {
|
|
36
|
-
encoded = safeEncodeApplyOperation(invalidPayload);
|
|
37
|
-
} catch {
|
|
38
|
-
encoded = null;
|
|
39
|
-
}
|
|
40
|
-
let display;
|
|
41
|
-
if (typeof invalidPayload === 'bigint') {
|
|
42
|
-
display = invalidPayload.toString() + 'n';
|
|
43
|
-
} else {
|
|
44
|
-
try {
|
|
45
|
-
const str = JSON.stringify(invalidPayload);
|
|
46
|
-
display = str.length > 128 ? `(payload size: ${str.length} bytes)` : str;
|
|
47
|
-
} catch {
|
|
48
|
-
const s = String(invalidPayload);
|
|
49
|
-
display = s.length > 128 ? `(payload size: ${s.length} bytes)` : s;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
t.ok(b4a.isBuffer(encoded), `payload: ${display}`);
|
|
53
|
-
}
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('safeDecodeApplyOperation - handles invalid payloads by returning null or object', t => {
|
|
57
|
-
for (const invalidPayload of fixtures.invalidPayloads) {
|
|
58
|
-
const decoded = safeDecodeApplyOperation(invalidPayload)
|
|
59
|
-
t.ok(decoded === null || typeof decoded === 'object', `should be null or object, we received: ${decoded}`);
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
test('safeEncodeAppyOperation - returns an empty buffer when multiple `oneof` fields are present', t => {
|
|
64
|
-
const encoded = safeEncodeApplyOperation(fixtures.invalidPayloadWithMultipleOneOfKeys)
|
|
65
|
-
console.log('Encoded (oneof conflict):', encoded)
|
|
66
|
-
t.ok(b4a.isBuffer(encoded), 'Should return a Buffer')
|
|
67
|
-
t.ok(encoded.equals(b4a.alloc(0)), 'Should return an empty buffer')
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
test('safeEncodeAppyOperation - when encodingLength throws due to multiple oneof fields, returns an empty buffer safely', t => {
|
|
72
|
-
const encoded = safeEncodeApplyOperation(fixtures.invalidPayloadWithMultipleOneOfKeys);
|
|
73
|
-
t.ok(b4a.isBuffer(encoded), 'returns a Buffer');
|
|
74
|
-
t.is(encoded.length, 0, 'returns empty buffer for multiple oneof fields');
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
test('safeDecodeApplyOperation - handles invalid offset/end parameters gracefully without throwing', t => {
|
|
78
|
-
const buf = b4a.from([8, 1]); // type = 1
|
|
79
|
-
|
|
80
|
-
const decodedWithInvalidEnd = safeDecodeApplyOperation(buf, 0, buf.length + 1);
|
|
81
|
-
t.ok(decodedWithInvalidEnd === null || typeof decodedWithInvalidEnd === 'object', 'Should return null or object when end > buffer length');
|
|
82
|
-
const decodedWithInvalidOffset = safeDecodeApplyOperation(buf, buf.length + 1);
|
|
83
|
-
t.ok(decodedWithInvalidOffset === null || typeof decodedWithInvalidOffset === 'object', 'Should return null or object when offset > buffer length');
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
test('safeDecodeApplyOperation - decode calls skip() on unknown wire type, safely returns null or object', t => {
|
|
88
|
-
const bufWithUnknownWire = b4a.from([0x0F]);
|
|
89
|
-
const decoded = safeDecodeApplyOperation(bufWithUnknownWire);
|
|
90
|
-
t.ok(decoded === null || typeof decoded === 'object', 'Should return null or object on unknown wire type');
|
|
91
|
-
});
|