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,123 +0,0 @@
|
|
|
1
|
-
import request from "supertest"
|
|
2
|
-
import { bufferToBigInt, licenseBufferToBigInt } from "../../../../src/utils/amountSerialization.js"
|
|
3
|
-
import { ZERO_WK } from "../../../../rpc/constants.js"
|
|
4
|
-
import { ADMIN_INITIAL_STAKED_BALANCE } from "../../../../src/utils/constants.js"
|
|
5
|
-
import { BALANCE_TO_STAKE } from "../../../../src/core/state/utils/balance.js"
|
|
6
|
-
import { randomAddress } from "../../../unit/state/stateTestUtils.js"
|
|
7
|
-
|
|
8
|
-
export const registerAccountTests = (context) => {
|
|
9
|
-
const formatNodeEntryResponse = (address, entry) => {
|
|
10
|
-
const licenseValue = licenseBufferToBigInt(entry.license)
|
|
11
|
-
return {
|
|
12
|
-
address,
|
|
13
|
-
writingKey: entry.wk.toString('hex'),
|
|
14
|
-
isWhitelisted: entry.isWhitelisted,
|
|
15
|
-
isValidator: entry.isWriter,
|
|
16
|
-
isIndexer: entry.isIndexer,
|
|
17
|
-
license: licenseValue === 0n ? null : licenseValue.toString(),
|
|
18
|
-
balance: bufferToBigInt(entry.balance).toString(),
|
|
19
|
-
stakedBalance: bufferToBigInt(entry.stakedBalance).toString(),
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
describe("GET /v1/account", () => {
|
|
24
|
-
it("returns admin account details", async () => {
|
|
25
|
-
const adminEntry = await context.rpcMsb.state.getNodeEntry(context.adminWallet.address)
|
|
26
|
-
expect(adminEntry).toBeTruthy()
|
|
27
|
-
|
|
28
|
-
const res = await request(context.server).get(`/v1/account/${context.adminWallet.address}`)
|
|
29
|
-
expect(res.statusCode).toBe(200)
|
|
30
|
-
expect(res.body).toEqual(formatNodeEntryResponse(context.adminWallet.address, adminEntry))
|
|
31
|
-
expect(res.body).toMatchObject({
|
|
32
|
-
isWhitelisted: true,
|
|
33
|
-
isValidator: true,
|
|
34
|
-
isIndexer: true,
|
|
35
|
-
stakedBalance: bufferToBigInt(ADMIN_INITIAL_STAKED_BALANCE).toString(),
|
|
36
|
-
license: '1',
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it("returns validator account details", async () => {
|
|
41
|
-
const writerEntry = await context.rpcMsb.state.getNodeEntry(context.wallet.address)
|
|
42
|
-
expect(writerEntry).toBeTruthy()
|
|
43
|
-
|
|
44
|
-
const res = await request(context.server).get(`/v1/account/${context.wallet.address}`)
|
|
45
|
-
expect(res.statusCode).toBe(200)
|
|
46
|
-
expect(res.body).toEqual(formatNodeEntryResponse(context.wallet.address, writerEntry))
|
|
47
|
-
expect(res.body).toMatchObject({
|
|
48
|
-
isWhitelisted: true,
|
|
49
|
-
isValidator: true,
|
|
50
|
-
stakedBalance: bufferToBigInt(BALANCE_TO_STAKE.value).toString(),
|
|
51
|
-
})
|
|
52
|
-
expect(res.body.license).not.toBeNull()
|
|
53
|
-
expect(res.body.license).not.toBe('1')
|
|
54
|
-
})
|
|
55
|
-
|
|
56
|
-
it("returns validator account details when confirmed=true", async () => {
|
|
57
|
-
const confirmedEntry = await context.rpcMsb.state.getNodeEntry(context.wallet.address)
|
|
58
|
-
expect(confirmedEntry).toBeTruthy()
|
|
59
|
-
|
|
60
|
-
const res = await request(context.server).get(`/v1/account/${context.wallet.address}?confirmed=true`)
|
|
61
|
-
expect(res.statusCode).toBe(200)
|
|
62
|
-
expect(res.body).toEqual(formatNodeEntryResponse(context.wallet.address, confirmedEntry))
|
|
63
|
-
})
|
|
64
|
-
|
|
65
|
-
it("returns validator account details (unconfirmed view)", async () => {
|
|
66
|
-
const unsignedEntry = await context.rpcMsb.state.getNodeEntryUnsigned(context.wallet.address)
|
|
67
|
-
expect(unsignedEntry).toBeTruthy()
|
|
68
|
-
|
|
69
|
-
const res = await request(context.server).get(`/v1/account/${context.wallet.address}?confirmed=false`)
|
|
70
|
-
expect(res.statusCode).toBe(200)
|
|
71
|
-
expect(res.body).toEqual(formatNodeEntryResponse(context.wallet.address, unsignedEntry))
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
it("returns default state for non-existent node", async () => {
|
|
75
|
-
const address = randomAddress(context.rpcMsb.config.addressPrefix)
|
|
76
|
-
|
|
77
|
-
const res = await request(context.server).get(`/v1/account/${address}`)
|
|
78
|
-
expect(res.statusCode).toBe(200)
|
|
79
|
-
expect(res.body).toEqual({
|
|
80
|
-
address: address,
|
|
81
|
-
writingKey: ZERO_WK.toString('hex'),
|
|
82
|
-
isWhitelisted: false,
|
|
83
|
-
isValidator: false,
|
|
84
|
-
isIndexer: false,
|
|
85
|
-
license: null,
|
|
86
|
-
balance: '0',
|
|
87
|
-
stakedBalance: '0',
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
|
|
91
|
-
it("returns 400 when address is missing", async () => {
|
|
92
|
-
const res = await request(context.server).get("/v1/account")
|
|
93
|
-
expect(res.statusCode).toBe(400)
|
|
94
|
-
expect(res.body).toEqual({ error: "Account address is required" })
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it("returns 400 for invalid address format", async () => {
|
|
98
|
-
const res = await request(context.server).get("/v1/account/not-a-valid-address")
|
|
99
|
-
expect(res.statusCode).toBe(400)
|
|
100
|
-
expect(res.body).toEqual({ error: "Invalid account address format" })
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it("returns 400 for invalid confirmed parameter", async () => {
|
|
104
|
-
const res = await request(context.server).get(`/v1/account/${context.wallet.address}?confirmed=test`)
|
|
105
|
-
expect(res.statusCode).toBe(400)
|
|
106
|
-
expect(res.body).toEqual({ error: 'Parameter "confirmed" must be exactly "true" or "false"' })
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it("returns 500 on internal error", async () => {
|
|
110
|
-
const originalGetNodeEntry = context.rpcMsb.state.getNodeEntry
|
|
111
|
-
|
|
112
|
-
context.rpcMsb.state.getNodeEntry = async () => { throw new Error("test") }
|
|
113
|
-
|
|
114
|
-
try {
|
|
115
|
-
const res = await request(context.server).get(`/v1/account/${context.wallet.address}`)
|
|
116
|
-
expect(res.statusCode).toBe(500)
|
|
117
|
-
expect(res.body).toEqual({ error: 'An error occurred processing the request.' })
|
|
118
|
-
} finally {
|
|
119
|
-
context.rpcMsb.state.getNodeEntry = originalGetNodeEntry
|
|
120
|
-
}
|
|
121
|
-
})
|
|
122
|
-
})
|
|
123
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import request from "supertest"
|
|
2
|
-
import { randomAddress } from "../../../unit/state/stateTestUtils.js"
|
|
3
|
-
|
|
4
|
-
export const registerBalanceTests = (context) => {
|
|
5
|
-
let expectedBalance
|
|
6
|
-
describe("GET /v1/balance", () => {
|
|
7
|
-
it("returns balance for confirmed view by default", async () => {
|
|
8
|
-
const res = await request(context.server).get(`/v1/balance/${context.wallet.address}`)
|
|
9
|
-
expect(res.statusCode).toBe(200)
|
|
10
|
-
expect(res.body.address).toBe(context.wallet.address)
|
|
11
|
-
expect(typeof res.body.balance).toBe("string")
|
|
12
|
-
expectedBalance = res.body.balance
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
it("returns balance for unconfirmed view", async () => {
|
|
16
|
-
const res = await request(context.server).get(`/v1/balance/${context.wallet.address}?confirmed=false`)
|
|
17
|
-
expect(res.statusCode).toBe(200)
|
|
18
|
-
expect(res.body).toEqual({ address: context.wallet.address, balance: expectedBalance })
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it("returns balance when confirmed flag is explicitly true", async () => {
|
|
22
|
-
const res = await request(context.server).get(`/v1/balance/${context.wallet.address}?confirmed=true`)
|
|
23
|
-
expect(res.statusCode).toBe(200)
|
|
24
|
-
expect(res.body).toEqual({ address: context.wallet.address, balance: expectedBalance })
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it("falls back to unconfirmed view on invalid confirmed flag", async () => {
|
|
28
|
-
const res = await request(context.server).get(`/v1/balance/${context.wallet.address}?confirmed=test`)
|
|
29
|
-
expect(res.statusCode).toBe(200)
|
|
30
|
-
expect(res.body).toEqual({ address: context.wallet.address, balance: expectedBalance })
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it("returns 400 when address is missing", async () => {
|
|
34
|
-
const res = await request(context.server).get("/v1/balance")
|
|
35
|
-
expect(res.statusCode).toBe(400)
|
|
36
|
-
expect(res.body).toEqual({ error: "Wallet address is required" })
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it("returns zero balance for an unknown address", async () => {
|
|
40
|
-
const address = randomAddress(context.rpcMsb.config.addressPrefix)
|
|
41
|
-
const res = await request(context.server).get(`/v1/balance/${address}`)
|
|
42
|
-
expect(res.statusCode).toBe(200)
|
|
43
|
-
expect(res.body.address).toBe(address)
|
|
44
|
-
expect(BigInt(res.body.balance)).toBe(0n)
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
it("returns 400 for an invalid address format", async () => {
|
|
48
|
-
const invalidAddress = "not-a-valid-address"
|
|
49
|
-
const res = await request(context.server).get(`/v1/balance/${invalidAddress}`)
|
|
50
|
-
expect(res.statusCode).toBe(400)
|
|
51
|
-
expect(res.body).toEqual({ error: "Invalid account address format" })
|
|
52
|
-
})
|
|
53
|
-
})
|
|
54
|
-
}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import request from "supertest"
|
|
2
|
-
import b4a from "b4a"
|
|
3
|
-
import { buildRpcSelfTransferPayload, waitForConnection } from "../../../helpers/transactionPayloads.mjs"
|
|
4
|
-
|
|
5
|
-
const toBase64 = (value) => b4a.toString(b4a.from(JSON.stringify(value)), "base64")
|
|
6
|
-
|
|
7
|
-
export const registerBroadcastTransactionTests = (context) => {
|
|
8
|
-
describe("POST /v1/broadcast-transaction", () => {
|
|
9
|
-
it("broadcasts transaction and returns lengths", async () => {
|
|
10
|
-
const { payload } = await buildRpcSelfTransferPayload(
|
|
11
|
-
context,
|
|
12
|
-
context.rpcMsb.state,
|
|
13
|
-
1n
|
|
14
|
-
);
|
|
15
|
-
await waitForConnection(context.rpcMsb)
|
|
16
|
-
const res = await request(context.server)
|
|
17
|
-
.post("/v1/broadcast-transaction")
|
|
18
|
-
.set("Accept", "application/json")
|
|
19
|
-
.send(JSON.stringify({ payload }))
|
|
20
|
-
|
|
21
|
-
expect(res.statusCode).toBe(200)
|
|
22
|
-
expect(res.body).toMatchObject({
|
|
23
|
-
result: {
|
|
24
|
-
message: "Transaction broadcasted successfully.",
|
|
25
|
-
signedLength: expect.any(Number),
|
|
26
|
-
unsignedLength: expect.any(Number),
|
|
27
|
-
tx: expect.any(String)
|
|
28
|
-
}
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it("returns 400 when payload is missing", async () => {
|
|
33
|
-
await waitForConnection(context.rpcMsb)
|
|
34
|
-
const res = await request(context.server)
|
|
35
|
-
.post("/v1/broadcast-transaction")
|
|
36
|
-
.set("Accept", "application/json")
|
|
37
|
-
.send(JSON.stringify({}))
|
|
38
|
-
|
|
39
|
-
expect(res.statusCode).toBe(400)
|
|
40
|
-
expect(res.body).toEqual({ error: "Payload is missing." })
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it("returns 400 when payload is not base64", async () => {
|
|
44
|
-
await waitForConnection(context.rpcMsb)
|
|
45
|
-
const res = await request(context.server)
|
|
46
|
-
.post("/v1/broadcast-transaction")
|
|
47
|
-
.set("Accept", "application/json")
|
|
48
|
-
.send(JSON.stringify({ payload: "not-base64" }))
|
|
49
|
-
|
|
50
|
-
expect(res.statusCode).toBe(400)
|
|
51
|
-
expect(res.body).toEqual({ error: "Payload must be a valid base64 string." })
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it("returns 400 when decoded payload is not valid JSON", async () => {
|
|
55
|
-
const invalidJsonBase64 = b4a.toString(b4a.from("{{invalid"), "base64")
|
|
56
|
-
|
|
57
|
-
await waitForConnection(context.rpcMsb)
|
|
58
|
-
const res = await request(context.server)
|
|
59
|
-
.post("/v1/broadcast-transaction")
|
|
60
|
-
.set("Accept", "application/json")
|
|
61
|
-
.send(JSON.stringify({ payload: invalidJsonBase64 }))
|
|
62
|
-
|
|
63
|
-
expect(res.statusCode).toBe(400)
|
|
64
|
-
expect(res.body).toEqual({ error: "Decoded payload is not valid JSON." })
|
|
65
|
-
})
|
|
66
|
-
|
|
67
|
-
it("returns 400 for invalid transaction structure", async () => {
|
|
68
|
-
const invalidStructure = {
|
|
69
|
-
type: 1,
|
|
70
|
-
address: context.wallet.address,
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
await waitForConnection(context.rpcMsb)
|
|
74
|
-
const res = await request(context.server)
|
|
75
|
-
.post("/v1/broadcast-transaction")
|
|
76
|
-
.set("Accept", "application/json")
|
|
77
|
-
.send(JSON.stringify({ payload: toBase64(invalidStructure) }))
|
|
78
|
-
|
|
79
|
-
expect(res.statusCode).toBe(400)
|
|
80
|
-
expect(res.body).toEqual({ error: "Invalid payload structure." })
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it("returns 413 when payload exceeds size limit", async () => {
|
|
84
|
-
const largeString = "a".repeat(2_100_000);
|
|
85
|
-
const payload = toBase64({ type: 1, address: context.wallet.address, txo: { large: largeString } });
|
|
86
|
-
|
|
87
|
-
await waitForConnection(context.rpcMsb);
|
|
88
|
-
const res = await request(context.server)
|
|
89
|
-
.post("/v1/broadcast-transaction")
|
|
90
|
-
.set("Accept", "application/json")
|
|
91
|
-
.send(JSON.stringify({ payload }));
|
|
92
|
-
|
|
93
|
-
expect(res.statusCode).toBe(413);
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
it("returns 429 on repeated broadcast failures", async () => {
|
|
98
|
-
const { payload } = await buildRpcSelfTransferPayload(context, context.rpcMsb.state, 1n);
|
|
99
|
-
const originalMethod = context.rpcMsb.broadcastPartialTransaction;
|
|
100
|
-
context.rpcMsb.broadcastPartialTransaction = async () => false;
|
|
101
|
-
|
|
102
|
-
try {
|
|
103
|
-
await waitForConnection(context.rpcMsb);
|
|
104
|
-
const res = await request(context.server)
|
|
105
|
-
.post("/v1/broadcast-transaction")
|
|
106
|
-
.set("Accept", "application/json")
|
|
107
|
-
.send(JSON.stringify({ payload }));
|
|
108
|
-
|
|
109
|
-
expect(res.statusCode).toBe(429);
|
|
110
|
-
expect(res.body).toEqual({ error: "Failed to broadcast transaction after multiple attempts." });
|
|
111
|
-
} finally {
|
|
112
|
-
context.rpcMsb.broadcastPartialTransaction = originalMethod;
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
})
|
|
116
|
-
}
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import request from "supertest"
|
|
2
|
-
|
|
3
|
-
export const registerConfirmedLengthTests = (context) => {
|
|
4
|
-
describe("GET /v1/confirmed-length", () => {
|
|
5
|
-
it("returns confirmed length", async () => {
|
|
6
|
-
const res = await request(context.server).get("/v1/confirmed-length")
|
|
7
|
-
expect(res.statusCode).toBe(200)
|
|
8
|
-
expect(res.body).toEqual({ confirmed_length: expect.any(Number) })
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
it("matches signed length from state", async () => {
|
|
12
|
-
const res = await request(context.server).get("/v1/confirmed-length")
|
|
13
|
-
expect(res.statusCode).toBe(200)
|
|
14
|
-
|
|
15
|
-
const signedLength = context.rpcMsb.state.getSignedLength()
|
|
16
|
-
expect(res.body).toEqual({ confirmed_length: signedLength })
|
|
17
|
-
})
|
|
18
|
-
})
|
|
19
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import request from "supertest"
|
|
2
|
-
|
|
3
|
-
export const registerFeeTests = (context) => {
|
|
4
|
-
describe("GET /v1/fee", () => {
|
|
5
|
-
it("returns fee", async () => {
|
|
6
|
-
const res = await request(context.server).get("/v1/fee")
|
|
7
|
-
expect(res.statusCode).toBe(200)
|
|
8
|
-
expect(res.body).toEqual({ fee: expect.stringMatching(/^-?\d+(\.\d+)?$/) })
|
|
9
|
-
})
|
|
10
|
-
})
|
|
11
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import request from "supertest"
|
|
2
|
-
|
|
3
|
-
export const registerHealthTests = (context) => {
|
|
4
|
-
describe("GET /v1/health", () => {
|
|
5
|
-
it("should return 200 and ok:true when healthy", async () => {
|
|
6
|
-
const res = await request(context.server).get("/v1/health")
|
|
7
|
-
expect(res.statusCode).toBe(200)
|
|
8
|
-
expect(res.body).toEqual({ ok: true })
|
|
9
|
-
})
|
|
10
|
-
|
|
11
|
-
it("should return 503 when the state is unavailable", async () => {
|
|
12
|
-
const originalState = context.rpcMsb.state;
|
|
13
|
-
Object.defineProperty(context.rpcMsb, 'state', {
|
|
14
|
-
get: () => null,
|
|
15
|
-
configurable: true
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
try {
|
|
19
|
-
const res = await request(context.server).get("/v1/health")
|
|
20
|
-
|
|
21
|
-
expect(res.statusCode).toBe(503)
|
|
22
|
-
expect(res.body).toEqual({
|
|
23
|
-
error: "Could not connect to RPC server"
|
|
24
|
-
})
|
|
25
|
-
} finally {
|
|
26
|
-
Object.defineProperty(context.rpcMsb, 'state', {
|
|
27
|
-
get: () => originalState,
|
|
28
|
-
configurable: true
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
})
|
|
32
|
-
})
|
|
33
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import { createServer } from "../../../rpc/create_server.js"
|
|
2
|
-
import { initTemporaryDirectory } from '../../helpers/setupApplyTests.js'
|
|
3
|
-
import { testKeyPair1, testKeyPair2, testKeyPair3 } from '../../fixtures/apply.fixtures.js'
|
|
4
|
-
import { randomBytes, setupMsbAdmin, setupMsbWriter, removeTemporaryDirectory, setupMsbPeer, tryToSyncWriters, waitForNodeState } from "../../helpers/setupApplyTests.js"
|
|
5
|
-
import { registerAccountTests } from "./account/account.test.mjs"
|
|
6
|
-
import { registerBalanceTests } from "./balance/balance.test.mjs"
|
|
7
|
-
import { registerBroadcastTransactionTests } from "./broadcast-transaction/broadcast-transaction.test.mjs"
|
|
8
|
-
import { registerConfirmedLengthTests } from "./confirmed-length/confirmed-length.test.mjs"
|
|
9
|
-
import { registerFeeTests } from "./fee/fee.test.mjs"
|
|
10
|
-
import { registerTxHashesTests } from "./tx-hashes/tx-hashes.test.mjs"
|
|
11
|
-
import { registerTxPayloadsBulkTests } from "./tx-payloads-bulk/tx-payloads-bulk.test.mjs"
|
|
12
|
-
import { registerTxDetailsTests } from "./tx-details/tx-details.test.mjs"
|
|
13
|
-
import { registerTxTests } from "./tx/tx.test.mjs"
|
|
14
|
-
import { registerTxvTests } from "./txv/txv.test.mjs"
|
|
15
|
-
import { registerUnconfirmedLengthTests } from "./unconfirmed-length/unconfirmed-length.test.mjs"
|
|
16
|
-
import { registerHealthTests } from "./health/health.test.mjs"
|
|
17
|
-
|
|
18
|
-
let toClose
|
|
19
|
-
let tmpDirectory
|
|
20
|
-
const additionalPeers = []
|
|
21
|
-
|
|
22
|
-
const testContext = {
|
|
23
|
-
writerMsb: null,
|
|
24
|
-
rpcMsb: null,
|
|
25
|
-
server: null,
|
|
26
|
-
wallet: null,
|
|
27
|
-
adminWallet: null,
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const setupNetwork = async () => {
|
|
31
|
-
tmpDirectory = await initTemporaryDirectory()
|
|
32
|
-
const rpcOpts = {
|
|
33
|
-
bootstrap: randomBytes(32).toString('hex'),
|
|
34
|
-
channel: randomBytes(32).toString('hex'),
|
|
35
|
-
enableRoleRequester: false,
|
|
36
|
-
enableWallet: true,
|
|
37
|
-
enableValidatorObserver: true,
|
|
38
|
-
enableInteractiveMode: false,
|
|
39
|
-
disableRateLimit: true,
|
|
40
|
-
enableTxApplyLogs: false,
|
|
41
|
-
storesDirectory: `${tmpDirectory}/admin/`,
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const admin = await setupMsbAdmin(testKeyPair1, tmpDirectory, rpcOpts)
|
|
45
|
-
const writer = await setupMsbWriter(admin, 'writer', testKeyPair2, tmpDirectory, admin.options);
|
|
46
|
-
additionalPeers.push(writer)
|
|
47
|
-
const reader = await setupMsbPeer('peer-2', testKeyPair3, tmpDirectory, { ...admin.options, enable_wallet: false });
|
|
48
|
-
additionalPeers.push(reader)
|
|
49
|
-
await tryToSyncWriters(admin, writer, reader)
|
|
50
|
-
await waitForNodeState(reader, writer.wallet.address, {
|
|
51
|
-
wk: writer.msb.state.writingKey,
|
|
52
|
-
isWhitelisted: true,
|
|
53
|
-
isWriter: true,
|
|
54
|
-
isIndexer: false,
|
|
55
|
-
})
|
|
56
|
-
return { writer, admin, reader }
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
beforeAll(async () => {
|
|
60
|
-
const { admin, writer, reader } = await setupNetwork()
|
|
61
|
-
const server = createServer(reader.msb, reader.config)
|
|
62
|
-
toClose = admin.msb
|
|
63
|
-
Object.assign(testContext, {
|
|
64
|
-
writerMsb: writer.msb,
|
|
65
|
-
rpcMsb: reader.msb,
|
|
66
|
-
server,
|
|
67
|
-
wallet: writer.msb.wallet,
|
|
68
|
-
adminWallet: admin.wallet,
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
afterAll(async () => {
|
|
73
|
-
const peersToClose = [...new Set(additionalPeers.map(peer => peer?.msb).filter(Boolean))]
|
|
74
|
-
await Promise.all([
|
|
75
|
-
toClose?.close(),
|
|
76
|
-
...peersToClose.map(instance => instance.close())
|
|
77
|
-
])
|
|
78
|
-
await removeTemporaryDirectory(tmpDirectory)
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
// The order here is important since the OPs change the network state. We wont boot up an instance before each because the tests are to verify rpc structure and the decision is to spare ci resources.
|
|
82
|
-
describe("API acceptance tests", () => {
|
|
83
|
-
registerConfirmedLengthTests(testContext)
|
|
84
|
-
registerUnconfirmedLengthTests(testContext)
|
|
85
|
-
registerTxvTests(testContext)
|
|
86
|
-
registerFeeTests(testContext)
|
|
87
|
-
registerTxHashesTests(testContext)
|
|
88
|
-
registerTxTests(testContext)
|
|
89
|
-
registerBalanceTests(testContext)
|
|
90
|
-
registerBroadcastTransactionTests(testContext)
|
|
91
|
-
registerTxPayloadsBulkTests(testContext)
|
|
92
|
-
registerTxDetailsTests(testContext)
|
|
93
|
-
registerAccountTests(testContext)
|
|
94
|
-
registerHealthTests(testContext)
|
|
95
|
-
})
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import request from "supertest"
|
|
2
|
-
import { buildRpcSelfTransferPayload, waitForConnection } from "../../../helpers/transactionPayloads.mjs"
|
|
3
|
-
|
|
4
|
-
export const registerTxTests = (context) => {
|
|
5
|
-
describe("GET /v1/tx/:hash", () => {
|
|
6
|
-
it("returns tx details for a broadcasted transaction", async () => {
|
|
7
|
-
const { payload, txHashHex } = await buildRpcSelfTransferPayload(
|
|
8
|
-
context,
|
|
9
|
-
context.rpcMsb.state,
|
|
10
|
-
1n
|
|
11
|
-
);
|
|
12
|
-
|
|
13
|
-
await waitForConnection(context.rpcMsb)
|
|
14
|
-
const broadcastRes = await request(context.server)
|
|
15
|
-
.post("/v1/broadcast-transaction")
|
|
16
|
-
.set("Accept", "application/json")
|
|
17
|
-
.send(JSON.stringify({ payload }))
|
|
18
|
-
expect(broadcastRes.statusCode).toBe(200)
|
|
19
|
-
|
|
20
|
-
const res = await request(context.server).get(`/v1/tx/${txHashHex}`)
|
|
21
|
-
expect(res.statusCode).toBe(200)
|
|
22
|
-
expect(res.body).toMatchObject({ txDetails: expect.any(Object) })
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it("returns 404 for non-existent transaction hash", async () => {
|
|
26
|
-
const nonExistentHash = "0b4d1c1dac48af13212f616601d7399457476a0b644850875b7f4b79df6ff89c"
|
|
27
|
-
const res = await request(context.server).get(`/v1/tx/${nonExistentHash}`)
|
|
28
|
-
expect(res.statusCode).toBe(404)
|
|
29
|
-
expect(res.body).toEqual({ txDetails: null })
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it("returns 400 for invalid hash format (too short)", async () => {
|
|
33
|
-
const invalidHash = '0'.repeat(63)
|
|
34
|
-
const res = await request(context.server).get(`/v1/tx/${invalidHash}`)
|
|
35
|
-
expect(res.statusCode).toBe(400)
|
|
36
|
-
expect(res.body).toEqual({ error: "Invalid transaction hash format" })
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it("returns 400 for invalid hash format (non-hex)", async () => {
|
|
40
|
-
const invalidHash = 'Z'.repeat(64)
|
|
41
|
-
const res = await request(context.server).get(`/v1/tx/${invalidHash}`)
|
|
42
|
-
expect(res.statusCode).toBe(400)
|
|
43
|
-
expect(res.body).toEqual({ error: "Invalid transaction hash format" })
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it("returns 400 when no hash provided", async () => {
|
|
47
|
-
const res = await request(context.server).get('/v1/tx')
|
|
48
|
-
expect(res.statusCode).toBe(400)
|
|
49
|
-
expect(res.body).toEqual({ error: "Transaction hash is required" })
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it("returns 400 for hash with invalid characters", async () => {
|
|
53
|
-
const invalidHash = '0b4d1c1dac48$af13212f6166017399457476a0b644850875b7f4b79df6ff89c'
|
|
54
|
-
const res = await request(context.server).get(`/v1/tx/${invalidHash}`)
|
|
55
|
-
expect(res.statusCode).toBe(400)
|
|
56
|
-
expect(res.body).toEqual({ error: "Invalid transaction hash format" })
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it("returns 400 for hash with special characters", async () => {
|
|
60
|
-
const invalidHash = '!@#$%^&*'.repeat(8)
|
|
61
|
-
const res = await request(context.server).get(`/v1/tx/${invalidHash}`)
|
|
62
|
-
expect(res.statusCode).toBe(400)
|
|
63
|
-
expect(res.body).toEqual({ error: "Invalid transaction hash format" })
|
|
64
|
-
})
|
|
65
|
-
|
|
66
|
-
it("returns 400 for hash with spaces", async () => {
|
|
67
|
-
const invalidHash = '0b4d1c1dac48af13212f616601d7399457476a0b644850875b7 4b79df6ff89c'
|
|
68
|
-
const res = await request(context.server).get(`/v1/tx/${invalidHash}`)
|
|
69
|
-
expect(res.statusCode).toBe(400)
|
|
70
|
-
expect(res.body).toEqual({ error: "Invalid transaction hash format" })
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
it("returns 400 for hash with 0x prefix", async () => {
|
|
74
|
-
const hash = "0x" + "0".repeat(62)
|
|
75
|
-
const res = await request(context.server).get(`/v1/tx/${hash}`)
|
|
76
|
-
expect(res.statusCode).toBe(400)
|
|
77
|
-
expect(res.body).toEqual({ error: "Invalid transaction hash format" })
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
it("returns 400 for odd-length hex", async () => {
|
|
81
|
-
const hash = "a".repeat(63)
|
|
82
|
-
const res = await request(context.server).get(`/v1/tx/${hash}`)
|
|
83
|
-
expect(res.statusCode).toBe(400)
|
|
84
|
-
expect(res.body).toEqual({ error: "Invalid transaction hash format" })
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
it("accepts uppercase hex", async () => {
|
|
89
|
-
const { payload, txHashHex } = await buildRpcSelfTransferPayload(context, context.rpcMsb.state, 1n);
|
|
90
|
-
|
|
91
|
-
// Send the transaction
|
|
92
|
-
await request(context.server)
|
|
93
|
-
.post("/v1/broadcast-transaction")
|
|
94
|
-
.send(JSON.stringify({ payload }));
|
|
95
|
-
|
|
96
|
-
// Waits for the node indexer to process
|
|
97
|
-
await new Promise(resolve => setTimeout(resolve, 500));
|
|
98
|
-
|
|
99
|
-
const uppercaseHash = txHashHex.toUpperCase();
|
|
100
|
-
const res = await request(context.server).get(`/v1/tx/${uppercaseHash}`);
|
|
101
|
-
|
|
102
|
-
expect(res.statusCode).toBe(200);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it("returns 400 for trailing space hash", async () => {
|
|
106
|
-
const hash = "a".repeat(64) + "%20" // Forcing space
|
|
107
|
-
const res = await request(context.server).get(`/v1/tx/${hash}`)
|
|
108
|
-
expect(res.statusCode).toBe(400)
|
|
109
|
-
})
|
|
110
|
-
})
|
|
111
|
-
}
|