trac-msb 0.2.18 → 0.2.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +62 -2
- package/SECURITY.md +9 -6
- package/cli/commandHandler.js +272 -0
- package/cli/handlers.js +210 -0
- package/cli/interactive.js +182 -0
- package/msb.mjs +7 -8
- package/package.json +25 -8
- package/rpc/create_server.js +44 -44
- package/rpc/handlers.js +43 -56
- package/rpc/routes/index.js +8 -8
- package/rpc/rpc_server.js +6 -2
- package/rpc/utils/helpers.js +46 -66
- package/scripts/pear-runner.js +170 -0
- package/src/config/args.js +60 -13
- package/src/config/config.js +138 -10
- package/src/config/env.js +36 -18
- package/src/core/network/Network.js +52 -24
- package/src/core/network/protocols/ProtocolInterface.js +5 -5
- package/src/core/network/protocols/connectionPolicies.js +86 -0
- package/src/core/network/protocols/legacy/NetworkMessageRouter.js +1 -1
- package/src/core/network/protocols/legacy/handlers/BaseStateOperationHandler.js +2 -2
- package/src/core/network/protocols/legacy/handlers/LegacyGetRequestHandler.js +3 -3
- package/src/core/network/protocols/legacy/handlers/LegacyRoleOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacySubnetworkOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/handlers/LegacyTransferOperationHandler.js +1 -1
- package/src/core/network/protocols/legacy/validators/base/BaseResponse.js +7 -10
- package/src/core/network/protocols/shared/validators/PartialBootstrapDeploymentValidator.js +2 -2
- package/src/core/network/protocols/shared/validators/PartialOperationValidator.js +23 -23
- package/src/core/network/protocols/shared/validators/PartialRoleAccessValidator.js +14 -14
- package/src/core/network/protocols/shared/validators/PartialTransactionValidator.js +5 -5
- package/src/core/network/protocols/shared/validators/PartialTransferValidator.js +12 -11
- package/src/core/network/protocols/v1/V1ProtocolError.js +5 -69
- package/src/core/network/protocols/v1/handlers/V1BaseOperationHandler.js +3 -2
- package/src/core/network/protocols/v1/handlers/V1BroadcastTransactionOperationHandler.js +130 -247
- package/src/core/network/protocols/v1/handlers/V1LivenessOperationHandler.js +6 -5
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionErrorMapper.js +84 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionOperationStrategies.js +128 -0
- package/src/core/network/protocols/v1/handlers/broadcastTransaction/BroadcastTransactionPayloadUtils.js +26 -0
- package/src/core/network/protocols/v1/validators/V1BaseOperation.js +32 -31
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionRequest.js +5 -3
- package/src/core/network/protocols/v1/validators/V1BroadcastTransactionResponse.js +34 -50
- package/src/core/network/protocols/v1/validators/V1ValidationSchema.js +1 -1
- package/src/core/network/services/ConnectionManager.js +11 -10
- package/src/core/network/services/MessageOrchestrator.js +53 -17
- package/src/core/network/services/PendingRequestService.js +22 -19
- package/src/core/network/services/TransactionCommitService.js +36 -36
- package/src/core/network/services/TransactionPoolService.js +39 -39
- package/src/core/network/services/TransactionRateLimiterService.js +8 -4
- package/src/core/network/services/ValidatorObserverService.js +397 -110
- package/src/core/state/State.js +190 -138
- package/src/core/state/utils/address.js +4 -9
- package/src/core/state/utils/balance.js +7 -7
- package/src/core/state/utils/roles.js +1 -1
- package/src/index.js +316 -275
- package/src/messages/network/v1/NetworkMessageBuilder.js +12 -21
- package/src/messages/network/v1/networkMessageFactory.js +1 -1
- package/src/messages/state/ApplyStateMessageBuilder.js +6 -6
- package/src/messages/state/applyStateMessageFactory.js +1 -1
- package/src/utils/buffer.js +1 -1
- package/src/utils/check.js +12 -13
- package/src/utils/constants.js +7 -0
- package/src/utils/errors.js +20 -0
- package/src/utils/fileUtils.js +12 -3
- package/src/utils/helpers.js +2 -2
- package/src/utils/migrationUtils.js +3 -3
- package/.dockerignore +0 -16
- package/CODE_OF_CONDUCT.md +0 -128
- package/docker-compose.yml +0 -17
- package/dockerfile +0 -41
- package/docs/fee_distribution.md +0 -89
- package/docs/trac_network_http_api.openapi.yaml +0 -889
- package/migration/.gitkeep +0 -0
- package/proto/applyOperations.proto +0 -117
- package/proto/network/v1/enums/message_type.proto +0 -16
- package/proto/network/v1/enums/result_code.proto +0 -84
- package/proto/network/v1/messages/broadcast_transaction_request.proto +0 -9
- package/proto/network/v1/messages/broadcast_transaction_response.proto +0 -13
- package/proto/network/v1/messages/liveness_request.proto +0 -8
- package/proto/network/v1/messages/liveness_response.proto +0 -11
- package/proto/network/v1/network_message.proto +0 -22
- package/rpc/rpc_services.js +0 -181
- package/scripts/generate-protobufs.js +0 -67
- package/src/core/network/identity/NetworkWalletFactory.js +0 -77
- package/src/core/network/protocols/shared/errors/SharedValidatorRejectionError.js +0 -27
- package/src/utils/cli.js +0 -130
- package/src/utils/cliCommands.js +0 -280
- package/tests/acceptance/v1/account/account.test.mjs +0 -129
- package/tests/acceptance/v1/balance/balance.test.mjs +0 -54
- package/tests/acceptance/v1/broadcast-transaction/broadcast-transaction.test.mjs +0 -116
- package/tests/acceptance/v1/confirmed-length/confirmed-length.test.mjs +0 -19
- package/tests/acceptance/v1/fee/fee.test.mjs +0 -11
- package/tests/acceptance/v1/health/health.test.mjs +0 -33
- package/tests/acceptance/v1/rpc.test.mjs +0 -95
- package/tests/acceptance/v1/tx/tx.test.mjs +0 -133
- package/tests/acceptance/v1/tx-details/tx-details.test.mjs +0 -241
- package/tests/acceptance/v1/tx-hashes/tx-hashes.test.mjs +0 -72
- package/tests/acceptance/v1/tx-payloads-bulk/tx-payloads-bulk.test.mjs +0 -27
- package/tests/acceptance/v1/txv/txv.test.mjs +0 -11
- package/tests/acceptance/v1/unconfirmed-length/unconfirmed-length.test.mjs +0 -11
- package/tests/fixtures/apply.fixtures.js +0 -77
- package/tests/fixtures/assembleMessage.fixtures.js +0 -41
- package/tests/fixtures/check.fixtures.js +0 -428
- package/tests/fixtures/networkV1.fixtures.js +0 -59
- package/tests/fixtures/protobuf.fixtures.js +0 -388
- package/tests/helpers/StateNetworkFactory.js +0 -155
- package/tests/helpers/address.js +0 -6
- package/tests/helpers/autobaseTestHelpers.js +0 -419
- package/tests/helpers/config.js +0 -4
- package/tests/helpers/createTestSignature.js +0 -13
- package/tests/helpers/regexHelper.js +0 -3
- package/tests/helpers/setupApplyTests.js +0 -587
- package/tests/helpers/transactionPayloads.mjs +0 -92
- package/tests/helpers/wrapper.js +0 -28
- package/tests/unit/messages/messages.test.js +0 -12
- package/tests/unit/messages/network/NetworkMessageBuilder.test.js +0 -436
- package/tests/unit/messages/network/NetworkMessageDirector.test.js +0 -347
- package/tests/unit/messages/state/applyStateMessageBuilder.complete.test.js +0 -525
- package/tests/unit/messages/state/applyStateMessageBuilder.partial.test.js +0 -237
- package/tests/unit/network/LegacyNetworkMessageRouter.test.js +0 -54
- package/tests/unit/network/NetworkWalletFactory.test.js +0 -156
- package/tests/unit/network/ProtocolSession.test.js +0 -127
- package/tests/unit/network/networkModule.test.js +0 -13
- package/tests/unit/network/services/ConnectionManager.test.js +0 -450
- package/tests/unit/network/services/MessageOrchestrator.test.js +0 -445
- package/tests/unit/network/services/PendingRequestService.test.js +0 -431
- package/tests/unit/network/services/TransactionCommitService.test.js +0 -246
- package/tests/unit/network/services/TransactionPoolService.test.js +0 -489
- package/tests/unit/network/services/TransactionRateLimiterService.test.js +0 -139
- package/tests/unit/network/services/ValidatorHealthCheckService.test.js +0 -115
- package/tests/unit/network/services/services.test.js +0 -17
- package/tests/unit/network/utils/v1TestUtils.js +0 -153
- package/tests/unit/network/v1/NetworkMessageRouterV1.test.js +0 -151
- package/tests/unit/network/v1/V1BaseOperation.test.js +0 -356
- package/tests/unit/network/v1/V1BroadcastTransactionOperationHandler.test.js +0 -129
- package/tests/unit/network/v1/V1BroadcastTransactionRequest.test.js +0 -53
- package/tests/unit/network/v1/V1BroadcastTransactionResponse.test.js +0 -512
- package/tests/unit/network/v1/V1LivenessRequest.test.js +0 -32
- package/tests/unit/network/v1/V1LivenessResponse.test.js +0 -45
- package/tests/unit/network/v1/V1ResultCode.test.js +0 -84
- package/tests/unit/network/v1/V1ValidationSchema.test.js +0 -13
- package/tests/unit/network/v1/connectionPolicies.test.js +0 -49
- package/tests/unit/network/v1/handlers/V1BaseOperationHandler.test.js +0 -284
- package/tests/unit/network/v1/handlers/V1BroadcastTransactionOperationHandler.test.js +0 -794
- package/tests/unit/network/v1/handlers/V1LivenessOperationHandler.test.js +0 -193
- package/tests/unit/network/v1/v1.handlers.test.js +0 -15
- package/tests/unit/network/v1/v1.test.js +0 -19
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionRequest.test.js +0 -119
- package/tests/unit/network/v1/v1ValidationSchema/broadcastTransactionResponse.test.js +0 -136
- package/tests/unit/network/v1/v1ValidationSchema/common.test.js +0 -308
- package/tests/unit/network/v1/v1ValidationSchema/livenessRequest.test.js +0 -90
- package/tests/unit/network/v1/v1ValidationSchema/livenessResponse.test.js +0 -133
- package/tests/unit/state/State.test.js +0 -80
- package/tests/unit/state/apply/addAdmin/addAdminHappyPathScenario.js +0 -42
- package/tests/unit/state/apply/addAdmin/addAdminScenarioHelpers.js +0 -276
- package/tests/unit/state/apply/addAdmin/adminEntryEncodingFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/adminEntryExistsScenario.js +0 -78
- package/tests/unit/state/apply/addAdmin/nodeEntryInitializationFailureScenario.js +0 -30
- package/tests/unit/state/apply/addAdmin/nonBootstrapNodeScenario.js +0 -68
- package/tests/unit/state/apply/addAdmin/state.apply.addAdmin.test.js +0 -159
- package/tests/unit/state/apply/addIndexer/addIndexerHappyPathScenario.js +0 -39
- package/tests/unit/state/apply/addIndexer/addIndexerMultipleIndexersInTheNetworkScenario.js +0 -167
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderAlreadyIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerPretenderNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/addIndexer/addIndexerRemoveAndReAddScenario.js +0 -186
- package/tests/unit/state/apply/addIndexer/addIndexerScenarioHelpers.js +0 -443
- package/tests/unit/state/apply/addIndexer/addIndexerWriterKeyAlreadyRegisteredScenario.js +0 -32
- package/tests/unit/state/apply/addIndexer/state.apply.addIndexer.test.js +0 -297
- package/tests/unit/state/apply/addWriter/addWriterHappyPathScenario.js +0 -41
- package/tests/unit/state/apply/addWriter/addWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/addWriter/addWriterNewWkScenario.js +0 -149
- package/tests/unit/state/apply/addWriter/addWriterRequesterAlreadyWriterScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/addWriter/addWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterRequesterNotWhitelistedScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterScenarioHelpers.js +0 -766
- package/tests/unit/state/apply/addWriter/addWriterStakeBalanceUpdateFailureScenario.js +0 -50
- package/tests/unit/state/apply/addWriter/addWriterStakeInsufficientBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidBalanceScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/addWriterStakeInvalidEntryScenario.js +0 -21
- package/tests/unit/state/apply/addWriter/addWriterStakeStakedBalanceFailureScenario.js +0 -37
- package/tests/unit/state/apply/addWriter/addWriterStakeSubtractFailureScenario.js +0 -42
- package/tests/unit/state/apply/addWriter/addWriterValidatorRewardScenario.js +0 -106
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyMismatchScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterWriterKeyOwnershipScenario.js +0 -54
- package/tests/unit/state/apply/addWriter/addWriterZeroWriterKeyScenario.js +0 -29
- package/tests/unit/state/apply/addWriter/state.apply.addWriter.test.js +0 -309
- package/tests/unit/state/apply/adminRecovery/adminRecoveryHappyPathScenario.js +0 -30
- package/tests/unit/state/apply/adminRecovery/adminRecoveryScenarioHelpers.js +0 -881
- package/tests/unit/state/apply/adminRecovery/state.apply.adminRecovery.test.js +0 -435
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistBanAndReapplyScenario.js +0 -78
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistExistingReaderHappyPathScenario.js +0 -98
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistFeeAfterDisableScenario.js +0 -66
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistHappyPathScenario.js +0 -55
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistInsufficientAdminBalanceScenario.js +0 -103
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistNodeAlreadyWhitelistedScenario.js +0 -60
- package/tests/unit/state/apply/appendWhitelist/appendWhitelistScenarioHelpers.js +0 -189
- package/tests/unit/state/apply/appendWhitelist/state.apply.appendWhitelist.test.js +0 -220
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationHappyPathScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/balanceInitializationScenarioHelpers.js +0 -111
- package/tests/unit/state/apply/balanceInitialization/invalidAmountScenario.js +0 -45
- package/tests/unit/state/apply/balanceInitialization/nodeEntryBalanceUpdateFailureScenario.js +0 -82
- package/tests/unit/state/apply/balanceInitialization/state.apply.balanceInitialization.test.js +0 -189
- package/tests/unit/state/apply/banValidator/banValidatorBanAndReWhitelistScenario.js +0 -156
- package/tests/unit/state/apply/banValidator/banValidatorHappyPathScenario.js +0 -36
- package/tests/unit/state/apply/banValidator/banValidatorScenarioHelpers.js +0 -531
- package/tests/unit/state/apply/banValidator/banValidatorSequentialBansScenario.js +0 -74
- package/tests/unit/state/apply/banValidator/banValidatorTargetDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetIndexerScenario.js +0 -32
- package/tests/unit/state/apply/banValidator/banValidatorTargetNodeEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorTargetRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedNonWriterScenario.js +0 -38
- package/tests/unit/state/apply/banValidator/banValidatorWhitelistedZeroBalanceScenario.js +0 -91
- package/tests/unit/state/apply/banValidator/banValidatorWithdrawFailureScenario.js +0 -19
- package/tests/unit/state/apply/banValidator/state.apply.banValidator.test.js +0 -266
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentDuplicateRegistrationScenario.js +0 -143
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentHappyPathScenario.js +0 -26
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentIncompleteOperationScenario.js +0 -94
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentInvalidDeploymentEntryScenario.js +0 -37
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentMultipleBootstrapScenario.js +0 -86
- package/tests/unit/state/apply/bootstrapDeployment/bootstrapDeploymentScenarioHelpers.js +0 -347
- package/tests/unit/state/apply/bootstrapDeployment/invalidValidatorNodeEntryScenario.js +0 -57
- package/tests/unit/state/apply/bootstrapDeployment/state.apply.bootstrapDeployment.test.js +0 -429
- package/tests/unit/state/apply/common/access-control/adminConsistencyMismatchScenario.js +0 -120
- package/tests/unit/state/apply/common/access-control/adminEntryDecodeFailureScenario.js +0 -130
- package/tests/unit/state/apply/common/access-control/adminEntryExistsScenario.js +0 -93
- package/tests/unit/state/apply/common/access-control/adminEntryMissingScenario.js +0 -108
- package/tests/unit/state/apply/common/access-control/adminOnlyGuardScenario.js +0 -126
- package/tests/unit/state/apply/common/access-control/adminPublicKeyDecodeFailureScenario.js +0 -121
- package/tests/unit/state/apply/common/access-control/roleAccessOperationValidationScenario.js +0 -50
- package/tests/unit/state/apply/common/adminControlOperationValidationScenario.js +0 -56
- package/tests/unit/state/apply/common/balances/adminEntryUpdateFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/base/requesterBalanceScenarioBase.js +0 -198
- package/tests/unit/state/apply/common/balances/feeDecodeFailureScenario.js +0 -52
- package/tests/unit/state/apply/common/balances/requesterBalanceDecodeFailureScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceFeeApplicationFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/requesterBalanceInsufficientScenario.js +0 -15
- package/tests/unit/state/apply/common/balances/requesterBalanceUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryRewardFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorEntryUpdateFailureScenario.js +0 -11
- package/tests/unit/state/apply/common/balances/validatorNodeEntryDecodeFailureScenario.js +0 -40
- package/tests/unit/state/apply/common/base/OperationValidationScenarioBase.js +0 -114
- package/tests/unit/state/apply/common/commonScenarioHelper.js +0 -103
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryDecodeFailureScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/indexer/indexerRoleUpdateFailureScenario.js +0 -29
- package/tests/unit/state/apply/common/indexer/indexerSequenceStateInvalidScenario.js +0 -66
- package/tests/unit/state/apply/common/invalidMessageComponentValidationScenario.js +0 -84
- package/tests/unit/state/apply/common/nodeEntryInitializationFailureScenario.js +0 -47
- package/tests/unit/state/apply/common/operationAlreadyAppliedScenario.js +0 -85
- package/tests/unit/state/apply/common/payload-structure/addressWithInvalidPublicKeyScenario.js +0 -52
- package/tests/unit/state/apply/common/payload-structure/initializationDisabledScenario.js +0 -54
- package/tests/unit/state/apply/common/payload-structure/invalidAddressValidationScenario.js +0 -73
- package/tests/unit/state/apply/common/payload-structure/invalidHashValidationScenario.js +0 -71
- package/tests/unit/state/apply/common/payload-structure/invalidPayloadValidationScenario.js +0 -31
- package/tests/unit/state/apply/common/payload-structure/invalidSignatureValidationScenario.js +0 -142
- package/tests/unit/state/apply/common/payload-structure/partialOperationValidationScenario.js +0 -87
- package/tests/unit/state/apply/common/requester/requesterNodeEntryBufferMissingScenario.js +0 -71
- package/tests/unit/state/apply/common/requester/requesterNodeEntryDecodeFailureScenario.js +0 -73
- package/tests/unit/state/apply/common/requester/requesterNodeEntryMissingScenario.js +0 -36
- package/tests/unit/state/apply/common/requesterAddressValidationScenario.js +0 -44
- package/tests/unit/state/apply/common/requesterPublicKeyValidationScenario.js +0 -25
- package/tests/unit/state/apply/common/transactionValidityMismatchScenario.js +0 -98
- package/tests/unit/state/apply/common/validatorConsistency/base/validatorConsistencyScenarioBase.js +0 -202
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryDecodeFailureScenario.js +0 -17
- package/tests/unit/state/apply/common/validatorConsistency/validatorEntryMissingScenario.js +0 -44
- package/tests/unit/state/apply/common/validatorConsistency/validatorInactiveScenario.js +0 -19
- package/tests/unit/state/apply/common/validatorConsistency/validatorWriterKeyMismatchScenario.js +0 -18
- package/tests/unit/state/apply/common/validatorEntryValidation/base/validatorEntryValidationScenarioBase.js +0 -315
- package/tests/unit/state/apply/common/validatorEntryValidation/validatorEntryInvalidBalanceScenario.js +0 -18
- package/tests/unit/state/apply/common/writerKeyExistsValidationScenario.js +0 -43
- package/tests/unit/state/apply/disableInitialization/disableInitializationAlreadyDisabledScenario.js +0 -53
- package/tests/unit/state/apply/disableInitialization/disableInitializationHappyPathScenario.js +0 -24
- package/tests/unit/state/apply/disableInitialization/disableInitializationScenarioHelpers.js +0 -204
- package/tests/unit/state/apply/disableInitialization/state.apply.disableInitialization.test.js +0 -161
- package/tests/unit/state/apply/missing-tests.md +0 -18
- package/tests/unit/state/apply/removeIndexer/removeIndexerHappyPathScenario.js +0 -58
- package/tests/unit/state/apply/removeIndexer/removeIndexerReAddAndRemoveAgainScenario.js +0 -98
- package/tests/unit/state/apply/removeIndexer/removeIndexerRemoveMultipleIndexersScenario.js +0 -167
- package/tests/unit/state/apply/removeIndexer/removeIndexerScenarioHelpers.js +0 -429
- package/tests/unit/state/apply/removeIndexer/removeIndexerTargetNotIndexerScenario.js +0 -22
- package/tests/unit/state/apply/removeIndexer/removeIndexerWriterKeyMissingScenario.js +0 -20
- package/tests/unit/state/apply/removeIndexer/state.apply.removeIndexer.test.js +0 -291
- package/tests/unit/state/apply/removeWriter/removeWriterAndAddWriterAgainScenario.js +0 -87
- package/tests/unit/state/apply/removeWriter/removeWriterHappyPathScenario.js +0 -38
- package/tests/unit/state/apply/removeWriter/removeWriterInvalidValidatorSignatureScenario.js +0 -32
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterBalanceInsufficientScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryDecodeFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterEntryMissingScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterIndexerScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterNotWriterScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterRequesterRoleUpdateFailureScenario.js +0 -19
- package/tests/unit/state/apply/removeWriter/removeWriterScenarioHelpers.js +0 -348
- package/tests/unit/state/apply/removeWriter/removeWriterThroughWriterValidatorScenario.js +0 -113
- package/tests/unit/state/apply/removeWriter/removeWriterUnstakeFailureScenario.js +0 -33
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyMismatchScenario.js +0 -21
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyOwnershipScenario.js +0 -26
- package/tests/unit/state/apply/removeWriter/removeWriterWriterKeyRegistryMissingScenario.js +0 -22
- package/tests/unit/state/apply/removeWriter/state.apply.removeWriter.test.js +0 -307
- package/tests/unit/state/apply/state.apply.test.js +0 -24
- package/tests/unit/state/apply/transfer/state.apply.transfer.test.js +0 -819
- package/tests/unit/state/apply/transfer/transferContractSchemaValidationScenario.js +0 -22
- package/tests/unit/state/apply/transfer/transferDoubleSpendAcrossValidatorsScenario.js +0 -146
- package/tests/unit/state/apply/transfer/transferDoubleSpendSameBatchScenario.js +0 -63
- package/tests/unit/state/apply/transfer/transferDoubleSpendSingleValidatorScenario.js +0 -67
- package/tests/unit/state/apply/transfer/transferExistingRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferExistingRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferHandlerGuardScenarios.js +0 -22
- package/tests/unit/state/apply/transfer/transferHappyPathScenario.js +0 -8
- package/tests/unit/state/apply/transfer/transferInvalidIncomingDataScenario.js +0 -66
- package/tests/unit/state/apply/transfer/transferNewRecipientAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferNewRecipientZeroAmountScenario.js +0 -31
- package/tests/unit/state/apply/transfer/transferScenarioHelpers.js +0 -1170
- package/tests/unit/state/apply/transfer/transferSelfTransferAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferSelfTransferZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientAmountScenario.js +0 -38
- package/tests/unit/state/apply/transfer/transferValidatorRecipientZeroAmountScenario.js +0 -38
- package/tests/unit/state/apply/txOperation/state.apply.txOperation.test.js +0 -318
- package/tests/unit/state/apply/txOperation/txOperationBootstrapNotRegisteredScenario.js +0 -70
- package/tests/unit/state/apply/txOperation/txOperationDifferentValidatorCreatorHappyPathScenario.js +0 -23
- package/tests/unit/state/apply/txOperation/txOperationInvalidDeploymentEntryScenario.js +0 -48
- package/tests/unit/state/apply/txOperation/txOperationInvalidFeeAmountScenario.js +0 -39
- package/tests/unit/state/apply/txOperation/txOperationInvalidSubnetCreatorAddressScenario.js +0 -46
- package/tests/unit/state/apply/txOperation/txOperationRequesterCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationScenarioHelpers.js +0 -432
- package/tests/unit/state/apply/txOperation/txOperationStandardHappyPathScenario.js +0 -21
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBalanceFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeAddValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeDecodeValidatorEntryScenario.js +0 -31
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardBypassScenario.js +0 -49
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeGuardScenarioFactory.js +0 -93
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInsufficientRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidCreatorBalanceScenario.js +0 -29
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterBalanceScenario.js +0 -28
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidRequesterEntryScenario.js +0 -17
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeInvalidValidatorBalanceScenario.js +0 -33
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeMissingCreatorEntryScenario.js +0 -18
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeSubtractFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateCreatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateFailureScenario.js +0 -25
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBalanceFailureScenario.js +0 -26
- package/tests/unit/state/apply/txOperation/txOperationTransferFeeUpdateValidatorBonusFailureScenario.js +0 -27
- package/tests/unit/state/apply/txOperation/txOperationValidatorCreatorHappyPathScenario.js +0 -21
- package/tests/unit/state/stateModule.test.js +0 -23
- package/tests/unit/state/stateTestUtils.js +0 -32
- package/tests/unit/state/utils/address.test.js +0 -63
- package/tests/unit/state/utils/adminEntry.test.js +0 -52
- package/tests/unit/state/utils/balance.test.js +0 -320
- package/tests/unit/state/utils/lengthEntry.test.js +0 -54
- package/tests/unit/state/utils/nodeEntry.test.js +0 -298
- package/tests/unit/state/utils/roles.test.js +0 -44
- package/tests/unit/unit.test.js +0 -14
- package/tests/unit/utils/amountSerialization/amountSerialization.test.js +0 -237
- package/tests/unit/utils/buffer/buffer.test.js +0 -251
- package/tests/unit/utils/check/adminControlOperation.test.js +0 -156
- package/tests/unit/utils/check/balanceInitializationOperation.test.js +0 -54
- package/tests/unit/utils/check/bootstrapDeploymentOperation.test.js +0 -104
- package/tests/unit/utils/check/check.test.js +0 -17
- package/tests/unit/utils/check/common.test.js +0 -419
- package/tests/unit/utils/check/coreAdminOperation.test.js +0 -95
- package/tests/unit/utils/check/roleAccessOperation.test.js +0 -255
- package/tests/unit/utils/check/transactionOperation.test.js +0 -107
- package/tests/unit/utils/check/transferOperation.test.js +0 -102
- package/tests/unit/utils/deepEqualApplyPayload/deepEqualApplyPayload.test.js +0 -102
- package/tests/unit/utils/fileUtils/readAddressesFromWhitelistFile.test.js +0 -95
- package/tests/unit/utils/fileUtils/readBalanceMigrationFile.test.js +0 -149
- package/tests/unit/utils/helpers/helpers.test.js +0 -11
- package/tests/unit/utils/helpers/isHexString.test.js +0 -12
- package/tests/unit/utils/helpers/normalizeHex.test.js +0 -82
- package/tests/unit/utils/migrationUtils/validateAddressFromIncomingFile.test.js +0 -100
- package/tests/unit/utils/normalizers/normalizers.test.js +0 -469
- package/tests/unit/utils/protobuf/applyOperations.test.js +0 -91
- package/tests/unit/utils/protobuf/operationHelpers.test.js +0 -303
- package/tests/unit/utils/protobuf/protobuf.test.js +0 -12
- package/tests/unit/utils/type/type.test.js +0 -25
- package/tests/unit/utils/utils.test.js +0 -21
- package/whitelist/.gitkeep +0 -0
|
@@ -1,587 +0,0 @@
|
|
|
1
|
-
import sodium from 'sodium-native';
|
|
2
|
-
import {generateMnemonic, mnemonicToSeed} from 'bip39-mnemonic';
|
|
3
|
-
import b4a from 'b4a'
|
|
4
|
-
import PeerWallet from "trac-wallet"
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import {MainSettlementBus} from '../../src/index.js'
|
|
7
|
-
import { createConfig, ENV } from '../../src/config/env.js'
|
|
8
|
-
import fileUtils from '../../src/utils/fileUtils.js'
|
|
9
|
-
import {EntryType} from '../../src/utils/constants.js';
|
|
10
|
-
import {sleep} from '../../src/utils/helpers.js'
|
|
11
|
-
import {formatIndexersEntry} from '../../src/utils/helpers.js';
|
|
12
|
-
import { applyStateMessageFactory } from "../../src/messages/state/applyStateMessageFactory.js";
|
|
13
|
-
import { safeEncodeApplyOperation } from "../../src/utils/protobuf/operationHelpers.js"
|
|
14
|
-
import { $TNK } from '../../src/core/state/utils/balance.js';
|
|
15
|
-
import { EventType } from '../../src/utils/constants.js';
|
|
16
|
-
import { Config } from '../../src/config/config.js';
|
|
17
|
-
let os, fsp;
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Ensures that the environment is ready for file system and OS operations.
|
|
21
|
-
*/
|
|
22
|
-
|
|
23
|
-
async function ensureEnvReady() {
|
|
24
|
-
if (!os || !fsp) {
|
|
25
|
-
if (typeof globalThis.Bare !== 'undefined') {
|
|
26
|
-
const bareOS = await import('bare-os');
|
|
27
|
-
os = bareOS.default || bareOS;
|
|
28
|
-
const bareFS = await import('bare-fs');
|
|
29
|
-
fsp = (bareFS.default || bareFS).promises;
|
|
30
|
-
} else {
|
|
31
|
-
const nodeOS = await import('os');
|
|
32
|
-
os = nodeOS.default || nodeOS;
|
|
33
|
-
const nodeFS = await import('fs/promises');
|
|
34
|
-
fsp = nodeFS.default || nodeFS;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function randomBytes(num) {
|
|
40
|
-
const buf = b4a.allocUnsafe(num);
|
|
41
|
-
sodium.randombytes_buf(buf);
|
|
42
|
-
return buf;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
async function randomKeypair() {
|
|
46
|
-
const keypair = {};
|
|
47
|
-
const mnemonic = generateMnemonic();
|
|
48
|
-
const seed = await mnemonicToSeed(mnemonic);
|
|
49
|
-
|
|
50
|
-
const publicKey = b4a.alloc(sodium.crypto_sign_PUBLICKEYBYTES);
|
|
51
|
-
const secretKey = b4a.alloc(sodium.crypto_sign_SECRETKEYBYTES);
|
|
52
|
-
|
|
53
|
-
const hash = b4a.alloc(sodium.crypto_hash_sha256_BYTES);
|
|
54
|
-
sodium.crypto_hash_sha256(hash, b4a.from(seed));
|
|
55
|
-
|
|
56
|
-
const seed32 = b4a.from(hash, 'hex');
|
|
57
|
-
|
|
58
|
-
sodium.crypto_sign_seed_keypair(publicKey, secretKey, seed32);
|
|
59
|
-
|
|
60
|
-
keypair.publicKey = publicKey;
|
|
61
|
-
keypair.secretKey = secretKey;
|
|
62
|
-
return keypair;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export const tick = () => new Promise(resolve => setImmediate(resolve));
|
|
66
|
-
|
|
67
|
-
export async function fundPeer(admin, toFund, amount) {
|
|
68
|
-
const txValidity = await admin.msb.state.getIndexerSequenceState()
|
|
69
|
-
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
70
|
-
.buildCompleteBalanceInitializationMessage(
|
|
71
|
-
admin.wallet.address,
|
|
72
|
-
toFund.wallet.address,
|
|
73
|
-
amount,
|
|
74
|
-
txValidity
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
78
|
-
await tick()
|
|
79
|
-
await admin.msb.state.base.forceFastForward() // required to update the balance on the peer, eliminates the possible racing condition
|
|
80
|
-
await tick()
|
|
81
|
-
return payload
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
export async function initMsbPeer(peerName, peerKeyPair, temporaryDirectory, options = {}) {
|
|
85
|
-
const config = createConfig(ENV.DEVELOPMENT, { ...options, storesDirectory: `${temporaryDirectory}/${peerName}` })
|
|
86
|
-
const peer = await initDirectoryStructure(peerName, peerKeyPair, config.storesFullPath);
|
|
87
|
-
peer.options = { ...options, storesDirectory: config.storesDirectory }
|
|
88
|
-
peer.config = config
|
|
89
|
-
const msb = new MainSettlementBus(peer.config);
|
|
90
|
-
|
|
91
|
-
peer.msb = msb;
|
|
92
|
-
peer.wallet = msb.wallet;
|
|
93
|
-
peer.name = peerName;
|
|
94
|
-
|
|
95
|
-
return peer;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export async function setupMsbPeer(peerName, peerKeyPair, temporaryDirectory, options = {}) {
|
|
99
|
-
const peer = await initMsbPeer(peerName, peerKeyPair, temporaryDirectory, options);
|
|
100
|
-
await peer.msb.ready();
|
|
101
|
-
return peer;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
export async function initMsbAdmin(keyPair, temporaryDirectory, options = {}) {
|
|
105
|
-
const peerName = 'admin';
|
|
106
|
-
const admin = await initMsbPeer(peerName, keyPair, temporaryDirectory, { ...options, bootstrap: randomBytes(32).toString('hex') });
|
|
107
|
-
|
|
108
|
-
await admin.msb.ready();
|
|
109
|
-
admin.options.bootstrap = admin.msb.state.writingKey.toString('hex');
|
|
110
|
-
admin.config = new Config(admin.options, admin.config)
|
|
111
|
-
await admin.msb.close();
|
|
112
|
-
|
|
113
|
-
admin.msb = new MainSettlementBus(admin.config);
|
|
114
|
-
await admin.msb.ready();
|
|
115
|
-
await admin.msb.state.append(null); // before initialization system.indexers is empty, we need to initialize first block to create system.indexers array
|
|
116
|
-
return admin;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
export async function setupMsbAdmin(keyPair, temporaryDirectory, options = {}) {
|
|
120
|
-
const admin = await initMsbAdmin(keyPair, temporaryDirectory, options);
|
|
121
|
-
const txValidity = await admin.msb.state.getIndexerSequenceState();
|
|
122
|
-
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
123
|
-
.buildCompleteAddAdminMessage(admin.wallet.address, admin.msb.state.writingKey, txValidity);
|
|
124
|
-
|
|
125
|
-
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
126
|
-
await tick();
|
|
127
|
-
return admin;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
export async function setupNodeAsWriter(admin, writerCandidate) {
|
|
131
|
-
try {
|
|
132
|
-
await setupWhitelist(admin, [writerCandidate.wallet.address]); // ensure if is whitelisted
|
|
133
|
-
|
|
134
|
-
const validity = await admin.msb.getIndexerSequenceState()
|
|
135
|
-
const req = await applyStateMessageFactory(writerCandidate.wallet, admin.config)
|
|
136
|
-
.buildPartialAddWriterMessage(
|
|
137
|
-
writerCandidate.wallet.address,
|
|
138
|
-
b4a.toString(writerCandidate.msb.state.writingKey, 'hex'),
|
|
139
|
-
b4a.toString(validity, 'hex'),
|
|
140
|
-
'json'
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
await waitWritable(admin, writerCandidate, async () => {
|
|
144
|
-
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
145
|
-
.buildCompleteAddWriterMessage(
|
|
146
|
-
admin.wallet.address,
|
|
147
|
-
b4a.from(req.rao.tx, 'hex'),
|
|
148
|
-
b4a.from(req.rao.txv, 'hex'),
|
|
149
|
-
b4a.from(req.rao.iw, 'hex'),
|
|
150
|
-
b4a.from(req.rao.in, 'hex'),
|
|
151
|
-
b4a.from(req.rao.is, 'hex')
|
|
152
|
-
);
|
|
153
|
-
await admin.msb.state.append(safeEncodeApplyOperation(payload))
|
|
154
|
-
})
|
|
155
|
-
|
|
156
|
-
return writerCandidate;
|
|
157
|
-
} catch (error) {
|
|
158
|
-
throw new Error('Error setting up MSB writer: ', error.message || error);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
export async function promoteToWriter(admin, writerCandidate) {
|
|
163
|
-
await setupWhitelist(admin, [writerCandidate.wallet.address]);
|
|
164
|
-
await waitForNodeState(writerCandidate,
|
|
165
|
-
writerCandidate.wallet.address,
|
|
166
|
-
{
|
|
167
|
-
wk: writerCandidate.msb.state.writingKey,
|
|
168
|
-
isWhitelisted: true,
|
|
169
|
-
isWriter: false,
|
|
170
|
-
isIndexer: false,
|
|
171
|
-
})
|
|
172
|
-
const validity = await admin.msb.state.getIndexerSequenceState()
|
|
173
|
-
const req = await applyStateMessageFactory(writerCandidate.wallet, writerCandidate.config)
|
|
174
|
-
.buildPartialAddWriterMessage(
|
|
175
|
-
writerCandidate.wallet.address,
|
|
176
|
-
b4a.toString(writerCandidate.msb.state.writingKey, 'hex'),
|
|
177
|
-
b4a.toString(validity, 'hex'),
|
|
178
|
-
'json'
|
|
179
|
-
);
|
|
180
|
-
|
|
181
|
-
await waitWritable(writerCandidate, writerCandidate, async () => {
|
|
182
|
-
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
183
|
-
.buildCompleteAddWriterMessage(
|
|
184
|
-
req.address,
|
|
185
|
-
b4a.from(req.rao.tx, 'hex'),
|
|
186
|
-
b4a.from(req.rao.txv, 'hex'),
|
|
187
|
-
b4a.from(req.rao.iw, 'hex'),
|
|
188
|
-
b4a.from(req.rao.in, 'hex'),
|
|
189
|
-
b4a.from(req.rao.is, 'hex')
|
|
190
|
-
);
|
|
191
|
-
await admin.msb.state.append(safeEncodeApplyOperation(payload))
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
return writerCandidate;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
export async function setupMsbWriter(admin, peerName, peerKeyPair, temporaryDirectory, options = {}) {
|
|
198
|
-
try {
|
|
199
|
-
const writerCandidate = await setupMsbPeer(peerName, peerKeyPair, temporaryDirectory, options);
|
|
200
|
-
await fundPeer(admin, writerCandidate, $TNK(10n)) // It is assumed that a writer will write and therefore, will need money to process stuff
|
|
201
|
-
return await promoteToWriter(admin, writerCandidate)
|
|
202
|
-
} catch (error) {
|
|
203
|
-
throw new Error('Error setting up MSB writer: ', error.message || error);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
export async function setupMsbIndexer(indexerCandidate, admin) {
|
|
208
|
-
try {
|
|
209
|
-
const validity = await admin.msb.state.getIndexerSequenceState()
|
|
210
|
-
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
211
|
-
.buildCompleteAddIndexerMessage(admin.wallet.address, indexerCandidate.wallet.address, validity);
|
|
212
|
-
|
|
213
|
-
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
214
|
-
await tick(); // wait for the request to be processed
|
|
215
|
-
|
|
216
|
-
const isIndexer = async () => {
|
|
217
|
-
const indexersEntry = await admin.msb.state.getIndexersEntry();
|
|
218
|
-
if (!indexersEntry) {
|
|
219
|
-
return false;
|
|
220
|
-
}
|
|
221
|
-
const formatted = formatIndexersEntry(indexersEntry, admin.config.addressLength);
|
|
222
|
-
if (!formatted || !formatted.addresses) return false;
|
|
223
|
-
return formatted.addresses.includes(indexerCandidate.wallet.address);
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
let counter;
|
|
227
|
-
const limit = 10; // maximum number of attempts to verify the role
|
|
228
|
-
for (counter = 0; counter < limit; counter++) {
|
|
229
|
-
if (await isIndexer(indexerCandidate.wallet.address) && await indexerCandidate.msb.state.isIndexer()) {
|
|
230
|
-
break;
|
|
231
|
-
}
|
|
232
|
-
await indexerCandidate.msb.state.append(null);
|
|
233
|
-
await indexerCandidate.msb.state.base.forceFastForward();
|
|
234
|
-
await indexerCandidate.msb.state.base.view.update();
|
|
235
|
-
await indexerCandidate.msb.network.swarm.flush()
|
|
236
|
-
await admin.msb.state.base.update()
|
|
237
|
-
await sleep(1000); // wait for the peer to sync state
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
return indexerCandidate;
|
|
241
|
-
} catch (error) {
|
|
242
|
-
throw new Error('Error setting up MSB indexer: ', error.message || error);
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
export async function setupWhitelist(admin, whitelistAddresses) {
|
|
247
|
-
if (!admin || !admin.msb || !admin.wallet) {
|
|
248
|
-
throw new Error('Admin is not properly initialized');
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
if (!Array.isArray(whitelistAddresses) || whitelistAddresses.length === 0) {
|
|
252
|
-
throw new Error('Whitelist addresses must be a non-empty array');
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
const adminEntry = await admin.msb.state.get(EntryType.ADMIN);
|
|
256
|
-
if (!adminEntry) {
|
|
257
|
-
throw new Error('Admin is not initialized. Execute /add_admin command first.');
|
|
258
|
-
}
|
|
259
|
-
// set up mock whitelist
|
|
260
|
-
const originalReadAddressesFromWhitelistFile = fileUtils.readAddressesFromWhitelistFile;
|
|
261
|
-
fileUtils.readAddressesFromWhitelistFile = async () => whitelistAddresses;
|
|
262
|
-
const validity = await admin.msb.state.getIndexerSequenceState()
|
|
263
|
-
for (const address of whitelistAddresses) {
|
|
264
|
-
const payload = await applyStateMessageFactory(admin.wallet, admin.config)
|
|
265
|
-
.buildCompleteAppendWhitelistMessage(admin.wallet.address, address, validity);
|
|
266
|
-
|
|
267
|
-
await admin.msb.state.append(safeEncodeApplyOperation(payload));
|
|
268
|
-
await sleep(100)
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
fileUtils.readAddressesFromWhitelistFile = originalReadAddressesFromWhitelistFile;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export async function initTemporaryDirectory() {
|
|
275
|
-
await ensureEnvReady();
|
|
276
|
-
const tmpDir = os.tmpdir();
|
|
277
|
-
const unique = `tempTestStore-${Date.now()}-${Math.random().toString(16).slice(2)}`;
|
|
278
|
-
const temporaryDirectory = path.join(tmpDir, unique);
|
|
279
|
-
await fsp.mkdir(temporaryDirectory, {recursive: true});
|
|
280
|
-
console.log('temporary directory: ', temporaryDirectory);
|
|
281
|
-
return temporaryDirectory;
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
export async function removeTemporaryDirectory(temporaryDirectory) {
|
|
285
|
-
await ensureEnvReady();
|
|
286
|
-
await fsp.rm(temporaryDirectory, {recursive: true, force: true})
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
export async function initDirectoryStructure(peerName, keyPair, temporaryDirectory) {
|
|
290
|
-
try {
|
|
291
|
-
await ensureEnvReady();
|
|
292
|
-
const corestoreDbDirectory = path.join(temporaryDirectory, 'db');
|
|
293
|
-
await fsp.mkdir(corestoreDbDirectory, {recursive: true});
|
|
294
|
-
|
|
295
|
-
const keypath = path.join(corestoreDbDirectory, 'keypair.json');
|
|
296
|
-
if (!keyPair || !keyPair.publicKey || !keyPair.secretKey) {
|
|
297
|
-
keyPair = await randomKeypair();
|
|
298
|
-
}
|
|
299
|
-
const wallet = new PeerWallet(keyPair)
|
|
300
|
-
await wallet.ready
|
|
301
|
-
await wallet.exportToFile(keypath)
|
|
302
|
-
return {
|
|
303
|
-
storesDirectory: temporaryDirectory,
|
|
304
|
-
corestoreDbDirectory,
|
|
305
|
-
keypath,
|
|
306
|
-
}
|
|
307
|
-
} catch (error) {
|
|
308
|
-
throw new Error('Error creating directory structure: ' + error)
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
export const deployExternalBootstrap = async (writer, externalNode) => {
|
|
313
|
-
const externalBootstrap = randomBytes(32).toString('hex');
|
|
314
|
-
const txValidity = await writer.msb.state.getIndexerSequenceState();
|
|
315
|
-
const payload = await applyStateMessageFactory(externalNode.msb.wallet, admin.config)
|
|
316
|
-
.buildPartialBootstrapDeploymentMessage(
|
|
317
|
-
externalNode.msb.wallet.address,
|
|
318
|
-
externalBootstrap,
|
|
319
|
-
randomBytes(32).toString('hex'),
|
|
320
|
-
txValidity.toString('hex'),
|
|
321
|
-
'json'
|
|
322
|
-
);
|
|
323
|
-
|
|
324
|
-
const rawPayload = await applyStateMessageFactory(writer.msb.wallet, admin.config)
|
|
325
|
-
.buildCompleteBootstrapDeploymentMessage(
|
|
326
|
-
payload.address,
|
|
327
|
-
b4a.from(payload.bdo.tx, 'hex'),
|
|
328
|
-
b4a.from(payload.bdo.txv, 'hex'),
|
|
329
|
-
b4a.from(payload.bdo.bs, 'hex'),
|
|
330
|
-
b4a.from(payload.bdo.ic, 'hex'),
|
|
331
|
-
b4a.from(payload.bdo.in, 'hex'),
|
|
332
|
-
b4a.from(payload.bdo.is, 'hex'),
|
|
333
|
-
)
|
|
334
|
-
await writer.msb.state.base.append(safeEncodeApplyOperation(rawPayload))
|
|
335
|
-
await tick()
|
|
336
|
-
await waitForHash(writer, payload.bdo.tx)
|
|
337
|
-
return externalBootstrap
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
export const generatePostTx = async (writer, externalNode, externalContractBootstrap) => {
|
|
341
|
-
const peerWriterKey = randomBytes(32).toString('hex');
|
|
342
|
-
|
|
343
|
-
const testObj = {
|
|
344
|
-
type: 'deployTest',
|
|
345
|
-
value: {
|
|
346
|
-
op: 'deploy',
|
|
347
|
-
tick: Math.random().toString(),
|
|
348
|
-
max: '21000000',
|
|
349
|
-
lim: '1000',
|
|
350
|
-
dec: 18
|
|
351
|
-
}
|
|
352
|
-
};
|
|
353
|
-
|
|
354
|
-
const contentHash = await PeerWallet.blake3(JSON.stringify(testObj));
|
|
355
|
-
const validity = await writer.msb.state.getIndexerSequenceState()
|
|
356
|
-
const tx = await applyStateMessageFactory(externalNode.wallet, admin.config)
|
|
357
|
-
.buildPartialTransactionOperationMessage(
|
|
358
|
-
externalNode.wallet.address,
|
|
359
|
-
peerWriterKey,
|
|
360
|
-
b4a.toString(validity, 'hex'),
|
|
361
|
-
b4a.toString(contentHash, 'hex'),
|
|
362
|
-
externalContractBootstrap,
|
|
363
|
-
b4a.toString(writer.msb.bootstrap, 'hex'),
|
|
364
|
-
'json'
|
|
365
|
-
)
|
|
366
|
-
|
|
367
|
-
const postTxPayload = await applyStateMessageFactory(writer.wallet, admin.config)
|
|
368
|
-
.buildCompleteTransactionOperationMessage(
|
|
369
|
-
tx.address,
|
|
370
|
-
b4a.from(tx.txo.tx, 'hex'),
|
|
371
|
-
b4a.from(tx.txo.txv, 'hex'),
|
|
372
|
-
b4a.from(tx.txo.iw, 'hex'),
|
|
373
|
-
b4a.from(tx.txo.in, 'hex'),
|
|
374
|
-
b4a.from(tx.txo.ch, 'hex'),
|
|
375
|
-
b4a.from(tx.txo.is, 'hex'),
|
|
376
|
-
b4a.from(tx.txo.bs, 'hex'),
|
|
377
|
-
b4a.from(tx.txo.mbs, 'hex')
|
|
378
|
-
);
|
|
379
|
-
|
|
380
|
-
const postTx = safeEncodeApplyOperation(postTxPayload);
|
|
381
|
-
return { postTx, txHash: tx.txo.tx };
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* You can synchronize multiple nodes by passing them as arguments,
|
|
386
|
-
* Useful for aligning signedLength values. If node is not a writer, it will be skipped.
|
|
387
|
-
*
|
|
388
|
-
* @example
|
|
389
|
-
* await tryToSyncWriters(admin, writer1, writer2, indexer1);
|
|
390
|
-
*/
|
|
391
|
-
export const tryToSyncWriters = async (...args) => {
|
|
392
|
-
try {
|
|
393
|
-
const [first, ..._] = args
|
|
394
|
-
await first.msb.state.base.forceFastForward()
|
|
395
|
-
await first.msb.state.base.view.update()
|
|
396
|
-
let attempts = 0;
|
|
397
|
-
const maxAttempts = 10;
|
|
398
|
-
while (attempts < maxAttempts) {
|
|
399
|
-
let maxLength = Math.max(...args.map(node => node.msb.state.getSignedLength()));
|
|
400
|
-
let allSynced = true;
|
|
401
|
-
for (const node of args) {
|
|
402
|
-
let signedLength = node.msb.state.getSignedLength();
|
|
403
|
-
if (signedLength < maxLength) {
|
|
404
|
-
await node.msb.state.base.view.update();
|
|
405
|
-
await node.msb.network.swarm.flush()
|
|
406
|
-
await sleep(1000);
|
|
407
|
-
allSynced = false;
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
if (allSynced) break;
|
|
411
|
-
attempts++;
|
|
412
|
-
}
|
|
413
|
-
} catch (error) {
|
|
414
|
-
throw new Error("Error synchronizing writers: " + error.message || error);
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
export async function waitForNotIndexer(indexer) {
|
|
419
|
-
try {
|
|
420
|
-
let attempts = 0;
|
|
421
|
-
const maxAttempts = 20;
|
|
422
|
-
while (attempts < maxAttempts) {
|
|
423
|
-
await indexer.msb.state.base.update();
|
|
424
|
-
await indexer.msb.state.base.view.update();
|
|
425
|
-
const indexersEntry = await indexer.msb.state.getIndexersEntry();
|
|
426
|
-
let notIndexer = false;
|
|
427
|
-
if (!indexersEntry) {
|
|
428
|
-
notIndexer = true;
|
|
429
|
-
} else {
|
|
430
|
-
const formatted = formatIndexersEntry(indexersEntry, admin.config.addressLength);
|
|
431
|
-
if (!formatted || !formatted.addresses) {
|
|
432
|
-
notIndexer = true;
|
|
433
|
-
} else if (!formatted.addresses.includes(indexer.wallet.address)) {
|
|
434
|
-
notIndexer = true;
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
if (notIndexer) {
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
await indexer.msb.network.swarm.flush()
|
|
441
|
-
await sleep(1000);
|
|
442
|
-
attempts++;
|
|
443
|
-
}
|
|
444
|
-
} catch (error) {
|
|
445
|
-
throw new Error("Error waiting for indexer to not be an indexer: " + error.message || error);
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
export async function waitIndexer(node, operation) {
|
|
450
|
-
const waiter = new Promise(resolve => {
|
|
451
|
-
node.msb.state.base.once(EventType.IS_INDEXER, (...args) => {
|
|
452
|
-
resolve(args)
|
|
453
|
-
})
|
|
454
|
-
})
|
|
455
|
-
await operation()
|
|
456
|
-
return waiter
|
|
457
|
-
}
|
|
458
|
-
|
|
459
|
-
export async function waitWritable(admin, node, operation) {
|
|
460
|
-
const waiter = new Promise(resolve => {
|
|
461
|
-
node.msb.state.base.once(EventType.WRITABLE, (...args) => {
|
|
462
|
-
resolve(args)
|
|
463
|
-
})
|
|
464
|
-
})
|
|
465
|
-
await operation()
|
|
466
|
-
await node.msb.state.base.view.update();
|
|
467
|
-
await admin.msb.state.base.update()
|
|
468
|
-
await node.msb.network.swarm.flush()
|
|
469
|
-
return waiter
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
export async function waitDemotion(node, operation) {
|
|
473
|
-
const waiter = new Promise(resolve => {
|
|
474
|
-
node.msb.state.base.once(EventType.UNWRITABLE, (...args) => {
|
|
475
|
-
resolve(args)
|
|
476
|
-
})
|
|
477
|
-
})
|
|
478
|
-
await operation()
|
|
479
|
-
return waiter
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
/**
|
|
483
|
-
* Waits until the given node sees the expected state for a target address.
|
|
484
|
-
*
|
|
485
|
-
* @param {object} node - The node whose state will be checked (the observer).
|
|
486
|
-
* @param {string} address - The address whose state we want to observe.
|
|
487
|
-
* @param {object} expected - Object with properties: wk (Buffer), isWhitelisted (boolean), isWriter (boolean), isIndexer (boolean)
|
|
488
|
-
* @returns {Promise<void>} Resolves when the observed state matches expected values.
|
|
489
|
-
*
|
|
490
|
-
* @example
|
|
491
|
-
* await waitForRemoteNodeState(writer1, writer2.wallet.address, {
|
|
492
|
-
* wk: writer2.msb.state.writingKey,
|
|
493
|
-
* isWhitelisted: true,
|
|
494
|
-
* isWriter: true,
|
|
495
|
-
* isIndexer: false
|
|
496
|
-
* });
|
|
497
|
-
*/
|
|
498
|
-
|
|
499
|
-
export async function waitForNodeState(node, address, expected) {
|
|
500
|
-
try {
|
|
501
|
-
await node.msb.state.base.flush()
|
|
502
|
-
let attempts = 0;
|
|
503
|
-
const maxAttempts = 50;
|
|
504
|
-
while (attempts < maxAttempts) {
|
|
505
|
-
const state = await node.msb.state.getNodeEntry(address);
|
|
506
|
-
if (
|
|
507
|
-
state &&
|
|
508
|
-
b4a.equals(state.wk, expected.wk) &&
|
|
509
|
-
state.isWhitelisted === (expected.isWhitelisted ?? expected.isWhiteListed) &&
|
|
510
|
-
state.isWriter === expected.isWriter &&
|
|
511
|
-
state.isIndexer === expected.isIndexer
|
|
512
|
-
) {
|
|
513
|
-
return;
|
|
514
|
-
}
|
|
515
|
-
await node.msb.network.swarm.flush()
|
|
516
|
-
await sleep(400);
|
|
517
|
-
attempts++;
|
|
518
|
-
}
|
|
519
|
-
} catch (error) {
|
|
520
|
-
throw new Error("Error synchronizing node state: " + error.message || error);
|
|
521
|
-
}
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
export async function waitForHash(node, expected) {
|
|
525
|
-
try {
|
|
526
|
-
let attempts = 0;
|
|
527
|
-
const maxAttempts = 20;
|
|
528
|
-
while (attempts < maxAttempts) {
|
|
529
|
-
const entry = await node.msb.state.get(expected);
|
|
530
|
-
if (
|
|
531
|
-
!!entry
|
|
532
|
-
) {
|
|
533
|
-
break;
|
|
534
|
-
}
|
|
535
|
-
await node.msb.network.swarm.flush()
|
|
536
|
-
await sleep(1000);
|
|
537
|
-
attempts++;
|
|
538
|
-
}
|
|
539
|
-
} catch (error) {
|
|
540
|
-
throw new Error('Error waiting for admin entry: ' + error.message || error);
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
export async function waitForAdminEntry(node, expected) {
|
|
545
|
-
try {
|
|
546
|
-
let attempts = 0;
|
|
547
|
-
const maxAttempts = 20;
|
|
548
|
-
while (attempts < maxAttempts) {
|
|
549
|
-
const adminEntry = await node.msb.state.getAdminEntry();
|
|
550
|
-
if (
|
|
551
|
-
adminEntry &&
|
|
552
|
-
b4a.equals(adminEntry.wk, expected.wk) &&
|
|
553
|
-
adminEntry.address === expected.address
|
|
554
|
-
) {
|
|
555
|
-
break;
|
|
556
|
-
}
|
|
557
|
-
await node.msb.network.swarm.flush()
|
|
558
|
-
await sleep(1000);
|
|
559
|
-
attempts++;
|
|
560
|
-
}
|
|
561
|
-
} catch (error) {
|
|
562
|
-
throw new Error('Error waiting for admin entry: ' + error.message || error);
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
|
|
566
|
-
export async function waitForIndexersEntry(node, expected) {
|
|
567
|
-
try {
|
|
568
|
-
let attempts = 0;
|
|
569
|
-
const maxAttempts = 20;
|
|
570
|
-
while (attempts < maxAttempts) {
|
|
571
|
-
const indexersEntry = await node.msb.state.getIndexersEntry();
|
|
572
|
-
if (!indexersEntry) {
|
|
573
|
-
attempts++;
|
|
574
|
-
await sleep(250);
|
|
575
|
-
continue;
|
|
576
|
-
}
|
|
577
|
-
const formatted = formatIndexersEntry(indexersEntry, admin.config.addressLength);
|
|
578
|
-
if (formatted && formatted.addresses && formatted.addresses.includes(expected.address)) {
|
|
579
|
-
break;
|
|
580
|
-
}
|
|
581
|
-
await sleep(250);
|
|
582
|
-
attempts++;
|
|
583
|
-
}
|
|
584
|
-
} catch (error) {
|
|
585
|
-
throw new Error("Error waiting for indexers entry: " + error.message || error);
|
|
586
|
-
}
|
|
587
|
-
}
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import b4a from "b4a";
|
|
2
|
-
import tracCrypto from "trac-crypto-api";
|
|
3
|
-
import PeerWallet from "trac-wallet";
|
|
4
|
-
import { $TNK } from "../../src/core/state/utils/balance.js";
|
|
5
|
-
import { createMessage } from "../../src/utils/buffer.js";
|
|
6
|
-
import { OperationType } from "../../src/utils/constants.js";
|
|
7
|
-
import { addressToBuffer } from "../../src/core/state/utils/address.js";
|
|
8
|
-
import { config } from '../helpers/config.js'
|
|
9
|
-
import { sleep } from "../../src/utils/helpers.js";
|
|
10
|
-
|
|
11
|
-
export const waitForConnection = async node => {
|
|
12
|
-
let attempts = 0
|
|
13
|
-
while (attempts < 60) {
|
|
14
|
-
const count = node.network.validatorConnectionManager.connectionCount()
|
|
15
|
-
if (count > 0) {
|
|
16
|
-
break
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
await sleep(300);
|
|
20
|
-
attempts++;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Build a base64-encoded transfer payload and matching tx hash
|
|
26
|
-
* that are compatible with MSB's PartialTransferValidator validator.
|
|
27
|
-
*
|
|
28
|
-
* This helper mirrors the hashing/signing logic used by
|
|
29
|
-
* PartialOperationValidator.validateSignature, so that tests broadcast
|
|
30
|
-
* transactions the node will accept without touching consensus code.
|
|
31
|
-
*
|
|
32
|
-
* @param {object} context - General context
|
|
33
|
-
* @param {import("../../src/core/state/State.js").default} state - MSB state instance.
|
|
34
|
-
* @param {bigint} [amountTnk=1n] - Transfer amount in TNK units.
|
|
35
|
-
* @returns {Promise<{ payload: string, txHashHex: string }>}
|
|
36
|
-
*/
|
|
37
|
-
export async function buildRpcSelfTransferPayload(context, state, amountTnk = 1n) {
|
|
38
|
-
const txvBuffer = await state.getIndexerSequenceState();
|
|
39
|
-
const txvHex = b4a.toString(txvBuffer, "hex");
|
|
40
|
-
|
|
41
|
-
const txData = await tracCrypto.transaction.preBuild(
|
|
42
|
-
context.wallet.address,
|
|
43
|
-
context.wallet.address,
|
|
44
|
-
b4a.toString($TNK(amountTnk), "hex"),
|
|
45
|
-
txvHex
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
const nonceHex = b4a.toString(txData.nonce, "hex");
|
|
49
|
-
const amountHex = txData.amount;
|
|
50
|
-
const toAddress = txData.to;
|
|
51
|
-
|
|
52
|
-
const txvBuf = b4a.from(txData.validity, "hex");
|
|
53
|
-
const nonceBuf = b4a.from(nonceHex, "hex");
|
|
54
|
-
const amountBuf = b4a.from(amountHex, "hex");
|
|
55
|
-
const toBuf = addressToBuffer(toAddress, config.addressPrefix);
|
|
56
|
-
|
|
57
|
-
const message = createMessage(
|
|
58
|
-
config.networkId,
|
|
59
|
-
txvBuf,
|
|
60
|
-
toBuf,
|
|
61
|
-
amountBuf,
|
|
62
|
-
nonceBuf,
|
|
63
|
-
OperationType.TRANSFER
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
const messageHash = await PeerWallet.blake3(message);
|
|
67
|
-
const signature = context.wallet.sign(messageHash);
|
|
68
|
-
|
|
69
|
-
const payloadObject = {
|
|
70
|
-
type: OperationType.TRANSFER,
|
|
71
|
-
address: context.wallet.address,
|
|
72
|
-
tro: {
|
|
73
|
-
tx: b4a.toString(messageHash, "hex"),
|
|
74
|
-
txv: txData.validity,
|
|
75
|
-
in: nonceHex,
|
|
76
|
-
to: toAddress,
|
|
77
|
-
am: amountHex,
|
|
78
|
-
is: b4a.toString(signature, "hex")
|
|
79
|
-
}
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
const payload = b4a.toString(
|
|
83
|
-
b4a.from(JSON.stringify(payloadObject)),
|
|
84
|
-
"base64"
|
|
85
|
-
);
|
|
86
|
-
|
|
87
|
-
return {
|
|
88
|
-
payload,
|
|
89
|
-
txHashHex: b4a.toString(messageHash, "hex")
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
|
package/tests/helpers/wrapper.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import {test as brittleTest, hook, solo as brittleSolo} from 'brittle';
|
|
2
|
-
|
|
3
|
-
const solo = (label, callback) => {
|
|
4
|
-
brittleSolo(label, async (t) => {
|
|
5
|
-
try{
|
|
6
|
-
await callback(t)
|
|
7
|
-
} catch (error) {
|
|
8
|
-
t.fail(`FAIL: ${label}`, error?.message || error);
|
|
9
|
-
}
|
|
10
|
-
})
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
const test = (label, callback) => {
|
|
14
|
-
brittleTest(label, async (t) => {
|
|
15
|
-
try{
|
|
16
|
-
await callback(t)
|
|
17
|
-
} catch (error) {
|
|
18
|
-
console.log(error?.message)
|
|
19
|
-
t.fail(`FAIL: ${label}`, error?.message || error);
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
export {
|
|
25
|
-
test,
|
|
26
|
-
hook,
|
|
27
|
-
solo
|
|
28
|
-
}
|