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,419 +0,0 @@
|
|
|
1
|
-
// The code below originates from the holepunch/autobase repository (https://github.com/holepunchto/autobase)
|
|
2
|
-
// License: Apache 2.0
|
|
3
|
-
// The holepunch team has granted permission to reuse this code in the Trac Systems project.
|
|
4
|
-
// Huge thanks to the holepunch team for their work and support!
|
|
5
|
-
import path from 'path';
|
|
6
|
-
import Corestore from 'corestore';
|
|
7
|
-
import Autobase from 'autobase';
|
|
8
|
-
import Hyperbee from 'hyperbee';
|
|
9
|
-
import b4a from 'b4a';
|
|
10
|
-
import PeerWallet from 'trac-wallet';
|
|
11
|
-
import Hypercore from 'hypercore';
|
|
12
|
-
import {
|
|
13
|
-
ACK_INTERVAL,
|
|
14
|
-
AUTOBASE_VALUE_ENCODING,
|
|
15
|
-
HYPERBEE_KEY_ENCODING,
|
|
16
|
-
HYPERBEE_VALUE_ENCODING,
|
|
17
|
-
TRAC_NAMESPACE
|
|
18
|
-
} from '../../src/utils/constants.js';
|
|
19
|
-
import Writer from 'autobase/lib/writer.js';
|
|
20
|
-
import { config } from './config.js';
|
|
21
|
-
|
|
22
|
-
const argv = typeof globalThis.Bare !== 'undefined' ? globalThis.Bare.argv : process.argv;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const originalWriterOpen = Writer.prototype._open;
|
|
26
|
-
Writer.prototype._open = async function patchedWriterOpen(...args) {
|
|
27
|
-
try {
|
|
28
|
-
return await originalWriterOpen.apply(this, args);
|
|
29
|
-
} catch (err) {
|
|
30
|
-
// On teardown GH runners sometimes open a writer against a closing core.
|
|
31
|
-
// Ignore assertion errors from Autobase writer open during that window.
|
|
32
|
-
if (err?.name === 'AssertionError') return;
|
|
33
|
-
throw err;
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
// Hypercore/Hyperbee can throw SESSION_CLOSED while the core is shutting down.
|
|
38
|
-
// Swallow those during tests to avoid teardown flakes on slower runners.
|
|
39
|
-
const originalSnapshot = Hypercore.prototype.snapshot;
|
|
40
|
-
Hypercore.prototype.snapshot = function patchedSnapshot(...args) {
|
|
41
|
-
try {
|
|
42
|
-
return originalSnapshot.apply(this, args);
|
|
43
|
-
} catch (err) {
|
|
44
|
-
if (err?.code === 'SESSION_CLOSED') return this;
|
|
45
|
-
throw err;
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
const originalCoreGet = Hypercore.prototype.get;
|
|
50
|
-
Hypercore.prototype.get = async function patchedCoreGet(...args) {
|
|
51
|
-
try {
|
|
52
|
-
return await originalCoreGet.apply(this, args);
|
|
53
|
-
} catch (err) {
|
|
54
|
-
if (err?.code === 'SESSION_CLOSED') return null;
|
|
55
|
-
throw err;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
const originalMakeSnapshot = Hyperbee.prototype._makeSnapshot;
|
|
60
|
-
Hyperbee.prototype._makeSnapshot = function patchedMakeSnapshot(...args) {
|
|
61
|
-
try {
|
|
62
|
-
return originalMakeSnapshot.apply(this, args);
|
|
63
|
-
} catch (err) {
|
|
64
|
-
if (err?.code === 'SESSION_CLOSED') return this.core;
|
|
65
|
-
throw err;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const encryptionKey = argv?.includes('--encrypt-all')
|
|
70
|
-
? b4a.alloc(32).fill('autobase-encryption-test')
|
|
71
|
-
: undefined;
|
|
72
|
-
|
|
73
|
-
export async function createStores(n, t, opts = {}) {
|
|
74
|
-
const storage = opts.storage || (() => tmpDir(t));
|
|
75
|
-
const offset = opts.offset || 0;
|
|
76
|
-
|
|
77
|
-
const stores = [];
|
|
78
|
-
for (let i = offset; i < n + offset; i++) {
|
|
79
|
-
const primaryKey = Buffer.alloc(32, i);
|
|
80
|
-
const globalCache = opts.globalCache || null;
|
|
81
|
-
const dir = await storage();
|
|
82
|
-
stores.push(new Corestore(dir, { primaryKey, encryptionKey, globalCache }));
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
t.teardown(async () => {
|
|
86
|
-
for (const store of stores) {
|
|
87
|
-
try {
|
|
88
|
-
await store.close();
|
|
89
|
-
} catch (err) {
|
|
90
|
-
console.error('corestore close failed', err);
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}, { order: 2 });
|
|
94
|
-
return stores;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export async function create(n, t, opts = {}) {
|
|
98
|
-
const stores = await createStores(n, t, opts);
|
|
99
|
-
const bases = [createBase(stores[0], null, t, opts)];
|
|
100
|
-
await bases[0].ready();
|
|
101
|
-
bases[0].name = 'a';
|
|
102
|
-
|
|
103
|
-
if (n === 1) return { stores, bases };
|
|
104
|
-
|
|
105
|
-
for (let i = 1; i < n; i++) {
|
|
106
|
-
const base = createBase(stores[i], bases[0].local.key, t, opts);
|
|
107
|
-
await base.ready();
|
|
108
|
-
base.name = String.fromCharCode('a'.charCodeAt(0) + i);
|
|
109
|
-
bases.push(base);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
return { stores, bases };
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
export function createBase(store, key, t, opts = {}) {
|
|
116
|
-
const {
|
|
117
|
-
open = defaultOpenHyperbeeView,
|
|
118
|
-
valueEncoding = AUTOBASE_VALUE_ENCODING,
|
|
119
|
-
ackInterval = ACK_INTERVAL,
|
|
120
|
-
bigBatches = false,
|
|
121
|
-
optimistic = false,
|
|
122
|
-
...rest
|
|
123
|
-
} = opts;
|
|
124
|
-
|
|
125
|
-
const base = new Autobase(store.session(), key, {
|
|
126
|
-
open,
|
|
127
|
-
close: undefined,
|
|
128
|
-
valueEncoding,
|
|
129
|
-
ackInterval,
|
|
130
|
-
bigBatches,
|
|
131
|
-
optimistic,
|
|
132
|
-
ackThreshold: 0,
|
|
133
|
-
encryptionKey,
|
|
134
|
-
fastForward: false,
|
|
135
|
-
...rest
|
|
136
|
-
});
|
|
137
|
-
|
|
138
|
-
base.on('error', err => {
|
|
139
|
-
if (err?.code === 'SESSION_CLOSED') return;
|
|
140
|
-
console.error('autobase error', err);
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
if (opts.maxSupportedVersion !== undefined) {
|
|
144
|
-
base.maxSupportedVersion = opts.maxSupportedVersion;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
t.teardown(async () => {
|
|
148
|
-
try {
|
|
149
|
-
await base.advance();
|
|
150
|
-
} catch (err) {
|
|
151
|
-
if (err?.code !== 'SESSION_CLOSED') {
|
|
152
|
-
console.error('base advance failed', err);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
try {
|
|
156
|
-
await base.close();
|
|
157
|
-
} catch (err) {
|
|
158
|
-
console.error('base close failed', err);
|
|
159
|
-
}
|
|
160
|
-
}, { order: 1 });
|
|
161
|
-
return base;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export function defaultOpenHyperbeeView(store) {
|
|
165
|
-
return new Hyperbee(store.get(TRAC_NAMESPACE), {
|
|
166
|
-
extension: false,
|
|
167
|
-
keyEncoding: HYPERBEE_KEY_ENCODING,
|
|
168
|
-
valueEncoding: HYPERBEE_VALUE_ENCODING
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
export async function createWallet(mnemonic = null) {
|
|
173
|
-
const wallet = new PeerWallet({
|
|
174
|
-
networkPrefix: config.addressPrefix,
|
|
175
|
-
derivationPath: config.derivationPath
|
|
176
|
-
});
|
|
177
|
-
await wallet.generateKeyPair(mnemonic, config.derivationPath);
|
|
178
|
-
return wallet;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
export function seedIndexerList(base, keys) {
|
|
182
|
-
base.system.indexers = keys.map(key => ({ key, length: 0 }));
|
|
183
|
-
if (base.system._indexerMap instanceof Map) {
|
|
184
|
-
for (const key of keys) {
|
|
185
|
-
base.system._indexerMap.set(b4a.toString(key, 'hex'), { key, length: 0 });
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export const seedBootstrapIndexer = (network) => {
|
|
191
|
-
const bootstrapPeer = network.adminBootstrap ?? network.bootstrap;
|
|
192
|
-
const key = bootstrapPeer.base.local.key;
|
|
193
|
-
for (const { base } of network.nodes) {
|
|
194
|
-
seedIndexerList(base, [key]);
|
|
195
|
-
}
|
|
196
|
-
};
|
|
197
|
-
|
|
198
|
-
export async function replicateAndSync(bases, opts) {
|
|
199
|
-
const done = replicate(bases);
|
|
200
|
-
await sync(bases, opts);
|
|
201
|
-
await done();
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export async function sync(bases, { checkHash = true } = {}) {
|
|
205
|
-
for (const base of bases) {
|
|
206
|
-
await base.update();
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
if (bases.length === 1) return;
|
|
210
|
-
|
|
211
|
-
return new Promise((resolve, reject) => {
|
|
212
|
-
let done = false;
|
|
213
|
-
let checks = 0;
|
|
214
|
-
|
|
215
|
-
for (const base of bases) {
|
|
216
|
-
base.on('update', check);
|
|
217
|
-
base.on('error', shutdown);
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
check();
|
|
221
|
-
|
|
222
|
-
async function check() {
|
|
223
|
-
checks++;
|
|
224
|
-
for (const base of bases) {
|
|
225
|
-
if (base.interrupted) return shutdown(new Error('base was interrupted, reason at base.interrupted'));
|
|
226
|
-
}
|
|
227
|
-
if (!(await areSame(checkHash))) return maybeShutdown();
|
|
228
|
-
for (const base of bases) {
|
|
229
|
-
await base.update();
|
|
230
|
-
}
|
|
231
|
-
if (!(await areSame(checkHash))) return maybeShutdown();
|
|
232
|
-
shutdown();
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function maybeShutdown() {
|
|
236
|
-
if (done) return shutdown();
|
|
237
|
-
checks--;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
async function areSame(checkHash) {
|
|
241
|
-
return sameHeadsAcross(bases) && await sameHash(bases, checkHash);
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function shutdown(err) {
|
|
245
|
-
checks--;
|
|
246
|
-
done = true;
|
|
247
|
-
if (checks !== 0 && !err) return;
|
|
248
|
-
|
|
249
|
-
for (const base of bases) {
|
|
250
|
-
base.off('update', check);
|
|
251
|
-
base.off('error', shutdown);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
if (err) reject(err);
|
|
255
|
-
else resolve();
|
|
256
|
-
}
|
|
257
|
-
});
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
function replicate(bases) {
|
|
261
|
-
const streams = [];
|
|
262
|
-
const missing = bases.slice();
|
|
263
|
-
|
|
264
|
-
while (missing.length) {
|
|
265
|
-
const a = missing.pop();
|
|
266
|
-
for (const b of missing) {
|
|
267
|
-
const s1 = a.replicate(true);
|
|
268
|
-
const s2 = b.replicate(false);
|
|
269
|
-
|
|
270
|
-
s1.on('error', err => {
|
|
271
|
-
if (err.code) console.log('autobase replicate error:', err.stack);
|
|
272
|
-
});
|
|
273
|
-
s2.on('error', err => {
|
|
274
|
-
if (err.code) console.log('autobase replicate error:', err.stack);
|
|
275
|
-
});
|
|
276
|
-
|
|
277
|
-
s1.pipe(s2).pipe(s1);
|
|
278
|
-
streams.push(s1, s2);
|
|
279
|
-
}
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
return close;
|
|
283
|
-
|
|
284
|
-
function close() {
|
|
285
|
-
return Promise.all(streams.map(s => {
|
|
286
|
-
s.destroy();
|
|
287
|
-
return new Promise(resolve => s.on('close', resolve));
|
|
288
|
-
}));
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
function sameHeadsAcross(bases) {
|
|
293
|
-
const first = bases[0];
|
|
294
|
-
for (let i = 1; i < bases.length; i++) {
|
|
295
|
-
if (!sameHeads(first, bases[i])) return false;
|
|
296
|
-
}
|
|
297
|
-
return true;
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
async function sameHash(bases, check) {
|
|
301
|
-
if (!check) return true;
|
|
302
|
-
const first = bases[0];
|
|
303
|
-
const h1 = await first.hash();
|
|
304
|
-
for (let i = 1; i < bases.length; i++) {
|
|
305
|
-
if (bases[i].signedLength !== first.signedLength) return false;
|
|
306
|
-
const h2 = await bases[i].hash();
|
|
307
|
-
if (!b4a.equals(h1, h2)) return false;
|
|
308
|
-
}
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
function sameHeads(a, b) {
|
|
313
|
-
if (a.updating || b.updating) return false;
|
|
314
|
-
|
|
315
|
-
const h1 = a.heads();
|
|
316
|
-
const h2 = b.heads();
|
|
317
|
-
|
|
318
|
-
if (h1.length !== h2.length) return false;
|
|
319
|
-
|
|
320
|
-
for (let i = 0; i < h1.length; i++) {
|
|
321
|
-
const h1i = h1[i];
|
|
322
|
-
const h2i = h2[i];
|
|
323
|
-
|
|
324
|
-
if (!b4a.equals(h1i.key, h2i.key)) return false;
|
|
325
|
-
if (h1i.length !== h2i.length) return false;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
return true;
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
export function eventFlush() {
|
|
332
|
-
return new Promise(resolve => setImmediate(resolve));
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export function deriveIndexerSequenceState(base) {
|
|
336
|
-
const indexers = base.system?.indexers || [];
|
|
337
|
-
const buffers = indexers
|
|
338
|
-
.map(entry => entry?.key)
|
|
339
|
-
.filter(key => key && key.length > 0);
|
|
340
|
-
const concatenated = buffers.length > 0 ? b4a.concat(buffers) : b4a.alloc(0);
|
|
341
|
-
return PeerWallet.blake3(concatenated);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
let osModule;
|
|
345
|
-
let fsPromises;
|
|
346
|
-
|
|
347
|
-
async function ensureEnvReady() {
|
|
348
|
-
if (osModule && fsPromises) return;
|
|
349
|
-
|
|
350
|
-
if (typeof globalThis.Bare !== 'undefined') {
|
|
351
|
-
const bareOs = await import('bare-os');
|
|
352
|
-
osModule = bareOs.default || bareOs;
|
|
353
|
-
|
|
354
|
-
const bareFs = await import('bare-fs');
|
|
355
|
-
const resolved = bareFs.default || bareFs;
|
|
356
|
-
fsPromises = resolved.promises;
|
|
357
|
-
} else {
|
|
358
|
-
const nodeOs = await import('os');
|
|
359
|
-
osModule = nodeOs.default || nodeOs;
|
|
360
|
-
|
|
361
|
-
const nodeFs = await import('fs/promises');
|
|
362
|
-
fsPromises = nodeFs.default || nodeFs;
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
async function tmpDir(t) {
|
|
367
|
-
await ensureEnvReady();
|
|
368
|
-
const prefix = path.join(osModule.tmpdir(), 'msb-autobase-');
|
|
369
|
-
const dir = await createTempDir(prefix);
|
|
370
|
-
t.teardown(() => cleanupTempDir(dir), { order: 3 });
|
|
371
|
-
return dir;
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
async function createTempDir(prefix) {
|
|
375
|
-
if (typeof fsPromises.mkdtemp === 'function') {
|
|
376
|
-
return fsPromises.mkdtemp(prefix);
|
|
377
|
-
}
|
|
378
|
-
const uniqueDir = `${prefix}${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`;
|
|
379
|
-
await fsPromises.mkdir(uniqueDir, { recursive: true });
|
|
380
|
-
return uniqueDir;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
async function cleanupTempDir(dir) {
|
|
384
|
-
if (!fsPromises) return;
|
|
385
|
-
|
|
386
|
-
try {
|
|
387
|
-
if (typeof fsPromises.rm === 'function') {
|
|
388
|
-
await fsPromises.rm(dir, { recursive: true, force: true });
|
|
389
|
-
} else if (typeof fsPromises.rmdir === 'function') {
|
|
390
|
-
await removeRecursively(dir);
|
|
391
|
-
}
|
|
392
|
-
} catch (err) {
|
|
393
|
-
if (err?.code === 'ENOENT') return;
|
|
394
|
-
// Windows sometimes keeps LOCK files open briefly. Ignore busy/permission errors during teardown.
|
|
395
|
-
if (err?.code === 'EBUSY' || err?.code === 'EPERM') return;
|
|
396
|
-
throw err;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
async function removeRecursively(target) {
|
|
401
|
-
let stats;
|
|
402
|
-
try {
|
|
403
|
-
stats = await fsPromises.lstat(target);
|
|
404
|
-
} catch (err) {
|
|
405
|
-
if (err?.code === 'ENOENT') return;
|
|
406
|
-
throw err;
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
if (!stats.isDirectory()) {
|
|
410
|
-
await fsPromises.unlink(target);
|
|
411
|
-
return;
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
const entries = await fsPromises.readdir(target);
|
|
415
|
-
for (const entry of entries) {
|
|
416
|
-
await removeRecursively(path.join(target, entry));
|
|
417
|
-
}
|
|
418
|
-
await fsPromises.rmdir(target);
|
|
419
|
-
}
|
package/tests/helpers/config.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import PeerWallet from 'trac-wallet';
|
|
2
|
-
import { config } from './config.js';
|
|
3
|
-
|
|
4
|
-
export async function createSignature(payloadBuffer) {
|
|
5
|
-
const wallet = new PeerWallet({ derivationPath: config.derivationPath });
|
|
6
|
-
await wallet.generateKeyPair(undefined, config.derivationPath);
|
|
7
|
-
const signature = wallet.sign(payloadBuffer);
|
|
8
|
-
return { signature, wallet };
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export default {
|
|
12
|
-
createSignature
|
|
13
|
-
};
|