trac-msb 0.2.18 → 0.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -2
- package/SECURITY.md +9 -6
- package/cli/commandHandler.js +272 -0
- package/cli/handlers.js +210 -0
- package/cli/interactive.js +182 -0
- package/msb.mjs +7 -8
- package/package.json +25 -8
- package/rpc/create_server.js +44 -44
- package/rpc/handlers.js +43 -56
- package/rpc/routes/index.js +8 -8
- package/rpc/rpc_server.js +6 -2
- package/rpc/utils/helpers.js +46 -66
- package/scripts/pear-runner.js +170 -0
- package/src/config/args.js +60 -13
- package/src/config/config.js +138 -10
- package/src/config/env.js +36 -18
- package/src/core/network/Network.js +52 -24
- package/src/core/network/protocols/ProtocolInterface.js +5 -5
- package/src/core/network/protocols/connectionPolicies.js +86 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +1 -1
- package/src/core/network/protocols/legacy/handlers/BaseStateOperationHandler.js +2 -2
- package/src/core/network/protocols/legacy/handlers/LegacyGetRequestHandler.js +3 -3
- package/src/core/network/protocols/legacy/handlers/LegacyRoleOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacySubnetworkOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacyTransferOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
- package/src/core/network/protocols/shared/validators/PartialBootstrapDeploymentValidator.js +2 -2
- package/src/core/network/protocols/shared/validators/PartialOperationValidator.js +23 -23
- package/src/core/network/protocols/shared/validators/PartialRoleAccessValidator.js +14 -14
- package/src/core/network/protocols/shared/validators/PartialTransactionValidator.js +5 -5
- package/src/core/network/protocols/shared/validators/PartialTransferValidator.js +12 -11
- package/src/core/network/protocols/v1/V1ProtocolError.js +5 -69
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +3 -2
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +130 -247
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +6 -5
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +84 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +128 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +26 -0
- package/src/core/network/protocols/v1/validators/V1BaseOperation.js +32 -31
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +5 -3
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +34 -50
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +1 -1
- package/src/core/network/services/ConnectionManager.js +11 -10
- package/src/core/network/services/MessageOrchestrator.js +53 -17
- package/src/core/network/services/PendingRequestService.js +22 -19
- package/src/core/network/services/TransactionCommitService.js +36 -36
- package/src/core/network/services/TransactionPoolService.js +39 -39
- package/src/core/network/services/TransactionRateLimiterService.js +8 -4
- package/src/core/network/services/ValidatorObserverService.js +397 -110
- package/src/core/state/State.js +190 -138
- package/src/core/state/utils/address.js +4 -9
- package/src/core/state/utils/balance.js +7 -7
- package/src/core/state/utils/roles.js +1 -1
- package/src/index.js +316 -275
- package/src/messages/network/v1/NetworkMessageBuilder.js +12 -21
- package/src/messages/network/v1/networkMessageFactory.js +1 -1
- package/src/messages/state/ApplyStateMessageBuilder.js +6 -6
- package/src/messages/state/applyStateMessageFactory.js +1 -1
- package/src/utils/buffer.js +1 -1
- package/src/utils/check.js +12 -13
- package/src/utils/constants.js +7 -0
- package/src/utils/errors.js +20 -0
- package/src/utils/fileUtils.js +12 -3
- package/src/utils/helpers.js +2 -2
- package/src/utils/migrationUtils.js +3 -3
- package/.dockerignore +0 -16
- package/CODE_OF_CONDUCT.md +0 -128
- package/docker-compose.yml +0 -17
- package/dockerfile +0 -41
- package/docs/fee_distribution.md +0 -89
- package/docs/trac_network_http_api.openapi.yaml +0 -889
- package/migration/.gitkeep +0 -0
- package/proto/applyOperations.proto +0 -117
- package/proto/network/v1/enums/message_type.proto +0 -16
- package/proto/network/v1/enums/result_code.proto +0 -84
- package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
- package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
- package/proto/network/v1/messages/liveness_request.proto +0 -8
- package/proto/network/v1/messages/liveness_response.proto +0 -11
- package/proto/network/v1/network_message.proto +0 -22
- package/rpc/rpc_services.js +0 -181
- package/scripts/generate-protobufs.js +0 -67
- package/src/core/network/identity/NetworkWalletFactory.js +0 -77
- package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
- package/src/utils/cli.js +0 -130
- package/src/utils/cliCommands.js +0 -280
- package/tests/acceptance/v1/account/account.test.mjs +0 -129
- package/tests/acceptance/v1/balance/balance.test.mjs +0 -54
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +0 -116
- package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +0 -19
- package/tests/acceptance/v1/fee/fee.test.mjs +0 -11
- package/tests/acceptance/v1/health/health.test.mjs +0 -33
- package/tests/acceptance/v1/rpc.test.mjs +0 -95
- package/tests/acceptance/v1/tx/tx.test.mjs +0 -133
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -241
- package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +0 -72
- package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +0 -27
- package/tests/acceptance/v1/txv/txv.test.mjs +0 -11
- package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +0 -11
- package/tests/fixtures/apply.fixtures.js +0 -77
- package/tests/fixtures/assembleMessage.fixtures.js +0 -41
- package/tests/fixtures/check.fixtures.js +0 -428
- package/tests/fixtures/networkV1.fixtures.js +0 -59
- package/tests/fixtures/protobuf.fixtures.js +0 -388
- package/tests/helpers/StateNetworkFactory.js +0 -155
- package/tests/helpers/address.js +0 -6
- package/tests/helpers/autobaseTestHelpers.js +0 -419
- package/tests/helpers/config.js +0 -4
- package/tests/helpers/createTestSignature.js +0 -13
- package/tests/helpers/regexHelper.js +0 -3
- package/tests/helpers/setupApplyTests.js +0 -587
- package/tests/helpers/transactionPayloads.mjs +0 -92
- package/tests/helpers/wrapper.js +0 -28
- package/tests/unit/messages/messages.test.js +0 -12
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +0 -436
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -347
- package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +0 -525
- package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +0 -237
- package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
- package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
- package/tests/unit/network/ProtocolSession.test.js +0 -127
- package/tests/unit/network/networkModule.test.js +0 -13
- package/tests/unit/network/services/ConnectionManager.test.js +0 -450
- package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
- package/tests/unit/network/services/PendingRequestService.test.js +0 -431
- package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
- package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
- package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
- package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
- package/tests/unit/network/services/services.test.js +0 -17
- package/tests/unit/network/utils/v1TestUtils.js +0 -153
- package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
- package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
- package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
- package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
- package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
- package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
- package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
- package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
- package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
- package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
- package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
- package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
- package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
- package/tests/unit/network/v1/v1.handlers.test.js +0 -15
- package/tests/unit/network/v1/v1.test.js +0 -19
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
- package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
- package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
- package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
- package/tests/unit/state/State.test.js +0 -80
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +0 -42
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +0 -276
- package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +0 -78
- package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +0 -68
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +0 -159
- package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +0 -39
- package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +0 -167
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +0 -186
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +0 -443
- package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +0 -32
- package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +0 -297
- package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +0 -41
- package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +0 -149
- package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +0 -766
- package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +0 -50
- package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +0 -37
- package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +0 -42
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +0 -106
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +0 -309
- package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +0 -30
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +0 -881
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +0 -435
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +0 -78
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +0 -98
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +0 -66
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +0 -55
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +0 -103
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +0 -60
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +0 -189
- package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +0 -220
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +0 -111
- package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +0 -45
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +0 -189
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +0 -156
- package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +0 -36
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +0 -531
- package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +0 -74
- package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +0 -32
- package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +0 -38
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +0 -91
- package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +0 -266
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +0 -143
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +0 -26
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +0 -94
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +0 -37
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +0 -86
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +0 -347
- package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +0 -57
- package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +0 -429
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +0 -120
- package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +0 -130
- package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +0 -93
- package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +0 -108
- package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +0 -126
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +0 -121
- package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +0 -50
- package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +0 -56
- package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +0 -198
- package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +0 -40
- package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +0 -114
- package/tests/unit/state/apply/common/commonScenarioHelper.js +0 -103
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +0 -29
- package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +0 -66
- package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +0 -84
- package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +0 -47
- package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +0 -85
- package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +0 -52
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +0 -54
- package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +0 -73
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +0 -71
- package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +0 -31
- package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +0 -142
- package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +0 -87
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +0 -71
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +0 -73
- package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +0 -44
- package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +0 -25
- package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +0 -98
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +0 -202
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +0 -17
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +0 -44
- package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +0 -19
- package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +0 -18
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +0 -315
- package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +0 -18
- package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +0 -43
- package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +0 -53
- package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +0 -24
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +0 -204
- package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +0 -161
- package/tests/unit/state/apply/missing-tests.md +0 -18
- package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +0 -58
- package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +0 -98
- package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +0 -167
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +0 -429
- package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +0 -22
- package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +0 -20
- package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +0 -291
- package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +0 -87
- package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +0 -38
- package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +0 -348
- package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +0 -113
- package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +0 -33
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +0 -26
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +0 -22
- package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +0 -307
- package/tests/unit/state/apply/state.apply.test.js +0 -24
- package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +0 -819
- package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +0 -22
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +0 -146
- package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +0 -63
- package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +0 -67
- package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +0 -22
- package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +0 -8
- package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +0 -66
- package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +0 -1170
- package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +0 -318
- package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +0 -70
- package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +0 -23
- package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +0 -48
- package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +0 -39
- package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +0 -46
- package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +0 -432
- package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +0 -31
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +0 -49
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +0 -93
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +0 -29
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +0 -33
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/stateModule.test.js +0 -23
- package/tests/unit/state/stateTestUtils.js +0 -32
- package/tests/unit/state/utils/address.test.js +0 -63
- package/tests/unit/state/utils/adminEntry.test.js +0 -52
- package/tests/unit/state/utils/balance.test.js +0 -320
- package/tests/unit/state/utils/lengthEntry.test.js +0 -54
- package/tests/unit/state/utils/nodeEntry.test.js +0 -298
- package/tests/unit/state/utils/roles.test.js +0 -44
- package/tests/unit/unit.test.js +0 -14
- package/tests/unit/utils/amountSerialization/amountSerialization.test.js +0 -237
- package/tests/unit/utils/buffer/buffer.test.js +0 -251
- package/tests/unit/utils/check/adminControlOperation.test.js +0 -156
- package/tests/unit/utils/check/balanceInitializationOperation.test.js +0 -54
- package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +0 -104
- package/tests/unit/utils/check/check.test.js +0 -17
- package/tests/unit/utils/check/common.test.js +0 -419
- package/tests/unit/utils/check/coreAdminOperation.test.js +0 -95
- package/tests/unit/utils/check/roleAccessOperation.test.js +0 -255
- package/tests/unit/utils/check/transactionOperation.test.js +0 -107
- package/tests/unit/utils/check/transferOperation.test.js +0 -102
- package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +0 -95
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +0 -149
- package/tests/unit/utils/helpers/helpers.test.js +0 -11
- package/tests/unit/utils/helpers/isHexString.test.js +0 -12
- package/tests/unit/utils/helpers/normalizeHex.test.js +0 -82
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +0 -100
- package/tests/unit/utils/normalizers/normalizers.test.js +0 -469
- package/tests/unit/utils/protobuf/applyOperations.test.js +0 -91
- package/tests/unit/utils/protobuf/operationHelpers.test.js +0 -303
- package/tests/unit/utils/protobuf/protobuf.test.js +0 -12
- package/tests/unit/utils/type/type.test.js +0 -25
- package/tests/unit/utils/utils.test.js +0 -21
- package/whitelist/.gitkeep +0 -0
package/src/utils/cli.js
DELETED
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
import b4a from 'b4a';
|
|
2
|
-
import { safeDecodeApplyOperation } from "./protobuf/operationHelpers.js";
|
|
3
|
-
import { bigIntToDecimalString, bufferToBigInt } from "./amountSerialization.js";
|
|
4
|
-
|
|
5
|
-
export async function verifyDag(state, network, wallet, writerKey) {
|
|
6
|
-
try {
|
|
7
|
-
console.log('---------- node & network stats ----------');
|
|
8
|
-
let dagView, lengthdagView, dagSystem, lengthdagSystem;
|
|
9
|
-
|
|
10
|
-
if (state?.base?.view?.core && state?.base?.system?.core) {
|
|
11
|
-
try {
|
|
12
|
-
dagView = await state.base.view.core.treeHash();
|
|
13
|
-
lengthdagView = state.base.view.core.length;
|
|
14
|
-
dagSystem = await state.base.system.core.treeHash();
|
|
15
|
-
lengthdagSystem = state.base.system.core.length;
|
|
16
|
-
} catch (e) {
|
|
17
|
-
console.log('Error getting DAG info:', e.message);
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
console.log('wallet.publicKey:', wallet?.publicKey?.toString('hex') ?? 'unset');
|
|
22
|
-
console.log('wallet.address:', (wallet && wallet.address) ? wallet.address : 'unset');
|
|
23
|
-
console.log('msb.writerKey:', writerKey ? writerKey.toString('hex') : 'unset');
|
|
24
|
-
console.log('swarm.connections.size:', network?.swarm?.connections?.size || 0);
|
|
25
|
-
if (state?.base?.view?.core) {
|
|
26
|
-
console.log('base.view.core.signedLength:', state.base.view.core.signedLength ?? 'unset');
|
|
27
|
-
console.log('base.view.core.length:', state.base.view.core.length ?? 'unset');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
if (state?.base) {
|
|
31
|
-
console.log("base.signedLength", state.base.signedLength ?? 'unset');
|
|
32
|
-
console.log("base.indexedLength", state.base.indexedLength ?? 'unset');
|
|
33
|
-
console.log("base.linearizer.indexers.length", state.base.linearizer?.indexers?.length ?? 'unset');
|
|
34
|
-
console.log(`base.key: ${state.base.key ? state.base.key.toString('hex') : 'unset'}`);
|
|
35
|
-
console.log('discoveryKey:', state.base.discoveryKey ? b4a.toString(state.base.discoveryKey, 'hex') : 'unset');
|
|
36
|
-
}
|
|
37
|
-
console.log(`VIEW Dag: ${dagView ? dagView.toString('hex') : 'unset'} (length: ${lengthdagView || 0})`);
|
|
38
|
-
console.log(`SYSTEM Dag: ${dagSystem ? dagSystem.toString('hex') : 'unset'} (length: ${lengthdagSystem || 0})`);
|
|
39
|
-
const wl = await state.getWriterLength();
|
|
40
|
-
console.log('Total Registered Writers:', wl !== null ? wl : 0);
|
|
41
|
-
|
|
42
|
-
console.log("---------- flags ----------");
|
|
43
|
-
try {
|
|
44
|
-
console.log(`isIndexer: ${state?.isIndexer?.() ?? 'unset'}`);
|
|
45
|
-
console.log(`isWriter: ${state?.isWritable?.() ?? 'unset'}`);
|
|
46
|
-
} catch (e) {
|
|
47
|
-
console.log('Error getting flags:', e.message);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
} catch (error) {
|
|
51
|
-
console.error('Error during DAG monitoring:', error.message);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export function printHelp(isAdminMode = false) {
|
|
56
|
-
if (isAdminMode) {
|
|
57
|
-
console.log('🚨 WARNING: IF YOU ARE NOT AN ADMIN, DO NOT USE THE COMMANDS BELOW! YOU RISK LOSING YOUR FUNDS! 🚨');
|
|
58
|
-
console.log('\nAdmin commands:');
|
|
59
|
-
console.log('- /add_admin: Register admin entry with bootstrap key (initial setup), or use --recovery flag to recover admin role');
|
|
60
|
-
console.log('- /balance_migration: Perform balance migration with the given initial balances CSV file');
|
|
61
|
-
console.log('- /add_whitelist: Add all specified whitelist addresses. If initialization is enabled, no fee is required.');
|
|
62
|
-
console.log('- /disable_initialization: Disable further balance initializations and whitelisting');
|
|
63
|
-
console.log('- /add_indexer <address>: Change a role of the selected writer node to indexer role. Charges a fee.');
|
|
64
|
-
console.log('- /remove_indexer <address>: Change a role of the selected indexer node to default role. Charges a fee.');
|
|
65
|
-
console.log('- /ban_writer <address>: Demote a whitelisted writer to default role and remove it from the whitelist. Charges a fee.');
|
|
66
|
-
}
|
|
67
|
-
console.log('Available commands:');
|
|
68
|
-
console.log('- /add_writer: Add yourself as a validator to this MSB once whitelisted. Requires a fee + 10x the fee as a stake in $TNK.');
|
|
69
|
-
console.log('- /remove_writer: Remove yourself from this MSB. Requires a fee, and the stake will be refunded.');
|
|
70
|
-
console.log('- /node_status <address>: Get network information about a node with the given address.');
|
|
71
|
-
console.log('- /stats: Check system stats such as writing key, DAG, etc.');
|
|
72
|
-
console.log('- /deployment <subnetwork_bootstrap> <channel>: Deploy a subnetwork with the given bootstrap. If channel is not provided, a random one will be generated. Requires a fee.');
|
|
73
|
-
console.log('- /get_deployment <subnetwork_bootstrap>: Get information about a subnetwork deployment with the given bootstrap.');
|
|
74
|
-
console.log('- /transfer <to_address> <amount>: Transfer the specified amount to the given address. Requires a fee.');
|
|
75
|
-
console.log('- /get_tx_info <tx_hash>: Get information about a transaction with the given hash.');
|
|
76
|
-
console.log('- /get_validator_addr <writing_key>: Get the validator address mapped to the given writing key.');
|
|
77
|
-
console.log('- /get_balance <address> <confirmed>: Get the balance of the node with specified address (confirmed = true is default)');
|
|
78
|
-
console.log('- /exit: Exit the program.');
|
|
79
|
-
console.log('- /help: Display this help.');
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export const printWalletInfo = (address, writingKey) => {
|
|
83
|
-
console.log('');
|
|
84
|
-
console.log('#####################################################################################');
|
|
85
|
-
console.log('# MSB Address: ', address, ' #');
|
|
86
|
-
console.log('# MSB Writer: ', writingKey.toString('hex'), '#');
|
|
87
|
-
console.log('#####################################################################################');
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export const printBalance = async (address, state, wallet_enabled) => {
|
|
91
|
-
if (wallet_enabled && state) {
|
|
92
|
-
const nodeEntry = await state.getNodeEntry(address);
|
|
93
|
-
const balance = nodeEntry ? bigIntToDecimalString(bufferToBigInt(nodeEntry.balance)) : '0';
|
|
94
|
-
console.log(`Balance: ${balance}`);
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export const get_confirmed_tx_info = async (state_instance, txHash) => {
|
|
99
|
-
const payload = await state_instance.getSigned(txHash);
|
|
100
|
-
if (!payload) {
|
|
101
|
-
return null
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
const decoded = safeDecodeApplyOperation(payload);
|
|
105
|
-
if (!decoded) {
|
|
106
|
-
throw new Error(`Failed to decode payload for transaction hash: ${txHash}`);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
return {
|
|
110
|
-
payload,
|
|
111
|
-
decoded
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export const get_unconfirmed_tx_info = async (state_instance, txHash) => {
|
|
116
|
-
const payload = await state_instance.get(txHash);
|
|
117
|
-
if (!payload) {
|
|
118
|
-
return null
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const decoded = safeDecodeApplyOperation(payload);
|
|
122
|
-
if (!decoded) {
|
|
123
|
-
throw new Error(`Failed to decode payload for transaction hash: ${txHash}`);
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
payload,
|
|
128
|
-
decoded
|
|
129
|
-
}
|
|
130
|
-
}
|
package/src/utils/cliCommands.js
DELETED
|
@@ -1,280 +0,0 @@
|
|
|
1
|
-
import { ZERO_WK } from "./buffer.js";
|
|
2
|
-
import { bigIntToDecimalString, bufferToBigInt } from "./amountSerialization.js";
|
|
3
|
-
import { normalizeDecodedPayloadForJson } from "./normalizers.js";
|
|
4
|
-
import { get_confirmed_tx_info, get_unconfirmed_tx_info } from "./cli.js";
|
|
5
|
-
import { EntryType } from "./constants.js";
|
|
6
|
-
import { bufferToAddress } from "../core/state/utils/address.js";
|
|
7
|
-
import deploymentEntryUtils from "../core/state/utils/deploymentEntry.js";
|
|
8
|
-
import { safeDecodeApplyOperation } from "./protobuf/operationHelpers.js";
|
|
9
|
-
|
|
10
|
-
export async function getBalanceCommand(state, address, confirmedFlag) {
|
|
11
|
-
const unconfirmedBalance = confirmedFlag === "false";
|
|
12
|
-
const nodeEntry = unconfirmedBalance
|
|
13
|
-
? await state.getNodeEntryUnsigned(address)
|
|
14
|
-
: await state.getNodeEntry(address);
|
|
15
|
-
|
|
16
|
-
if (nodeEntry) {
|
|
17
|
-
console.log({
|
|
18
|
-
Address: address,
|
|
19
|
-
Balance: bigIntToDecimalString(bufferToBigInt(nodeEntry.balance))
|
|
20
|
-
});
|
|
21
|
-
return {
|
|
22
|
-
address,
|
|
23
|
-
balance: bufferToBigInt(nodeEntry.balance).toString()
|
|
24
|
-
};
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
console.log("Node Entry:", {
|
|
28
|
-
WritingKey: ZERO_WK.toString("hex"),
|
|
29
|
-
IsWhitelisted: false,
|
|
30
|
-
IsWriter: false,
|
|
31
|
-
IsIndexer: false,
|
|
32
|
-
balance: bigIntToDecimalString(0n)
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export async function nodeStatusCommand(state, address) {
|
|
37
|
-
const nodeEntry = await state.getNodeEntry(address);
|
|
38
|
-
if (nodeEntry) {
|
|
39
|
-
const licenseValue = nodeEntry.license.readUInt32BE(0);
|
|
40
|
-
const licenseDisplay = licenseValue === 0 ? "N/A" : licenseValue.toString();
|
|
41
|
-
console.log("Node Status:", {
|
|
42
|
-
Address: address,
|
|
43
|
-
WritingKey: nodeEntry.wk.toString("hex"),
|
|
44
|
-
IsWhitelisted: nodeEntry.isWhitelisted,
|
|
45
|
-
IsWriter: nodeEntry.isWriter,
|
|
46
|
-
IsIndexer: nodeEntry.isIndexer,
|
|
47
|
-
License: licenseDisplay,
|
|
48
|
-
StakedBalance: bigIntToDecimalString(bufferToBigInt(nodeEntry.stakedBalance)),
|
|
49
|
-
Balance: bigIntToDecimalString(bufferToBigInt(nodeEntry.balance))
|
|
50
|
-
});
|
|
51
|
-
return {
|
|
52
|
-
address,
|
|
53
|
-
writingKey: nodeEntry.wk.toString("hex"),
|
|
54
|
-
isWhitelisted: nodeEntry.isWhitelisted,
|
|
55
|
-
isWriter: nodeEntry.isWriter,
|
|
56
|
-
isIndexer: nodeEntry.isIndexer,
|
|
57
|
-
license: licenseDisplay,
|
|
58
|
-
stakedBalance: bigIntToDecimalString(bufferToBigInt(nodeEntry.stakedBalance))
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
console.log("Node Status:", {
|
|
63
|
-
WritingKey: ZERO_WK.toString("hex"),
|
|
64
|
-
IsWhitelisted: false,
|
|
65
|
-
IsWriter: false,
|
|
66
|
-
IsIndexer: false,
|
|
67
|
-
license: "N/A",
|
|
68
|
-
stakedBalance: "0"
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export async function coreInfoCommand(state) {
|
|
73
|
-
const admin = await state.getAdminEntry();
|
|
74
|
-
console.log("Admin:", admin ? {
|
|
75
|
-
address: admin.address,
|
|
76
|
-
writingKey: admin.wk.toString("hex")
|
|
77
|
-
} : null);
|
|
78
|
-
const formattedIndexers = await state.getIndexersEntry().then(entry => entry ? entry : null);
|
|
79
|
-
if (!formattedIndexers || (Array.isArray(formattedIndexers) && formattedIndexers.length === 0)) {
|
|
80
|
-
console.log("Indexers: no indexers");
|
|
81
|
-
} else {
|
|
82
|
-
console.log("Indexers:", formattedIndexers);
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export async function getValidatorAddressCommand(state, wkHexString, prefix) {
|
|
87
|
-
const payload = await state.getSigned(EntryType.WRITER_ADDRESS + wkHexString);
|
|
88
|
-
if (payload === null) {
|
|
89
|
-
console.log(`No address assigned to the writer key: ${wkHexString}`);
|
|
90
|
-
} else {
|
|
91
|
-
console.log(`Address assigned to the writer key: ${wkHexString} - ${bufferToAddress(payload, prefix)}`);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
export async function getDeploymentCommand(state, bootstrapHex, addressLength) {
|
|
96
|
-
const deploymentEntry = await state.getRegisteredBootstrapEntry(bootstrapHex);
|
|
97
|
-
console.log(`Searching deployment for bootstrap: ${bootstrapHex}`);
|
|
98
|
-
if (deploymentEntry) {
|
|
99
|
-
const decodedDeploymentEntry = deploymentEntryUtils.decode(deploymentEntry, addressLength);
|
|
100
|
-
const txhash = decodedDeploymentEntry.txHash.toString("hex");
|
|
101
|
-
console.log(`Bootstrap deployed under transaction hash: ${txhash}`);
|
|
102
|
-
const payload = await state.getSigned(txhash);
|
|
103
|
-
if (payload) {
|
|
104
|
-
const decoded = safeDecodeApplyOperation(payload);
|
|
105
|
-
console.log("Decoded Bootstrap Deployment Payload:", decoded);
|
|
106
|
-
} else {
|
|
107
|
-
console.log(`No payload found for transaction hash: ${txhash}`);
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
console.log(`No deployment found for bootstrap: ${bootstrapHex}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
export async function getTxInfoCommand(state, txHash) {
|
|
115
|
-
const txInfo = await get_confirmed_tx_info(state, txHash);
|
|
116
|
-
if (txInfo) {
|
|
117
|
-
console.log(`Payload for transaction hash ${txHash}:`);
|
|
118
|
-
console.log(txInfo.decoded);
|
|
119
|
-
} else {
|
|
120
|
-
console.log(`No information found for transaction hash: ${txHash}`);
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
export async function getLicenseNumberCommand(state, address) {
|
|
125
|
-
const nodeEntry = await state.getNodeEntry(address);
|
|
126
|
-
if (nodeEntry) {
|
|
127
|
-
console.log({
|
|
128
|
-
Address: address,
|
|
129
|
-
License: bufferToBigInt(nodeEntry.license).toString()
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
export async function getLicenseAddressCommand(state, licenseId) {
|
|
135
|
-
if (isNaN(licenseId) || licenseId < 0) {
|
|
136
|
-
console.log("Invalid license ID. Please provide a valid non-negative number.");
|
|
137
|
-
return;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const address = await state.getAddressByLicenseId(licenseId);
|
|
141
|
-
if (address) {
|
|
142
|
-
console.log({
|
|
143
|
-
LicenseId: licenseId,
|
|
144
|
-
Address: address
|
|
145
|
-
});
|
|
146
|
-
} else {
|
|
147
|
-
console.log(`No address found for license ID: ${licenseId}`);
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
export async function getLicenseCountCommand(state, isAdminFn) {
|
|
152
|
-
const adminEntry = await state.getAdminEntry();
|
|
153
|
-
|
|
154
|
-
if (!adminEntry) {
|
|
155
|
-
throw new Error("Cannot read license count. Admin does not exist");
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
if (!isAdminFn(adminEntry)) {
|
|
159
|
-
throw new Error("Cannot perform this operation - you are not the admin!.");
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
const licenseCount = await state.getLicenseCount();
|
|
163
|
-
console.log({
|
|
164
|
-
LicensesCount: licenseCount
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
export async function getTxvCommand(state) {
|
|
169
|
-
const txv = await state.getIndexerSequenceState();
|
|
170
|
-
console.log("Current TXV:", txv.toString("hex"));
|
|
171
|
-
return txv;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
export function getFeeCommand(state) {
|
|
175
|
-
const fee = state.getFee();
|
|
176
|
-
console.log("Current FEE:", bigIntToDecimalString(bufferToBigInt(fee)));
|
|
177
|
-
return bufferToBigInt(fee).toString();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export function getConfirmedLengthCommand(state) {
|
|
181
|
-
const confirmedLength = state.getSignedLength();
|
|
182
|
-
console.log("Confirmed_length:", confirmedLength);
|
|
183
|
-
return confirmedLength;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export function getUnconfirmedLengthCommand(state) {
|
|
187
|
-
const unconfirmedLength = state.getUnsignedLength();
|
|
188
|
-
console.log("Unconfirmed_length:", unconfirmedLength);
|
|
189
|
-
return unconfirmedLength;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
export async function getTxPayloadsBulkCommand(state, hashes, config) {
|
|
193
|
-
if (!Array.isArray(hashes) || hashes.length === 0) {
|
|
194
|
-
throw new Error("Missing hash list.");
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (hashes.length > 1500) {
|
|
198
|
-
throw new Error("Length of input tx hashes exceeded.");
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const res = { results: [], missing: [] };
|
|
202
|
-
|
|
203
|
-
const promises = hashes.map(hash => get_confirmed_tx_info(state, hash));
|
|
204
|
-
const results = await Promise.all(promises);
|
|
205
|
-
|
|
206
|
-
results.forEach((result, index) => {
|
|
207
|
-
const hash = hashes[index];
|
|
208
|
-
if (result === null || result === undefined) {
|
|
209
|
-
res.missing.push(hash);
|
|
210
|
-
} else {
|
|
211
|
-
const decodedResult = normalizeDecodedPayloadForJson(result.decoded, config);
|
|
212
|
-
res.results.push({ hash, payload: decodedResult });
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
|
|
216
|
-
return res;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
export async function getTxHashesCommand(state, start, end) {
|
|
220
|
-
try {
|
|
221
|
-
const hashes = await state.confirmedTransactionsBetween(start, end);
|
|
222
|
-
return { hashes };
|
|
223
|
-
} catch (error) {
|
|
224
|
-
throw new Error("Invalid params to perform the request.", error.message);
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
export async function getTxDetailsCommand(state, hash, config) {
|
|
229
|
-
try {
|
|
230
|
-
const rawPayload = await get_confirmed_tx_info(state, hash);
|
|
231
|
-
if (!rawPayload) {
|
|
232
|
-
console.log(`No payload found for tx hash: ${hash}`);
|
|
233
|
-
return null;
|
|
234
|
-
}
|
|
235
|
-
return normalizeDecodedPayloadForJson(rawPayload.decoded, config);
|
|
236
|
-
} catch (error) {
|
|
237
|
-
throw new Error("Invalid params to perform the request.", error.message);
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
export async function getExtendedTxDetailsCommand(state, hash, confirmed, config) {
|
|
242
|
-
if (confirmed) {
|
|
243
|
-
const rawPayload = await get_confirmed_tx_info(state, hash);
|
|
244
|
-
if (!rawPayload) {
|
|
245
|
-
throw new Error(`No payload found for tx hash: ${hash}`);
|
|
246
|
-
}
|
|
247
|
-
const confirmedLength = await state.getTransactionConfirmedLength(hash);
|
|
248
|
-
if (confirmedLength === null) {
|
|
249
|
-
throw new Error(`No confirmed length found for tx hash: ${hash} in confirmed mode`);
|
|
250
|
-
}
|
|
251
|
-
const normalizedPayload = normalizeDecodedPayloadForJson(rawPayload.decoded, config);
|
|
252
|
-
const fee = state.getFee();
|
|
253
|
-
return {
|
|
254
|
-
txDetails: normalizedPayload,
|
|
255
|
-
confirmed_length: confirmedLength,
|
|
256
|
-
fee: bufferToBigInt(fee).toString()
|
|
257
|
-
};
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
const rawPayload = await get_unconfirmed_tx_info(state, hash);
|
|
261
|
-
if (!rawPayload) {
|
|
262
|
-
throw new Error(`No payload found for tx hash: ${hash}`);
|
|
263
|
-
}
|
|
264
|
-
const normalizedPayload = normalizeDecodedPayloadForJson(rawPayload.decoded, config);
|
|
265
|
-
const length = await state.getTransactionConfirmedLength(hash);
|
|
266
|
-
if (length === null) {
|
|
267
|
-
return {
|
|
268
|
-
txDetails: normalizedPayload,
|
|
269
|
-
confirmed_length: 0,
|
|
270
|
-
fee: "0"
|
|
271
|
-
};
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
const fee = state.getFee();
|
|
275
|
-
return {
|
|
276
|
-
txDetails: normalizedPayload,
|
|
277
|
-
confirmed_length: length,
|
|
278
|
-
fee: bufferToBigInt(fee).toString()
|
|
279
|
-
};
|
|
280
|
-
}
|
|
@@ -1,129 +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
|
-
const failingAddress = randomAddress(context.rpcMsb.config.addressPrefix)
|
|
112
|
-
|
|
113
|
-
context.rpcMsb.state.getNodeEntry = async (address) => {
|
|
114
|
-
if (address === failingAddress) {
|
|
115
|
-
throw new Error("test")
|
|
116
|
-
}
|
|
117
|
-
return originalGetNodeEntry.call(context.rpcMsb.state, address)
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
try {
|
|
121
|
-
const res = await request(context.server).get(`/v1/account/${failingAddress}`)
|
|
122
|
-
expect(res.statusCode).toBe(500)
|
|
123
|
-
expect(res.body).toEqual({ error: 'An error occurred processing the request.' })
|
|
124
|
-
} finally {
|
|
125
|
-
context.rpcMsb.state.getNodeEntry = originalGetNodeEntry
|
|
126
|
-
}
|
|
127
|
-
})
|
|
128
|
-
})
|
|
129
|
-
}
|
|
@@ -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
|
-
}
|